Skip to content

Repository files navigation

🚀 FastAPI Monolith Template

✨ Features

  • FastAPI — high-performance async API framework
  • 🧱 Modular Monolith Architecture — scalable structure without microservices overhead
  • 🗃️ SQLAlchemy (async) — modern ORM with async support
  • 🔄 Unit of Work pattern — transaction management abstraction
  • 📦 Repository pattern — clean data access layer
  • 🧪 Pytest — unit & integration testing setup
  • 🐳 Docker support — ready for containerized environments
  • 🧬 Alembic migrations — database versioning
  • ⚙️ Environment-based config
  • 🧵 Async-first design

Key Principles

  • Separation of concerns
  • Dependency inversion
  • Testability
  • Explicit transaction handling (UoW)

🧪 Testing

The project includes a testing setup using pytest:

  • Unit tests for repositories and services
  • Integration tests with a test database
  • Async test support

Run tests:

pytest

⚙️ Setup

1. Clone repository

git clone https://github.com/AstralMortem/fastapi-monolith-template.git
cd fastapi-monolith-template

2. Install dependencies (using uv)

uv sync
source .venv/bin/activate

The project uses uv for fast dependency management ([GitHub][1])


3. Configure environment

Copy .env.example:

cp .env.example .env

Update variables (DB, Redis, etc.)


4. Run database migrations

alembic upgrade head

5. Run the application

uvicorn app.main:app --reload

🐳 Docker

Run with Docker:

docker-compose up --build

📦 Tech Stack

  • FastAPI
  • SQLAlchemy (async)
  • PostgreSQL
  • Alembic
  • Redis (optional)
  • Pytest
  • Docker

📐 Design Patterns Used

  • Repository Pattern
  • Unit of Work
  • Dependency Injection (FastAPI-based)
  • Service Layer

🚀 Why Modular Monolith?

A modular monolith gives you:

  • Simpler deployment than microservices
  • Clear boundaries between modules
  • Easier refactoring
  • Ability to scale into microservices later

About

A production-ready modular monolith template built with FastAPI, following clean architecture principles and best practices for scalability, maintainability, and testability.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages