These docs are for v0.12. Click to read the latest docs for v0.16.

Folder Structure

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.

Minimum Folder Structure

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.

.
├── App
│   └── main.swift
├── Public
└── Package.swift

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.

Models

The Models folder is a recommendation of where you can put your database and other models, following the MVC pattern.

.
├── App
.   └── Models
.       └── User.swift

Controllers

The Controllers folder is a recommendation of where you can put your route controllers, following the MVC pattern.

.
├── App
.   └── Controllers
.       └── UserController.swift

Views

The Views folder in Resources is where the View() class will look when you create views.

.
├── App
└── Resources
    └── Views
         └── user.html

The following code would load the user.html file.

View(path: "user.html")

Config

Vapor has a sophisticated configuration system that involves a hierarchy of configuration importance.

.
├── App
└── Config
	└── app.json       // defaults
    └── development
         └── app.json  // overrides defaults in dev env
    └── production
         └── app.json  // overrides defaults in prod env
    └── secrets
         └── app.json  // overrides defaults and env config

.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.