This is a template repository aimed to kick start your project with a setup from a real-world application! This template utilizes the following tech-stack:
When the Docker is started, these are the URL addresses:
- Backend Application (API docs)
$\rightarrow$ http://localhost:8001/docs - Database editor (Adminer)
$\rightarrow$ http//lcoalhost:8081
Well, the easy answer is Asynchronousity and Speed!
- FastAPI is crowned as the fastest web framework for Python and thus we use it for our backend development.
- The database of my choice is the asynchronous version of PostgreSQL (via SQLAlchemy 2.0). Why asynchronous? Well.. Speed! Read this blog from Packt if you want to educate yourself further about the topic Asynchronous, Synchronous, Concurrency, and Parallelism.
- And Docker is the technology that will hold your team together because your app will live in a container where the gravity of your personal machine specs don't matter anymore!
The above listed technologies are just the main ones. There are other technologies utilized in this project template to ensure that your application is robust and provides the best-possible development environment for your team! These technologies are:
- TOML
$\rightarrow$ The one-for-all configuration file. This makes it simpler to setup our project. - Pyenv
$\rightarrow$ The simplest way to manage our Python versions. - Pyenv-VirtualEnv
$\rightarrow$ The plugin forPyenvto manage the virtual environment for our packages. - Pre-Commit
$\rightarrow$ Git hook scripts to identify issues and quality of your code before pushing it to GitHub. These hooks are implemented for the following linting pakcages:- Black (Python)
$\rightarrow$ Manage your code style with auto formatting and parallel continuous integration runner for Python. - Isort (Python)
$\rightarrow$ Sort yourimportfor clarity. Also for Python. - MyPy (Python)
$\rightarrow$ A static type checker for Python that helps you write a cleaner code.
- Black (Python)
- Pre-Commit CI
$\rightarrow$ Continuous integration for our Pre-Commit hook that fixes and updates our hook versions. - CodeCov
$\rightarrow$ A platform that analyze the result of your automated tests. - PyTest
$\rightarrow$ The testing framework for Python code. - DBDiagram
$\rightarrow$ A platform that lets your design your database by writing SQL and converting it into ERD. This paltform provides a complete symbol for entity relationships (not like many other platforms!). - GitHub Actions
$\rightarrow$ The platform to setup our CI/CD by GitHub. - SQLAlchemy 2.0
$\rightarrow$ The go-to database interface library for Python. The 2.0 is the most recent update where it provides asynchronous setup. - CODEOWNERS
$\rightarrow$ A file for distributing the responsibilities in our project to each team/team mate.
The choice for my project development worklow is usually the Trund-Based Development, hence the name trunk for the main branch repository instead of master or main.
Not a beginner? Great, here is the step to setup this template repository:
-
Backend setup: The backend server runs on http://localhost:8000
cd backend mdkir coverage pyenv virtualenv 3.11.0 any_venv_name pyenv local any_venv_name pip3 install -r requirements.txt # Test run your backend server uvicorn src.main:backend_app --reload # Testing pytest # Might throw an error without docker becasue of the imports
-
Pre-Commitsetup:# Make sure you are in the ROOT project directory pre-commit install pre-commit update -
.envsetup: If you are not used to VIM or Linux CLI, then ignore theechocommand and do it manually. All the secret variables for this template is located in.env.example.If you want to have another names for the secret variables, don't forget to change them also in:
backend/src/config/base.pydocker-compose.yaml
# Make sure you are in the ROOT project directory touch .env echo "SECRET_VARIABLE=SECRET_VARIABLE_VALUE" >> .env
-
CODEOWNERSsetup: Go to.github/and openCODEOWNERSfile. This file is to assign the code to specific team member so you can distribute the weights of the project clearly. -
Docker setup:
# Make sure you are in the ROOT project directory chmod +x backend/entrypoint.sh docker-compose build docker-compose up # Everytime you write a new code, update your container with: docker-compose up -d --build
-
(IMPORTANT) Finishing setup:
# Generate revision for the database auto-migrations docker exec backend_app alembic revision --autogenerate -m "YOUR MIGRATION TITLE" docker exec backend_app alembic upgrade head # to register the database classes # For testing within Docker container docker exec backend_app pytest # backend
-
Go to https://about.codecov.io/, and sign up with your github to get the
CODECOV_TOKEN -
Go to your GitHub and register all the secret variables in your repository (
settings$\rightarrow$ (scroll down a bit)Secrets$\rightarrow$ Actions$\rightarrow$ New repository secret)
IMPORTANT: Without the secrets registered in Codecov and GitHub, your CI will fail and life will be horrible 🤮🤬 IMPORTANT: Remember to always run the container update every once in a while. Without the arguments -d --build, your Docker dashboard will be full of junk containers!
Read morea bout how the backend/ application is set up here
You can delete these 3 files (or change its content based on your need):
LICENSE.mdREADME.mdbackend/README.md
Enjoy your development and may your technology be forever useful to everyone 😉🚀🧬