# suksham-sharma/probo_v1 architecture

> Architecture diagram of the GitHub repository suksham-sharma/probo_v1, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/suksham-sharma/probo_v1
- Repository: https://github.com/suksham-sharma/probo_v1

## Overview

##### Main Components
- API Service: Located in the “api” directory, this Node.js/Express backend exposes REST endpoints (see routes for balance, order, orderbook, stocks, and user). It is likely responsible for handling client requests, coordinating with other microservices, and offering the gateway into the backend.
- Database Server (db-server): This component manages the PostgreSQL database (using Prisma ORM as indicated in the “prisma/schema.prisma” file and migration directories). It handles reliable data storage and also makes use of Redis for caching tasks.
- Engine Service: Found under the “engine” directory, the engine encapsulates the core business logic or trading algorithms. It includes integrations (such as with AWS, as seen from the “awsClient.ts”) and appears to be responsible for processing trades, managing task queues (via Redis), and possibly integrating with archival storage.
- WebSocket Server (ws): Housed in the “ws” directory, this service replaces traditional polling with a WebSocket-based approach to provide live, real-time updates to clients.
- Kubernetes Configurations: The “kube” directory contains YAML files that define deployments and services (e.g., for dbserver, engine, websocket server, ingress, Redis, etc.), indicating that the system is designed for dynamic, containerized deployment.
- External Services: Key external technologies include Redis (for caching, Pub/Sub, and asynchronous task processing), Amazon S3 (for durable archival storage), and PostgreSQL (for relational data storage).

##### Understand the Relationships and Interactions
- The API Service serves as the entry point for client applications. It interacts with both the Engine Service (for processing orders/trades) and the Database Server (for data persistence and retrieval).
- The Engine Service communicates with Redis for task queues and caching, while also interfacing with external services like Amazon S3 for archival storage.
- The WebSocket Service maintains persistent, bidirectional connections with clients, pushing real-time updates such as changes in order status or market data.
- The Database Server not only interacts with incoming queries but is also responsible for executing migrations (through Prisma) and potentially serving archived data.
- Kubernetes manifests suggest that all these services are containerized and orchestrated, enabling dynamic scaling and simplified deployment.

##### Architectural Patterns and Key Technologies
- Modular Design: Each service (API, Engine, DB, WS) is built as a self-contained module. This supports scalability and independent deployment.
- Asynchronous Task Processing: Redis is heavily utilized for background tasks, Pub/Sub messaging, and caching.
- Real-Time Interactions: The WebSocket service ensures low-latency communication with clients.
- Cloud Integration: Components such as Amazon S3 (and potentially AWS clients within the Engine) indicate the system’s integration with cloud services.
- DevOps and Containerization: Dockerfiles in each module and Kubernetes deployment files emphasize a cloud-native, containerized environment.

## Diagram (Mermaid)

```mermaid
flowchart TD

    %% External Entities
    Clients["External Clients"]:::external
    Redis["Redis (Caching & Queues)"]:::external
    S3["Amazon S3 (Archival Storage)"]:::external
    K8sConf["Kubernetes Configurations"]:::k8s

    %% Kubernetes Cluster Subgraph
    subgraph "Kubernetes Cluster"
        API["API Service (Express/Node.js)"]:::internal
        DB["DB Server (PostgreSQL/Prisma)"]:::internal
        Engine["Engine Service (Trading Logic)"]:::internal
        WS["WebSocket Server (Real-Time Updates)"]:::internal
    end

    %% AWS Integration as part of Engine Service
    AWS["AWS Integration"]:::internal

    %% Interactions between External Clients and API/WS
    Clients -->|"requests"| API
    WS -->|"pushUpdates"| Clients

    %% API interactions
    API -->|"persistData"| DB
    API -->|"processOrder"| Engine

    %% Engine interactions
    Engine -->|"asyncTask"| Redis
    Engine -->|"triggerArchive"| AWS
    AWS -->|"store"| S3

    %% Kubernetes orchestration for containerized services
    K8sConf -->|"deploys"| API
    K8sConf -->|"deploys"| DB
    K8sConf -->|"deploys"| Engine
    K8sConf -->|"deploys"| WS

    %% Click Events
    click API "https://github.com/suksham-sharma/probo_v1/tree/main/api/src/routes"
    click DB "https://github.com/suksham-sharma/probo_v1/tree/main/db-server/"
    click Engine "https://github.com/suksham-sharma/probo_v1/tree/main/engine/src/handlers"
    click AWS "https://github.com/suksham-sharma/probo_v1/blob/main/engine/src/lib/awsClient.ts"
    click WS "https://github.com/suksham-sharma/probo_v1/blob/main/ws/index.ts"
    click K8sConf "https://github.com/suksham-sharma/probo_v1/tree/main/kube/"

    %% Styles
    classDef internal fill:#cce5ff,stroke:#004085,stroke-width:2px;
    classDef external fill:#d4edda,stroke:#155724,stroke-width:2px;
    classDef k8s fill:#fff3cd,stroke:#856404,stroke-width:2px;
```
