Skip to main content

A modern FastAPI project scaffolding CLI tool

Project description

Forge Logo

PyPI version Python Versions Downloads Downloads per month License: MIT


Forge is a powerful command-line tool that helps you quickly bootstrap production-ready FastAPI projects with best practices, intelligent defaults, and a beautiful interactive interface.

โœจ Features

  • ๐ŸŽจ Beautiful Interactive UI - Stunning terminal interface with gradient colors and smooth animations
  • ๐Ÿš€ Smart Presets - Carefully curated presets for testing, dev tools, deployment, and monitoring
  • ๐Ÿ” Authentication Ready - Built-in support for JWT authentication (Basic & Complete)
  • ๐Ÿ—„๏ธ Database Flexibility - Support for PostgreSQL, MySQL, and SQLite with SQLModel/SQLAlchemy
  • ๐Ÿ”ด Redis Integration - Built-in Redis support for caching, sessions, and message queues
  • ๐Ÿ“‹ Background Tasks - Celery integration with Redis broker for async task processing
  • ๐Ÿ’พ Database Backup - Automated database backup tasks supporting all database types
  • ๐Ÿ“ฆ Modular Architecture - Choose only the features you need
  • ๐Ÿงช Testing Built-in - Pre-configured pytest with async support and coverage
  • ๐Ÿณ Docker Ready - Production-ready Docker and Docker Compose configurations
  • ๐Ÿ” Type Safe - Full type hints throughout generated code
  • โšก Async First - Optimized for FastAPI's async capabilities

๐Ÿ“‹ Requirements

  • Python 3.9+
  • uv (recommended) or pip

๐Ÿš€ Quick Start

Installation

From PyPI (Recommended)

pip install ningfastforge

Upgrade to Latest Version

If you already have Forge installed, upgrade to the latest version:

pip install --upgrade ningfastforge

๐Ÿ’ก Tip: Always use the latest version to get new features, bug fixes, and security updates!

From Source

# Clone the repository
git clone https://github.com/ning3739/forge.git
cd forge

# Install with uv (recommended)
uv sync

# Or with pip
pip install -e .

Verify Installation

Check that Forge is installed correctly and see the current version:

forge --version

Create Your First Project

# Interactive mode (recommended)
forge init

# Or specify project name
forge init my-awesome-api

# Non-interactive mode with defaults
forge init my-api --no-interactive

Run Your Project

cd my-awesome-api
uv sync
uv run uvicorn app.main:app --reload
# Visit:
http://127.0.0.1:8000/docs # docs
http://127.0.0.1:8000/redoc #redoc

๐Ÿ—๏ธ Architecture

Forge follows a "Configuration-First" design principle with a dynamic generator system:

  1. Init Command collects user preferences interactively
  2. Configuration File (.forge/config.json) is saved first
  3. Dynamic Generator System automatically discovers and executes generators based on configuration

Dynamic Generator System

Forge uses a decorator-based system for automatic generator discovery and management:

@Generator(
    category="model",
    priority=40,
    requires=["DatabaseConnectionGenerator"],
    enabled_when=lambda c: c.has_auth()
)
class UserModelGenerator:
    def generate(self):
        # Generate user model code

Benefits:

  • โœ… Automatic generator discovery - no manual registration needed
  • โœ… Dependency resolution - generators execute in correct order
  • โœ… Conditional execution - only enabled generators run
  • โœ… Easy extensibility - add new generators by creating files

This separation ensures:

  • โœ… Configuration persistence and traceability
  • โœ… Clear separation of concerns
  • โœ… Easy project regeneration and updates
  • โœ… Configuration sharing and templates
  • โœ… Modular and maintainable codebase

๐ŸŽฏ Configuration Options

Database Options

  • PostgreSQL (Recommended) - Robust, feature-rich, excellent for production
  • MySQL - Popular, widely supported relational database
  • SQLite - Lightweight, serverless database perfect for development and small projects

ORM Support

  • SQLModel (Recommended) - Modern, type-safe ORM built on SQLAlchemy and Pydantic
  • SQLAlchemy - Mature and powerful ORM with extensive features

Authentication & Security

Authentication Options

  • Complete JWT Auth (Recommended) - Full-featured authentication system
    • Login & Register
    • Email Verification
    • Password Reset (Forgot Password)
    • Email Service (SMTP)
    • Refresh Token
  • Basic JWT Auth - Simple authentication
    • Login & Register only
    • Optional Refresh Token

