The system follows a Microservices-ready Monolith architecture. While currently designed as a modular monolith for simplicity and learning, the components are loosely coupled to allow future separation into microservices (e.g., separate Data Feeder, Strategy Engine, Execution Service).
- Presentation Layer (Frontend): Interactive dashboard for monitoring, configuration, and agent interaction.
- API Gateway / Application Layer (Backend): RESTful API and WebSocket server handling requests, authentication, and orchestration.
- Domain Layer (Core Logic):
- Quant Engine: Strategy execution, backtesting, market data processing.
- AI Agent Core: LLM integration, memory management, planning.
- Infrastructure Layer (Data & External): Databases, Exchange APIs, LLM Providers.
- Framework: Next.js (React) - For server-side rendering and modern routing.
- Language: TypeScript - For type safety.
- Styling: Tailwind CSS + ShadcnUI - For rapid, beautiful UI development.
- State Management: Zustand or TanStack Query.
- Charts: Lightweight Charts (TradingView) or Recharts.
- Framework: FastAPI (Python) - High performance, async support, auto-generated docs.
- Language: Python 3.10+ - The standard for AI and Quant.
- Task Queue: Celery + Redis - For asynchronous backtesting tasks and scheduled jobs.
- Data Handling: Pandas, NumPy.
- Exchange Interface: CCXT - Unified API for 100+ crypto exchanges.
- Orchestration: LangChain or LangGraph - For building stateful agents.
- LLM Interface: OpenAI API / Anthropic / Ollama (Local).
- Memory (RAG):
- Vector Store: ChromaDB or pgvector (PostgreSQL extension).
- Embeddings: OpenAI Embeddings or HuggingFace (Local).
- Relational & Time-Series: PostgreSQL with TimescaleDB extension.
- Why: Efficiently stores OHLCV market data and structured trade records in one place.
- Cache: Redis - For real-time market data caching and pub/sub.
- Responsibilities: Fetch historical data, stream real-time websocket data.
- Flow: Exchange API -> Normalizer -> TimescaleDB / Redis.
- Responsibilities: Calculate indicators, generate signals (Buy/Sell/Hold).
- Design: Abstract Base Class
Strategywith methodson_tick(),on_candle(). - Backtesting: Event-driven simulation engine using historical data to validate logic.
- Responsibilities: Order management (OMS), position tracking, risk checks.
- Safety: Implements "Paper Trading" mode vs "Live" mode switch.
- Components:
- Planner: Breaks down user goals (e.g., "Find a low-risk strategy for ETH").
- Tools: Custom tools to query the database, run backtests, or check news.
- Critic: Reviews strategy code generated by the LLM for errors or logic flaws.
- Workflow: User Query -> Planner -> Tool Execution -> Observation -> Reasoning -> Response.
kurisu/
├── frontend/ # Next.js Application
├── backend/ # FastAPI Application
│ ├── app/
│ │ ├── api/ # API Routes (v1)
│ │ ├── core/ # Config, Security, DB Connections
│ │ ├── services/ # Business Logic (MarketData, TradeExec)
│ │ ├── agents/ # AI Agent Logic (Prompts, Tools, Memory)
│ │ ├── strategies/ # Strategy Implementations
│ │ └── models/ # Pydantic & SQL Models
│ └── tests/
├── data/ # Local data storage (docker volumes)
├── docs/ # Documentation
└── docker-compose.yml # Orchestration
Goal: Establish the core infrastructure and basic functionality.
| Week | Tasks | Deliverables |
|---|---|---|
| 1 | Project setup | Repository structure, Docker configuration, Poetry/Node setup |
| 2 | Database design | PostgreSQL + TimescaleDB schema, migrations, connection pooling |
| 3 | Data ingestion | CCXT integration, historical data fetcher, WebSocket streams |
| 4 | Basic API | FastAPI skeleton, health endpoints, database CRUD operations |
Milestone: Working data pipeline storing BTC/USDT OHLCV data.
Goal: Build the quantitative analysis and backtesting capabilities.
| Week | Tasks | Deliverables |
|---|---|---|
| 5 | Strategy framework | Abstract Strategy class, indicator library integration |
| 6 | Backtesting engine | Event-driven simulator, order matching, slippage model |
| 7 | Performance metrics | Sharpe ratio, max drawdown, win rate calculations |
| 8 | Strategy examples | Moving average crossover, RSI strategy, grid trading |
Milestone: Complete backtest of a simple strategy with performance report.
Goal: Integrate LLM capabilities and build the cognitive agent.
| Week | Tasks | Deliverables |
|---|---|---|
| 9 | LLM integration | OpenAI/Anthropic/Ollama connectors, prompt templates |
| 10 | Agent tools | Market data tools, backtest tools, analysis tools |
| 11 | Memory system | Vector database setup, RAG implementation |
| 12 | Agent workflow | LangGraph state machine, ReAct pattern implementation |
Milestone: Agent can analyze market data and explain trading decisions.
Goal: Build an intuitive user interface for all features.
| Week | Tasks | Deliverables |
|---|---|---|
| 13 | Dashboard | Real-time charts, portfolio overview, position monitoring |
| 14 | Agent chat | Chat interface, message history, code highlighting |
| 15 | Backtest lab | Strategy configuration, parameter tuning, result visualization |
| 16 | Strategy editor | Monaco Editor integration, syntax validation, save/load |
Milestone: Fully functional web interface for all core features.
Goal: Enable safe paper and live trading capabilities.
| Week | Tasks | Deliverables |
|---|---|---|
| 17 | Paper trading | Simulated order execution, virtual portfolio management |
| 18 | Risk management | Position limits, stop-loss logic, kill-switch |
| 19 | Live trading | Exchange API integration, order management system |
| 20 | Monitoring | Real-time alerts, performance tracking, logging |
Milestone: Safe paper trading with configurable risk parameters.
Goal: Enhance the agent with advanced capabilities.
| Week | Tasks | Deliverables |
|---|---|---|
| 21 | Strategy generation | LLM-based code generation, syntax validation |
| 22 | Multi-agent | Agent collaboration, role-based agents |
| 23 | Self-improvement | Performance feedback loop, strategy optimization |
| 24 | Documentation | API docs, user guide, deployment guide |
Milestone: Agent can autonomously improve strategies based on feedback.
- All API keys must be stored in environment variables or secure vaults
- Implement rate limiting on all public endpoints
- Add authentication for sensitive operations (live trading)
- Design for horizontal scaling from the start
- Use Redis for caching frequently accessed data
- Consider read replicas for database as load increases
- Unit tests for all core business logic
- Integration tests for API endpoints
- End-to-end tests for critical user flows
- Backtesting validation against known market scenarios
- Structured logging with correlation IDs
- Performance metrics collection
- Error tracking and alerting
- Database query performance monitoring