Skip to main content

A CLI for generating modular FastAPI projects with environment and dependency management

Project description

FasCraft ๐Ÿš€

PyPI version Python 3.10+ License: MIT

FasCraft is a powerful CLI tool designed to streamline the creation and management of modular FastAPI projects. It eliminates boilerplate code and enforces best practices from the start, allowing developers to focus on business logic.

โœจ Features

  • ๐Ÿš€ Project Generation - Create new FastAPI projects with domain-driven architecture
  • ๐Ÿ”ง Module Management - Generate, list, update, and remove domain modules
  • ๐Ÿ—๏ธ Domain-Driven Design - Self-contained modules with models, schemas, services, and routers
  • โš™๏ธ Smart Configuration - Automatic project detection and configuration management
  • ๐Ÿ›ก๏ธ Safety First - Confirmations, backups, and rollback capabilities
  • ๐ŸŽจ Rich CLI - Beautiful tables, color coding, and progress indicators
  • ๐Ÿงช Production Ready - Comprehensive testing and error handling
  • ๐ŸŒ Environment Management - Complete .env templates with database configurations
  • ๐Ÿ“ฆ Dependency Management - Production-ready requirements files for development and production
  • ๐Ÿ—„๏ธ Database Support - MongoDB, PostgreSQL, MySQL, and SQLite configurations
  • โšก Service Integration - Redis, Celery, JWT, and CORS configurations
  • ๐Ÿ” Project Analysis - Analyze existing projects and suggest improvements
  • ๐Ÿš€ Migration Tools - Convert legacy projects to domain-driven architecture
  • โš™๏ธ Configuration Management - Project-specific FasCraft settings via .fascraft.toml
  • ๐Ÿ”„ Base Router Architecture - Centralized router management for all modules
  • ๐Ÿ“ Git Integration - Automatic .gitignore file generation for new projects

๐Ÿš€ Quick Start

Installation

# Install from PyPI
pip install fascraft

# Or install from source
git clone https://github.com/LexxLuey/fascraft.git
cd fascraft
poetry install

Note: FasCraft itself uses Poetry for development, but the projects it generates support both Poetry and pip!

Create Your First Project

# Generate a new FastAPI project
fascraft new my-awesome-api

# Navigate to your project
cd my-awesome-api

# Install dependencies (choose your preferred method)
# Option 1: Using Poetry (recommended)
poetry install

# Option 2: Using pip
pip install -r requirements.txt

# Start the development server
uvicorn main:app --reload

๐Ÿ’ก Pro Tip: Your generated project includes both Poetry and pip configurations, so you can use whichever dependency manager you prefer!

โš ๏ธ Important: You must install dependencies before running the FastAPI server. The generated project structure is ready, but dependencies need to be installed first.

Add Domain Modules

# Generate a customers module
fascraft generate customers

# Generate a products module
fascraft generate products

# Your project now has:
# โ”œโ”€โ”€ customers/
# โ”‚   โ”œโ”€โ”€ models.py
# โ”‚   โ”œโ”€โ”€ schemas.py
# โ”‚   โ”œโ”€โ”€ services.py
# โ”‚   โ”œโ”€โ”€ routers.py
# โ”‚   โ””โ”€โ”€ tests/
# โ””โ”€โ”€ products/
#     โ”œโ”€โ”€ models.py
#     โ”œโ”€โ”€ schemas.py
#     โ”œโ”€โ”€ services.py
#     โ”œโ”€โ”€ routers.py
#     โ””โ”€โ”€ tests/

Advanced Project Management

# Analyze your project structure and get recommendations
fascraft analyze

# Migrate legacy projects to domain-driven architecture
fascraft migrate

# Manage project configuration
fascraft config show
fascraft config create
fascraft config update project.name "new-name"
fascraft config validate

๐Ÿ—๏ธ Architecture & Stability

