Skip to content

About

FastAPI service with Clean Architecture, Dishka DI, async SQLAlchemy 2.0, JWT (RS256), Alembic, Redis rate limiting, email validation, and async email notifications via FastStream + Kafka; Docker Compose profiles with Loki/Promtail/Grafana.

Topics

Resources

Stars

11 stars

Watchers

1 watching

Forks

Repository files navigation

FastAPI Example

REST API built with FastAPI, following a layered architecture.

Stack

  • Python 3.12, FastAPI, uvicorn
  • PostgreSQL (asyncpg + SQLAlchemy 2.0)
  • Redis (refresh tokens, rate limiting)
  • Kafka via FastStream (email notifications)
  • MailDev (local SMTP)
  • Dishka (dependency injection)
  • JWT RS256 (access + refresh tokens)

Architecture

src/fastapi_example/
├── domain/              # entities, value objects
├── application/         # use cases, commands/queries, interfaces
├── infrastructure/      # DB repos, cache, SMTP, Kafka, HTTP clients
├── presentation/        # FastAPI controllers, DTOs, exception handlers
└── core/                # settings, DI container setup

Run locally

1. Start infrastructure

docker compose -f docker-compose.dev.yml up -d

2. Generate JWT keys

mkdir -p .certs
openssl genrsa -out .certs/jwt-private.pem 2048
openssl rsa -in .certs/jwt-private.pem -pubout -out .certs/jwt-public.pem

3. Configure environment

cp .env_example .env

Edit .env if needed (defaults work with docker-compose.dev.yml).

4. Run migrations

uv run alembic upgrade head

5. Start API

uv run api

API is available at http://localhost:8080. Docs at /docs.

Run with Docker

docker compose -f docker-compose.yaml --profile api --profile port-forwarder run --rm migrations
docker compose -f docker-compose.yaml --profile api --profile port-forwarder up api

API Endpoints

Method Endpoint Description
GET /health Health check
POST /users Register user
GET /users Get current user
PATCH /users Update current user
DELETE /users Delete current user
POST /auth/login/email Login by email
POST /auth/refresh Refresh tokens
POST /auth/logout Logout (revoke refresh token)

Dev commands

uv run ruff check src/fastapi_example    # lint
uv run ruff format src/fastapi_example   # format
uv run mypy src/fastapi_example          # typecheck

About

FastAPI service with Clean Architecture, Dishka DI, async SQLAlchemy 2.0, JWT (RS256), Alembic, Redis rate limiting, email validation, and async email notifications via FastStream + Kafka; Docker Compose profiles with Loki/Promtail/Grafana.

Topics

Resources

Stars

11 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages