A comprehensive FastAPI reference implementation demonstrating modern development practices with the RealWorld API specification using Domain-Driven Design principles.
# Clone and setup
git clone <repository-url>
cd fastapi-realworld-demo
poetry install
# Start databases and apply migrations
make setup-dev
make migrate
# Run the application
make runπ Visit: http://localhost:8000/docs for interactive API documentation
π New here? β Development Quickstart (5-minute setup)
- Architecture Diagrams - Complete C4 model visualization with PlantUML diagrams
- System Overview - Technology stack with architectural diagrams
- Development Quickstart - 5-minute setup
- Getting Started Guide - Detailed setup with troubleshooting
- API Usage Guide - Complete API reference with examples
- Domain-Driven Design - DDD architecture patterns with domain model
- Event-Driven Architecture - Event system design with request flow diagrams
- Exception Handling - Standardized error handling
- Transaction Management - Database transaction patterns
- Development Workflow - Complete development process
- Testing Guide - Comprehensive testing strategies with test pyramid architecture
- Commit Guidelines - Git commit conventions
- Production Deployment - Complete deployment guide
- β User Management: Registration, authentication, profile management
- β Article System: CRUD operations with slug-based URLs
- β Social Features: Following users, favoriting articles
- β Content Features: Comments, tags, personalized feeds
- β Pagination: Efficient list pagination across endpoints
- β Domain-Driven Design: Clean separation of concerns with clear layer boundaries
- β Event-Driven Architecture: Loose coupling via domain events with extensible framework
- β Type Safety: Full MyPy validation for compile-time error detection
- β Comprehensive Testing: Unit, integration, and E2E tests with optimized fixtures
- β
Transaction Management: Automatic UoW pattern with
@transactional()decorator
- FastAPI 0.115+ with Pydantic v2
- PostgreSQL with async SQLAlchemy 2.0
- JWT Authentication with bcrypt
- Docker for development databases
- Poetry for dependency management
- pytest with async support
# Run all tests
make test
# Run specific test types
poetry run pytest tests/unit/ # Unit tests
poetry run pytest tests/integration/ # Integration tests
poetry run pytest tests/e2e/ # End-to-end tests
# Run with coverage
make test-covπ― Development Focus: This project prioritizes development experience, code quality, and architectural patterns. While it includes deployment-ready code, additional configuration is needed for full production deployment (monitoring, security hardening, performance optimization, etc.).
# Essential commands
make run # Start with auto-reload
make test # Run all tests
make lint # Format and lint code
make type-check # MyPy type checking
# Database management
make migrate # Apply migrations
make migration msg="Add field" # Create migration
make db-check # Test connection
# Quality assurance
make format # Auto-format code
make health-all # Check all systemsπ― Development Focus: This project prioritizes development experience, code quality, and architectural patterns. While it includes deployment-ready code and solid architectural foundations, additional configuration is needed for full production deployment (monitoring, security hardening, etc.).
@transactional()
async def create_article(uow: AsyncUnitOfWork, article_data: ArticleCreate, user: User) -> Article:
# Business logic - automatic commit/rollback# Domain layer raises business exceptions
raise ArticleNotFoundError(slug)
# API layer automatically converts to HTTP responses
# β 404 {"errors": {"body": ["Article not found"]}}# Publish domain events from service layer
shared_event_bus.publish(ArticleCreated(
article_id=article.id,
title=article.title,
slug=article.slug
))The codebase follows a clean, layered architecture:
app/
βββ api/ # π HTTP endpoints (FastAPI routers)
βββ service_layer/ # βοΈ Use cases and orchestration
βββ domain/ # ποΈ Business logic and entities
βββ adapters/ # π Infrastructure (repositories, ORM)
βββ events/ # π‘ Event-driven architecture
βββ shared/ # π οΈ Common utilities
tests/
βββ unit/ # Pure business logic tests
βββ integration/ # Database and API tests
βββ e2e/ # Complete workflow tests
π Visual Architecture: See the Component Diagram for detailed layer relationships and Architecture Diagrams for the complete system visualization.
- Interactive Docs: http://localhost:8000/docs (Swagger UI)
- ReDoc: http://localhost:8000/redoc (Alternative documentation)
- Health Check: http://localhost:8000/healthcheck (Basic status endpoint)
- OpenAPI Spec: http://localhost:8000/openapi.json (Machine-readable specification)
π RealWorld Spec: Fully implements the RealWorld API specification
- Setup: Follow the Development Quickstart
- Standards: Review Development Workflow
- Commits: Use Conventional Commits
- Testing: Ensure comprehensive test coverage
- Type Safety: All code must pass MyPy validation
- π Project Overview - Complete technology overview
- ποΈ Architecture Guides - Detailed design patterns
- π οΈ Development Guides - Complete development workflow
- π All Documentation - Browse complete documentation
π‘ Questions? Check the documentation or open an issue!