FasCraft is built on a stable, well-designed architecture that prioritizes reliability and maintainability:

  • ๐Ÿ”’ Stable Core: The CLI architecture and template system are designed to last
  • ๐Ÿ›๏ธ Modular Design: Clean separation of concerns with extensible command structure
  • ๐Ÿ”„ Base Router System: Centralized router management for consistent API structure
  • ๐Ÿ“ Domain-Driven: Self-contained modules with clear boundaries
  • โš™๏ธ Configuration First: Project-specific settings via .fascraft.toml
  • ๐Ÿงช Comprehensive Testing: 100% test coverage ensures reliability
  • ๐Ÿ“ Git Ready: Automatic .gitignore generation for immediate version control

Our commitment: New features extend the existing architecture rather than replacing it, ensuring your projects remain stable and maintainable.

๐Ÿš€ Complete Workflow Example

Here's the complete workflow from project creation to running your API:

# 1. Create new project
fascraft new my-ecommerce-api

# 2. Navigate to project directory
cd my-ecommerce-api

# 3. Install dependencies (choose one)
poetry install                    # Poetry (recommended)
# OR
pip install -r requirements.txt   # pip

# 4. Start development server
uvicorn main:app --reload

# 5. Add domain modules as needed
fascraft generate products
fascraft generate orders

# 6. Analyze your project structure
fascraft analyze

# 7. Manage project configuration
fascraft config show

๐Ÿ“š Available Commands

Project Management

fascraft new <project_name>          # Create new FastAPI project
fascraft generate <module_name>      # Add new domain module

Advanced Project Management (Phase 3)

fascraft analyze [path]              # Analyze project structure and get recommendations
fascraft migrate [path]              # Convert legacy projects to domain-driven architecture
fascraft config <action> [path]      # Manage project configuration (.fascraft.toml)

Module Management

fascraft list                        # List all modules with health status
fascraft remove <module_name>        # Remove module with safety confirmations
fascraft update <module_name>        # Update module templates with backups

Utility Commands

fascraft hello [name]                # Say hello
fascraft version                     # Show version
fascraft --help                      # Show all available commands

๐Ÿ—๏ธ Project Structure

FasCraft generates projects with a clean, domain-driven architecture and centralized router management:

my-awesome-api/
โ”œโ”€โ”€ config/                           # Configuration and shared utilities
โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚   โ”œโ”€โ”€ settings.py                   # Pydantic settings with environment support
โ”‚   โ”œโ”€โ”€ database.py                   # SQLAlchemy configuration
โ”‚   โ”œโ”€โ”€ exceptions.py                 # Custom HTTP exceptions
โ”‚   โ””โ”€โ”€ middleware.py                 # CORS and timing middleware
โ”œโ”€โ”€ routers/                          # Centralized router management
โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚   โ””โ”€โ”€ base.py                       # Base router with common prefix (/api/v1)
โ”œโ”€โ”€ customers/                        # Domain module (self-contained)
โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚   โ”œโ”€โ”€ models.py                     # SQLAlchemy models
โ”‚   โ”œโ”€โ”€ schemas.py                    # Pydantic schemas
โ”‚   โ”œโ”€โ”€ services.py                   # Business logic
โ”‚   โ”œโ”€โ”€ routers.py                    # FastAPI routes (no hardcoded prefix)
โ”‚   โ””โ”€โ”€ tests/                        # Module-specific tests
โ”œโ”€โ”€ products/                         # Another domain module
โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚   โ”œโ”€โ”€ models.py
โ”‚   โ”œโ”€โ”€ schemas.py
โ”‚   โ”œโ”€โ”€ services.py
โ”‚   โ”œโ”€โ”€ routers.py
โ”‚   โ””โ”€โ”€ tests/
โ”œโ”€โ”€ main.py                           # FastAPI application entry point
โ”œโ”€โ”€ pyproject.toml                    # Poetry configuration with all dependencies
โ”œโ”€โ”€ .env                              # Environment configuration (database, Redis, etc.)
โ”œโ”€โ”€ .env.sample                       # Sample environment file
โ”œโ”€โ”€ requirements.txt                  # Core dependencies (pip)
โ”œโ”€โ”€ requirements.dev.txt              # Development dependencies (pip)
โ”œโ”€โ”€ requirements.prod.txt             # Production dependencies (pip)
โ”œโ”€โ”€ .gitignore                        # Git ignore file (automatically generated)
โ”œโ”€โ”€ fascraft.toml                     # FasCraft project configuration
โ””โ”€โ”€ README.md                         # Project documentation

