Skip to main content

A modular scaffolding system for FastAPI backends

Project description

๐Ÿงฉ FastAPI Blocks Registry

A modular scaffolding system for FastAPI backends, inspired by shadcn-vue. Add production-ready modules (like auth, users, billing) to your FastAPI project with a single CLI command.

๐ŸŽฏ Project Goal

FastAPI Blocks Registry allows you to quickly add complete, production-ready modules to your FastAPI projects. Each module includes models, schemas, routers, services, and all necessary configurations - just copy and customize.

Unlike traditional packages, modules are copied directly into your project, giving you full control to modify and adapt them to your needs.

โœจ Features

  • ๐Ÿ“ฆ Copy, not install - Modules are copied into your project for full customization
  • ๐Ÿ”ง Auto-configuration - Automatically updates main.py, requirements.txt, and .env
  • ๐ŸŽจ Production-ready - Each module follows best practices and includes proper error handling
  • ๐Ÿ”’ Type-safe - Full type hints and Pydantic validation
  • ๐Ÿ“š Well-documented - Clear code structure with docstrings
  • ๐Ÿš€ Quick start - Get authentication, user management, and more in seconds

๐Ÿš€ Quick Start

Installation

# Install from source (for development)
pip install -e .

# Or install from PyPI (when published)
pip install fastapi-blocks-registry

Usage

# Initialize a new FastAPI project
fastapi-registry init

# List available modules
fastapi-registry list

# Show module details
fastapi-registry info auth

# Add a module to your project
fastapi-registry add auth

# Remove a module
fastapi-registry remove auth

What Gets Installed

When you initialize a project, the CLI creates:

  • โœ… Complete FastAPI project structure with app/ directory
  • โœ… Backend documentation in app/README.md (architecture, patterns, best practices)
  • โœ… Configuration files (.env, requirements.txt, pyproject.toml)
  • โœ… Core utilities (config.py, database.py, middleware)

When you add a module, the CLI automatically:

  • โœ… Copies module files to app/modules/<module>/
  • โœ… Updates main.py to register the router
  • โœ… Adds dependencies to requirements.txt
  • โœ… Adds environment variables to .env

๐Ÿ“ฆ Available Modules

Auth Module

Complete JWT-based authentication system with:

  • User registration with password strength validation
  • Login with JWT access and refresh tokens
  • Password reset flow
  • Password change for authenticated users
  • Token blacklisting support

Endpoints:

  • POST /api/v1/auth/register - Register new user
  • POST /api/v1/auth/login - Login user
  • POST /api/v1/auth/refresh - Refresh access token
  • POST /api/v1/auth/forgot-password - Request password reset
  • POST /api/v1/auth/reset-password - Reset password with token
  • POST /api/v1/auth/change-password - Change password (authenticated)
  • GET /api/v1/auth/me - Get current user info

Technologies:

  • PyJWT for token management
  • Passlib + bcrypt for password hashing
  • Pydantic for validation
  • In-memory user store (easily replaceable with database)

๐Ÿ—๏ธ Project Structure

fastapi-blocks-registry/
โ”œโ”€โ”€ fastapi_registry/
โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚   โ”œโ”€โ”€ cli.py                  # CLI implementation
โ”‚   โ”œโ”€โ”€ registry.json           # Module registry
โ”‚   โ”œโ”€โ”€ core/
โ”‚   โ”‚   โ”œโ”€โ”€ file_utils.py       # File operations
โ”‚   โ”‚   โ”œโ”€โ”€ installer.py        # Module installer
โ”‚   โ”‚   โ””โ”€โ”€ registry_manager.py # Registry management
โ”‚   โ”œโ”€โ”€ modules/
โ”‚   โ”‚   โ””โ”€โ”€ auth/               # Auth module
โ”‚   โ”‚       โ”œโ”€โ”€ __init__.py
โ”‚   โ”‚       โ”œโ”€โ”€ models.py       # User model & store
โ”‚   โ”‚       โ”œโ”€โ”€ schemas.py      # Pydantic schemas
โ”‚   โ”‚       โ”œโ”€โ”€ router.py       # FastAPI routes
โ”‚   โ”‚       โ”œโ”€โ”€ service.py      # Business logic
โ”‚   โ”‚       โ”œโ”€โ”€ dependencies.py # FastAPI dependencies
โ”‚   โ”‚       โ”œโ”€โ”€ auth_utils.py   # JWT & password utils
โ”‚   โ”‚       โ””โ”€โ”€ exceptions.py   # Custom exceptions
โ”‚   โ””โ”€โ”€ templates/              # Project templates
โ”‚       โ””โ”€โ”€ fastapi_project/
โ”‚           โ””โ”€โ”€ app/
โ”‚               โ””โ”€โ”€ README.md   # Backend documentation (copied to projects)
โ”œโ”€โ”€ tests/
โ”œโ”€โ”€ docs/
โ”œโ”€โ”€ CLAUDE.md                   # Development guidelines
โ”œโ”€โ”€ README.md
โ””โ”€โ”€ pyproject.toml

๐Ÿง  Module Structure

Each module follows a consistent structure:

  • models.py - Data models (Pydantic or SQLAlchemy)
  • schemas.py - Request/response schemas with validation
  • router.py - FastAPI route definitions
  • service.py - Business logic layer
  • dependencies.py - FastAPI dependency injection
  • exceptions.py - Module-specific exceptions
  • __init__.py - Module initialization

๐Ÿ’ป Example Usage

