# rafab15/distribuidos-tp architecture

> Architecture diagram of the GitHub repository rafab15/distribuidos-tp, 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/rafab15/distribuidos-tp
- Repository: https://github.com/rafab15/distribuidos-tp

## Overview

##### Main Components
- Client Component: This is where data originates. The “client” directory contains the main.go file and a Dockerfile, indicating it acts as the entry point sending games and reviews into the system.
- Service Pipeline (Distributed Processing Services): The services are logically grouped by their functionality and exist as individual microservices under the “system” directory. Examples include:
- Game Mapper: Receives game data, extracts essential fields.
- OS Accumulator and OS Final Accumulator: Aggregate game counts based on supported OS. Note the use of an EOF (“end-of-file”) signal to denote completion.
- Decade Filter: Filters games for those published in the 2010s, specifically for Indie genre.
- Top Ten Accumulator: Retains only the top 10 games with the highest average playtime.
- English Filter and English Review Accumulator: Process reviews by filtering for English language and then aggregating positive/negative counts.
- Positive Review Filter: Filters reviews with more than 5,000 positive reviews.
- Multiple Joiners and Final Joiners: These services perform matching between games and their corresponding review data.
- Review Mapper, All Review Accumulator, Top Positive Reviews, and Percentile Accumulator: Handle further processing for specific queries like percentile calculations and top positive reviews.
- Middleware: Every service has a middleware submodule for managing communications (e.g., the “middleware” directory and similar folders under each system component).
- Persistence Layer: Each service contains a “persistence” directory, typically with a “repository.go”, that handles storage and state tracking for intermediate results.
- Internal and Utils: The “internal” directory contains protocol definitions, helper utilities, partitioning logic, and serialization tools, which are foundational to ensure data flows correctly through the pipeline.
- Containerization and Orchestration: Dockerfiles for each microservice in the “client” and “system” (and its subcomponents) indicate containerization. Additionally, docker-compose YAML files are used to spin up the entire distributed architecture.

##### Relationships and Data Flow
- Data flows from the Game Mapper to the OS Accumulator and then to the OS Final Accumulator.
- In parallel, the pipeline for the Indie genre (games) follows: Game Mapper → Decade Filter → Top Ten Accumulator.
- For reviews, the flow is: Entry Point (possibly part of the system/entrypoint) → English Filter → English Review Accumulator → Positive Review Filter → Joiners.
- The multiple Joiner services receive pieces from both game services and review services and merge them based on matching IDs (using partitioning strategies defined in the “internal/compare_results” and “internal/client_protocol” directories).
- Finally, Final Joiners and Top Positive Reviews or Percentile Accumulator forward the final query results back to the entrypoint for delivery to the client.

##### Architectural Patterns and Technologies
- Microservices Architecture: Each service is self-contained, deployed in containers, and interacts via message passing or publish-subscribe patterns.
- Pipeline/Stream Processing: Services process data in a staged pipeline, each waiting for an EOF from its predecessor to indicate completion of data input.
- Horizontal Scalability: Some services are designed to scale (for example, OS Accumulator and English Review Accumulator, where partitioning is evident) to handle load distribution.
- Use of Docker Compose & Makefile: Deployment is managed using Docker Compose (with different files like docker-compose-dev.yaml) and build automation through the Makefile.
- Message Tracking and State Management: Middleware components and nodes (as seen in “internal/system_protocol/node”) suggest detailed tracking of message flows and error-handling (graceful shutdowns) across the distributed components.

