6.8 KiB
CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Development Commands
Package Manager: Bun (v1.1.0+)
Build & Development:
bun install- Install dependenciesbun run dev- Start all services in development mode (uses Turbo)bun run build- Build all services and librariesbun run build:libs- Build only shared libraries./scripts/build-all.sh- Custom build script with options
Testing:
bun test- Run all testsbun run test:libs- Test only shared librariesbun run test:apps- Test only applicationsbun run test:coverage- Run tests with coverage
Code Quality:
bun run lint- Lint TypeScript filesbun run lint:fix- Auto-fix linting issuesbun run format- Format code using Prettier./scripts/format.sh- Format script
Infrastructure:
bun run infra:up- Start database infrastructure (PostgreSQL, QuestDB, MongoDB, Dragonfly)bun run infra:down- Stop infrastructurebun run infra:reset- Reset infrastructure with clean volumesbun run docker:admin- Start admin GUIs (pgAdmin, Mongo Express, Redis Insight)
Database Setup:
bun run db:setup-ib- Setup Interactive Brokers database schemabun run db:init- Initialize database schemas
Architecture Overview
Microservices Architecture with shared libraries and multi-database storage:
Core Services (apps/)
- data-ingestion - Market data ingestion from multiple providers (Yahoo, QuoteMedia, IB)
- processing-service - Data cleaning, validation, and technical indicators
- strategy-service - Trading strategies and backtesting (multi-mode: live, event-driven, vectorized, hybrid)
- execution-service - Order management and risk controls
- portfolio-service - Position tracking and performance analytics
- web-app - React dashboard with real-time updates
Shared Libraries (libs/)
- config - Environment configuration with Zod validation
- logger - Loki-integrated structured logging (use
getLogger()pattern) - http - HTTP client with proxy support and rate limiting
- cache - Redis/Dragonfly caching layer
- queue - BullMQ-based job processing with batch support
- postgres-client - PostgreSQL operations with transactions
- questdb-client - Time-series data storage
- mongodb-client - Document storage operations
- utils - Financial calculations and technical indicators
Database Strategy
- PostgreSQL - Transactional data (orders, positions, strategies)
- QuestDB - Time-series data (OHLCV, indicators, performance metrics)
- MongoDB - Document storage (configurations, raw responses)
- Dragonfly - Event bus and caching (Redis-compatible)
Key Patterns & Conventions
Library Usage:
- Import from shared libraries:
import { getLogger } from '@stock-bot/logger' - Use configuration:
import { databaseConfig } from '@stock-bot/config' - Logger pattern:
const logger = getLogger('service-name')
Service Structure:
- Each service has
src/index.tsas entry point - Routes in
src/routes/using Hono framework - Handlers/services in
src/handlers/orsrc/services/ - Use dependency injection pattern
Data Processing:
- Raw data → QuestDB via handlers
- Processed data → PostgreSQL via processing service
- Event-driven communication via Dragonfly
- Queue-based batch processing for large datasets
Multi-Mode Backtesting:
- Live Mode - Real-time trading with brokers
- Event-Driven - Realistic simulation with market conditions
- Vectorized - Fast mathematical backtesting for optimization
- Hybrid - Validation by comparing vectorized vs event-driven results
Development Workflow
- Start Infrastructure:
bun run infra:up - Build Libraries:
bun run build:libs - Start Development:
bun run dev - Access UIs:
- Dashboard: http://localhost:4200
- QuestDB Console: http://localhost:9000
- Grafana: http://localhost:3000
- pgAdmin: http://localhost:8080
Important Files & Locations
Configuration:
- Environment variables in
.envfiles - Service configs in
libs/config/src/ - Database init scripts in
database/postgres/init/
Key Scripts:
scripts/build-all.sh- Production build with cleanupscripts/docker.sh- Docker managementscripts/format.sh- Code formattingscripts/setup-mcp.sh- Setup Model Context Protocol servers for database access
Documentation:
SIMPLIFIED-ARCHITECTURE.md- Detailed architecture overviewDEVELOPMENT-ROADMAP.md- Development phases and priorities- Individual library READMEs in
libs/*/README.md
Current Development Phase
Phase 1: Data Foundation Layer (In Progress)
- Enhancing data provider reliability and rate limiting
- Implementing data validation and quality metrics
- Optimizing QuestDB storage for time-series data
- Building robust HTTP client with circuit breakers
Focus on data quality and provider fault tolerance before advancing to strategy implementation.
Testing & Quality
- Use Bun's built-in test runner
- Integration tests with TestContainers for databases
- ESLint for code quality with TypeScript rules
- Prettier for code formatting
- All services should have health check endpoints
Model Context Protocol (MCP) Setup
MCP Database Servers are configured in .vscode/mcp.json for direct database access:
-
PostgreSQL MCP Server: Provides read-only access to PostgreSQL database
- Connection:
postgresql://trading_user:trading_pass_dev@localhost:5432/trading_bot - Package:
@modelcontextprotocol/server-postgres
- Connection:
-
MongoDB MCP Server: Official MongoDB team server for database and Atlas interaction
- Connection:
mongodb://trading_admin:trading_mongo_dev@localhost:27017/stock?authSource=admin - Package:
mongodb-mcp-server(official MongoDB JavaScript team package)
- Connection:
Setup Commands:
./scripts/setup-mcp.sh- Setup and test MCP serversbun run infra:up- Start database infrastructure (required for MCP)
Usage: Once configured, Claude Code can directly query and inspect database schemas and data through natural language commands.
Environment Variables
Key environment variables (see .env example):
NODE_ENV- Environment (development/production)DATA_SERVICE_PORT- Port for data serviceDRAGONFLY_HOST/PORT- Cache/event bus connection- Database connection strings for PostgreSQL, QuestDB, MongoDB
Monitoring & Observability
- Logging: Structured JSON logs to Loki
- Metrics: Prometheus metrics collection
- Visualization: Grafana dashboards
- Queue Monitoring: Bull Board for job queues
- Health Checks: All services expose
/healthendpoints