Skip to content

FastAPI project Template generator to make your life easier 🧬 πŸš€

License

Notifications You must be signed in to change notification settings

Lolomgrofl/fastapi-genesis

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

FastAPI Genesis 🧬 - Project Template Generator πŸš€

Simple FastAPI project template with Docker, Alembic, PostgreSQL, Poetry and pre-commit to kickstart your new projects.

How to use it πŸ€“

Go to the directory where you want to create your project and run:

pip install cookiecutter
cookiecutter https://github.com/Lolomgrofl/fastapi-genesis.git

What's included in the template πŸŽ‰

  • Here is an explanation of the directory structure of the template:
β”œβ”€β”€ .github                 <- GitHub deployment workflow
β”‚
β”œβ”€β”€ alembic                 <- Alembic migrations
β”‚
β”œβ”€β”€ app                     <- Source code of the application (the main package)
β”‚   β”œβ”€β”€ daos                <- Data Access Objects (DAOs) to interact with the database
β”‚   β”œβ”€β”€ models              <- SQLAlchemy models (the database schema)
β”‚   β”œβ”€β”€ routers             <- FastAPI routers (endpoints)
β”‚   β”œβ”€β”€ schemas             <- Pydantic schemas for request and response models
β”‚   β”œβ”€β”€ services            <- Business logic layer (services)
β”‚   β”œβ”€β”€ db.py               <- Database initialization and session management code
β”‚   β”œβ”€β”€ main.py             <- FastAPI application instance and startup code
β”‚   └── settings.py         <- Settings management code (using pydantic settings)
β”‚
β”œβ”€β”€ scripts                 <- Scripts to perform various tasks like alembic migrations, etc.
β”‚
β”œβ”€β”€ static                  <- Static files like images, documents, etc.
β”‚
β”œβ”€β”€ tests                   <- Unit tests, one subdirectory per application module
β”‚
β”œβ”€β”€ .env                    <- Environment variables. Should not be committed to VCS
β”‚
β”œβ”€β”€ .gitignore              <- Files and directories to be ignored by git
β”‚
β”œβ”€β”€ .pre-commit-config.yaml <- Configuration of pre-commit hooks (see https://pre-commit.com/)
β”‚
β”œβ”€β”€ alembic.ini             <- Alembic configuration file
β”‚
β”œβ”€β”€ docker-compose.yml      <- Docker compose configuration file
β”‚
β”œβ”€β”€ Dockerfile              <- Dockerfile for building the image of the application
β”‚
β”œβ”€β”€ Makefile                <- Makefile with useful commands for development and project setup
β”‚
β”œβ”€β”€ pyproject.toml          <- Python dependencies for Poetry (see https://python-poetry.org/)
β”‚
β”œβ”€β”€ README.md               <- File with useful information about the project and how to use it

Features 🧩

  • Docker and docker-compose for local development
  • FastAPI application with uvicorn server
  • AsyncPG for asynchronous access to PostgreSQL
  • Pydantic for data validation
  • Poetry for managing Python dependencies
  • Alembic for database migrations
  • Pre-commit hooks for code formatting and linting
  • JWT token authentication
  • SQLAlchemy models
  • CORS (Cross Origin Resource Sharing)
  • GitOps ( GitHub Workflows)

User flow as an example of how to use the template πŸ’‘

  • It consists of the following steps:
    - Register a new user
    - Login with the new user
    - Change password
    - Get all users
    - Delete user by id
    - Delete all users
  • This following example will show you the pattern and good practices to follow in order to continue developing your application.

Cookiecutter parameters explained πŸͺ

  • repo_name: Name of the project repository (e.g. my_project)
  • app_container_name: Name of the Docker container for the FastAPI application server inside docker-compose.yaml file
  • app_service_port: Port on the host machine to which the FastAPI application will be exposed inside docker-compose.yaml file and Dockerfile
  • db_container_name: Name of the Docker container for the PostgreSQL database server inside docker-compose.yaml file
  • db_service_port: Port on the host machine to which the PostgreSQL database server will be exposed inside docker-compose.yaml file
  • pgadmin_container_name: Name of the Docker container for the pgAdmin web interface inside docker-compose.yaml file
  • pgadmin_service_port: Port on the host machine to which the pgAdmin web interface will be exposed inside docker-compose.yaml file
  • network_name: Name of the Docker network that will be created inside docker-compose.yaml file

GLHF πŸš€

License

This project is licensed under the terms of the MIT license.