How bnbong/fastapi-fastkit works
Project type and purpose
• FastAPI-fastkit is a CLI tool (Python package) that scaffolds new FastAPI projects, manages virtual environments, installs dependencies, and provides template-based project creation.
• Its key features (from README) include commands like init, startdemo, addroute, runserver, and automatic template quality assurance.
File structure
• Top-level: .github/, docs/, scripts/, src/fastapi_fastkit/, tests/, config files (pyproject.toml, Makefile, etc.).
• src/fastapi_fastkit/cli.py and __main__.py: entrypoints for the CLI.
• src/fastapi_fastkit/backend/: inspector, transducer, package_managers (base, factory, pdm/poetry/pip/uv managers).
• src/fastapi_fastkit/core/: exceptions, settings.
• src/fastapi_fastkit/utils/: logging, main helpers.
• src/fastapi_fastkit/fastapi_project_template/: dozens of FastAPI project templates (async CRUD, Docker, PSQL-ORM, empty, etc.).
• scripts/: wrapper shell scripts for formatting, linting, testing.
• tests/: unit tests for each subsystem (backend, CLI, utils, templates).
Extract insights from the README
• The tool exposes multiple CLI commands, each wiring together backend components: CLI → Inspector → Transducer → PackageManager → filesystem & Python environment.
• Supports multiple “package manager” implementations via a factory (Strategy or Factory pattern).
• Templates are versioned and tested automatically (Template Quality Assurance).
Main components and their interactions
• Component A: CLI Layer (cli.py / __main__.py)
• Parses user input, dispatches to command handlers (InitHandler, StartDemoHandler, etc.).
• Component B: Core Services
• Inspector: Checks system state (Python version, existing venvs, OS specifics).
• Transducer: Orchestrates the flow: loads templates, renders files, calls package managers.
• Settings / Exceptions: Global configuration and error handling.
• Component C: Package Manager Module
• Factory selects one of {PipManager, PoetryManager, PDMManager, UVManager} based on CLI option.
• Each manager implements methods: create_virtualenv(), install_dependencies(), run_server().
• Component D: Template Store
• A directory of templated projects (fastapi-async-crud, fastapi-dockerized, etc.).
• Template renderer: Reads .tpl files, substitutes placeholders, writes to new project dir.
• Component E: Utilities
• Logging (rich-powered output), file I/O helpers, version retrieval.
• Component F: External Systems
• OS filesystem, Python runtime, shell commands (pip, uvicorn, pdm, poetry), network for docs.
Architectural patterns and design principles
• Separation of Concerns: CLI parsing vs. business logic vs. file templating vs. environment management.
• Factory Pattern: package_managers.factory chooses the appropriate package manager.
• Template Pattern: Uniform interface for loading and rendering project templates.
• Modular Layering: CLI layer → Core services → Infrastructure (FS/Processes).
Putting it all together
• Off to the right: Utilities (purple) feeding cross-cutting concerns like logging/rich.
• At the bottom: Automated QA Pipeline showing GitHub Actions / tests running against templates.
Detail
• How new templates or package managers plug in.
• Core config (core/settings.py) driving behavior across components.