Skip to content

mhhoss/fastapi-stack

Β 
Β 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

7 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

FastAPI Stack πŸš€

Python FastAPI Docker License Tests

A modern, modular FastAPI backend template for building secure and scalable Python APIs.
Includes JWT authentication, PostgreSQL, Redis, WebSockets, Docker, and full test coverage β€” perfect for learning, refactoring, or production use.

πŸ“‹ Table of Contents

πŸš€ Features

Core FastAPI Features

  • βœ… RESTful API Design - Complete CRUD operations with proper HTTP methods
  • βœ… Automatic OpenAPI Documentation - Interactive docs at /docs and /redoc
  • βœ… Request/Response Validation - Pydantic models with automatic validation
  • βœ… Dependency Injection - Clean, testable code with FastAPI's DI system
  • βœ… Authentication & Authorization - JWT-based auth with OAuth2 flow
  • βœ… API Versioning - Support for multiple API versions (/api/v1/, /api/v2/)

Advanced Features

  • πŸ”„ Real-time Communication - WebSockets and Server-Sent Events
  • πŸ“ File Upload/Download - Streaming file operations with validation
  • ⚑ Background Tasks - Asynchronous task processing
  • πŸ—„οΈ Caching - Redis-based caching for performance
  • πŸ—ƒοΈ Database Integration - SQLAlchemy ORM with async support
  • πŸ”§ Middleware - Custom middleware for CORS, rate limiting, and monitoring

Development & Production

  • πŸ§ͺ Comprehensive Testing - Unit, integration, and performance tests
  • 🐳 Docker Support - Multi-service container setup
  • πŸ”„ Database Migrations - Alembic for schema management
  • πŸ“Š Monitoring & Logging - Structured logging and health checks
  • πŸ“ˆ Performance Benchmarking - Built-in API performance testing

πŸ› οΈ Tech Stack

Category Technology Version Purpose
Framework FastAPI 0.104+ Web framework
Language Python 3.11+ Programming language
Database PostgreSQL 15+ Primary database
ORM SQLAlchemy 2.0+ Database ORM
Cache Redis 7+ Caching layer
Authentication python-jose 3.3+ JWT handling
Testing pytest 7.4+ Testing framework
Documentation OpenAPI/Swagger 3.0+ API documentation
Containerization Docker 20+ Container platform
Web Server Uvicorn 0.24+ ASGI server

πŸ“ Project Structure