๐ŸŒ Environment & Dependency Management

FasCraft generates comprehensive environment and dependency files for production-ready applications:

Environment Configuration

  • .env - Configure your environment like a true 12 factor app that it is.
  • .env.sample - Template for team collaboration. Complete environment configuration with database connections
  • Database Support - MongoDB, PostgreSQL, MySQL, SQLite configurations
  • Service Integration - Redis, Celery, JWT, CORS settings
  • Production Ready - Optimized for different deployment environments

Dependency Management

FasCraft generates projects with dual dependency management - you can use either Poetry or pip!

  • pyproject.toml - Complete Poetry configuration with all dependencies and development tools
  • requirements.txt - Core production dependencies for pip users
  • requirements.dev.txt - Development tools and testing frameworks for pip users
  • requirements.prod.txt - Production-optimized dependencies with Gunicorn for pip users

Quick Setup

Option 1: Using Poetry (Recommended)

# Install all dependencies (production + development)
poetry install

# Install only production dependencies
poetry install --only main

# Install with specific groups
poetry install --with dev,prod

Option 2: Using pip

# Install production dependencies
pip install -r requirements.txt

# Install development dependencies
pip install -r requirements.dev.txt

# Install production dependencies
pip install -r requirements.prod.txt

๐Ÿ“ฆ Dual Dependency Management

FasCraft generates projects with both Poetry and pip support, giving you the flexibility to choose your preferred dependency manager:

๐ŸŽฏ Poetry Configuration (pyproject.toml)

  • Complete dependency management with version pinning
  • Development tools (pytest, black, ruff, mypy, etc.)
  • Production dependencies (Gunicorn, database drivers, etc.)
  • Group-based installation (main, dev, prod)
  • Lock file for reproducible builds

๐Ÿ”ง pip Configuration (requirements files)

  • requirements.txt - Core production dependencies
  • requirements.dev.txt - Development and testing tools
  • requirements.prod.txt - Production-optimized with Gunicorn
  • Simple installation with standard pip commands
  • Easy deployment to environments without Poetry

๐Ÿš€ Why Both?

  • Team flexibility - Some developers prefer Poetry, others prefer pip
  • Deployment options - CI/CD pipelines often work better with requirements files
  • Learning curve - New developers can start with pip, graduate to Poetry
  • Production ready - Both approaches are production-tested

๐Ÿ”ง Module Management

List Modules

fascraft list

Shows a beautiful table with:

  • Module health status (โœ… Healthy / โš ๏ธ Incomplete)
  • File counts and test coverage
  • Module size and last modified date

๐Ÿš€ Advanced Project Management

FasCraft now includes powerful tools for analyzing, migrating, and configuring existing FastAPI projects:

๐Ÿ” Project Analysis (fascraft analyze)

Analyze your project structure and get intelligent recommendations:

# Analyze current directory
fascraft analyze

# Analyze specific project
fascraft analyze /path/to/project

# What you get:
# ๐Ÿ“Š Project Overview - Structure analysis and module count
# ๐Ÿ—๏ธ Structure Analysis - Configuration and architecture assessment
# ๐Ÿ’ก Recommendations - Specific improvements for your project
# ๐Ÿ“ฆ Missing Components - What could be added for better structure

Example Output:

๐Ÿ“Š Project Overview
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ Property        โ”‚ Value   โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ Project Name    โ”‚ my-api  โ”‚
โ”‚ Domain Modules  โ”‚ 3       โ”‚
โ”‚ Config Files    โ”‚ 2       โ”‚
โ”‚ Router Includes โ”‚ 5       โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

