Architecture¶
Internal architecture overview of how fastappkit works.
Component Overview¶
fastappkit consists of several key components:
- AppLoader: Discovers and loads apps from configuration
- AppResolver: Resolves app entries to actual locations
- ManifestLoader: Loads external app manifests
- EntrypointLoader: Loads and validates entrypoint functions
- RouterAssembler: Mounts routers to FastAPI app
- MigrationRunner: Executes migrations in correct order
- MigrationOrderer: Determines migration execution order
- IsolationValidator: Validates app isolation rules
App Loading Process¶
1. Configuration Loading¶
2. App Resolution¶
For each app entry:
# Internal app: "apps.blog"
if entry.startswith("apps."):
app_name = entry.split(".", 1)[1]
app_path = project_root / "apps" / app_name
# Verify exists and has __init__.py
# External app: "payments"
else:
module = importlib.import_module(entry)
# Verify importable and has manifest
3. Manifest Loading¶
For external apps:
# Load fastappkit.toml from package directory
manifest = load_manifest(app_info)
# Validate required fields
4. Entrypoint Validation¶
# Validate entrypoint is importable
entrypoint = manifest.get("entrypoint", f"{app_name}:register")
load_entrypoint(entrypoint, app_info.import_path)
5. App Registration¶
Registration Execution¶
When FastAppKit.create_app() is called:
- Create FastAPI app instance
- Load all apps via
AppLoader - Execute registrations for each app:
- Mount routers via
RouterAssembler
Router Assembly¶
After all apps are registered:
- Mount routers in order from
fastappkit.toml - Check for collisions after all mounts
- Emit warnings if collisions detected (not fatal)
for app_metadata in registry.list():
if app_metadata.router:
prefix = app_metadata.prefix # From manifest or default
app.include_router(app_metadata.router, prefix=prefix)
Settings Management¶
Initialization Flow¶
- Project defines Settings in
core/config.py - Settings initialized in
core/app.py: - FastAppKit created with settings:
- Global access via
get_settings():
CLI Commands¶
CLI commands use ensure_settings_loaded():
def ensure_settings_loaded(project_root: Path) -> None:
# Imports core.app, which initializes Settings
import core.app
This ensures settings are available for migration commands.
Migration System Internals¶
Migration Ordering¶
- Core (always first)
- Internal apps (from
fastappkit.tomlor[tool.fastappkit.migration.order]) - External apps (from
fastappkit.toml)
Version Tables¶
- Core + Internal:
alembic_version(shared) - External:
alembic_version_<appname>(per-app)
Migration Execution¶
For each app: 1. Build Alembic config 2. Load migration scripts 3. Check database state 4. Determine upgrade path 5. Execute migrations
Learn More¶
- Extending FastAppKit - Customization guide
- Best Practices - Recommended patterns