FastAPIVerseHub/                    # 🏠 Project root
β”œβ”€β”€ app/                            # πŸ“¦ Main application package
β”‚   β”œβ”€β”€ __init__.py                 # πŸ“„ Package initializer
β”‚   β”œβ”€β”€ main.py                     # πŸš€ Application entry point
β”‚   β”œβ”€β”€ core/                       # βš™οΈ Core configurations
β”‚   β”‚   β”œβ”€β”€ __init__.py
β”‚   β”‚   β”œβ”€β”€ config.py               # πŸ”§ Settings & environment config
β”‚   β”‚   β”œβ”€β”€ dependencies.py         # πŸ’‰ Dependency injection
β”‚   β”‚   β”œβ”€β”€ logging.py              # πŸ“ Logging configuration
β”‚   β”‚   └── security.py             # πŸ” Security utilities (JWT, hashing)
β”‚   β”œβ”€β”€ api/                        # 🌐 API route definitions
β”‚   β”‚   β”œβ”€β”€ __init__.py
β”‚   β”‚   β”œβ”€β”€ v1/                     # πŸ“Œ API version 1
β”‚   β”‚   β”‚   β”œβ”€β”€ __init__.py
β”‚   β”‚   β”‚   β”œβ”€β”€ auth.py             # πŸ”‘ Authentication endpoints
β”‚   β”‚   β”‚   β”œβ”€β”€ users.py            # πŸ‘₯ User management
β”‚   β”‚   β”‚   β”œβ”€β”€ courses.py          # πŸ“š Course CRUD operations
β”‚   β”‚   β”‚   β”œβ”€β”€ uploads.py          # πŸ“ File upload/download
β”‚   β”‚   β”‚   β”œβ”€β”€ websocket.py        # πŸ”„ WebSocket connections
β”‚   β”‚   β”‚   β”œβ”€β”€ sse.py              # πŸ“‘ Server-Sent Events
β”‚   β”‚   β”‚   └── forms.py            # πŸ“ Form data handling
β”‚   β”‚   └── v2/                     # πŸ“Œ API version 2 (Enhanced)
β”‚   β”‚       β”œβ”€β”€ __init__.py
β”‚   β”‚       β”œβ”€β”€ advanced_auth.py    # πŸ”‘ Enhanced authentication
β”‚   β”‚       └── advanced_courses.py # πŸ“š Advanced course features
β”‚   β”œβ”€β”€ models/                     # πŸ—ƒοΈ Database models
β”‚   β”‚   β”œβ”€β”€ __init__.py
β”‚   β”‚   β”œβ”€β”€ user.py                 # πŸ‘€ User database model
β”‚   β”‚   β”œβ”€β”€ course.py               # πŸ“– Course database model
β”‚   β”‚   └── token.py                # 🎫 Token/session models
β”‚   β”œβ”€β”€ schemas/                    # πŸ“‹ Pydantic request/response models
β”‚   β”‚   β”œβ”€β”€ __init__.py
β”‚   β”‚   β”œβ”€β”€ user.py                 # πŸ‘€ User validation schemas
β”‚   β”‚   β”œβ”€β”€ course.py               # πŸ“– Course validation schemas
β”‚   β”‚   β”œβ”€β”€ auth.py                 # πŸ”‘ Authentication schemas
β”‚   β”‚   └── common.py               # πŸ”§ Shared schemas
β”‚   β”œβ”€β”€ services/                   # 🏒 Business logic layer
β”‚   β”‚   β”œβ”€β”€ __init__.py
β”‚   β”‚   β”œβ”€β”€ auth_service.py         # πŸ”‘ Authentication logic
β”‚   β”‚   β”œβ”€β”€ user_service.py         # πŸ‘₯ User management logic
β”‚   β”‚   β”œβ”€β”€ course_service.py       # πŸ“š Course business logic
β”‚   β”‚   └── notification_service.py # πŸ“’ Real-time notifications
β”‚   β”œβ”€β”€ common/                     # πŸ› οΈ Shared utilities
β”‚   β”‚   β”œβ”€β”€ __init__.py
β”‚   β”‚   β”œβ”€β”€ cache_utils.py          # πŸ’Ύ Caching helpers
β”‚   β”‚   β”œβ”€β”€ file_utils.py           # πŸ“ File handling utilities
β”‚   β”‚   β”œβ”€β”€ email_utils.py          # πŸ“§ Email utilities
β”‚   β”‚   └── validators.py           # βœ… Custom validators
β”‚   β”œβ”€β”€ exceptions/                 # ❌ Custom exception classes
β”‚   β”‚   β”œβ”€β”€ __init__.py
β”‚   β”‚   β”œβ”€β”€ base_exceptions.py      # πŸ—οΈ Base exception classes
β”‚   β”‚   β”œβ”€β”€ auth_exceptions.py      # πŸ”‘ Auth-related errors
β”‚   β”‚   └── validation_exceptions.py # ❌ Validation errors
β”‚   β”œβ”€β”€ middleware/                 # πŸ”§ Custom middleware
β”‚   β”‚   β”œβ”€β”€ __init__.py
β”‚   β”‚   β”œβ”€β”€ cors_middleware.py      # 🌐 CORS configuration
β”‚   β”‚   β”œβ”€β”€ rate_limiter.py         # 🚦 API rate limiting
β”‚   β”‚   └── request_timer.py        # ⏱️ Request timing
β”‚   β”œβ”€β”€ tests/                      # πŸ§ͺ Test suite
β”‚   β”‚   β”œβ”€β”€ __init__.py
β”‚   β”‚   β”œβ”€β”€ conftest.py             # βš™οΈ Pytest configuration
β”‚   β”‚   β”œβ”€β”€ test_auth.py            # πŸ”‘ Authentication tests
β”‚   β”‚   β”œβ”€β”€ test_courses.py         # πŸ“š Course tests
β”‚   β”‚   β”œβ”€β”€ test_uploads.py         # πŸ“ File upload tests
β”‚   β”‚   β”œβ”€β”€ test_websockets.py      # πŸ”„ WebSocket tests
β”‚   β”‚   β”œβ”€β”€ test_sse.py             # πŸ“‘ SSE tests
β”‚   β”‚   └── test_middleware.py      # πŸ”§ Middleware tests
β”‚   └── templates/                  # πŸ“„ Jinja2 templates
β”‚       β”œβ”€β”€ welcome_email.html      # πŸ“§ Welcome email template
β”‚       β”œβ”€β”€ reset_password.html     # πŸ”“ Password reset template
β”‚       └── api_docs.html           # πŸ“š Custom API docs
β”œβ”€β”€ docs/                           # πŸ“š Documentation
β”‚   β”œβ”€β”€ concepts_map.md             # πŸ—ΊοΈ FastAPI concepts mapping
β”‚   β”œβ”€β”€ quick_reference.md          # ⚑ Quick reference guide
β”‚   β”œβ”€β”€ architecture_decisions.md   # πŸ›οΈ Architecture decisions (ADRs)
β”‚   β”œβ”€β”€ learning_path.md            # πŸŽ“ Structured learning guide
β”‚   β”œβ”€β”€ api_usage_guide.md          # πŸ“˜ API usage examples
β”‚   β”œβ”€β”€ async_best_practices.md     # ⚑ Async/await best practices
β”‚   β”œβ”€β”€ testing_guide.md            # πŸ§ͺ Testing strategies
β”‚   └── deployment_guide.md         # πŸš€ Deployment instructions
β”œβ”€β”€ scripts/                        # πŸ› οΈ Development scripts
β”‚   β”œβ”€β”€ generate_fake_data.py       # 🎭 Sample data generation
β”‚   β”œβ”€β”€ benchmark_apis.py           # πŸ“Š Performance benchmarking
β”‚   β”œβ”€β”€ run_tests.sh               # πŸ§ͺ Test execution script
β”‚   └── generate_openapi_spec.py    # πŸ“‹ OpenAPI spec generation
β”œβ”€β”€ .env.example                    # πŸ”§ Environment variables template
β”œβ”€β”€ .gitignore                      # 🚫 Git ignore rules
β”œβ”€β”€ Dockerfile                      # 🐳 Container configuration
β”œβ”€β”€ docker-compose.yml              # 🐳 Multi-service orchestration
β”œβ”€β”€ pyproject.toml                  # πŸ“¦ Project configuration
└── README.md                       # πŸ“– This file