๐Ÿ’ก Recommendations
โ€ข Consider adding FasCraft configuration for better project management
โ€ข Use 'fascraft generate <module_name>' to create additional domain modules

๐Ÿ”„ Project Migration (fascraft migrate)

Convert legacy FastAPI projects to modern domain-driven architecture:

# Migrate current directory
fascraft migrate

# Migrate with backup
fascraft migrate --backup

# What happens:
# 1. ๐Ÿ” Analysis - Detects current project structure
# 2. ๐Ÿ’พ Backup - Creates timestamped backup (optional)
# 3. ๐Ÿ—๏ธ Restructure - Creates base router and domain modules
# 4. โš™๏ธ Configuration - Generates fascraft.toml
# 5. ๐Ÿ“ Summary - Shows what was migrated

Migration Features:

  • Flat Structure Detection - Identifies projects with separate models/, schemas/, routers/ directories
  • Automatic Restructuring - Converts to domain-driven modules
  • Base Router Creation - Implements centralized router management
  • Configuration Generation - Creates project-specific settings

โš™๏ธ Configuration Management (fascraft config)

Manage your project's FasCraft configuration:

# Show current configuration
fascraft config show

# Create new configuration
fascraft config create

# Update specific settings
fascraft config update project.name "new-name"
fascraft config update router.base_prefix "/api/v2"

# Validate configuration
fascraft config validate

Configuration Sections:

[project]
name = "my-api"
version = "0.1.0"

[router]
base_prefix = "/api/v1"
health_endpoint = true

[database]
type = "postgresql"
pool_size = 20

[modules]
auto_include = true
prefix_strategy = "plural"

๐Ÿ”„ Base Router Architecture

FasCraft now implements a centralized router system that provides:

  • Consistent API Structure - All endpoints use /api/v1 prefix
  • Automatic Module Integration - New modules are automatically added to the base router
  • Health Check Endpoint - Built-in /api/v1/health endpoint
  • Clean Module Routers - Individual module routers focus on business logic, not URL structure

How It Works:

  1. Base Router (/routers/base.py) manages all module routers
  2. Module Routers contain only business logic, no hardcoded prefixes
  3. Automatic Integration - fascraft generate automatically updates the base router
  4. Consistent Structure - All endpoints follow the same pattern

Example API Structure:

/api/v1/health                    # Health check
/api/v1/customers                # Customer endpoints
/api/v1/products                 # Product endpoints
/api/v1/orders                   # Order endpoints

๐Ÿ’ก Practical Examples

Getting Started with Poetry

# Create and navigate to your project
fascraft new my-api
cd my-api

# Install dependencies
poetry install

# Start development server
uvicorn main:app --reload

Complete Development Workflow

# 1. Create project
fascraft new ecommerce-api
cd ecommerce-api

# 2. Install dependencies
poetry install

# 3. Generate domain modules
fascraft generate users
fascraft generate products
fascraft generate orders

# 4. Analyze project structure
fascraft analyze

# 5. Customize configuration
fascraft config update project.name "E-Commerce API"
fascraft config update router.base_prefix "/api/v2"

# 6. Start development
uvicorn main:app --reload

Migrating Legacy Projects

# Navigate to existing FastAPI project
cd /path/to/legacy-project

# Analyze current structure
fascraft analyze

# Migrate to domain-driven architecture
fascraft migrate --backup

# Verify migration
fascraft analyze

Module Management

# List all modules with health status
fascraft list

# Remove a module (with confirmation)
fascraft remove old-module

# Update module templates
fascraft update users

๐Ÿ”ง Configuration Reference

Environment Variables

FasCraft generates comprehensive environment configuration:

# Database Configuration
DATABASE_URL=postgresql://user:pass@localhost/dbname
DATABASE_POOL_SIZE=20

