# pasha1coil/server_and_client_message_processing architecture

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

- Interactive diagram: https://gitdiagram.com/pasha1coil/server_and_client_message_processing
- Repository: https://github.com/pasha1coil/server_and_client_message_processing

## Overview

##### Server Component
- Message Generator (shows the msg structure generation)
- SSE (Server-Sent Events) Handler for /task endpoint
- Report Handler for /report endpoint
- BBolt Storage (for failed messages)
- Client Queue Manager (for tracking "free" clients)
- Message Retry System (for handling up to 3 retries)

##### Client Component
- Internal components:
- Batch Size Generator (2-10)
- SSE Client Connection
- Goroutine Pool Manager
- Period Handler (with panic scenarios)
- Report Sender

##### Data Stores
- BBolt Database (for failed messages)
- In-memory state tracking for processed messages

Flow Directions to Show:

##### Primary Data Flow
→ Server generates msg structures
→ Messages flow to available clients via SSE
→ Clients process messages in goroutines
→ Clients send reports back to server
→ Failed messages go to BBolt storage

##### Control Flow
→ Client registration/connection
→ Batch size negotiation
→ Error handling paths
→ Retry mechanisms

Use these visual elements:

- Blue: Server components
- Green: Client components
- Red: Error/Failure paths
- Yellow: Storage components

##### Concurrency Visualization
- Goroutine pools within clients
- Message queue management

##### Error Handling
- Retry paths
- Panic handling for Period > 800
- Client termination for Period > 900
- BBolt storage for failed messages

##### State Management
- How "free" clients are tracked
- Message processing states
- Batch size limits

- State indicators
- Special symbols

Key Relationships to Emphasize:
##### Server message retry mechanism

Level of Detail:
- Keep main components visible at a glance
- Timing constraints (Period values)
- Batch size limits

## Diagram (Mermaid)

```mermaid
graph TB
    %% Main Components
    subgraph Server
        SCore["Server Core"]:::server
        MsgGen["Message Generator"]:::server
        SSEHandler["/task SSE Handler"]:::server
        ReportHandler["/report Handler"]:::server
        CQM["Client Queue Manager"]:::server
        MRS["Message Retry System"]:::server
        BBolt[(BBolt Storage)]:::storage
    end

    subgraph "Client 1"
        C1Core["Client Core"]:::client
        C1BSG["Batch Size Generator<br/>(2-10)"]:::client
        C1SSE["SSE Client Connection"]:::client
        C1GP["Goroutine Pool"]:::client
        C1PH["Period Handler"]:::client
        C1RS["Report Sender"]:::client
    end

    subgraph "Client 2"
        C2Core["Client Core"]:::client
        C2BSG["Batch Size Generator<br/>(2-10)"]:::client
        C2SSE["SSE Client Connection"]:::client
        C2GP["Goroutine Pool"]:::client
        C2PH["Period Handler"]:::client
        C2RS["Report Sender"]:::client
    end

    %% Data Flow
    MsgGen --> SSEHandler
    SSEHandler --> C1SSE
    SSEHandler --> C2SSE
    C1RS --> ReportHandler
    C2RS --> ReportHandler
    ReportHandler --> BBolt
    
    %% Internal Client Flows
    C1SSE --> C1GP
    C1GP --> C1PH
    C1PH --> C1RS
    C2SSE --> C2GP
    C2GP --> C2PH
    C2PH --> C2RS

    %% Control Flow
    CQM -.-> SSEHandler
    MRS -.-> SSEHandler
    MRS -.-> BBolt

    %% Decision Points
    C1PH -- "Period > 900" --> Terminate1{{"Terminate"}}:::error
    C1PH -- "Period > 800" --> Panic1{{"Panic"}}:::error
    C2PH -- "Period > 900" --> Terminate2{{"Terminate"}}:::error
    C2PH -- "Period > 800" --> Panic2{{"Panic"}}:::error

    %% Styling
    classDef server fill:#b3d9ff,stroke:#333
    classDef client fill:#90EE90,stroke:#333
    classDef storage fill:#ffeb99,stroke:#333
    classDef error fill:#ffcccc,stroke:#333

    %% Click Events
    click SCore "https://github.com/pasha1coil/Server_And_Client_Message_Processing/blob/main/server/server.go"
    click C1Core "https://github.com/pasha1coil/Server_And_Client_Message_Processing/blob/main/client/client.go"
    click C2Core "https://github.com/pasha1coil/Server_And_Client_Message_Processing/blob/main/client/client.go"
    click MsgGen "https://github.com/pasha1coil/Server_And_Client_Message_Processing/blob/main/models/msg.go"
    click SCore "https://github.com/pasha1coil/Server_And_Client_Message_Processing/blob/main/server/configs/config.yml"
    click SCore "https://github.com/pasha1coil/Server_And_Client_Message_Processing/blob/main/server/server_test.go"
    click C1Core "https://github.com/pasha1coil/Server_And_Client_Message_Processing/blob/main/client/client_test.go"

    %% Legend
    subgraph Legend
        L1["Server Component"]:::server
        L2["Client Component"]:::client
        L3[(Storage)]:::storage
        L4{{"Error State"}}:::error
        L5["--- Data Flow"]
        L6["-.- Control Flow"]
    end
```