🚦 Quick Start

Prerequisites

Option 1: Docker Setup (πŸ”₯ Recommended)

# 1️⃣ Clone the repository
git clone https://github.com/mhhoss/fastapi-.git
cd fastapi-stack

# 2️⃣ Copy environment configuration
cp .env.example .env

# 3️⃣ Create required __init__.py files
touch app/__init__.py app/core/__init__.py app/api/__init__.py \
      app/api/v1/__init__.py app/api/v2/__init__.py app/models/__init__.py \
      app/schemas/__init__.py app/services/__init__.py app/common/__init__.py \
      app/exceptions/__init__.py app/middleware/__init__.py app/tests/__init__.py

# 4️⃣ Start all services
docker-compose up -d

# 5️⃣ Check service status
docker-compose ps

# 6️⃣ View logs (optional)
docker-compose logs -f app

# πŸŽ‰ Access the application
# API: http://localhost:8000
# Docs: http://localhost:8000/docs
# Admin Panel: http://localhost:5050 (pgAdmin)

Option 2: Local Development

# 1️⃣ Clone and setup
git clone https://github.com/mhhoss/fastapi-stack.git
cd fastapi-stack

# 2️⃣ Create virtual environment
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate

# 3️⃣ Install dependencies
pip install -e ".[dev]"

