2.4 KiB
2.4 KiB
Enhanced Separation of Concerns
This guide describes how the project architecture has been improved to better separate concerns through a modular libs structure.
New Library Structure
We've reorganized the project's shared libraries for improved maintainability:
1. Shared Types (@stock-bot/shared-types)
Types are now organized by domain:
libs/shared-types/
├── src/
│ ├── market/ # Market data types (OHLCV, OrderBook)
│ ├── trading/ # Trading types (Orders, Positions)
│ ├── strategy/ # Strategy and signal types
│ ├── events/ # Event definitions
│ ├── api/ # API response/request types
│ └── config/ # Configuration types
2. Event Bus (@stock-bot/event-bus)
A consistent event publishing system:
libs/event-bus/
├── src/
│ ├── EventBus.ts # Core event bus implementation
│ └── index.ts # Public API
3. Utils (@stock-bot/utils)
Shared utility functions:
libs/utils/
├── src/
│ ├── dateUtils.ts # Date manipulation helpers
│ ├── financialUtils.ts # Financial calculations
│ ├── logger.ts # Standardized logging
│ └── index.ts # Public API
4. API Client (@stock-bot/api-client)
Type-safe service clients:
libs/api-client/
├── src/
│ ├── BaseApiClient.ts # Common HTTP client logic
│ ├── BacktestClient.ts # Backtest service client
│ ├── StrategyClient.ts # Strategy service client
│ └── index.ts # Public API
Service Architecture Improvements
The intelligence services have been split into focused services:
strategy-orchestrator: Core strategy managementbacktest-engine: Dedicated historical testingsignal-engine: Signal generation
This provides:
- Better scaling for resource-intensive operations
- Focused codebases for each concern
- Independent deployment cycles
- Clear service boundaries
Usage Guidelines
- Use the shared types library for all data models
- Use the event bus for inter-service communication
- Use the API clients for direct service calls
- Use utility functions instead of duplicating common code
Next Steps
- Continue migrating services to use the new libraries
- Add comprehensive tests for each library
- Create a complete API gateway for external access
- Document service boundaries with OpenAPI schemas