# ricomateo/tp0 architecture

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

- Interactive diagram: https://gitdiagram.com/ricomateo/tp0
- Repository: https://github.com/ricomateo/tp0

## Overview

##### Main Components to Highlight
- Client Container(s): Represent the Golang-based client(s) (located under the “client” directory) which are responsible for generating and sending messages (or bets in later exercises). Note that there may be multiple client instances (for example, client1, client2, …) as generated by the “generar-compose.sh” script.
- Server Container: Represent the Python-based server (located under the “server” directory) that listens for incoming connections, processes messages (echo or lottery-related bets), and coordinates concurrency aspects such as parallel processing and synchronization.
- Shared Volumes/Configuration Files: Show that configuration files (config.yaml for the client and config.ini for the server) are externally mounted into the containers via Docker volumes for dynamic configuration updates without rebuilding images.
- Data Sources: Include a reference to the .data directory (containing dataset.zip, which has the agency files for bets) being injected via volumes into the client containers.

##### Relationships and Interactions
- Flow: clients initiate a connection to the server, send messages or batches of bets, wait for and process the server’s echo or bet processing confirmation, and optionally follow-up with additional actions (like winner queries).
- Routing of configuration updates via external volumes.
- Docker Compose orchestration which sets up containers, networks, and shared resources (volumes, networks).

##### Architectural Patterns and Design Principles
- Separation of Concerns: Emphasize the distinct roles of the client and server.
- Containerization: Clearly highlight that both applications run within Docker containers, with images built per language (Golang for the client and Python for the server).
- Microservices Elements: Even though the system is composed of two main services, the Docker Compose file manages multiple instances (especially multiple clients) suggesting a microservice-like approach regarding scaling and isolation.
- Concurrency & Synchronization: On the server side, detail the use of multiprocessing (spawned processes, use of locks and barriers) for handling concurrent client interactions.

##### Relevant Technologies, Frameworks, and Libraries
- Golang: For the client application.
- Python: For the server application.
- Docker & Docker Compose: For containerization and environment management.
- Makefile: For controlling operations (building images, scaling containers, etc.).
- Multiprocessing in Python: For parallel processing and synchronization primitives (locks and barriers).
- Docker Volumes: For in-container configuration and the usage of external datasets.

## Diagram (Mermaid)

```mermaid
graph TD
    %% Docker Compose Orchestration
    subgraph "Docker Compose Orchestration"
        DC1("Makefile"):::compose
        DC2("docker-compose-dev.yaml"):::compose
    end

    %% Client Containers (Golang)
    subgraph "Client Containers (Golang)"
        C1("Client Container"):::client
        C1a("client/Dockerfile"):::client
        C1b("client/main.go"):::client
        C1c("client/common/client.go"):::client
        C1d("client/config.yaml"):::volume
    end

    %% Server Container (Python)
    subgraph "Server Container (Python)"
        S1("Server Container"):::server
        S1a("server/Dockerfile"):::server
        S1b("server/main.py"):::server
        S1c("server/config.ini"):::volume
        subgraph "Server Common Modules"
            S1d("server/common/server.py"):::server
            S1e("server/common/utils.py"):::server
        end
        S2("Concurrency & Synchronization"):::server
    end

    %% Shared Data Sources and Volumes
    subgraph "Shared Data Sources"
        D1(".data directory"):::data
        D2(".data/dataset.zip"):::data
    end

    %% Relationships - Orchestration
    DC1 -->|"orchestrates"| C1
    DC1 -->|"orchestrates"| S1
    DC2 -->|"orchestrates"| C1
    DC2 -->|"orchestrates"| S1

    %% Relationships - Client and Server Communication
    C1 -->|"sends message"| S1
    S1 -->|"responds to"| C1

    %% Relationships - Configuration and Data Volumes
    C1d -.->|"mounted into"| D1
    S1c -.->|"mounted into"| D1
    D1 -.->|"contains"| D2

    %% Internal Server Concurrency Flow
    S1b -->|"triggers"| S2

    %% Click Events
    click DC1 "https://github.com/ricomateo/tp0/tree/master/Makefile"
    click DC2 "https://github.com/ricomateo/tp0/blob/master/docker-compose-dev.yaml"
    click C1a "https://github.com/ricomateo/tp0/tree/master/client/Dockerfile"
    click C1b "https://github.com/ricomateo/tp0/blob/master/client/main.go"
    click C1c "https://github.com/ricomateo/tp0/blob/master/client/common/client.go"
    click C1d "https://github.com/ricomateo/tp0/blob/master/client/config.yaml"
    click S1a "https://github.com/ricomateo/tp0/tree/master/server/Dockerfile"
    click S1b "https://github.com/ricomateo/tp0/blob/master/server/main.py"
    click S1c "https://github.com/ricomateo/tp0/blob/master/server/config.ini"
    click S1d "https://github.com/ricomateo/tp0/blob/master/server/common/server.py"
    click S1e "https://github.com/ricomateo/tp0/blob/master/server/common/utils.py"
    click D1 "https://github.com/ricomateo/tp0/blob/master/.data"
    click D2 "https://github.com/ricomateo/tp0/blob/master/.data/dataset.zip"

    %% Styles
    classDef compose fill:#AED6F1,stroke:#1F618D,stroke-width:2px;
    classDef client fill:#A9DFBF,stroke:#1E8449,stroke-width:2px;
    classDef server fill:#F9E79F,stroke:#B7950B,stroke-width:2px;
    classDef volume fill:#F5CBA7,stroke:#AF601A,stroke-width:2px;
    classDef data fill:#D7BDE2,stroke:#6C3483,stroke-width:2px;
```