# 4️⃣ Setup environment
cp .env.example .env
# Edit .env with your database and Redis URLs

# 5️⃣ Create __init__.py files (same as Docker option step 3)

# 6️⃣ Setup database (if using local PostgreSQL)
createdb fastapi_verse_hub  # or use your preferred method

# 7️⃣ Run database migrations
alembic upgrade head

# 8️⃣ Start the application
uvicorn app.main:app --host 0.0.0.0 --port 8000 --reload

# πŸŽ‰ Open http://localhost:8000 in your browser

πŸš€ Quick Health Check

# Test if everything is working
curl http://localhost:8000/health

# Expected response:
# {"status":"healthy","timestamp":"...","version":"1.0.0"}

πŸ“š API Documentation

Once running, access the comprehensive API documentation:

Documentation Type URL Description
🎨 Swagger UI http://localhost:8000/docs Interactive API documentation
πŸ“– ReDoc http://localhost:8000/redoc Alternative documentation view
πŸ“‹ OpenAPI Spec http://localhost:8000/openapi.json Raw OpenAPI specification

πŸ”‘ Default Test Account

For testing purposes, use these credentials:

  • πŸ“§ Email: admin@example.com
  • πŸ”’ Password: admin123
  • πŸ‘‘ Role: Administrator

🌐 API Endpoints

πŸ”‘ Authentication

Method Endpoint Description Auth Required
POST /api/v1/auth/register User registration ❌
POST /api/v1/auth/token User login ❌
POST /api/v1/auth/refresh Token refresh βœ…

πŸ‘₯ User Management

Method Endpoint Description Auth Required
GET /api/v1/users/me Get current user βœ…
PUT /api/v1/users/me Update current user βœ…
GET /api/v1/users/ List users (paginated) βœ…

πŸ“š Course Management

Method Endpoint Description Auth Required
GET /api/v1/courses/ List courses ❌
POST /api/v1/courses/ Create course βœ…
GET /api/v1/courses/{id} Get course details ❌
PUT /api/v1/courses/{id} Update course βœ…
DELETE /api/v1/courses/{id} Delete course βœ…

πŸ“ File Operations

Method Endpoint Description Auth Required
POST /api/v1/uploads/ Upload file βœ…
GET /api/v1/uploads/{id}/download Download file βœ…
GET /api/v1/uploads/my-files List user files βœ…

πŸ“Š System Endpoints

Method Endpoint Description Auth Required
GET /health Basic health status ❌
GET /ready Readiness probe ❌

πŸ”„ Real-time Features

🌐 WebSocket Connection

// Connect to WebSocket
const ws = new WebSocket("ws://localhost:8000/api/v1/ws");

// Authenticate
ws.onopen = () => {
  ws.send(
    JSON.stringify({
      type: "authenticate",
      token: "your-jwt-token",
    })
  );
};

// Send message
ws.send(
  JSON.stringify({
    type: "message",
    content: "Hello, World!",
    room: "general",
  })
); 

πŸ“‘ Server-Sent Events

// Subscribe to notifications
const eventSource = new EventSource(
  "http://localhost:8000/api/v1/sse/notifications?token=your-jwt-token"
);

eventSource.onmessage = (event) => {
  const data = JSON.parse(event.data);
  console.log("Notification:", data);
};

πŸ§ͺ Testing

πŸš€ Quick Test Run

# Run all tests
./scripts/run_tests.sh

