Genius Dynamics Logo
Backend
189
43
Updated 2y ago

FastAPI Starter Kit

A production-ready FastAPI starter template with authentication, database integration, and deployment scripts

Python
FastAPI
SQLAlchemy
PostgreSQL
Redis
Docker

FastAPI Starter Kit

A comprehensive, production-ready FastAPI starter template that includes everything you need to build robust APIs quickly and efficiently.

๐Ÿš€ Features

  • FastAPI Framework: Modern, fast web framework for building APIs
  • Authentication: JWT-based authentication with refresh tokens
  • Database Integration: SQLAlchemy ORM with PostgreSQL support
  • Redis Caching: Built-in Redis integration for performance
  • API Documentation: Auto-generated Swagger/OpenAPI docs
  • Docker Support: Containerized deployment ready
  • Testing: Comprehensive test suite with pytest
  • Security: CORS, rate limiting, and security headers
  • Monitoring: Health checks and metrics endpoints

๐Ÿ“ฆ What's Included

Core Features

  • User authentication and authorization
  • Database models and migrations
  • API versioning
  • Request/response validation
  • Error handling
  • Logging configuration

Development Tools

  • Hot reload development server
  • Code formatting (Black)
  • Linting (Flake8)
  • Type checking (mypy)
  • Pre-commit hooks

Deployment Ready

  • Docker and docker-compose files
  • Nginx configuration
  • Environment-based configuration
  • Production settings

๐Ÿ› ๏ธ Quick Start

Prerequisites

  • Python 3.8+
  • PostgreSQL
  • Redis (optional)

Installation

``bash

Clone the repository

git clone https://github.com/geniusdynamics/fastapi-starter.git cd fastapi-starter

Create virtual environment

python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate

Install dependencies

pip install -r requirements.txt

Set up environment variables

cp .env.example .env

Edit .env with your configuration

Run database migrations

alembic upgrade head

Start the development server

uvicorn app.main:app --reload
`

The API will be available at http://localhost:8000 and documentation at http://localhost:8000/docs.

๐Ÿ“š API Endpoints

Authentication

`http POST /api/v1/auth/login POST /api/v1/auth/register POST /api/v1/auth/refresh POST /api/v1/auth/logout `

Users

`http GET /api/v1/users/me PUT /api/v1/users/me DELETE /api/v1/users/me `

Items (Example Resource)

`http GET /api/v1/items POST /api/v1/items GET /api/v1/items/{id} PUT /api/v1/items/{id} DELETE /api/v1/items/{id} `

๐Ÿ—๏ธ Project Structure

` fastapi-starter/ โ”œโ”€โ”€ app/ โ”‚ โ”œโ”€โ”€ api/ โ”‚ โ”‚ โ”œโ”€โ”€ v1/ โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ endpoints/ โ”‚ โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ auth.py โ”‚ โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ users.py โ”‚ โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ items.py โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ api.py โ”‚ โ”œโ”€โ”€ core/ โ”‚ โ”‚ โ”œโ”€โ”€ config.py โ”‚ โ”‚ โ”œโ”€โ”€ security.py โ”‚ โ”‚ โ””โ”€โ”€ database.py โ”‚ โ”œโ”€โ”€ models/ โ”‚ โ”‚ โ”œโ”€โ”€ user.py โ”‚ โ”‚ โ””โ”€โ”€ item.py โ”‚ โ”œโ”€โ”€ schemas/ โ”‚ โ”‚ โ”œโ”€โ”€ user.py โ”‚ โ”‚ โ””โ”€โ”€ item.py โ”‚ โ”œโ”€โ”€ services/ โ”‚ โ”‚ โ”œโ”€โ”€ auth.py โ”‚ โ”‚ โ””โ”€โ”€ user.py โ”‚ โ”œโ”€โ”€ main.py โ”‚ โ””โ”€โ”€ __init__.py โ”œโ”€โ”€ tests/ โ”‚ โ”œโ”€โ”€ conftest.py โ”‚ โ”œโ”€โ”€ test_auth.py โ”‚ โ””โ”€โ”€ test_users.py โ”œโ”€โ”€ alembic/ โ”œโ”€โ”€ docker/ โ”œโ”€โ”€ docs/ โ”œโ”€โ”€ .env.example โ”œโ”€โ”€ docker-compose.yml โ”œโ”€โ”€ Dockerfile โ”œโ”€โ”€ requirements.txt โ””โ”€โ”€ README.md `

๐Ÿ”ง Configuration

The application uses environment variables for configuration:

`bash

Database

DATABASE_URL=postgresql://user:password@localhost/dbname

Security

SECRET_KEY=your-secret-key-here JWT_SECRET_KEY=your-jwt-secret JWT_ALGORITHM=HS256 ACCESS_TOKEN_EXPIRE_MINUTES=30

Redis (optional)

REDIS_URL=redis://localhost:6379

Email

SMTP_SERVER=smtp.gmail.com SMTP_PORT=587 SMTP_USERNAME=your-email@gmail.com SMTP_PASSWORD=your-app-password
`

๐Ÿงช Testing

`bash

Run all tests

pytest

Run with coverage

pytest --cov=app --cov-report=html

Run specific test file

pytest tests/test_auth.py

Run tests in verbose mode

pytest -v
`

๐Ÿš€ Deployment

Using Docker

`bash

Build the image

docker build -t fastapi-starter .

Run with docker-compose

docker-compose up -d

Or run manually

docker run -p 8000:8000 fastapi-starter
`

Manual Deployment

`bash

Install production dependencies

pip install -r requirements.prod.txt

Set environment to production

export ENVIRONMENT=production

Run with gunicorn

gunicorn app.main:app -w 4 -k uvicorn.workers.UvicornWorker --bind 0.0.0.0:8000
`

๐Ÿ”’ Security Features

  • JWT Authentication: Secure token-based authentication
  • Password Hashing: Bcrypt password hashing
  • CORS Protection: Configurable CORS settings
  • Rate Limiting: API rate limiting to prevent abuse
  • Input Validation: Pydantic models for request validation
  • SQL Injection Protection: SQLAlchemy ORM protection
  • HTTPS Enforcement: SSL/TLS encryption in production

๐Ÿ“Š Monitoring

Health Checks

`http GET /health - Overall health status GET /health/db - Database health GET /health/redis - Redis health `

Metrics

`http GET /metrics - Application metrics (Prometheus format) `

๐Ÿค Contributing

  • Fork the repository
  • Create a feature branch (git checkout -b feature/amazing-feature)
  • Commit your changes (git commit -m 'Add amazing feature')
  • Push to the branch (git push origin feature/amazing-feature`)
  • Open a Pull Request
  • ๐Ÿ“ License

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

    ๐Ÿ™ Acknowledgments

    • FastAPI team for the incredible framework
    • SQLAlchemy for the powerful ORM
    • All contributors and the open source community

    ๐Ÿ“ž Support

    ---

    _Built with ๐Ÿ by Genius Dynamics_

    Tags:
    Python
    FastAPI
    SQLAlchemy
    PostgreSQL
    Redis
    Docker

    Contribute to This Project

    Help us improve this project and make it even better. Your contributions are welcome!

    Genius Dynamics Logo

    Enabling Growth by improving efficiency with our innovative technology solutions.

    Get In Touch
    Stay Updated

    Subscribe to our newsletter for the latest insights on technology and cost reduction strategies.

    ISO 27001 Certified
    65+ Enterprise Clients
    Kenya-Based
    24/7 Support

    ยฉ 2026 GENIUS DYNAMICS LTD. All Rights Reserved.

    Efficiency and Growth