Giter Site home page Giter Site logo

fastapi-clean-architecture's Introduction

fastapi-clean-architecture

description

Base FastAPI project for applying general RestAPI Application cases. openapi-docs

concept

  1. Minimal functionality.
  2. Convincing architecture.
  3. Easy to read.
  4. Compatibility.
  5. Versatility.

base models

  1. user
  2. post [user (1 : n) post]
  3. tag [post (n : n) tag]

integrated with

  1. Python3.9+
  2. Fastapi 0.78.0
  3. Database
    1. MySQL5.7+
    2. Migration with alembic
    3. pytest with real DB
    4. Load with two ways (eager, lazy)
    5. Modeling with schema (1:1, 1:n, n:n)
  4. dependency-injector
    1. service-repository pattern
  5. JWT authentication
    1. role separation each endpoint
  6. Deployment
    1. container environment(k8s, docker)
    2. raw WAS(Web Application Server)

commands

  1. db(alembic)
    1. alembic upgrade head: apply every migrations
    2. alembic downgrade base: rollback every migrations
    3. alembic revision --autogenerate -m "revision_name": create new migration
    4. alembic history: get alembic revision history
  2. How to migration
    1. Create or modify models from app/model/*.py
    2. alembic -x ENV=[dev|stage|prod] revision --autogenerate -m "revision_name"
    3. Check auto generated migration file from app/migrations/versions/*.py
    4. alembic -x ENV=[dev|stage|prod] upgrade head
      If ENV does not exist, it will be applied to the test.
  3. server
    1. uvicorn app.main:app --reload: base
    2. options
      1. host: --host 0.0.0.0
      2. port: --port 8000
  4. test
    1. pytest: base
    2. pytest --cov=app --cov-report=term-missing: coverage with stdout
    3. pytest --cov=app --cov-report=html: coverage with html

sample env

# mysql case
ENV=dev
DB=mysql
DB_USER=root
DB_PASSWORD=qwer1234
DB_HOST=localhost
DB_PORT=3306

# postgres case
ENV=dev
DB=postgresql
DB_USER=gyu
DB_PASSWORD=
DB_HOST=localhost
DB_PORT=5432

references

  1. FastAPI official docs
  2. alembic official tutorial
  3. Dependency Injector

fastapi-clean-architecture's People

Contributors

jujumilk3 avatar web-flow avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

fastapi-clean-architecture's Issues

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.