# Run with coverage report
./scripts/run_tests.sh --coverage

# Run specific test types
./scripts/run_tests.sh --type unit --verbose
./scripts/run_tests.sh --type integration
./scripts/run_tests.sh --type performance

🎭 Generate Test Data

# Generate sample users and courses
python scripts/generate_fake_data.py

# Options:
# - 50 users (including 1 admin)
# - 30 courses with realistic data
# - Course enrollments
# - Sample file records

πŸ“Š Performance Benchmarking

# Run API performance tests
python scripts/benchmark_apis.py --total 100 --concurrent 10

# Export results to JSON
python scripts/benchmark_apis.py --export results.json

🎯 Test Coverage Goals

  • Unit Tests: 90%+ coverage
  • Integration Tests: All API endpoints
  • Performance Tests: Sub-100ms response times
  • E2E Tests: Critical user workflows

πŸ”§ Development

πŸ› οΈ Development Commands

# πŸ“Š Generate fake data for testing
python scripts/generate_fake_data.py

# πŸ“‹ Export OpenAPI specification
python scripts/generate_openapi_spec.py

# πŸ“ˆ Run performance benchmarks
python scripts/benchmark_apis.py

# πŸ—ƒοΈ Database migrations
alembic revision --autogenerate -m "Add new feature"
alembic upgrade head
alembic downgrade -1

# 🎨 Code formatting and linting
black app/          # Format code
isort app/          # Sort imports
flake8 app/         # Lint code
mypy app/           # Type checking

πŸ”„ Development Workflow

  1. 🌿 Branch: Create feature branch from main
  2. πŸ’» Code: Implement feature with tests
  3. πŸ§ͺ Test: Run full test suite
  4. 🎨 Format: Apply code formatting
  5. πŸ“ Document: Update documentation
  6. πŸ” Review: Create pull request
  7. πŸš€ Deploy: Merge and deploy

🐳 Docker Development

# πŸ—οΈ Build and start development environment
docker-compose up -d --build

# πŸ” View service logs
docker-compose logs -f app

# πŸ—ƒοΈ Access database directly
docker-compose exec db psql -U fastapi_user -d fastapi_verse_hub

# πŸ’Ύ Access Redis CLI
docker-compose exec redis redis-cli

# πŸ“Š Monitor with management tools
# pgAdmin: http://localhost:5050 (admin@example.com / admin)
# Redis Commander: http://localhost:8081 (admin / admin)

πŸ—οΈ Architecture

🎯 Project Philosophy

  • πŸ›οΈ Clean Architecture - Clear separation of concerns
  • 🎯 Domain-Driven Design - Business logic in services layer
  • ⚑ SOLID Principles - Maintainable and extensible code
  • πŸ§ͺ Test-Driven Development - Comprehensive test coverage
  • πŸ“‹ API-First Design - OpenAPI specification driven

🧩 Key Components

βš™οΈ Core Layer (app/core/)

  • πŸ”§ Configuration Management - Pydantic Settings with environment variables
  • πŸ” Security Utilities - JWT handling and password hashing
  • πŸ—ƒοΈ Database Connection - Async SQLAlchemy setup
  • πŸ’‰ Dependency Injection - FastAPI dependencies
  • πŸ“ Structured Logging - JSON logging with correlation IDs

🌐 API Layer (app/api/)

  • πŸ›£οΈ RESTful Endpoints - Standard HTTP methods and status codes
  • βœ… Request/Response Validation - Automatic Pydantic validation
  • ❌ Error Handling - Consistent error responses
  • πŸ“Œ API Versioning - Support for multiple API versions

🏒 Business Logic (app/services/)

  • πŸ“ˆ Domain Rules - Business logic implementation
  • πŸ—ƒοΈ Database Operations - Data access patterns
  • 🌐 External Integrations - Third-party service calls
  • ⚑ Background Tasks - Async task management

