moved dashboard to top level and created a new system plan

This commit is contained in:
Bojan Kucera 2025-06-04 21:31:38 -04:00
parent 5e692f4ab5
commit 7993148a95
76 changed files with 783 additions and 500 deletions

View file

@ -1,232 +0,0 @@
# 🔄 Current System Communication Flow
## Active Services (Currently Running)
```mermaid
graph TB
%% External Data Sources
subgraph "External APIs"
EXT[Demo Data Generation<br/>Alpha Vantage Ready<br/>Yahoo Finance Ready]
end
%% Currently Active Services
subgraph "Active Services"
MDG[Market Data Gateway<br/>Port 3001<br/>✅ Running]
TD[Trading Dashboard<br/>Port 5173<br/>✅ Running]
end
%% Storage Layer
subgraph "Storage"
DRAGONFLY[(Dragonfly<br/>📡 Events & Cache<br/>🔧 Configured)]
end
%% Data Flow
EXT -->|HTTP Fetch| MDG
MDG -->|REST API| TD
MDG -->|WebSocket Stream| TD
MDG -->|Events| DRAGONFLY
%% Styling
classDef active fill:#90EE90
classDef storage fill:#FFE4B5
classDef external fill:#FFB6C1
class MDG,TD active
class DRAGONFLY storage
class EXT external
```
## Next Phase Services (Ready to Implement)
```mermaid
graph TB
%% Current Services
subgraph "Current Layer"
MDG[Market Data Gateway<br/>✅ Operational]
TD[Trading Dashboard<br/>✅ Operational]
end
%% Next Phase Services
subgraph "Next Phase - Priority 1"
SO[Strategy Orchestrator<br/>🚧 Package Created<br/>📋 Ready to Implement]
RG[Risk Guardian<br/>🚧 Package Created<br/>📋 Ready to Implement]
end
%% Communication Infrastructure
subgraph "Event Infrastructure"
DRAGONFLY[(Dragonfly Streams<br/>✅ Configured)]
WS[WebSocket Server<br/>✅ Active in MDG]
end
%% Data Flows
MDG -->|Market Data Events| DRAGONFLY
MDG -->|Real-time Stream| WS
WS -->|Live Updates| TD
DRAGONFLY -->|Market Events| SO
DRAGONFLY -->|All Events| RG
SO -->|Strategy Events| DRAGONFLY
SO -->|Risk Check| RG
RG -->|Risk Alerts| DRAGONFLY
%% Styling
classDef current fill:#90EE90
classDef next fill:#FFE4B5
classDef infrastructure fill:#E6E6FA
class MDG,TD current
class SO,RG next
class DRAGONFLY,WS infrastructure
```
## Detailed Communication Patterns
### 1. **Current System (Working)**
```
┌─────────────────┐ HTTP REST ┌─────────────────┐
│ Trading │ ←──────────────→ │ Market Data │
│ Dashboard │ │ Gateway │
│ (React/Tremor) │ ←──────────────→ │ (Hono/Bun) │
└─────────────────┘ WebSocket └─────────────────┘
┌─────────────────┐
│ Dragonfly Events │
│ (Configured) │
└─────────────────┘
```
### 2. **Next Phase Implementation**
```
┌─────────────────┐
│ Strategy │
│ Orchestrator │ ──┐
└─────────────────┘ │
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
│ Market Data │→│ Dragonfly Event │←│ Risk Guardian │
│ Gateway │ │ Stream │ │ │
└─────────────────┘ └─────────────────┘ └─────────────────┘
│ │ │
▼ ▼ ▼
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
│ Trading │ │ WebSocket │ │ Alert Manager │
│ Dashboard │ │ Real-time │ │ (Future) │
└─────────────────┘ └─────────────────┘ └─────────────────┘
```
## Event Flow Diagram
```mermaid
sequenceDiagram
participant TD as Trading Dashboard
participant MDG as Market Data Gateway
participant DRAGONFLY as Dragonfly Events
participant SO as Strategy Orchestrator (Next)
participant RG as Risk Guardian (Next)
Note over TD,DRAGONFLY: Current System - Working
MDG->>MDG: Generate demo market data
MDG->>TD: WebSocket real-time updates
MDG->>DRAGONFLY: Publish MARKET_DATA events
TD->>MDG: HTTP API requests
MDG->>TD: JSON responses
Note over SO,RG: Next Phase - To Implement
DRAGONFLY->>SO: Subscribe to MARKET_DATA events
SO->>SO: Analyze market conditions
SO->>DRAGONFLY: Publish SIGNAL_GENERATED events
DRAGONFLY->>RG: Subscribe to ALL events
RG->>RG: Monitor risk thresholds
RG->>DRAGONFLY: Publish RISK_ALERT events
DRAGONFLY->>TD: All events via WebSocket
TD->>TD: Update dashboard with alerts
```
## Service Dependencies
### **Current Dependencies (Satisfied)**
```
Market Data Gateway
├── ✅ Hono (Web framework)
├── ✅ ioredis (Redis client)
├── ✅ @stock-bot/config (Workspace package)
└── ✅ ws (WebSocket library)
Trading Dashboard
├── ✅ React + TypeScript
├── ✅ Tremor UI (Financial components)
├── ✅ Vite (Build tool)
└── ✅ WebSocket client
```
### **Next Phase Dependencies (Ready)**
```
Strategy Orchestrator
├── ✅ Package.json created
├── ✅ Dependencies specified
├── 📋 Implementation needed
└── 🔧 node-cron (Strategy scheduling)
Risk Guardian
├── ✅ Package.json created
├── ✅ Dependencies specified
├── 📋 Implementation needed
└── 🛡️ Risk monitoring logic
```
## Port & Endpoint Map
| Service | Port | Endpoints | Status |
|---------|------|-----------|--------|
| **Market Data Gateway** | 3001 | `/health`, `/api/market-data/:symbol`, `/api/ohlcv/:symbol`, WebSocket | ✅ Active |
| **Trading Dashboard** | 5173 | Vite dev server | ✅ Active |
| **Strategy Orchestrator** | 4001 | `/health`, `/api/strategies`, `/api/signals` | 📋 Planned |
| **Risk Guardian** | 3002 | `/health`, `/api/risk-checks`, `/api/limits` | 📋 Planned |
## Data Types & Events
### **Market Data Event**
```typescript
interface MarketDataEvent {
type: 'MARKET_DATA';
data: {
symbol: string;
price: number;
bid: number;
ask: number;
volume: number;
timestamp: Date;
};
timestamp: Date;
}
```
### **Strategy Event (Next Phase)**
```typescript
interface StrategyEvent {
type: 'SIGNAL_GENERATED' | 'STRATEGY_START' | 'STRATEGY_STOP';
strategyId: string;
signal?: TradingSignal;
timestamp: Date;
}
```
### **Risk Event (Next Phase)**
```typescript
interface RiskEvent {
type: 'RISK_ALERT' | 'RISK_CHECK';
severity: 'LOW' | 'MEDIUM' | 'HIGH' | 'CRITICAL';
message: string;
data: any;
timestamp: Date;
}
```
This architecture shows how your current working system will expand into a comprehensive trading platform with clear communication patterns and event flows.

