The app consists of several domains(like users, items, etc.) Each domain has 3 layers of abstraction:
- Handlers layer. Responsible for creating API route function, validation input user data, and creating/closing database connection at the start/end of each request.
- Service layer. It's a place for all business logic and additional validation.
- Database layer. Responsible for creating actual SQL queries and executing them.
- FastAPI
- SQLAlchemy 2.0
- Poetry
- Linters and formatters: black, isort, ruff
- Commands: Typer
- pytest
- Docker
- Celery and Redis
- Sentry
- Kafka(WIP)
poetry install --only=dev
pre-commit installEnvironment variables for development can be found in .env.example. You must create app/.env file and fill missing variables with value SET_VALUE from stage environment.
- Using docker compose or prepared commands from makefile
docker compose up appmake dc-up- Using local shell
- Create virtual environment
poetry shell- Install all dependencies
poetry install --no-root- Start application
docker/start.sh- Using docker compose
docker compose up worker- Using docker compose with any pytest flag or prepared makefile
docker compose run --rm test -smake dc-testmake dc-test tests/integrationmake dc-test-parallelmake dc-test-unit tests/unit# run test and restart if code base is changed
make dc-test-watch - All test running using pytest
- Option
--reuse-dballow to use the same database without deleting it - Parallel tests allow to run tests in parallel procceses. For each proccess created it's own database based on worker_id
- Option
--without-dballow to run withou creating database and only for unit tests
- autogenerate migration
docker compose run --rm migrations alembic revision --autogenerate -m 'Migration message'make dc-migrations 'Migration message'- upgrade to latest version
docker compose run --rm migrations upgrade headsmake dc-migrate- upgrade to previous version
docker compose run --rm alembic downgrade -1make dc-migrate-rollback- Run only check
make lint-check- Run linters and modify files
make lint