πŸ—ƒοΈ Data Layer (app/models/)

  • πŸ“Š ORM Models - SQLAlchemy database models
  • πŸ”— Relationships - Database table relationships
  • βœ… Constraints - Data integrity rules

πŸ“‹ Validation Layer (app/schemas/)

  • πŸ“₯ Request Models - Input validation schemas
  • πŸ“€ Response Models - Output serialization schemas
  • πŸ“š Documentation - Automatic API docs generation

πŸš€ Deployment

🐳 Docker Production

# 🌐 Production deployment
docker-compose -f docker-compose.yml -f docker-compose.prod.yml up -d

# πŸ”’ With SSL (requires nginx configuration)
docker-compose --profile production up -d

# πŸ“Š Monitor deployment
docker-compose ps
docker-compose logs -f

πŸ–₯️ Traditional Server

# πŸ“¦ Install production dependencies
pip install -e ".[production]"

# πŸš€ Run with Gunicorn
gunicorn app.main:app \
    --workers 4 \
    --worker-class uvicorn.workers.UvicornWorker \
    --bind 0.0.0.0:8000 \
    --access-logfile - \
    --error-logfile -

☁️ Cloud Deployment

The project includes deployment configurations for:

Platform Service Configuration
🟠 AWS ECS/Fargate Container-based deployment
πŸ”΅ Google Cloud Cloud Run Serverless container platform
🟦 Azure Container Instances Simple container deployment
☸️ Kubernetes Any cluster Full orchestration setup

πŸ“š Detailed Instructions: See docs/deployment_guide.md

πŸ“ˆ Performance

🎯 Performance Benchmarks

Metric Target Description
⚑ Response Time < 50ms Average for simple endpoints
πŸš€ Throughput 1000+ RPS Requests per second with caching
πŸ‘₯ Concurrent Users 500+ WebSocket connections
πŸ“ File Upload 100MB+ Streaming support

πŸ”§ Optimization Features

  • πŸ’Ύ Redis Caching - Database query caching
  • 🏊 Connection Pooling - Efficient database connections
  • ⚑ Async/Await - Non-blocking operations throughout
  • βš™οΈ Background Tasks - Offloaded processing
  • πŸ—œοΈ Response Compression - Reduced payload sizes

πŸ“Š Performance Monitoring

# πŸ” Run performance benchmarks
python scripts/benchmark_apis.py \
    --concurrent 10 \
    --total 1000 \
    --export performance_report.json

# πŸ“ˆ Analyze results
# Check average response times, error rates, and throughput

πŸ”’ Security

πŸ›‘οΈ Implemented Security Measures

Feature Implementation Description
πŸ”‘ Authentication JWT tokens Stateless authentication
πŸ”’ Password Security bcrypt hashing Secure password storage
🌐 CORS Protection Custom middleware Cross-origin request control
🚦 Rate Limiting Token bucket API abuse prevention
βœ… Input Validation Pydantic models Data sanitization
πŸ›‘οΈ SQL Injection SQLAlchemy ORM Parameterized queries
πŸ“ File Security Type validation Safe file uploads
πŸ” Security Headers Custom middleware OWASP recommendations

πŸ” Security Best Practices

# πŸ”‘ Generate secure keys for production
python -c "import secrets; print(secrets.token_urlsafe(32))"

# πŸ” Security audit
pip install safety bandit
safety check
bandit -r app/

# πŸ›‘οΈ Update dependencies regularly
pip-audit

πŸ“Š Monitoring

πŸ₯ Health Checks

Endpoint Purpose Response
GET /health Basic health Service status
GET /ready Readiness probe Dependencies status

πŸ“ˆ Metrics & Logging

  • πŸ“ Structured Logging - JSON format with correlation IDs
  • ⏱️ Request Timing - Response time tracking
  • ❌ Error Tracking - Comprehensive error logging
  • πŸ“Š Custom Metrics - Business metrics collection
  • πŸ” Prometheus - Metrics endpoint for monitoring

