fbpx

12 Factor App — Codebase

12 Factor App — Codebase
Reading Time: 3 minutes

by Felipe Quevedo, Senior Software Engineer at Growth Acceleration Partners.

This series of posts is a journey through the 12 Factor App methodology. I will feature some examples, but this doesn’t have to be a mandatory way to apply these principles, since there are different ways and tools to do so.

Version Control

The first principle of the 12 Factor App is Codebase. Therefore, according to Creating Cloud-Based Applications by Applying the 12-Factor Apps Principles, we have to create a repository first. In this case, we are going to use GIT as our version control system. You can find how to install it on your machine here.

Then, let’s create the repository in your local machine by using these commands in your terminal:

cd /path_to_my_codebase

git init -b main

git add .

git commit

Considering that our repo is created on our local machine, we want to enable our team to collaborate on it, so we need to share the repo in the cloud. For this purpose, you have to choose a service to host and manage the repo in the cloud. There are a bunch of options, but for our example, we are going to use GitHub.

On GitHub, you have to create an empty repository first; this means one repository without README file. You can follow the steps from GitHub documentation. Then, we need to sync our local repository with the one from GitHub by using these commands in our local:

git remote add origin <REMOTE_URL>

git push -u origin main

Now that the application has its repository, it is important to establish a workflow to manage changes with the team. We can start a very simple workflow, where team members can review and approve pull requests from other teammates. The important thing here is to start the project with a workflow and some rules, and these processes should be in continuous improvement until the project reaches a robust and suitable process for the team.

This is an example of how this could be started:

It is easy to have this workflow on the repository by using the “branch protection settings” feature on GitHuh and enabling “Require pull request reviews before merging.”

CI/CD

Another part of the “Codebase” factor is to guarantee all the deployments of the application are coming from the same codebase. Perhaps they could have different versions, but they should share the same codebase.

One way to guarantee the deployments to different environments are coming from the same repository is establishing an automatic CI/CD pipeline. Also, it is necessary to assure all the developers who are going to collaborate with the repository can run the application on their local machines.

Just like the workflow to manage changes on the repository, the process of CI/CD is different depending on the project or organization. For this reason, you can use tools like GitHub actions to trigger builds and deployments to avoid human error and guarantee all of them are being made from the same codebase.

Conclusion

By applying the codebase factor, you are creating modular and manageable code for your pp. This is done thanks to the version control of the code because it facilitates parallel development efforts and collaboration among team members. Also, having a CI/CD process to guarantee all deployments are coming from the same codebase allows you to deliver faster updates and features, while maintaining the stability of the overall application.