Vapor — Generated files overview

What are those files and folders for?

Alexandre Cools
4 min readOct 23, 2020

Before starting, if you don’t know how to create a new Vapor project, I suggest you to read this article who explain how to get started with Vapor.

Generated files

When you create a new Vapor project by doing this:

vapor new [ProjectName] -n

Vapor generate some files and folders for you.

Vapor generated files and folders

But what are those files generated for?

Dockerfile & docker-compose.yml

Those two files are generated if you want to use Docker with your project. If you don’t know about Docker, you can simply ignore them. (you can also remove them, but maybe you want to use Docker in the future, so, it could be a great idea to keep them there).

Package.resolved:

A part of the package.resolved file

This file is all about your project dependencies. If you open it, you can see all the Swift Package Dependencies with some informations about them (repository URL, branch, version, etc).

When you create a new project, you have only one dependency: Vapor, but this dependency have a lot of sub-dependencies, so it’s why there are a lot of dependencies by default.

This file allow you to install all the dependencies with the same versions if you install your project on another computer (you don’t want to update automatically all of your dependencies when you clone your project on a new machine, believe me…).

AppTests.swift

AppTests.swift generated file

The test folder is created to contain unit tests to test your project and check if all is working as expected. It’s not required, but if you have a big project, I recommend you to try to write at least some tests for your criticals features. It will ensure that’s you don’t create regression when you update some code.

Sources folder

The source folder contain your project source code. In this folder, you can find two subfolders: App and Run. The App folder contain all of your source code and the Run folder contain your project starting point (source code executed when you launch your Vapor application).

If you open the main.swift file, you can see the following code:

Code of the main.swift file

The two interesting lines here are:

try app.run() — will start your project and listen for events indefinitely.

try configure(app) — will execute the code written in the configure.swift file (in your App folder).

configure.swift

configure(_ app:) function of the configure.swift

This configure method will register all the routes defined in your routes.swift file. At the start there are only two routes (/ and /hello), but you can easily add more.

The two generated routes

So, to come back to the main.swift file, you don’t have to edit it. If you want to configure your application, you can do it in the configure(_app:) method of the configure.swift file.

Tips: if you have a lot of routes defined for your application, you can create sub-route files (like Controllers; by the way, that’s why an empty folder named Controllers was generated) to don’t have a massive routes.swift file.

🚀 What’s next

If you missed the previous article, you can read it here: Vapor — How to get started. And if you want to learn more about Vapor, you’ll be happy to know that a new article will come soon (Vapor — Create a GET route).

Don’t forget to “clap” and share this article if you like it and want to see more content like this! 👏

And if you have any question, feel free to let a comment right below, I’ll answer you with pleasure!

Thanks for reading,

--

--

Alexandre Cools

iOS Developer @LunabeeStudio 👨🏻‍💻 — Sport addict 🏊‍♂️🚴‍♂️🏃‍♂️ — Travel enthusiast ✈️