- Start at the client which sends game and review data to the system through a unified entrypoint.
- How different branches of the pipeline process the data:
▪ One branch for aggregating OS support and calculating totals.
▪ Another branch for filtering by publication decade, then selecting games based on average playtime.
▪ A parallel branch handling reviews with language identification and positive/negative aggregation.
▪ Joiner modules that merge these processed datasets before final aggregation.
- Error handling and graceful shutdown procedures (referencing utilities in the “internal/utils” directory).
- Use of partitioning to keep related messages (by game ID) together for processing.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Side
    subgraph "Client Side"
        C["Client Component\n(Entry point for data)"]:::client
    end

    %% Game Service Pipeline
    subgraph "Game Service Pipeline"
        GM["Game Mapper\n(Extracts game fields)"]:::service
        OSA["OS Accumulator\n(Aggregates OS counts)"]:::service
        OSFA["OS Final Accumulator\n(Finalizes OS aggregation)"]:::service
        DF["Decade Filter\n(Filters games from 2010s Indie)"]:::service
        TT["Top Ten Accumulator\n(Selects top 10 by playtime)"]:::service
    end

    %% Review Service Pipeline
    subgraph "Review Service Pipeline"
        EP["Entry Point\n(Receives review data)"]:::service
        ERF["English Reviews Filter\n(Filters English reviews)"]:::service
        ERA["English Reviews Accumulator\n(Aggregates review counts)"]:::service
        PRF["Positive Review Filter\n(Filters >5000 positive reviews)"]:::service
        ARA["All Review Accumulator\n(Aggregates all reviews)"]:::service
        TPR["Top Positive Reviews\n(Selects top positive reviews)"]:::service
        PERC["Percentile Accumulator\n(Calculates percentiles)"]:::service
    end

    %% Joiner and Output Services
    subgraph "Joiner & Output"
        JS["Joiner Services\n(Merges game and review data)"]:::service
        FJ["Final Joiners\n(Finalizes merged results)"]:::service
        Out["Final Output\n(Returns results to client)"]:::output
    end

    %% Data Flow from Client
    C -->|"sends game data"| GM
    C -->|"sends review data"| EP

    %% Game Pipeline Flow
    GM -->|"processes"| OSA
    OSA -->|"EOF signal"| OSFA
    GM -->|"processes"| DF
    DF -->|"filters"| TT

    %% Review Pipeline Flow
    EP -->|"processes"| ERF
    ERF -->|"aggregates"| ERA
    ERA -->|"filters"| PRF
    ERA -->|"aggregates"| ARA
    ERA -->|"selects"| TPR
    ERA -->|"calculates"| PERC

    %% Merging Pipelines
    OSFA -->|"merges"| JS
    TT -->|"merges"| JS
    PRF -->|"merges"| JS
    ARA -->|"merges"| JS
    TPR -->|"merges"| JS
    PERC -->|"merges"| JS

    %% Final Processing and Output
    JS -->|"finalizes"| FJ
    FJ -->|"returns"| Out
    Out -->|"delivers result"| C

    %% Click Events for Component Mapping
    click C "https://github.com/rafab15/distribuidos-tp/blob/main/client/main.go"
    click C "https://github.com/rafab15/distribuidos-tp/tree/main/client/Dockerfile"
    click GM "https://github.com/rafab15/distribuidos-tp/blob/main/system/game_mapper/logic/game_mapper.go"
    click OSA "https://github.com/rafab15/distribuidos-tp/blob/main/system/os_accumulator/logic/os_accumulator.go"
    click OSFA "https://github.com/rafab15/distribuidos-tp/blob/main/system/os_final_accumulator/logic/os_final_accumulator.go"
    click DF "https://github.com/rafab15/distribuidos-tp/blob/main/system/decade_filter/logic/decade_filter.go"
    click TT "https://github.com/rafab15/distribuidos-tp/blob/main/system/top_ten_accumulator/logic/top_ten_accumulator.go"
    click EP "https://github.com/rafab15/distribuidos-tp/blob/main/system/entrypoint/logic/entrypoint.go"
    click ERF "https://github.com/rafab15/distribuidos-tp/blob/main/system/english_reviews_filter/logic/english_reviews_filter.go"
    click ERA "https://github.com/rafab15/distribuidos-tp/blob/main/system/english_reviews_accumulator/logic/english_reviews_accumulator.go"
    click ARA "https://github.com/rafab15/distribuidos-tp/blob/main/system/reviews_accumulator/logic/reviews_accumulator.go"
    click TPR "https://github.com/rafab15/distribuidos-tp/blob/main/system/top_positive_reviews/logic/top_positive_reviews.go"
    click PERC "https://github.com/rafab15/distribuidos-tp/blob/main/system/percentile_accumulator/logic/percentile_accumulator.go"
    click JS "https://github.com/rafab15/distribuidos-tp/tree/main/internal/system_protocol/joiner"

    %% Styles
    classDef client fill:#fbf,stroke:#333,stroke-width:2px;
    classDef service fill:#def,stroke:#333,stroke-width:2px;
    classDef output fill:#dfd,stroke:#333,stroke-width:2px;
```
