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 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
โ”œโ”€โ”€ 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
  • 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 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.1.3.tar.gz (45.8 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.1.3-py3-none-any.whl (59.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: fastapi_blocks_registry-0.1.3.tar.gz
  • Upload date:
  • Size: 45.8 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.1.3.tar.gz
Algorithm Hash digest
SHA256 8f560150355cb04848d4069c2923a3ca514ba5f08af241b6d8c99429ff780ad6
MD5 3a37ccfbcd8e1923a0f3c09b08459df4
BLAKE2b-256 a419b69a15fba7d37e18f706d5e36b8b92d530e7658d6a840d43ec34bb2c02c9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fastapi_blocks_registry-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 c2933b1c19fbd9620a4567d8136abf09917627d3201fc2013cf25cac994e5221
MD5 08a766a0e54bd1db67275a5d1cfd1210
BLAKE2b-256 9eb53b29ce142b80648822b923f25d1b86b91605c708bcb946c200ba0172f00e

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