# Overall System Architecture

This diagram shows the complete system architecture with API Server Cluster, Compute Worker Cluster, and their interactions with the database and external services.

```mermaid
graph TB
    subgraph "Monorepo Structure"
        subgraph "API Server Cluster"
            API1[Managing.Api<br/>API-1<br/>Orleans]
            API2[Managing.Api<br/>API-2<br/>Orleans]
            API3[Managing.Api<br/>API-3<br/>Orleans]
        end
        
        subgraph "Compute Worker Cluster"
            W1[Managing.Compute<br/>Worker-1<br/>8 cores, 6 jobs]
            W2[Managing.Compute<br/>Worker-2<br/>8 cores, 6 jobs]
            W3[Managing.Compute<br/>Worker-3<br/>8 cores, 6 jobs]
        end
        
        subgraph "Shared Projects"
            APP[Managing.Application<br/>Business Logic]
            DOM[Managing.Domain<br/>Domain Models]
            INFRA[Managing.Infrastructure<br/>Database Access]
        end
    end
    
    subgraph "External Services"
        DB[(PostgreSQL<br/>Job Queue)]
        INFLUX[(InfluxDB<br/>Candles)]
    end
    
    subgraph "Clients"
        U1[User 1]
        U2[User 2]
        U1000[User 1000]
    end
    
    U1 --> API1
    U2 --> API2
    U1000 --> API3
    
    API1 --> DB
    API2 --> DB
    API3 --> DB
    
    W1 --> DB
    W2 --> DB
    W3 --> DB
    
    W1 --> INFLUX
    W2 --> INFLUX
    W3 --> INFLUX
    
    API1 -.uses.-> APP
    API2 -.uses.-> APP
    API3 -.uses.-> APP
    W1 -.uses.-> APP
    W2 -.uses.-> APP
    W3 -.uses.-> APP
    
    style API1 fill:#4A90E2
    style API2 fill:#4A90E2
    style API3 fill:#4A90E2
    style W1 fill:#50C878
    style W2 fill:#50C878
    style W3 fill:#50C878
    style DB fill:#FF6B6B
    style INFLUX fill:#FFD93D
```

## Components

- **API Server Cluster**: Handles HTTP requests, creates jobs, returns immediately
- **Compute Worker Cluster**: Processes CPU-intensive backtest jobs
- **PostgreSQL**: Job queue and state management
- **InfluxDB**: Time-series data for candles
- **Shared Projects**: Common business logic used by both API and Compute services