Security Features

  • CORS (Configurable)
  • Rate Limiting (Built-in decorator - auto-included)
  • Input Validation (Pydantic - auto-included)
  • Password Hashing (bcrypt - auto-included with auth)
  • SQL Injection Protection (ORM - auto-included)
  • XSS Protection (FastAPI - auto-included)

Core Features

All projects include:

  • Logging - Structured logging with Loguru (automatically included)
  • API Documentation - Swagger UI and ReDoc (automatically included)
  • Health Check - Basic health check endpoint (automatically included)
  • Rate Limiting - Decorator-based rate limiting for API protection (automatically included)

Background Tasks & Caching

  • Redis - In-memory data structure store for caching, sessions, and message queues
  • Celery - Distributed task queue for background job processing
  • Database Backup - Automated backup tasks supporting MySQL, PostgreSQL, and SQLite
  • Task Scheduling - Cron-based task scheduling with Celery Beat (production)

Development Tools

  • Standard (Recommended) - Black (formatter) + Ruff (linter)
  • None - Skip dev tools

Testing Setup

When you enable testing, Forge generates:

  • pytest - Testing framework with async support
  • httpx - HTTP client for testing
  • pytest-cov - Code coverage
  • pytest-asyncio - Async test support

Generated Test Files:

  • tests/conftest.py - Pytest configuration with database fixtures
  • tests/test_main.py - Tests for main API endpoints (health check, docs)
  • tests/api/test_auth.py - Authentication endpoint tests
  • tests/api/test_users.py - User endpoint tests

Running Tests:

# Run all tests
pytest

# Run with coverage
pytest --cov=app tests/

# Run specific test file
pytest tests/test_main.py

# Run with verbose output
pytest -v

Deployment

  • Docker - Dockerfile and docker-compose.yml
  • Includes database service configuration
  • Production-ready setup

๐Ÿ“ Generated Project Structure

my-awesome-api/
โ”œโ”€โ”€ app/
โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚   โ”œโ”€โ”€ main.py              # FastAPI application entry point
โ”‚   โ”œโ”€โ”€ core/
โ”‚   โ”‚   โ”œโ”€โ”€ config/          # Configuration management
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ base.py      # Base configuration
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ settings.py  # Settings aggregator
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ modules/     # Config modules (app, database, jwt, cors, email, logger, redis, celery)
โ”‚   โ”‚   โ”œโ”€โ”€ database/        # Database connection
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ connection.py
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ dependencies.py
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ postgresql.py / mysql.py / sqlite.py
โ”‚   โ”‚   โ”œโ”€โ”€ redis.py         # Redis connection manager (if Redis enabled)
โ”‚   โ”‚   โ”œโ”€โ”€ celery.py        # Celery configuration (if Celery enabled)
โ”‚   โ”‚   โ”œโ”€โ”€ deps.py          # Global dependencies
โ”‚   โ”‚   โ”œโ”€โ”€ logger.py        # Logging configuration
โ”‚   โ”‚   โ””โ”€โ”€ security.py      # Security utilities (password hashing, JWT)
โ”‚   โ”œโ”€โ”€ decorators/          # Custom decorators
โ”‚   โ”‚   โ””โ”€โ”€ rate_limit.py    # Rate limiting decorator
โ”‚   โ”œโ”€โ”€ models/              # Database models
โ”‚   โ”‚   โ”œโ”€โ”€ user.py
โ”‚   โ”‚   โ””โ”€โ”€ token.py         # (if refresh token enabled)
โ”‚   โ”œโ”€โ”€ schemas/             # Pydantic schemas
โ”‚   โ”‚   โ”œโ”€โ”€ user.py
โ”‚   โ”‚   โ””โ”€โ”€ token.py
โ”‚   โ”œโ”€โ”€ crud/                # CRUD operations
โ”‚   โ”‚   โ”œโ”€โ”€ user.py
โ”‚   โ”‚   โ””โ”€โ”€ token.py         # (if refresh token enabled)
โ”‚   โ”œโ”€โ”€ services/            # Business logic
โ”‚   โ”‚   โ””โ”€โ”€ auth.py
โ”‚   โ”œโ”€โ”€ tasks/               # Celery tasks (if Celery enabled)
โ”‚   โ”‚   โ”œโ”€โ”€ __init__.py      # Task exports
โ”‚   โ”‚   โ””โ”€โ”€ backup_database_task.py  # Database backup task
โ”‚   โ”œโ”€โ”€ routers/             # API routes
โ”‚   โ”‚   โ””โ”€โ”€ v1/              # API version 1
โ”‚   โ”‚       โ”œโ”€โ”€ __init__.py  # Router aggregator
โ”‚   โ”‚       โ”œโ”€โ”€ auth.py
โ”‚   โ”‚       โ””โ”€โ”€ users.py
โ”‚   โ””โ”€โ”€ utils/               # Utility functions
โ”‚       โ””โ”€โ”€ email.py         # (if complete auth enabled)
โ”œโ”€โ”€ tests/                   # Test files (if enabled)
โ”‚   โ”œโ”€โ”€ conftest.py          # Pytest configuration and fixtures
โ”‚   โ”œโ”€โ”€ test_main.py         # Main API endpoint tests
โ”‚   โ”œโ”€โ”€ api/
โ”‚   โ”‚   โ”œโ”€โ”€ test_auth.py     # Authentication tests
โ”‚   โ”‚   โ””โ”€โ”€ test_users.py    # User endpoint tests
โ”‚   โ””โ”€โ”€ unit/                # Unit tests directory
โ”œโ”€โ”€ alembic/                 # Database migrations (if enabled)
โ”‚   โ”œโ”€โ”€ versions/            # Migration versions
โ”‚   โ”œโ”€โ”€ env.py               # Alembic environment
โ”‚   โ”œโ”€โ”€ script.py.mako       # Migration template
โ”‚   โ””โ”€โ”€ README.md
โ”œโ”€โ”€ static/                  # Static files
โ”‚   โ””โ”€โ”€ email_template/      # Email templates (if complete auth)
โ”‚       โ”œโ”€โ”€ base.html
โ”‚       โ”œโ”€โ”€ verification.html
โ”‚       โ”œโ”€โ”€ password_reset.html
โ”‚       โ””โ”€โ”€ welcome.html
โ”œโ”€โ”€ secret/                  # Environment files
โ”‚   โ”œโ”€โ”€ .env.example         # Environment variables template
โ”‚   โ”œโ”€โ”€ .env.development     # Development environment
โ”‚   โ””โ”€โ”€ .env.production      # Production environment
โ”œโ”€โ”€ docker-compose.yml       # Docker Compose configuration (if enabled)
โ”œโ”€โ”€ Dockerfile               # Docker configuration (if enabled)
โ”œโ”€โ”€ .dockerignore            # Docker ignore file (if enabled)
โ”œโ”€โ”€ .gitignore               # Git ignore file
โ”œโ”€โ”€ pyproject.toml           # Project dependencies
โ”œโ”€โ”€ uv.lock                  # UV lock file
โ””โ”€โ”€ README.md                # Project documentation

