2.2 KiB
2.2 KiB
Stock Bot Project Structure Refactoring
This document outlines the changes made to improve separation of concerns in the stock-bot project architecture.
Directory Structure Changes
- Created a dedicated
libs/directory (replacing the previouspackages/approach) - Split monolithic type definitions into domain-specific modules
- Created specialized libraries for cross-cutting concerns
New Libraries
1. @stock-bot/shared-types
Domain-specific type definitions organized by functional area:
market/- Market data structures (OHLCV, OrderBook, etc.)trading/- Trading types (Orders, Positions, etc.)strategy/- Strategy and signal typesevents/- Event definitions for the event busapi/- Common API request/response typesconfig/- Configuration type definitions
2. @stock-bot/event-bus
A Redis-based event bus implementation for inter-service communication:
- Publish/subscribe pattern for asynchronous messaging
- Support for typed events
- Reliable message delivery
3. @stock-bot/utils
Common utility functions shared across services:
dateUtils- Date/time helpers for market datafinancialUtils- Financial calculations (Sharpe ratio, drawdown)logger- Standardized logging service
4. @stock-bot/api-client
Type-safe API clients for inter-service communication:
BaseApiClient- Common HTTP client functionality- Service-specific clients (BacktestClient, StrategyClient)
Benefits of the New Architecture
-
Better Separation of Concerns
- Each library has a clear, focused purpose
- Domain types are logically grouped
-
Improved Maintainability
- Smaller, focused modules
- Clear dependencies between modules
-
Type Safety
- Consistent types across the entire system
- Better IDE autocompletion and error checking
-
Reduced Duplication
- Shared utilities in a central location
- Consistent implementation of common patterns
Next Steps
- Update service implementations to use the new libraries
- Migrate from the old packages directory to the new libs structure
- Implement domain-specific validations in each type module
- Add unit tests for each library