Skip to content

Tom-Laurent-TL/octopus

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

31 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ™ Octopus CLI

The AI-Friendly FastAPI Architecture Generator

Stop wrestling with project structure. Start building features.

Python 3.10+ FastAPI Typer UV


โšก Why Octopus?

Traditional FastAPI project setup:

mkdir my-api && cd my-api
touch main.py requirements.txt
# ... 30 minutes of boilerplate later ...

With Octopus:

octopus init
uv run fastapi dev
uv run pytest
# โœจ Production-ready FastAPI app in 2 seconds

๐ŸŽฏ Built for Modern Development

๐Ÿค– AI-First Design - Structure so clean that AI assistants understand it instantly
๐Ÿš€ Zero Config - No manual imports, no router mounting, no configuration hell
๐ŸŽจ Beautiful DX - Rich CLI with colors, trees, and helpful feedback
โ™พ๏ธ Infinite Nesting - Features inside features, as deep as you need
๐Ÿง… Onion Architecture - Clean layers: Router โ†’ Service โ†’ Entities/Schemas
๐Ÿ”„ Auto-Discovery - Add a feature, it's instantly available in your API
โœจ Path Syntax - Create nested features from anywhere: octopus add feature users/profile
๐Ÿ“ฆ Modern Stack - FastAPI + UV + Pydantic + Your choice of DB/Auth

๐ŸŽฌ See It In Action

# Create your app
octopus init
cd app

# Add features - they auto-mount to your API
octopus add feature users
octopus add feature products

# Add shared modules - instantly available everywhere
octopus add shared database
octopus add shared auth

# Navigate anywhere, add nested features
cd app/users
octopus add feature profile
octopus add feature settings

# Or use path syntax - no need to navigate!
octopus add feature products/inventory
octopus add feature users/profile/avatar

# Visualize your structure
octopus structure

Beautiful visualization:

๐Ÿ™ test_app/
โ””โ”€โ”€ ๐Ÿ  app/
    โ”œโ”€โ”€ โšก products/ (1 route)
    โ”‚   โ”œโ”€โ”€ GET /status Get status of the products feature.
    โ”‚   โ””โ”€โ”€ โšก inventory/ (1 route)
    โ”‚       โ””โ”€โ”€ GET /status Get status of the inventory feature.
    โ”œโ”€โ”€ โšก users/ (1 route)
    โ”‚   โ”œโ”€โ”€ GET /status Get status of the users feature.
    โ”‚   โ””โ”€โ”€ โšก profile/ (1 route)
    โ”‚       โ”œโ”€โ”€ GET /status Get status of the profile feature.
    โ”‚       โ””โ”€โ”€ โšก avatar/ (1 route)
    โ”‚           โ””โ”€โ”€ GET /status Get status of the avatar feature.
    โ”œโ”€โ”€ ๐Ÿ“ฆ auth/
    โ”œโ”€โ”€ ๐Ÿ“ฆ config/
    โ”œโ”€โ”€ ๐Ÿ“ฆ database/
    โ””โ”€โ”€ ๐Ÿ“ฆ routing/

๐Ÿ“Š Statistics: 5 features โ€ข 4 shared modules โ€ข 5 routers โ€ข 9 services

Run it:

# Run it
uv run fastapi dev

Result: Fully working API with routes:

  • GET /users/ โœ…
  • GET /users/profile/ โœ…
  • GET /users/settings/ โœ…
  • GET /products/ โœ…

No manual configuration. No imports. No routing setup. It just works.


๐Ÿ“– What Is Octopus?

Octopus is a production-ready CLI tool that generates well-structured FastAPI applications following a recursive fractal onion architecture.

๐Ÿค– AI-Friendly by Design - Created specifically to be understood by AI assistants while maintaining high structural quality. Clear separation of concerns, consistent patterns, and self-documenting structure make it ideal for AI-assisted development with GitHub Copilot, ChatGPT, or any coding assistant.

Every component (app, feature, shared module) can contain nested features and shared modules, creating a self-similar structure at any depth.

Key Features

โœจ Recursive Architecture - Features can contain sub-features infinitely deep
๐Ÿง… Onion Layer Pattern - Clear separation: Router โ†’ Service โ†’ Entities/Schemas
๐Ÿ”„ Auto-Discovery - Routers automatically mount without manual configuration
๐Ÿ“ฆ Context-Aware - Commands detect where you are in the project structure
๐ŸŽฏ Service Layer Pattern - Business logic isolated from routing and data layers
๐ŸŒŠ Cascading Shared Modules - App-level utilities available at any depth
๐Ÿ“š Comprehensive Docs - Every app includes architecture guides and examples
๐Ÿ”ง UV Package Manager - Modern Python dependency management
โšก Tab Completion - Shell autocompletion support for all commands


๐Ÿš€ Quick Start

Install

Requirements: Python 3.10+ and UV package manager

git clone https://github.com/Tom-Laurent-TL/octopus.git
cd octopus
uv venv && .venv\Scripts\Activate.ps1
uv pip install -e .