๐ŸŽจ Smart Features

Intelligent Defaults

  • Database: PostgreSQL with SQLModel
  • Migration: Alembic enabled
  • Authentication: Complete JWT Auth with Refresh Token
  • Caching: Redis enabled
  • Background Tasks: Celery with Redis broker
  • Security: CORS enabled
  • Dev Tools: Black + Ruff
  • Testing: pytest with coverage
  • Deployment: Docker + Docker Compose

Technology Recommendations

  • PostgreSQL for database (production-ready, feature-rich)
  • SQLModel for ORM (modern, type-safe, FastAPI-friendly)
  • JWT for authentication (stateless, scalable, API-friendly)
  • Redis for caching and message queues (fast, reliable)
  • Celery for background tasks (mature, scalable)
  • Alembic for migrations (industry standard)

๐Ÿ› ๏ธ Commands

forge init

Initialize a new FastAPI project with interactive prompts.

# Interactive mode
forge init

# Specify project name
forge init my-project

# Non-interactive mode (uses defaults)
forge init my-project --no-interactive

forge --version

Show the current version of Forge.

forge --version
# or
forge -v

๐ŸŽฏ Best Practices

For API Projects

โœ… PostgreSQL + SQLModel
โœ… Complete JWT Auth
โœ… Redis + Celery
โœ… CORS enabled
โœ… Black + Ruff
โœ… pytest with coverage
โœ… Docker deployment

For Simple Projects

โœ… SQLite + SQLModel
โœ… Basic JWT Auth (or no auth)
โœ… CORS enabled
โœ… Docker deployment

๐Ÿ“‚ Project Structure