# Redis Configuration
REDIS_URL=redis://localhost:6379

# JWT Configuration
JWT_SECRET_KEY=your-secret-key
JWT_ALGORITHM=HS256

# CORS Configuration
CORS_ORIGINS=["http://localhost:3000"]

FasCraft Configuration (.fascraft.toml)

[project]
name = "my-api"
version = "0.1.0"
description = "A FastAPI project generated with FasCraft"

[router]
base_prefix = "/api/v1"
health_endpoint = true
auto_include_modules = true

[database]
type = "postgresql"
pool_size = 20
echo_queries = false

[modules]
prefix_strategy = "plural"
auto_generate_tests = true

[development]
debug = true
reload = true
host = "0.0.0.0"
port = 8000

[production]
debug = false
reload = false
workers = 4

๐ŸŽฏ Use Cases

  • ๐Ÿš€ Rapid Prototyping - Get a production-ready API structure in seconds
  • ๐Ÿข Enterprise Applications - Consistent architecture across teams
  • ๐Ÿ“š Learning FastAPI - Best practices built into every template
  • ๐Ÿ”„ Legacy Migration - Convert existing projects to domain-driven design
  • ๐Ÿ‘ฅ Team Onboarding - Standardized project structure for new developers

๐Ÿ› ๏ธ Development

Prerequisites

  • Python 3.8+
  • Poetry (for dependency management) - Optional for generated projects
  • FastAPI knowledge (for customizing generated code)

Setup Development Environment

git clone https://github.com/LexxLuey/fascraft.git
cd fascraft
poetry install
poetry run pytest  # Run all tests

Running Tests

# Run all tests
poetry run pytest

# Run with coverage
poetry run pytest --cov=fascraft

# Run specific test file
poetry run pytest tests/test_generate_command.py

๐Ÿ“– Documentation

  • ROADMAP.md - Development phases and current status (Phase 3: Advanced Project Detection next)
  • CONTRIBUTING.md - How to contribute to FasCraft
  • CHANGELOG.md - Version history and changes

๐Ÿค Contributing

We welcome contributions! Please see our Contributing Guide for details on:

  • Code style and standards
  • Testing requirements
  • Pull request process
  • Development setup

๐Ÿ“„ License

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

๐Ÿ™ Acknowledgments

  • FastAPI - The amazing web framework that makes this possible
  • Typer - Beautiful CLI framework
  • Rich - Rich text and beautiful formatting
  • Jinja2 - Powerful templating engine

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

fascraft-0.3.2.tar.gz (32.7 kB view details)

Uploaded Source

Built Distribution

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

fascraft-0.3.2-py3-none-any.whl (51.4 kB view details)

Uploaded Python 3

File details

Details for the file fascraft-0.3.2.tar.gz.

File metadata

  • Download URL: fascraft-0.3.2.tar.gz
  • Upload date:
  • Size: 32.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.4 CPython/3.13.3 Windows/10

File hashes

Hashes for fascraft-0.3.2.tar.gz
Algorithm Hash digest
SHA256 9ca65a1257a36a906f003ffbdee659951cf5aad30b21a77c9d54fe9a8e62dfb6
MD5 afacf326e7196b9008cffae772ca57b4
BLAKE2b-256 70203246ed2c8211a06cefc7e63ad4cfc75c6d78197a28c782387597a666c314

See more details on using hashes here.

File details

Details for the file fascraft-0.3.2-py3-none-any.whl.

File metadata

  • Download URL: fascraft-0.3.2-py3-none-any.whl
  • Upload date:
  • Size: 51.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.4 CPython/3.13.3 Windows/10

File hashes

Hashes for fascraft-0.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 41f0ed40850ac54d7cf4ac8d3b6cb43a65a0f4cbf7285256bfdeb1769ce55513
MD5 b7d0ad45b99b3ca0dcd13cc2670d3e74
BLAKE2b-256 a81d70c050aec87b4336e70d36861a115c27a4aae0b591c9e9de771fd252037e

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