Architecture Overview
MangroveAI follows a layered architecture with clear separation of concerns. Four foundational patterns are applied consistently across all domains.Three-Layer Architecture
Routes Layer
- Parses and validates request payloads
- Maps HTTP inputs to domain request models
- Calls the service layer
- Returns standardized responses
- Does NOT contain business logic or database calls
Service Layer
- Implements domain logic and orchestration
- Coordinates between multiple data layers when needed
- Does NOT contain raw SQL
- Uses the data layer for persistence
Data Layer (Repository / DAO)
- Encapsulates SQL and database connections
- Returns domain entities or simple DTOs
- Does NOT call external APIs or LLMs
Active Domains
| Domain | Description |
|---|---|
ai_copilot | Conversation management and AI workflow |
auth | Authentication and authorization |
backtesting | Historical backtest execution and metrics |
batch | Batch processing operations |
crypto_assets | Crypto asset risk scoring and data |
indicators | 40+ technical indicator classes |
managers | Trading components and execution |
organizations | Multi-tenant org management |
positions | Persistence for positions, orders, trades |
signals | 136 trading signals (TRIGGER/FILTER) |
strategies | Strategy management and loading |
Dependency Injection
Services receive their dependencies (data layers, API clients) through constructor injection. This enables:- Unit testing with mocked dependencies
- Swapping implementations (e.g., local vs external knowledge base)
- Clear dependency graphs between components
Error Handling
All endpoints return standardized error responses:VALIDATION_ERROR(400) — Invalid inputUNAUTHORIZED(401) — Missing or invalid authAUTHORIZATION_ERROR(403) — Insufficient permissionsRESOURCE_NOT_FOUND(404) — Entity not foundSERVICE_ERROR(500) — Internal failure
External Dependencies
| Service | Purpose |
|---|---|
| PostgreSQL + pgvector | Primary database with vector search |
| OpenAI API | LLM for AI Copilot and RAG embeddings |
| CoinAPI | Historical market data for backtesting |
| CoinGecko | Market cap, volume, trending data |
| Nansen | On-chain analytics and smart money tracking |
| Firebase Auth | User authentication (Google OAuth) |
| Knowledge Base (FastAPI) | Trading education content and search |