Forge/
โ”œโ”€โ”€ commands/              # CLI command modules
โ”‚   โ”œโ”€โ”€ __init__.py       # Command exports
โ”‚   โ””โ”€โ”€ init.py           # Project initialization command
โ”œโ”€โ”€ core/                 # Core business logic
โ”‚   โ”œโ”€โ”€ decorators/       # Decorator system
โ”‚   โ”‚   โ””โ”€โ”€ generator.py  # @Generator decorator and registry
โ”‚   โ”œโ”€โ”€ config_reader.py  # Configuration file reader
โ”‚   โ”œโ”€โ”€ project_generator.py  # Project generator
โ”‚   โ”œโ”€โ”€ generators/       # Code generators
โ”‚   โ”‚   โ”œโ”€โ”€ structure.py  # Project structure generator
โ”‚   โ”‚   โ”œโ”€โ”€ orchestrator.py  # Dynamic generator coordinator
โ”‚   โ”‚   โ”œโ”€โ”€ configs/      # Config file generators
โ”‚   โ”‚   โ”œโ”€โ”€ deployment/   # Deployment config generators
โ”‚   โ”‚   โ””โ”€โ”€ templates/    # Application code generators
โ”‚   โ””โ”€โ”€ utils/            # Utility functions
โ”œโ”€โ”€ ui/                   # User interface components
โ”‚   โ”œโ”€โ”€ colors.py         # Color management system
โ”‚   โ”œโ”€โ”€ components.py     # UI components
โ”‚   โ””โ”€โ”€ logo.py           # Logo rendering
โ”œโ”€โ”€ main.py               # CLI entry point
โ”œโ”€โ”€ pyproject.toml        # Project configuration
โ””โ”€โ”€ README.md             # This file

Key Components

  • @Generator Decorator - Automatic generator registration system
  • orchestrator.py - Discovers and executes generators in correct order
  • 40+ Generators - Each responsible for specific files/features
  • Configuration-First - All decisions driven by .forge/config.json

๐Ÿค Contributing

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

Development Setup

# Clone the repository
git clone https://github.com/ning3739/forge.git
cd forge

# Install dependencies
uv sync

# Test build
./scripts/test_build.sh

Publishing

Automated Release Process

The project uses automated publishing via GitHub Actions:

  1. Update version in pyproject.toml
  2. Update CHANGELOG.md with changes
  3. Commit and push:
    git add pyproject.toml CHANGELOG.md
    git commit -m "Bump version to 0.1.1"
    git push
    
  4. Create and push tag:
    git tag v0.1.1
    git push origin v0.1.1
    
  5. Automatic process:
    • โœ… CI tests run on all Python versions
    • โœ… Package is built and validated
    • โœ… Published to PyPI automatically
    • โœ… GitHub Release is created

See PUBLISHING.md for detailed instructions.

๐Ÿ“ License

MIT License

๐ŸŽ‰ Changelog

See CHANGELOG.md for version history and release notes.

๐Ÿ™ Acknowledgments

Built with:

๐Ÿ“ง Support

For issues, questions, or suggestions, please open an issue on GitHub.


Made with โค๏ธ for the FastAPI community

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

ningfastforge-0.1.6.tar.gz (102.2 kB view details)

Uploaded Source

Built Distribution

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

ningfastforge-0.1.6-py3-none-any.whl (125.4 kB view details)

Uploaded Python 3

File details

Details for the file ningfastforge-0.1.6.tar.gz.

File metadata

  • Download URL: ningfastforge-0.1.6.tar.gz
  • Upload date:
  • Size: 102.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for ningfastforge-0.1.6.tar.gz
Algorithm Hash digest
SHA256 a6f3c7343b0aee31e4141c50383edf5ee55c7da8f73498619c179946568e0af2
MD5 1dc35192c2b4e55a26c0ce29456d3913
BLAKE2b-256 a43d7e4a0f4512163ddfd0c478b087508550de97728a4cba7945c69456f4cf97

See more details on using hashes here.

Provenance

The following attestation bundles were made for ningfastforge-0.1.6.tar.gz:

Publisher: publish.yml on ning3739/forge

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ningfastforge-0.1.6-py3-none-any.whl.

File metadata

  • Download URL: ningfastforge-0.1.6-py3-none-any.whl
  • Upload date:
  • Size: 125.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for ningfastforge-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 f96cf8bd1fa0ae279101de50871e84daa4b8e5cba8a1d4bf6bcfb8650a11e04e
MD5 76d4474c4ccc64938688ccfbb3070ae6
BLAKE2b-256 89f8db54ce22b4eab5a486b59fec05e8024219af734fbcfd1f4492b7902bb3ed

See more details on using hashes here.

Provenance

The following attestation bundles were made for ningfastforge-0.1.6-py3-none-any.whl:

Publisher: publish.yml on ning3739/forge

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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