- Add SQLCipher encryption for ait-mainnet database with configurable flag - Add db_encryption_enabled and db_encryption_key_path config settings - Implement encryption key loading and PRAGMA key setup via connection events - Add shutdown_db function for proper database cleanup - Export middleware classes in aitbc/__init__.py - Fix import path in sync.py for settings - Remove duplicate agent documentation from docs
6.0 KiB
Coordinator-API Monolith Breakup Analysis
Overview
This document analyzes the coordinator-api monolith and proposes a bounded-context breakup strategy.
Current Structure
The coordinator-api monolith contains:
- 59 routers in
apps/coordinator-api/src/app/routers/ - 101 services in
apps/coordinator-api/src/app/services/ - 33 domain modules in
apps/coordinator-api/src/app/domain/ - Approximately 80K lines of code
Identified Bounded Contexts
1. Agent Service (agent.aitbc.local)
Routers:
- agent_creativity.py
- agent_identity.py
- agent_integration_router.py
- agent_performance.py
- agent_router.py
- agent_security_router.py
Responsibilities:
- Agent registration and identity management
- Agent performance tracking
- Agent security and authentication
- Agent creativity metrics
- Agent integration coordination
Estimated Size: ~140K lines
2. Marketplace Service (marketplace.aitbc.local)
Routers:
- marketplace.py
- marketplace_enhanced.py
- marketplace_enhanced_app.py
- marketplace_enhanced_health.py
- marketplace_enhanced_simple.py
- marketplace_gpu.py
- marketplace_offers.py
- marketplace_performance.py
- global_marketplace.py
- global_marketplace_integration.py
Responsibilities:
- GPU marketplace listings
- Marketplace offers and pricing
- Marketplace performance monitoring
- Global marketplace integration
Estimated Size: ~130K lines
3. Governance Service (governance.aitbc.local)
Routers:
- governance.py
- governance_enhanced.py
- staking.py
Responsibilities:
- DAO governance
- Proposal management
- Voting mechanisms
- Staking operations
Estimated Size: ~50K lines
4. Trading Service (trading.aitbc.local)
Routers:
- trading.py
- exchange.py
- settlement.py
- payments.py
Responsibilities:
- Trading operations
- Exchange integration
- Cross-chain settlements
- Payment processing
Estimated Size: ~60K lines
5. GPU Service (gpu.aitbc.local)
Routers:
- edge_gpu.py
- gpu_multimodal_health.py
- miner.py
Responsibilities:
- GPU resource management
- GPU health monitoring
- Mining operations
Estimated Size: ~15K lines
6. Cross-Chain Service (crosschain.aitbc.local)
Routers:
- cross_chain_integration.py
Responsibilities:
- Cross-chain bridge operations
- Cross-chain transaction management
Estimated Size: ~25K lines
7. Analytics Service (analytics.aitbc.local)
Routers:
- analytics.py
- monitoring_dashboard.py
- web_vitals.py
Responsibilities:
- Performance analytics
- Monitoring dashboards
- Web vitals collection
Estimated Size: ~45K lines
8. Platform Service (platform.aitbc.local)
Routers:
- admin.py
- client.py
- developer_platform.py
- partners.py
- registry.py
- users.py
Responsibilities:
- Platform administration
- Client management
- Developer platform
- Partner management
- Service registry
- User management
Estimated Size: ~70K lines
9. AI/ML Service (ai.aitbc.local)
Routers:
- ml_zk_proofs.py
- zk_applications.py
- adaptive_learning_health.py
- modality_optimization_health.py
- multimodal_health.py
- openclaw_enhanced_health.py
Responsibilities:
- ZK proof generation
- AI/ML model operations
- Health monitoring for AI services
Estimated Size: ~40K lines
Shared Dependencies
Shared Utilities to Extract to aitbc-core:
- Database session management
- Authentication middleware
- Rate limiting middleware
- Logging configuration
- Common exception classes
- API response models
- Utility functions
Shared Services:
- Blockchain RPC client
- Encryption service
- Cache management
- Event bus/message queue
Proposed Breakup Strategy
Phase 1: Extract Shared Utilities (Week 1-2)
- Identify and extract common utilities to aitbc-core
- Create shared middleware package
- Update coordinator-api to use shared utilities
Phase 2: Extract GPU Service (Week 2-3)
- Create new FastAPI app for GPU service
- Extract GPU-related routers and services
- Create systemd service
- Update routing
Phase 3: Extract Marketplace Service (Week 3-4)
- Create new FastAPI app for marketplace service
- Extract marketplace-related routers and services
- Create systemd service
- Update routing
Phase 4: Extract Agent Service (Week 4-5)
- Create new FastAPI app for agent service
- Extract agent-related routers and services
- Create systemd service
- Update routing
Phase 5: Extract Trading Service (Week 5-6)
- Create new FastAPI app for trading service
- Extract trading-related routers and services
- Create systemd service
- Update routing
Phase 6: Extract Governance Service (Week 6-7)
- Create new FastAPI app for governance service
- Extract governance-related routers and services
- Create systemd service
- Update routing
Phase 7: Extract Remaining Services (Week 7-8)
- Extract remaining services (analytics, platform, AI/ML, cross-chain)
- Create API gateway or service discovery
- Update client SDKs
- Performance testing
API Gateway Considerations
Options:
- Nginx reverse proxy - Simple, well-understood
- Kubernetes Ingress - If using Kubernetes
- FastAPI gateway - Custom API gateway
- Traefik - Dynamic routing with service discovery
Recommendation:
Start with Nginx reverse proxy for simplicity, migrate to more sophisticated solution if needed.
Database Considerations
Options:
- Shared database - All services share the same database (simpler migration)
- Separate databases - Each service has its own database (better isolation)
Recommendation:
Start with shared database for easier migration, consider separating databases in future phases.
Success Metrics
- Reduced coordinator-api codebase by 70%
- Each microservice can be deployed independently
- Service latency < 100ms for 95th percentile
- No regression in existing functionality
- Improved code maintainability and developer productivity
Next Steps
- Review and approve this breakup strategy
- Create detailed implementation plan for Phase 1
- Begin extracting shared utilities to aitbc-core