Skip to content

almeidaraphael/realworld-fastapi-ddd

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

35 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

FastAPI RealWorld Demo

A comprehensive FastAPI reference implementation demonstrating modern development practices with the RealWorld API specification using Domain-Driven Design principles.

πŸš€ Quick Start

# 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)

πŸ“– Documentation Hub

πŸ“Š Visual Architecture

πŸƒβ€β™‚οΈ Getting Started

πŸ—οΈ Architecture & Design

πŸ› οΈ Development & Testing

πŸš€ Deployment & Production

πŸ“‹ Browse All Documentation

⚑ What You Get

🌍 RealWorld API Implementation

  • βœ… 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

πŸ—οΈ Development-Ready Architecture

  • βœ… 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

πŸ› οΈ Modern Development Stack

  • 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

πŸ§ͺ Testing

# 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.).

πŸš€ Development Commands

# 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

🎯 Key Features

🎯 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.).

Automatic Transaction Management

@transactional()
async def create_article(uow: AsyncUnitOfWork, article_data: ArticleCreate, user: User) -> Article:
    # Business logic - automatic commit/rollback

Standardized Exception Handling

# Domain layer raises business exceptions
raise ArticleNotFoundError(slug)

# API layer automatically converts to HTTP responses
# β†’ 404 {"errors": {"body": ["Article not found"]}}

Event-Driven Architecture

# Publish domain events from service layer
shared_event_bus.publish(ArticleCreated(
    article_id=article.id,
    title=article.title,
    slug=article.slug
))

πŸ—οΈ Project Structure

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.

πŸ”— API Documentation

πŸ“Š RealWorld Spec: Fully implements the RealWorld API specification

🀝 Contributing

  1. Setup: Follow the Development Quickstart
  2. Standards: Review Development Workflow
  3. Commits: Use Conventional Commits
  4. Testing: Ensure comprehensive test coverage
  5. Type Safety: All code must pass MyPy validation

πŸ“š Learn More


πŸ’‘ Questions? Check the documentation or open an issue!

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages