stock-bot/docs/enhanced-architecture.md

87 lines
2.4 KiB
Markdown

# 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/types`)
Types are now organized by domain:
```
libs/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:
1. `strategy-orchestrator`: Core strategy management
2. `backtest-engine`: Dedicated historical testing
3. `signal-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
1. Continue migrating services to use the new libraries
2. Add comprehensive tests for each library
3. Create a complete API gateway for external access
4. Document service boundaries with OpenAPI schemas