πŸ” Monitoring Setup

# πŸ“Š View application logs
docker-compose logs -f app

# πŸ“ˆ Access metrics endpoint
curl http://localhost:8000/metrics

# πŸ₯ Check health status
curl http://localhost:8000/health
curl http://localhost:8000/ready

πŸ“– Learning Resources

πŸŽ“ Recommended Learning Path

Step Resource Duration Focus
1️⃣ docs/learning_path.md 2-3 weeks Complete FastAPI journey
2️⃣ docs/quick_reference.md 1 day FastAPI patterns
3️⃣ docs/api_usage_guide.md 2 days API usage examples
4️⃣ docs/architecture_decisions.md 1 day Design decisions
5️⃣ docs/testing_guide.md 3 days Testing strategies
6️⃣ docs/deployment_guide.md 2 days Production deployment

πŸ’‘ Key Concepts Demonstrated

  • ⚑ Async Programming - Proper async/await usage patterns
  • πŸ’‰ Dependency Injection - FastAPI's powerful DI system
  • βœ… Data Validation - Pydantic models and custom validators
  • πŸ”‘ Authentication - JWT and OAuth2 implementation
  • πŸ”„ Real-time Communication - WebSockets and Server-Sent Events
  • πŸ§ͺ Testing - Comprehensive testing strategies
  • πŸ“‹ API Design - RESTful best practices and standards

πŸ“š External Resources

🀝 Contributing

We welcome contributions! Here's how to get started:

πŸš€ Quick Contribution Guide

  1. 🍴 Fork the repository
  2. 🌿 Create a feature branch (git checkout -b feature/amazing-feature)
  3. πŸ’» Make your changes with tests
  4. πŸ§ͺ Ensure all tests pass (./scripts/run_tests.sh)
  5. πŸ“ Commit your changes (git commit -m 'Add amazing feature')
  6. ⬆️ Push to branch (git push origin feature/amazing-feature)
  7. πŸ”„ Open a Pull Request

πŸ“‹ Development Guidelines

  • 🎨 Code Style - Follow PEP 8 and use black formatter
  • πŸ”€ Type Hints - Add type hints to all functions
  • πŸ§ͺ Testing - Write tests for new functionality (aim for 90%+ coverage)
  • πŸ“š Documentation - Update relevant documentation
  • ⚑ Commits - Keep commits atomic and well-described

🏷️ Contribution Types

  • πŸ› Bug Fixes - Fix issues and improve stability
  • ✨ New Features - Add new functionality
  • πŸ“š Documentation - Improve docs and examples
  • 🎨 Code Quality - Refactoring and optimization
  • πŸ§ͺ Testing - Add or improve tests
  • πŸ”’ Security - Security improvements

🎯 Good First Issues

Look for issues labeled with:

  • good-first-issue - Perfect for beginners
  • documentation - Documentation improvements
  • tests - Adding or improving tests
  • enhancement - Small feature additions

πŸ› Troubleshooting

πŸ” Common Issues

πŸ—ƒοΈ Database Connection Errors
# Check if database is running
docker-compose ps db

# Check connection string
echo $DATABASE_URL

# Reset database
docker-compose down -v
docker-compose up -d db

# Check logs
docker-compose logs db
πŸ’Ύ Redis Connection Issues
# Test Redis connectivity
redis-cli ping  # Should return PONG

# Check Redis URL
echo $REDIS_URL

# Restart Redis
docker-compose restart redis

# Check Redis logs
docker-compose logs redis
πŸ“¦ Import Errors
# Ensure virtual environment is activated
source venv/bin/activate

# Reinstall dependencies
pip install -e ".[dev]"

# Check Python path
python -c "import sys; print(sys.path)"

# Ensure __init__.py files exist
find app -name "__init__.py" | head -10
πŸ” Permission Errors
# Fix upload directory permissions
chmod -R 755 uploads/