Create Your First App

octopus init --path your/path/my-project (will create the path if needed)
uv run fastapi dev

๐ŸŽ‰ That's it! Open http://localhost:8000 - your API is live!

Build Something Real

# Add user management
octopus add feature users
octopus add shared database

# Add nested features - two ways:
# 1. Navigate into the feature
cd app/users
octopus add feature authentication
octopus add feature profile

# 2. Or use path syntax from anywhere
octopus add feature users/settings
octopus add feature users/profile/avatar

# View your structure
octopus structure --routes

๐Ÿ“š Documentation

Every generated app includes comprehensive guides:

Guide What You'll Learn
ARCHITECTURE.md Complete architecture explanation, fractal structure, auto-discovery
BEST_PRACTICES.md Service patterns, dependency injection, error handling, security
EXAMPLES.md Full CRUD example, nested features, JWT auth, database setup
cd my-api
cat docs/ARCHITECTURE.md      # Start here!

๐ŸŽ“ Deep Dive

๐Ÿ“‹ Available Commands

Initialize Application

# Initialize a new FastAPI application with full architecture
octopus init

# Initialize in a specific directory
octopus init --path my-api

Creates a complete FastAPI project with:

  • Main app with config as a shared module
  • Comprehensive documentation (ARCHITECTURE.md, BEST_PRACTICES.md, EXAMPLES.md)
  • Test structure with example health check test
  • Placeholder TODO files for planning
  • UV package management setup
  • Ready-to-run FastAPI application

Add Feature

# Add a feature module (context-aware)
octopus add feature <NAME>

# Examples
octopus add feature users           # In app root - creates app/users/
octopus add feature hello_world     # Inside features/users/ - creates nested feature

# Or use path syntax from anywhere (no need to cd!)
octopus add feature users/profile   # Creates app/users/features/profile/
octopus add feature users/profile/settings  # Deeply nested!

Creates:

  • Router with automatic mounting
  • Service class for business logic
  • entities.py for database models
  • schemas.py for API models
  • Auto-imports for sibling shared modules (commented)
  • On-demand features/ and shared/ subdirectories

Add Shared Module

# Add a shared module (context-aware)
octopus add shared <NAME>

# Examples
octopus add shared database         # Creates shared/database/
octopus add shared auth            # Creates shared/auth/

Creates:

  • Service class pattern
  • Automatically updates all sibling features with import comments
  • Special handling for config module (includes Settings class)

Remove Feature or Shared Module

# Remove a feature (context-aware)
octopus remove feature <NAME>

# Remove a shared module (context-aware)
octopus remove shared <NAME>

# Examples
octopus remove feature users
octopus remove shared database

Safely removes features or shared modules, including:

  • All files and directories
  • Nested features and shared modules
  • Updates imports in sibling units

Display Project Structure

# Display a rich tree view of your project structure
octopus structure

# Show full structure with all files
octopus structure --full

# Show API routes
octopus structure --routes

Visualizes your Octopus project with:

  • Color-coded features and shared modules
  • Nesting depth indicators
  • Optional route mapping
  • File and directory counts
๐Ÿ—๏ธ Generated Project Structure
my-api/
โ”œโ”€โ”€ app/
โ”‚   โ”œโ”€โ”€ __init__.py          # Auto-discovery: mounts all features & shared
โ”‚   โ”œโ”€โ”€ main.py              # FastAPI app entry point
โ”‚   โ”œโ”€โ”€ router.py            # Root API router
โ”‚   โ”œโ”€โ”€ users/               # Feature (created with: octopus add feature users)
โ”‚   โ”‚   โ”œโ”€โ”€ __init__.py      # Auto-mounts sub-features & shared modules
โ”‚   โ”‚   โ”œโ”€โ”€ router.py        # Routes: /users/*
โ”‚   โ”‚   โ”œโ”€โ”€ service.py       # Business logic (UsersService class)
โ”‚   โ”‚   โ”œโ”€โ”€ entities.py      # Database models (SQLAlchemy)
โ”‚   โ”‚   โ”œโ”€โ”€ schemas.py       # API models (Pydantic)
โ”‚   โ”‚   โ”œโ”€โ”€ features/        # Nested features (created on-demand)
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ profile/     # Sub-feature: /users/profile/*
โ”‚   โ”‚   โ”‚       โ”œโ”€โ”€ router.py
โ”‚   โ”‚   โ”‚       โ”œโ”€โ”€ service.py
โ”‚   โ”‚   โ”‚       โ””โ”€โ”€ ...
โ”‚   โ”‚   โ””โ”€โ”€ shared/          # Feature-scoped shared modules
โ”‚   โ”‚       โ””โ”€โ”€ validation/  # Shared within users feature
โ”‚   โ””โ”€โ”€ shared/              # App-level shared modules
โ”‚       โ”œโ”€โ”€ config/          # Configuration (created by default)
โ”‚       โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚       โ”‚   โ””โ”€โ”€ service.py   # Settings class + ConfigService
โ”‚       โ”œโ”€โ”€ database/        # (created with: octopus add shared database)
โ”‚       โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚       โ”‚   โ””โ”€โ”€ service.py   # DatabaseService class
โ”‚       โ””โ”€โ”€ auth/            # (created with: octopus add shared auth)
โ”‚           โ”œโ”€โ”€ __init__.py
โ”‚           โ””โ”€โ”€ service.py   # AuthService class
โ”œโ”€โ”€ docs/
โ”‚   โ”œโ”€โ”€ ARCHITECTURE.md      # Complete architecture guide
โ”‚   โ”œโ”€โ”€ BEST_PRACTICES.md    # Coding standards & patterns
โ”‚   โ””โ”€โ”€ EXAMPLES.md          # Real-world implementation examples
โ”œโ”€โ”€ pyproject.toml           # UV package configuration
โ””โ”€โ”€ uv.lock                  # Locked dependencies