View file

@ -1,87 +0,0 @@
# 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
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

View file

@ -1,26 +0,0 @@
# Interface Services
Interface services provide user-facing applications and APIs for interacting with the trading platform.
## Services
### Trading Dashboard
- **Purpose**: Web-based user interface for trading operations
- **Key Functions**:
- Real-time portfolio monitoring and visualization
- Trading strategy configuration and management
- Performance analytics and reporting dashboards
- Risk monitoring and alerting interface
- Market data visualization and charting
- Order management and execution tracking
## Architecture
Interface services create the user experience layer of the trading platform, providing intuitive and responsive interfaces for traders, analysts, and administrators. They translate complex backend operations into accessible visual interfaces and interactive workflows.
## Technology Stack
- **Frontend**: React-based single-page applications
- **Visualization**: Real-time charts and data visualization
- **State Management**: Modern React patterns and state libraries
- **API Integration**: RESTful and WebSocket connections to backend services

View file

@ -1,87 +0,0 @@
# Trading Dashboard
## Overview
The Trading Dashboard service provides a comprehensive web-based user interface for monitoring, analyzing, and controlling trading activities within the stock-bot platform. It serves as the primary visual interface for traders, analysts, and administrators to interact with the platform's capabilities and visualize market data and trading performance.
## Key Features
### Portfolio Monitoring
- **Position Dashboard**: Real-time view of all open positions
- **P&L Tracking**: Current and historical profit/loss visualization
- **Risk Metrics**: Visual representation of key risk indicators
- **Performance Analytics**: Strategy and portfolio performance charts
### Market Visualization
- **Real-time Charts**: Interactive price and volume charts
- **Technical Indicators**: Overlay of key technical indicators
- **Market Depth**: Order book visualization where available
- **Multi-instrument View**: Customizable multi-asset dashboards
### Trading Controls
- **Order Management**: Create, track, and modify orders
- **Strategy Controls**: Enable, disable, and configure strategies
- **Risk Parameters**: Adjust risk thresholds and limits
- **Alert Configuration**: Set up custom trading alerts
### Advanced Analytics
- **Strategy Performance**: Detailed analytics on strategy execution
- **Attribution Analysis**: Performance attribution by strategy/instrument
- **Historical Backtests**: Visualization of backtest results
- **Market Correlation**: Relationship analysis between instruments
## Integration Points
### Upstream Connections
- Market Data Gateway (for real-time market data)
- Strategy Orchestrator (for strategy status and control)
- Risk Guardian (for risk metrics)
- Order Management System (for order status)
### Downstream Components
- User Authentication Service
- Notification Service
- Export/Reporting Services
## Technical Implementation
### Technology Stack
- **Framework**: Angular with RxJS for reactive programming
- **UI Components**: Angular Material and custom components
- **Styling**: Tailwind CSS for responsive design
- **Charting**: Lightweight charting libraries for performance
- **Real-time Updates**: WebSocket connections for live data
### Architecture Pattern
- Component-based architecture
- State management with services and observables
- Lazy-loaded modules for performance
- Responsive design for multiple device types
## Development Guidelines
### Component Structure
- Smart/presentational component pattern
- Reusable UI component library
- State management best practices
- Performance optimization techniques
### Data Visualization
- Chart configuration standards
- Data refresh strategies
- Animation guidelines
- Accessibility requirements
### User Experience
- Consistent UI/UX patterns
- Keyboard shortcuts and navigation
- Form validation approach
- Error handling and feedback
## Future Enhancements
- Advanced customization capabilities
- User-defined dashboards and layouts
- Mobile-optimized interface
- Collaborative features (comments, annotations)
- AI-powered insights and recommendations
- Enhanced export and reporting capabilities
- Dark/light theme support