# rosalita/distributed-lottery-analyser architecture

> Architecture diagram of the GitHub repository rosalita/distributed-lottery-analyser, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-06). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/rosalita/distributed-lottery-analyser
- Repository: https://github.com/rosalita/distributed-lottery-analyser

## Overview

This repository gathers UK lottery draw histories and uses them to find historically profitable tickets. The data-gathering command updates per-game CSV summaries and fetches per-draw prize details. The analyser loads those histories, then a leader partitions the ticket search space into rank ranges; workers evaluate ranges and report top tickets for the leader to aggregate. The README documents Kubernetes orchestration and horizontal worker scaling, but those deployment details are not represented as runtime components. Some subsystem links are based on README statements because their full implementation was not sampled.

Main entry points: [`cmd/analyser/internal/coordinator/leader.go`](https://github.com/rosalita/distributed-lottery-analyser/blob/main/cmd/analyser/internal/coordinator/leader.go) (Leader coordinator), [`cmd/analyser/internal/worker/worker.go`](https://github.com/rosalita/distributed-lottery-analyser/blob/main/cmd/analyser/internal/worker/worker.go) (Worker client), [`cmd/analyser/internal/evaluator/evaluator.go`](https://github.com/rosalita/distributed-lottery-analyser/blob/main/cmd/analyser/internal/evaluator/evaluator.go) (Ticket evaluator), [`cmd/analyser/main.go`](https://github.com/rosalita/distributed-lottery-analyser/blob/main/cmd/analyser/main.go) (Analyser entry)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_gather["History gathering"]
  node_gather_cmd["History updater<br/>[main.go]"]
  node_draw_parser["Draw parser"]
  node_history_store[("Draw history")]
end

subgraph group_analysis["Analysis runtime"]
  node_entry["Analyser entry<br/>[main.go]"]
  node_loader["History loader<br/>[loader.go]"]
  node_draw_models["Draw models<br/>[models.go]"]
end

subgraph group_compute["Ticket computation"]
  node_evaluator["Ticket evaluator<br/>[evaluator.go]"]
  node_combinadics["Rank decoding<br/>[combinadics.go]"]
  node_bitmasks["Bitmask helpers<br/>[masking.go]"]
end

subgraph group_protocol["Worker coordination"]
  node_leader["Leader coordinator<br/>[leader.go]"]
  node_worker["Worker client<br/>[worker.go]"]
  node_grpc_contract["RPC contract<br/>[analyser.proto]"]
end

node_operator(("Operator"))
node_lottery(("Lottery service"))

node_operator -->|"updates history"| node_gather_cmd
node_gather_cmd -->|"downloads draws"| node_lottery
node_gather_cmd -->|"extracts draws"| node_draw_parser
node_gather_cmd -->|"writes files"| node_history_store
node_entry -->|"loads histories"| node_loader
node_loader -->|"reads files"| node_history_store
node_entry -->|"starts leader"| node_leader
node_entry -->|"starts worker"| node_worker
node_entry -->|"selects game"| node_evaluator
node_leader -->|"prepares draws"| node_evaluator
node_leader -->|"uses draw data"| node_draw_models
node_worker -->|"evaluates ranges"| node_evaluator
node_worker -->|"maps draw data"| node_draw_models
node_leader -->|"assigns work"| node_worker
node_worker -->|"reports results"| node_leader
node_leader -->|"implements RPCs"| node_grpc_contract
node_worker -->|"uses RPCs"| node_grpc_contract
node_evaluator -.->|"decodes ranks"| node_combinadics
node_evaluator -.->|"uses masks"| node_bitmasks

click node_gather_cmd "https://github.com/rosalita/distributed-lottery-analyser/blob/main/cmd/getdrawhistory/main.go"
click node_draw_parser "https://github.com/rosalita/distributed-lottery-analyser/blob/main/cmd/getdrawhistory/draw_number_parser.go"
click node_history_store "https://github.com/rosalita/distributed-lottery-analyser/tree/main/cmd/getdrawhistory/data"
click node_entry "https://github.com/rosalita/distributed-lottery-analyser/blob/main/cmd/analyser/main.go"
click node_loader "https://github.com/rosalita/distributed-lottery-analyser/blob/main/cmd/analyser/internal/data/loader.go"
click node_draw_models "https://github.com/rosalita/distributed-lottery-analyser/blob/main/cmd/analyser/internal/data/models.go"
click node_leader "https://github.com/rosalita/distributed-lottery-analyser/blob/main/cmd/analyser/internal/coordinator/leader.go"
click node_worker "https://github.com/rosalita/distributed-lottery-analyser/blob/main/cmd/analyser/internal/worker/worker.go"
click node_grpc_contract "https://github.com/rosalita/distributed-lottery-analyser/blob/main/protos/analyser.proto"
click node_evaluator "https://github.com/rosalita/distributed-lottery-analyser/blob/main/cmd/analyser/internal/evaluator/evaluator.go"
click node_combinadics "https://github.com/rosalita/distributed-lottery-analyser/blob/main/cmd/analyser/internal/evaluator/combinadics.go"
click node_bitmasks "https://github.com/rosalita/distributed-lottery-analyser/blob/main/cmd/analyser/internal/evaluator/masking.go"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_gather_cmd,node_draw_parser,node_history_store toneBlue
class node_entry,node_loader,node_draw_models toneAmber
class node_evaluator,node_combinadics,node_bitmasks toneMint
class node_leader,node_worker,node_grpc_contract toneRose
class node_operator,node_lottery toneIndigo
```

## Components

### History gathering

- [History updater](https://github.com/rosalita/distributed-lottery-analyser/blob/main/cmd/getdrawhistory/main.go): `cmd/getdrawhistory/main.go`
- [Draw parser](https://github.com/rosalita/distributed-lottery-analyser/blob/main/cmd/getdrawhistory/draw_number_parser.go): `cmd/getdrawhistory/draw_number_parser.go`
- [Draw history](https://github.com/rosalita/distributed-lottery-analyser/tree/main/cmd/getdrawhistory/data): `cmd/getdrawhistory/data`

### Analysis runtime

- [Analyser entry](https://github.com/rosalita/distributed-lottery-analyser/blob/main/cmd/analyser/main.go): `cmd/analyser/main.go`
- [History loader](https://github.com/rosalita/distributed-lottery-analyser/blob/main/cmd/analyser/internal/data/loader.go): `cmd/analyser/internal/data/loader.go`
- [Draw models](https://github.com/rosalita/distributed-lottery-analyser/blob/main/cmd/analyser/internal/data/models.go): `cmd/analyser/internal/data/models.go`

### Ticket computation

- [Ticket evaluator](https://github.com/rosalita/distributed-lottery-analyser/blob/main/cmd/analyser/internal/evaluator/evaluator.go): `cmd/analyser/internal/evaluator/evaluator.go`
- [Rank decoding](https://github.com/rosalita/distributed-lottery-analyser/blob/main/cmd/analyser/internal/evaluator/combinadics.go): `cmd/analyser/internal/evaluator/combinadics.go`
- [Bitmask helpers](https://github.com/rosalita/distributed-lottery-analyser/blob/main/cmd/analyser/internal/evaluator/masking.go): `cmd/analyser/internal/evaluator/masking.go`

### Worker coordination

- [Leader coordinator](https://github.com/rosalita/distributed-lottery-analyser/blob/main/cmd/analyser/internal/coordinator/leader.go): `cmd/analyser/internal/coordinator/leader.go`
- [Worker client](https://github.com/rosalita/distributed-lottery-analyser/blob/main/cmd/analyser/internal/worker/worker.go): `cmd/analyser/internal/worker/worker.go`
- [RPC contract](https://github.com/rosalita/distributed-lottery-analyser/blob/main/protos/analyser.proto): `protos/analyser.proto`

### Other components

- **Operator**
- **Lottery service**

## Connections

- Operator → History updater: updates history (evidence: `README.md`)
- History updater → Lottery service: downloads draws (evidence: `README.md`)
- History updater → Draw parser: extracts draws (evidence: `cmd/getdrawhistory/main.go`)
- History updater → Draw history: writes files (evidence: `README.md`)
- Analyser entry → History loader: loads histories (evidence: `cmd/analyser/main.go`)
- History loader → Draw history: reads files (evidence: `cmd/analyser/internal/data/loader.go`)
- Analyser entry → Leader coordinator: starts leader (evidence: `cmd/analyser/main.go`)
- Analyser entry → Worker client: starts worker (evidence: `cmd/analyser/main.go`)
- Analyser entry → Ticket evaluator: selects game (evidence: `cmd/analyser/main.go`)
- Leader coordinator → Ticket evaluator: prepares draws (evidence: `cmd/analyser/internal/coordinator/leader.go`)
- Leader coordinator → Draw models: uses draw data (evidence: `cmd/analyser/internal/coordinator/leader.go`)
- Worker client → Ticket evaluator: evaluates ranges (evidence: `cmd/analyser/internal/worker/worker.go`)
- Worker client → Draw models: maps draw data (evidence: `cmd/analyser/internal/worker/worker.go`)
- Leader coordinator → Worker client: assigns work (evidence: `README.md`)
- Worker client → Leader coordinator: reports results (evidence: `README.md`)
- Leader coordinator → RPC contract: implements RPCs (evidence: `protos/analyser.proto`)
- Worker client → RPC contract: uses RPCs (evidence: `protos/analyser.proto`)
- Ticket evaluator → Rank decoding: decodes ranks
- Ticket evaluator → Bitmask helpers: uses masks