Key Architecture Principles

๐Ÿ” Recursive Structure - Every unit (app, feature) can contain:

  • features/ - Nested features (self-similar structure)
  • shared/ - Shared modules for that scope
  • Standard files: router.py, service.py, entities.py, schemas.py

๐Ÿง… Onion Layers (dependency direction: โ†’)

Router โ†’ Service โ†’ Entities/Schemas

๐Ÿš€ Auto-Discovery - No manual imports needed:

  • app/__init__.py auto-mounts all features
  • Feature __init__.py auto-mounts sub-features
  • Uses centralized auto_discover_routers() utility

๐ŸŒŠ Cascading Shared Modules - The killer feature:

app/shared/config/     # Automatically available to ALL features
app/shared/database/   # At ANY nesting depth

# Even deeply nested features have access (absolute imports):
# app/features/users/features/profile/features/avatar/__init__.py
# from app.shared.config.service import settings    โœ… Works!
# from app.shared.database.service import get_db    โœ… Works!

# No more unreadable relative imports like:
# from ......shared.config import settings  โŒ Avoid this!

๐Ÿ“ฆ Service Layer Pattern - All business logic in XxxService classes:

class UsersService:
    def get_all(self): ...
    def create(self, data): ...
๐Ÿ› ๏ธ Technology Stack

CLI

  • Typer - Modern CLI framework with beautiful terminal output and Rich integration
  • Rich - Beautiful terminal formatting, colors, and progress indicators
  • Python 3.10+ - Modern Python features

Generated Applications

  • FastAPI - High-performance async web framework
  • Pydantic - Data validation and settings management
  • Pydantic-Settings - Environment-based configuration
  • UV - Fast Python package manager
  • SQLAlchemy - ORM (in documentation examples)
  • Python-Jose - JWT tokens (in auth examples)
  • Bcrypt - Password hashing (in auth examples)
โšก Shell Autocompletion

Enable tab completion for your shell:

PowerShell:

octopus --install-completion powershell
# Restart your terminal

Bash:

octopus --install-completion bash
source ~/.bashrc

Zsh:

octopus --install-completion zsh
source ~/.zshrc

Fish:

octopus --install-completion fish
# Restart your terminal

After installation, press TAB to autocomplete commands, subcommands, and options!


โœ… What's Implemented

  • โœ… Full app scaffolding with recursive structure
  • โœ… Feature generation with Service class pattern
  • โœ… Shared module generation with auto-imports
  • โœ… Context-aware commands (detects current location)
  • โœ… Auto-discovery system (no manual router mounting)
  • โœ… Comprehensive documentation (3 markdown guides per app)
  • โœ… Test structure generation with examples
  • โœ… Remove commands for features and shared modules
  • โœ… Structure visualization with rich tree display
  • โœ… UV package management integration
  • โœ… Shell autocompletion support
  • โœ… On-demand directory creation (no empty folders)
  • โœ… Absolute imports (works at any nesting depth)

๐Ÿ”ฎ Roadmap

  • CI/CD templates - GitHub Actions, GitLab CI workflows
  • Database migration integration - Alembic setup and templates
  • Docker configuration - Dockerfile and docker-compose templates

๐Ÿ™‹ Getting Help

# General help
octopus --help

# Command-specific help
octopus init --help
octopus add --help
octopus add feature --help
octopus add shared --help
octopus remove --help
octopus structure --help

๐Ÿค Contributing

Contributions are welcome! Areas for contribution:

  • Enhanced test generation for features
  • Additional documentation templates
  • Database migration templates
  • Docker and CI/CD configurations
  • Improved error handling
  • Add tests for the CLI itself
  • Plugin system development

Built with ๐Ÿค– AI-First thinking | Made for developers who โค๏ธ clean architecture

โญ Star us on GitHub if Octopus makes your FastAPI development easier!

Report Bug โ€ข Request Feature โ€ข Contribute

๐Ÿ“„ License

MIT License - See LICENSE file for details


Built with โค๏ธ for FastAPI developers

About

The AI-Friendly FastAPI Architecture Generator

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages