# kangaroux/go-prd architecture

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

- Interactive diagram: https://gitdiagram.com/kangaroux/go-prd
- Repository: https://github.com/kangaroux/go-prd

## Overview

##### Project Type and Purpose
- This is a small command-line Go utility (an open-source tool) whose sole purpose is to simulate and approximate the C-value parameter used in Pseudo Random Distribution (PRD) systems.
- It generates simulation results in parallel, aggregates statistics (probability and expected value for each C-value), and outputs them as CSV.

##### File Structure Analysis
- Top level:
- go.mod – declares module and dependencies (standard Go libs only).
- main.go – entry point containing all logic.
- README.md – project documentation.
- sample/ – folder with sample data:
– README.md – explanation of sample output.
– dataset.csv – example results.
- No subpackages or external services. All code lives in one file and relies on Go’s goroutines for concurrency.

##### Key Components
a. CLI Interface
- Parses constants (initial C-value, precision, simulation count).
- Exposes flags or hard-coded constants at top of main.go.
b. Simulation Manager
- Orchestrates a pool of goroutines (workers).
- Distributes C-value simulation tasks.
c. Worker Goroutines (Probability Engine)
- Each worker runs a large number of trials for a given C-value.
- Implements the PRD logic: increment probability by C-value on each failure until success, reset on success.
d. Aggregator
- Collects results from all workers via channels.
- Computes average probability and expected value per C-value.
e. Output Writer
- Formats aggregated data into CSV lines.
- Writes to STDOUT (or redirected to out.csv).
f. Sample Data (static)
- Provides a reference dataset (dataset.csv) stored under sample/ for comparison.

##### Architectural Patterns and Principles
- Concurrency Pattern: Worker pool using goroutines and channels for parallel simulation.
- Single-binary, in-memory processing—no external DB or services.
- Separation of concerns: task orchestration (manager), computation (workers), data aggregation, and I/O.

##### Technology and Libraries
- Go standard library: “fmt”, “sync”, “time”, “runtime”, channels.
- No third-party dependencies beyond standard Go.

## Diagram (Mermaid)

```mermaid
flowchart TD
    Start["User invokes \"go run .\""]:::external
    CLI["CLI Interface\n(parses flags)"]:::orchestration
    Manager["Simulation Manager"]:::orchestration
    Worker["Worker Goroutines\n(Probability Engine)"]:::computation
    Aggregator["Aggregator"]:::aggregation
    Writer["Output Writer"]:::io
    STDOUT["STDOUT or file"]:::io

    subgraph "Static Files"
        SampleData["Sample Data (dataset.csv)"]:::static
        SampleDoc["Sample Data Documentation"]:::static
        ProjectDoc["Project Documentation (README.md)"]:::static
        ModuleDecl["Module Declaration (go.mod)"]:::static
    end

    Start -->|"invoke"| CLI
    CLI -->|"C-value task"| Manager
    Manager -->|"assign tasks via channels"| Worker
    Worker -->|"Trial result"| Aggregator
    Aggregator -->|"CSV row"| Writer
    Writer -->|"output"| STDOUT

    %% Static files are referenced but not in data flow
    SampleData
    SampleDoc
    ProjectDoc
    ModuleDecl

    %% Click Events
    click CLI "https://github.com/kangaroux/go-prd/blob/master/main.go"
    click Manager "https://github.com/kangaroux/go-prd/blob/master/main.go"
    click Worker "https://github.com/kangaroux/go-prd/blob/master/main.go"
    click Aggregator "https://github.com/kangaroux/go-prd/blob/master/main.go"
    click Writer "https://github.com/kangaroux/go-prd/blob/master/main.go"
    click SampleData "https://github.com/kangaroux/go-prd/blob/master/sample/dataset.csv"
    click SampleDoc "https://github.com/kangaroux/go-prd/blob/master/sample/README.md"
    click ProjectDoc "https://github.com/kangaroux/go-prd/blob/master/README.md"
    click ModuleDecl "https://github.com/kangaroux/go-prd/blob/master/go.mod"

    %% Styles
    classDef orchestration fill:#add8e6,stroke:#333,stroke-width:1px
    classDef computation fill:#90ee90,stroke:#333,stroke-width:1px
    classDef aggregation fill:#ffffe0,stroke:#333,stroke-width:1px
    classDef io fill:#ffa500,stroke:#333,stroke-width:1px
    classDef static fill:#d3d3d3,stroke:#333,stroke-width:1px
    classDef external fill:#cccccc,stroke:#333,stroke-width:1px
```