# Fix Docker volume permissions
sudo chown -R $USER:$USER uploads/

# Check file ownership
ls -la uploads/
πŸš€ Application Won't Start
# Check if port is in use
lsof -i :8000

# Check environment variables
python -c "from app.core.config import settings; print(settings.DATABASE_URL)"

# Start with debug mode
uvicorn app.main:app --host 0.0.0.0 --port 8000 --reload --log-level debug

# Check application logs
docker-compose logs -f app

πŸ†˜ Getting Help

πŸ† Project Goals

This project serves as a comprehensive learning resource and production-ready template for:

  1. πŸŽ“ Learning FastAPI - From basic concepts to advanced patterns
  2. πŸ“ˆ Best Practices - Industry-standard development patterns
  3. 🏭 Real-world Usage - Production-ready features and deployment
  4. 🌍 Community Education - Open-source learning resource
  5. πŸš€ Template for Projects - Starter template for new FastAPI projects

πŸ“Š Project Statistics

  • πŸ“ Total Files: 77
  • πŸ“¦ Directories: 17
  • πŸ§ͺ Test Coverage: 80%+ (target: 90%+)
  • πŸ“‹ API Endpoints: 15+ (across v1 and v2)
  • πŸ“š Documentation Pages: 8
  • πŸ› οΈ Utility Scripts: 4

🎯 Roadmap

πŸ”œ Upcoming Features

  • πŸ” OAuth2 Social Login - Google, GitHub, Facebook integration
  • πŸ“Š Admin Dashboard - Web-based administration interface
  • πŸ“ˆ Analytics & Metrics - Detailed usage analytics
  • πŸ” Full-text Search - Elasticsearch integration
  • πŸ“± Mobile API - Mobile-optimized endpoints
  • 🌍 Internationalization - Multi-language support

πŸ—οΈ Technical Improvements

  • πŸ“¦ Microservices - Service decomposition guide
  • 🎭 Event Sourcing - Event-driven architecture patterns
  • πŸ—ΊοΈ GraphQL - GraphQL endpoints alongside REST
  • πŸ€– ML Integration - Machine learning model serving
  • ☁️ Cloud Native - Kubernetes-native deployment

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ“‹ License Summary

MIT License - Free for commercial and private use
βœ… Commercial use    βœ… Modification    βœ… Distribution    βœ… Private use
❌ Liability         ❌ Warranty

πŸ™ Acknowledgments

πŸ† Special Thanks

  • ⚑ FastAPI - The amazing web framework by SebastiΓ‘n Ramirez
  • πŸ“‹ Pydantic - Data validation and settings management
  • πŸ—ƒοΈ SQLAlchemy - The Python SQL toolkit and ORM
  • ⭐ Starlette - Lightweight ASGI framework
  • πŸ§ͺ pytest - Testing framework
  • **🌟 **Open Source Community** - For inspiration and contributions

πŸ‘₯ Contributors

  • Satvik Praveen - Project creator and maintainer
  • Mahdi Hosseini – Maintainer of Fastapi-stack with personal improvements and modular enhancements
  • Community Contributors - Thank you to everyone who contributes!

πŸ”— Links

Resource URL Description
πŸ“š Documentation docs/ Complete project documentation
🎨 API Reference http://localhost:8000/docs Interactive API documentation
πŸ› Issues GitHub Issues Bug reports and feature requests
πŸ’¬ Discussions GitHub Discussions Community discussions
⭐ Repository GitHub Repo Source code repository
πŸ‘€ Owner @mhhoss Project maintainer

Based on FastAPIVerseHub


πŸš€ Happy coding! πŸš€

FastAPI Stack - Where FastAPI learning meets real-world application.

⭐ If you find this project helpful, please give it a star! ⭐

Releases

No releases published

Packages

No packages published

Languages

  • Python 85.5%
  • Shell 8.3%
  • HTML 6.0%
  • Dockerfile 0.2%