FastAPI Monolith & Routers
Relevant source files
The following files were used as context for generating this wiki page:
The FastAPI Monolith serves as the primary backend engine for the Infinity OS ecosystem, hosting the core business logic, AI orchestration, and data management services. It is designed as a comprehensive suite of over 80 specialized routers that handle everything from identity management to autonomous code generation. While the frontend and edge services utilize Cloudflare Workers, the FastAPI backend acts as the "executive layer" for heavy computation, complex state management, and long-running background tasks.
The architecture follows a "Three-Lane Mesh" pattern where traffic is logically separated into Lane 1 (AI/Nexus), Lane 2 (User/Infinity), and Lane 3 (Data/Hive). This monolith is currently deployed on Fly.io using PostgreSQL for persistence, providing a robust, scalable environment for the platform's diverse micro-services.
Sources: PLATFORM_ARCHITECTURE_ANALYSIS.md:14-30, DEPLOY_GUIDE.md:8-25
Core Architecture & Lane Mapping
The backend is structured around a Three-Lane Mesh architecture. Each router is assigned to a specific lane or designated as a cross-lane service.
Three-Lane Mesh Structure
The following diagram illustrates how routers are categorized across the platform lanes:
The diagram shows the logical separation of backend routers into functional lanes.
Sources: PLATFORM_ARCHITECTURE_ANALYSIS.md:41-86, PROJECT_PULSE_SESSION6.md:58-69
Router Categories
| Lane | Description | Key Routers |
|---|---|---|
| Lane 1 (AI) | Agent communication and swarm intelligence. | nexus.py, cornelius.py, savania.py, agent_manager.py |
| Lane 2 (User) | User navigation, identity, and creative workspaces. | guardian.py, i_mind.py, resonate.py, users.py |
| Lane 3 (Data) | Data transfer, knowledge extraction, and assets. | hive.py, library.py, taimra.py, files.py |
| Cross-Lane | Shared capabilities like security and observability. | observatory.py, sentinel_station.py, build.py |
Sources: PLATFORM_ARCHITECTURE_ANALYSIS.md:41-86
Functional Router Modules
Build & Package System (build.py)
The Build router manages multi-platform compilation and packaging for various targets including PWAs, Android APKs, and Docker containers. It handles background execution of build jobs and artifact management.
- Key Endpoints:
POST /api/v1/builds: Triggers a new build job.GET /api/v1/builds/{build_id}: Retrieves build status and metadata.GET /api/v1/builds/targets/available: Lists supported platforms (Electron, Tauri, npm, etc.).
- Data Models:
BuildJob(database model),BuildRequest(Pydantic schema).
Sequence of a build job execution from request to artifact generation.
Sources: backend/routers/build.py:18-35, backend/routers/build.py:133-176, backend/routers/build.py:220-256
The Library Knowledge Engine (library.py)
Located on Lane 3 (Data/Hive), the Library manages automated knowledge extraction and AI-powered article generation. It maintains a topic taxonomy and provides full-text search across extracted data.
- Key Features:
- Article Generation: Uses AI to create structured content based on outlines and style preferences.
- Knowledge Extraction: Extracts entities, summaries, and key points from unstructured source text.
- Topic Taxonomy: Organizes knowledge into categories like Security, AI, and Architecture.
- Key Endpoints:
POST /api/v1/library/articles/generate: Creates new documentation articles.POST /api/v1/library/articles/extract: Processes documents for entities/key points.GET /api/v1/library/search: Performs token-based search across the knowledge base.
Sources: backend/routers/library.py:10-24, backend/routers/library.py:133-146, backend/routers/library.py:214-230
Tranquillity Realm Routers
Integrated during Phase 16, these routers focus on user wellbeing and digital twin analysis.
tranquillity.py: Gateway orchestrator for wellbeing services.i_mind.py: Cognitive wellness exercises and mindfulness tracking.taimra.py: 7-dimension digital twin model tracking 15 biomarker types for predictive interventions.savania.py: AI healer and crisis detection engine with guardian protocols.
Sources: PROJECT_PULSE_SESSION6.md:31-40, PROJECT_PULSE_SESSION6.md:72-87
Deployment & Production Validation
The monolith is configured for deployment on Fly.io, utilizing Docker for containerization and a rolling update strategy.
Production Stack Configuration
| Component | Implementation |
|---|---|
| API Framework | FastAPI |
| Runtime | Python 3.11-slim |
| Persistence | PostgreSQL |
| Deployment | Fly.io (Rolling Strategy) |
| Gateway | Nginx / Cloudflare Worker |
Sources: DEPLOY_GUIDE.md:27-55, scripts/deploy-live.sh:91-118
Validation Suite
The validate-production.sh script performs automated health checks across the router fleet to ensure production readiness. It verifies core API health, authentication endpoints, and the status of all primary routers.
# Core API Health Checks
check_http "Backend health endpoint" "$BASE_URL/health"
check_http "API docs (Swagger)" "$BASE_URL/docs"
# Router Availability Check
ROUTERS=("ai" "appstore" "artifacts" "billing" "build" "codegen" ...)
for router in "${ROUTERS[@]}"; do
check_http_warn "Router: $router" "$BASE_URL/api/v1/$router" "200"
done
Sources: scripts/validate-production.sh:105-125
Summary
The FastAPI Monolith is the core intelligence hub of Infinity OS. By organizing its functionality into the Three-Lane Mesh architecture, it ensures that AI orchestration, user services, and data management remain decoupled yet highly integrated. Through specialized routers like build.py and library.py, and the expansive Tranquillity Realm, the backend provides the complex logic required to support a browser-native virtual operating system.