Starting from Scratch

1. Initialize a new project

# Create project directory
mkdir my-fastapi-app
cd my-fastapi-app

# Initialize project structure
fastapi-registry init --name "My FastAPI App"

2. Set up virtual environment

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

3. Install dependencies

pip install -r requirements.txt

4. Add modules

# Add authentication module
fastapi-registry add auth

5. Configure and run

# Edit .env with your settings
# Then start the server
uvicorn main:app --reload

Adding to Existing Project

1. Add the auth module to your project

cd your-fastapi-project
fastapi-registry add auth

2. Install dependencies

pip install -r requirements.txt

3. Configure environment variables

Edit your .env file:

SECRET_KEY=your-secret-key-min-32-characters
JWT_ALGORITHM=HS256
ACCESS_TOKEN_EXPIRES_MINUTES=30
REFRESH_TOKEN_EXPIRES_DAYS=7

4. Start your server

uvicorn main:app --reload

5. Test the endpoints

# Register a new user
curl -X POST "http://localhost:8000/api/v1/auth/register" \
  -H "Content-Type: application/json" \
  -d '{
    "email": "user@example.com",
    "password": "Test123!@#",
    "name": "Test User"
  }'

# Login
curl -X POST "http://localhost:8000/api/v1/auth/login" \
  -H "Content-Type: application/json" \
  -d '{
    "email": "user@example.com",
    "password": "Test123!@#"
  }'

๐Ÿ”ง CLI Commands

fastapi-registry init

Initialize a new FastAPI project with proper structure:

  • Creates main.py with FastAPI app setup
  • Sets up app/ directory structure with backend-specific documentation
  • Creates app/core/ with config and database utilities
  • Creates app/modules/ for your modules
  • Generates requirements.txt with essential dependencies
  • Creates .env with default configuration
  • Adds .gitignore, README.md, and development config files
  • Includes app/README.md with backend architecture documentation
  • Includes code quality tools config (.flake8, .pylintrc, pyproject.toml)

Options:

  • --project-path, -p - Path to create project (default: current directory)
  • --name, -n - Project name (default: directory name)
  • --description, -d - Project description
  • --force, -f - Initialize even if directory is not empty

Example:

# Initialize in current directory
fastapi-registry init

# Create a new project directory
mkdir my-api && cd my-api
fastapi-registry init --name "My API" --description "My awesome API"

# Initialize in specific path
fastapi-registry init --project-path /path/to/project

fastapi-registry list

Display all available modules from the registry

Options:

  • --search, -s - Search modules by name or description

fastapi-registry info <module>

Show detailed information about a specific module

fastapi-registry add <module>

Add a module to your project:

  • Copies module files to app/modules/<module>/
  • Updates main.py with router registration
  • Adds dependencies to requirements.txt
  • Adds environment variables to .env

Options:

  • --project-path, -p - Path to FastAPI project (default: current directory)
  • --yes, -y - Skip confirmation prompts

fastapi-registry remove <module>

Remove a module from your project (manual cleanup required for dependencies)

Options:

  • --project-path, -p - Path to FastAPI project (default: current directory)
  • --yes, -y - Skip confirmation prompts

fastapi-registry version

Show version information

๐Ÿ› ๏ธ Development

Setup

# Clone the repository
git clone https://github.com/yourusername/fastapi-blocks-registry
cd fastapi-blocks-registry

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

# Install in editable mode
pip install -e .

Running Tests

pytest

Code Quality

# Format code
black .

# Lint code
ruff check .

# Type checking
mypy fastapi_registry

๐Ÿ”ฎ Roadmap

  • CLI implementation with Typer
  • Project initialization command
  • Auth module with JWT
  • Auto-configuration system
  • Users module with RBAC
  • Database integration (SQLAlchemy)
  • Alembic migrations support
  • Email module
  • Billing/subscription module
  • Projects/workspaces module
  • Remote registry support (GitHub)
  • PyPI publication
  • Module templates generator
  • Test generation for modules

๐Ÿค Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

๐Ÿ“„ License

MIT

๐Ÿ™ Inspiration

This project is inspired by:

  • shadcn-vue - Copy, don't install philosophy
  • FastAPI - Modern Python web framework
  • Typer - CLI framework by the creator of FastAPI

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fastapi_blocks_registry-0.2.0.tar.gz (76.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fastapi_blocks_registry-0.2.0-py3-none-any.whl (102.0 kB view details)

Uploaded Python 3

File details

Details for the file fastapi_blocks_registry-0.2.0.tar.gz.

File metadata

  • Download URL: fastapi_blocks_registry-0.2.0.tar.gz
  • Upload date:
  • Size: 76.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for fastapi_blocks_registry-0.2.0.tar.gz
Algorithm Hash digest
SHA256 d2c3c327c97e0dbdae31aca244bf38bcccd18674f8e0737b548ee6ad4649717f
MD5 118117170f06d51d3f5e9c4716e6025b
BLAKE2b-256 d2dfb3231d4ade3379a163c12e870233bcd030d680517019324443e4702a68a0

See more details on using hashes here.

File details

Details for the file fastapi_blocks_registry-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for fastapi_blocks_registry-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 dab38153ef95a9dd87d8a03090f18f5a6fda7b7f25c7c746429bcf423df38117
MD5 3cb2e019c983fd067675291e8175f5d5
BLAKE2b-256 5e2f6483781e503c708a9a6b27c2363fd62c1d4924bc27f29cb2121de9c9b14e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page