github.com/ismailbayram/bigpicture@v0.0.0-20231225173155-e4b21f5efcff/README.md (about) 1 # BigPicture: Validate Architecture 2 **Do not tell the rules, define them.** 3 4 BigPicture is a tool to validate the architecture of project. 5 It can be used in Continuous Integration (CI) pipelines to validate the architecture of the project 6 like in the `.github/workflows/codequality.yml`. 7 8 # Why do we need this tool? 9 There are many rules to define the architecture of a project and it is hard to keep them in mind. 10 For instance, 11 - In a layered architecture, a package can not import a package from the upper layer. 12 - In a hexagonal architecture, a package can not import a package from the outer layer. 13 - A package can not have a file which has more than 100 lines. 14 - A package can not have a function which has more than 20 lines. 15 16 BigPicture allows you to define these rules in a `.bigpicture.json` file and validate the architecture of the project. 17 18 19 # Supported Languages 20 - Go 21 - Python 22 - Java 23 - C# (Under Development) 24 - JS (Under Development) 25 -------------------- 26 - [Installation](#installation) 27 - [Install with Go](#install-with-go) 28 - [Install on Linux](#install-on-linux) 29 - [Install on Macos](#install-on-macos) 30 - [Usage](#usage) 31 - [Server](#server) 32 - [Validate](#validate) 33 - [.bigpicture.json File](#bigpicturejson-file) 34 - [Validators](#validators) 35 - [NoImportValidator](#noimportvalidator) 36 - [LineCountValidator](#linecountvalidator) 37 - [FunctionValidator](#functionvalidator) 38 - [InstabilityValidator](#instabilityvalidator) 39 - [FileNameValidator](#filenamevalidator) 40 - [SizeValidator](#sizevalidator) 41 - [Contribution](#contribution) 42 43 # Installation 44 ## Install with Go 45 ```bash 46 go install github.com/ismailbayram/bigpicture@1.2.2 47 ``` 48 ## Install on Linux 49 ```bash 50 curl -L https://github.com/ismailbayram/bigpicture/releases/download/1.2.2/bigpicture-amd64-linux -o /usr/local/bin/bigpicture 51 chmod +x /usr/local/bin/bigpicture 52 ``` 53 ## Install on Macos 54 ```bash 55 curl -L https://github.com/ismailbayram/bigpicture/releases/download/1.2.2/bigpicture-amd64-darwin -o /usr/local/bin/bigpicture 56 chmod +x /usr/local/bin/bigpicture 57 ``` 58 59 # Usage 60 ## Server 61 Runs a server on port 44525. Architecture of the project can be seen on the browser. 62 ```bash 63 bigpicture server 64 ``` 65 ![Source Graph](./source_graph.png) 66 67 ## Validate 68 Validates the architecture of the project according to the rules defined in the `.bigpicture.json` file. 69 ```bash 70 bigpicture validate 71 ``` 72 73 ## .bigpicture.json File 74 `.bigpicture.json` file is used to define the rules. It should be in the root directory of the project. 75 ```json 76 { 77 "lang": "go", 78 "port": 44525, 79 "ignore": [ 80 "web" 81 ], 82 "validators": [ 83 ... 84 ] 85 } 86 ``` 87 **root_dir**: Let's say that you have java project and its structure is like this: 88 ``` 89 src 90 ├── main 91 ├──├── java 92 ``` 93 But imports are like this: 94 ``` 95 import com.example.project 96 ``` 97 In this case, you should define the root directory of the project as `/src/main/java/` 98 in order to bigpicture build import maps correctly. Do not forget `/` both at the beginning and the end of the path. 99 100 *Note: Supported for Java and Python.* 101 102 **lang**: BigPicture sometimes fails on detecting language of the project. You can define the language of the project. 103 104 **port**: Port number of the server. Default value is 44525. 105 106 **ignore**: Directories to ignore. Default value is empty. For instance in this project `web` directory includes 107 non-go files, thus it should be ignored. 108 109 **validators**: List of validators. Default value is empty. See [Validators](#validators) section for more information. 110 111 ## Validators 112 ### NoImportValidator 113 Checks if the package imports the given package. **It can be used in layered architectures.** 114 115 **Example 1**: 116 For instance, in this project, `/internal/config` package can not import any other package. 117 ```json 118 { 119 "type": "no_import", 120 "args": { 121 "from": "/internal/config", 122 "to": "*" 123 } 124 } 125 ``` 126 **Example 2**: 127 For instance, in this project, `/internal/validator` package can not import any package in the `/internal/browser` package. 128 ```json 129 { 130 "type": "no_import", 131 "args": { 132 "from": "/internal/validator", 133 "to": "/internal/browser" 134 } 135 } 136 ``` 137 138 ### LineCountValidator 139 Checks if the package has files which have more than the given number of lines. 140 141 **Example**: 142 For instance, in this project, `/internal/browser` package can not have files which have more than 100 lines. 143 ```json 144 { 145 "type": "line_count", 146 "args": { 147 "module": "/internal/browser", 148 "max": 100, 149 "ignore": ["*_test.go", "test/*.go"] 150 } 151 } 152 ``` 153 154 ### FunctionValidator 155 Checks if the package has functions which have more than the given number of lines. 156 157 **Example**: 158 For instance, in this project, `/internal/browser` package can not have functions which have more than 10 lines. 159 ```json 160 { 161 "type": "function", 162 "args": { 163 "module": "/internal", 164 "max_line_count": 50, 165 "ignore": ["*_test.go", "test/*.go"] 166 } 167 } 168 ``` 169 170 ### InstabilityValidator 171 Checks if the instability metric of a package according to its directory is more than the given number. 172 173 **Instability Calculation**: 174 175 Package A is imported by 3 packages and it imports 2 packages. Instability metric of the package A is 176 `2 / (2 + 3) = 0.4`. 177 178 **Example**: 179 For instance, in this project, `/internal/graph` package can not have instability metric more than 0.5. 180 ```json 181 { 182 "type": "instability", 183 "args": { 184 "module": "/internal/graph", 185 "max": 0.5 186 } 187 } 188 ``` 189 190 ### FileNameValidator 191 Checks if the package has files which do not match the given regular expression. 192 193 ```json 194 { 195 "type": "file_name", 196 "args": { 197 "module": "/internal", 198 "max_length": 12, 199 "regexp": "^[a-z]+$", 200 "ignore": [ 201 "*_test.go" 202 ] 203 } 204 } 205 ``` 206 207 ### SizeValidator 208 Checks the percentage size of the packages under the given directory according to the lines of code. 209 210 ```json 211 { 212 "type": "size", 213 "args": { 214 "module": "/internal", 215 "max": 25 216 } 217 } 218 ``` 219 220 221 # Contribution 222 There are many ways in which you can participate in this project, for example: 223 224 - Implement a new validator in `/internal/validator` directory. 225 - Implement a new language support in `/internal/browser` directory.