Code Monkey home page Code Monkey logo

fastapi-genesis_-'s Introduction

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.