{"metadata":{"image":[],"title":"","description":""},"api":{"url":"","auth":"required","params":[],"results":{"codes":[]},"settings":""},"next":{"description":"","pages":[]},"title":"Folder Structure","type":"basic","slug":"folder-structure","excerpt":"","body":"The first step to creating an awesome application is knowing where things are. If you created your project using the CLI or from a template, you will already have the folder structure created. \n\nIf you are making a Vapor application from scratch, this will show you exactly how to set it up.\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Minimum Folder Structure\"\n}\n[/block]\nWe recommend putting all of your Swift code inside of the `App/` folder. This will allow you to create subfolders of the `App/` folder to put your models and more in. \n\nThis works best with the Swift package manager's restrictions on how packages should be structured.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \".\\n├── App\\n│   └── main.swift\\n├── Public\\n└── Package.swift\",\n      \"language\": \"text\"\n    }\n  ]\n}\n[/block]\nThe `Public` folder is where all publicly accessible files should go. This folder will be automatically checked every time a URL is requested that is not found in your routes. \n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Models\"\n}\n[/block]\nThe `Models` folder is a recommendation of where you can put your database and other models, following the MVC pattern.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \".\\n├── App\\n.   └── Models\\n.       └── User.swift\",\n      \"language\": \"text\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Controllers\"\n}\n[/block]\nThe `Controllers` folder is a recommendation of where you can put your route controllers, following the MVC pattern.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \".\\n├── App\\n.   └── Controllers\\n.       └── UserController.swift\",\n      \"language\": \"text\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Views\"\n}\n[/block]\nThe `Views` folder in `Resources` is where the `View()` class will look when you create views.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \".\\n├── App\\n└── Resources\\n    └── Views\\n         └── user.html\",\n      \"language\": \"text\"\n    }\n  ]\n}\n[/block]\nThe following code would load the `user.html` file.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"View(path: \\\"user.html\\\")\",\n      \"language\": \"swift\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Config\"\n}\n[/block]\nVapor has a sophisticated configuration system that involves a hierarchy of configuration importance.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \".\\n├── App\\n└── Config\\n\\t└── app.json       // defaults\\n    └── development\\n         └── app.json  // overrides defaults in dev env\\n    └── production\\n         └── app.json  // overrides defaults in prod env\\n    └── secrets\\n         └── app.json  // overrides defaults and env config\",\n      \"language\": \"text\"\n    }\n  ]\n}\n[/block]\n`.json` files are structured in the `Config` folder like so. The configuration will be applied dependant on where the `.json` file exists in the folder. Learn more about `Config` \n\nLearn about changing environments (`the --env=` flag) in the Application section.","updates":[],"order":0,"isReference":false,"hidden":false,"sync_unique":"","link_url":"","link_external":false,"_id":"5768701b72cd4c0e000fad1d","parentDoc":null,"user":"57086f3d447c410e00221bd1","version":{"version":"0.12","version_clean":"0.12.0","codename":"Client Clyde","is_stable":false,"is_beta":true,"is_hidden":false,"is_deprecated":true,"categories":["5768701b72cd4c0e000fad19","5768701b72cd4c0e000fad1a","5768701b72cd4c0e000fad1b","5768701b72cd4c0e000fad1c"],"_id":"5768701b72cd4c0e000fad18","releaseDate":"2016-06-20T22:37:15.641Z","__v":1,"createdAt":"2016-06-20T22:37:15.641Z","project":"57086fe855a4690e005de407"},"category":{"sync":{"isSync":false,"url":""},"pages":[],"title":"Guide","slug":"getting-started","order":1,"from_sync":false,"reference":false,"_id":"5768701b72cd4c0e000fad1a","createdAt":"2016-04-09T04:31:52.489Z","__v":0,"version":"5768701b72cd4c0e000fad18","project":"57086fe855a4690e005de407"},"__v":2,"createdAt":"2016-06-13T15:44:49.170Z","project":"57086fe855a4690e005de407","githubsync":""}
The first step to creating an awesome application is knowing where things are. If you created your project using the CLI or from a template, you will already have the folder structure created. If you are making a Vapor application from scratch, this will show you exactly how to set it up. [block:api-header] { "type": "basic", "title": "Minimum Folder Structure" } [/block] We recommend putting all of your Swift code inside of the `App/` folder. This will allow you to create subfolders of the `App/` folder to put your models and more in. This works best with the Swift package manager's restrictions on how packages should be structured. [block:code] { "codes": [ { "code": ".\n├── App\n│ └── main.swift\n├── Public\n└── Package.swift", "language": "text" } ] } [/block] The `Public` folder is where all publicly accessible files should go. This folder will be automatically checked every time a URL is requested that is not found in your routes. [block:api-header] { "type": "basic", "title": "Models" } [/block] The `Models` folder is a recommendation of where you can put your database and other models, following the MVC pattern. [block:code] { "codes": [ { "code": ".\n├── App\n. └── Models\n. └── User.swift", "language": "text" } ] } [/block] [block:api-header] { "type": "basic", "title": "Controllers" } [/block] The `Controllers` folder is a recommendation of where you can put your route controllers, following the MVC pattern. [block:code] { "codes": [ { "code": ".\n├── App\n. └── Controllers\n. └── UserController.swift", "language": "text" } ] } [/block] [block:api-header] { "type": "basic", "title": "Views" } [/block] The `Views` folder in `Resources` is where the `View()` class will look when you create views. [block:code] { "codes": [ { "code": ".\n├── App\n└── Resources\n └── Views\n └── user.html", "language": "text" } ] } [/block] The following code would load the `user.html` file. [block:code] { "codes": [ { "code": "View(path: \"user.html\")", "language": "swift" } ] } [/block] [block:api-header] { "type": "basic", "title": "Config" } [/block] Vapor has a sophisticated configuration system that involves a hierarchy of configuration importance. [block:code] { "codes": [ { "code": ".\n├── App\n└── Config\n\t└── app.json // defaults\n └── development\n └── app.json // overrides defaults in dev env\n └── production\n └── app.json // overrides defaults in prod env\n └── secrets\n └── app.json // overrides defaults and env config", "language": "text" } ] } [/block] `.json` files are structured in the `Config` folder like so. The configuration will be applied dependant on where the `.json` file exists in the folder. Learn more about `Config` Learn about changing environments (`the --env=` flag) in the Application section.