# felipe783/problema_papai-noel architecture

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

- Interactive diagram: https://gitdiagram.com/felipe783/problema_papai-noel
- Repository: https://github.com/felipe783/problema_papai-noel

## Overview

This repository implements a finite Santa Claus synchronization simulation in C/pthreads, with a separate infinite, interactive variant. The main workflow parses a run configuration, starts Noel, elf and reindeer threads, resolves group-help versus reindeer-trip requests, then computes metrics and exports CSVs. The README also documents experiment and graph-generation capabilities. The graph includes the infinite variant’s runtime and web interface; its server-to-simulator wiring is not shown in the sampled source, so that relationship is marked unverified.

Main entry points: [`src/main.c`](https://github.com/felipe783/problema_papai-noel/blob/main/src/main.c) (Run coordinator), [`papai_noel_infinito/src/main.c`](https://github.com/felipe783/problema_papai-noel/blob/main/papai_noel_infinito/src/main.c) (Infinite coordinator), [`src/noel.c`](https://github.com/felipe783/problema_papai-noel/blob/main/src/noel.c) (Noel decisions), [`papai_noel_infinito/src/noel.c`](https://github.com/felipe783/problema_papai-noel/blob/main/papai_noel_infinito/src/noel.c) (Infinite Noel decisions)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_finite["Finite Simulation"]
  node_finite_main["Run coordinator<br/>[main.c]"]
  node_shared_finite["Shared state<br/>[comum.h]"]
  node_elves["Elf threads<br/>[elfo.c]"]
  node_reindeer["Reindeer threads<br/>[rena.c]"]
  node_santa["Noel decisions<br/>[noel.c]"]
  node_timing["Monotonic timing<br/>[tempo.c]"]
  node_metrics["Run metrics<br/>[metricas.c]"]
  node_csv["CSV export<br/>[csv.c]"]
end

subgraph group_analysis["Experiment Analysis"]
  node_csv_store[("Run CSV files")]
  node_experiments["Experiment runs"]
  node_charts["Charts and wait table<br/>[graficos.py]"]
end

subgraph group_infinite["Infinite Simulation"]
  node_infinite_main["Infinite coordinator<br/>[main.c]"]
  node_shared_infinite["Infinite shared state<br/>[comum.h]"]
  node_infinite_elves["Infinite elf threads<br/>[elfo.c]"]
  node_infinite_reindeer["Infinite reindeer threads<br/>[rena.c]"]
  node_infinite_santa["Infinite Noel decisions<br/>[noel.c]"]
  node_virtual_clock["Virtual clock<br/>[relogio.c]"]
  node_event_output["JSON event output<br/>[saida.c]"]
end

subgraph group_interface["Live Interface"]
  node_server["Web event server<br/>[servidor.py]"]
  node_web_ui["Browser interface<br/>[app.js]"]
end

node_operator(("Run operator"))

node_operator -->|"configures run"| node_finite_main
node_finite_main -->|"initializes state"| node_shared_finite
node_finite_main -->|"creates threads"| node_elves
node_finite_main -->|"creates threads"| node_reindeer
node_finite_main -->|"creates thread"| node_santa
node_finite_main -->|"uses timing"| node_timing
node_santa -->|"checks and updates"| node_shared_finite
node_santa -->|"simulates work"| node_timing
node_finite_main -->|"calculates after joins"| node_metrics
node_finite_main -->|"exports results"| node_csv
node_csv -->|"appends CSVs"| node_csv_store
node_operator -->|"runs experiments"| node_experiments
node_experiments -->|"runs configurations"| node_finite_main
node_operator -->|"generates charts"| node_charts
node_charts -->|"reads results"| node_csv_store
node_operator -->|"starts simulation"| node_infinite_main
node_infinite_main -->|"initializes state"| node_shared_infinite
node_infinite_main -->|"creates thread"| node_infinite_santa
node_infinite_main -->|"creates threads"| node_infinite_elves
node_infinite_main -->|"creates threads"| node_infinite_reindeer
node_infinite_main -->|"controls time"| node_virtual_clock
node_infinite_santa -->|"sleeps for work"| node_virtual_clock
node_infinite_santa -->|"emits events"| node_event_output
node_event_output -.->|"streams events"| node_server
node_server -.->|"feeds interface"| node_web_ui

click node_finite_main "https://github.com/felipe783/problema_papai-noel/blob/main/src/main.c"
click node_shared_finite "https://github.com/felipe783/problema_papai-noel/blob/main/src/comum.h"
click node_elves "https://github.com/felipe783/problema_papai-noel/blob/main/src/elfo.c"
click node_reindeer "https://github.com/felipe783/problema_papai-noel/blob/main/src/rena.c"
click node_santa "https://github.com/felipe783/problema_papai-noel/blob/main/src/noel.c"
click node_timing "https://github.com/felipe783/problema_papai-noel/blob/main/src/tempo.c"
click node_metrics "https://github.com/felipe783/problema_papai-noel/blob/main/src/metricas.c"
click node_csv "https://github.com/felipe783/problema_papai-noel/blob/main/src/csv.c"
click node_csv_store "https://github.com/felipe783/problema_papai-noel/tree/main/dados"
click node_experiments "https://github.com/felipe783/problema_papai-noel/blob/main/scripts/run_experimentos.sh"
click node_charts "https://github.com/felipe783/problema_papai-noel/blob/main/scripts/graficos.py"
click node_infinite_main "https://github.com/felipe783/problema_papai-noel/blob/main/papai_noel_infinito/src/main.c"
click node_shared_infinite "https://github.com/felipe783/problema_papai-noel/blob/main/papai_noel_infinito/src/comum.h"
click node_infinite_elves "https://github.com/felipe783/problema_papai-noel/blob/main/papai_noel_infinito/src/elfo.c"
click node_infinite_reindeer "https://github.com/felipe783/problema_papai-noel/blob/main/papai_noel_infinito/src/rena.c"
click node_infinite_santa "https://github.com/felipe783/problema_papai-noel/blob/main/papai_noel_infinito/src/noel.c"
click node_virtual_clock "https://github.com/felipe783/problema_papai-noel/blob/main/papai_noel_infinito/src/relogio.c"
click node_event_output "https://github.com/felipe783/problema_papai-noel/blob/main/papai_noel_infinito/src/saida.c"
click node_server "https://github.com/felipe783/problema_papai-noel/blob/main/papai_noel_infinito/servidor.py"
click node_web_ui "https://github.com/felipe783/problema_papai-noel/blob/main/papai_noel_infinito/web/app.js"

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_finite_main,node_shared_finite,node_elves,node_reindeer,node_santa,node_timing,node_metrics,node_csv toneBlue
class node_csv_store,node_experiments,node_charts toneAmber
class node_infinite_main,node_shared_infinite,node_infinite_elves,node_infinite_reindeer,node_infinite_santa,node_virtual_clock,node_event_output toneMint
class node_server,node_web_ui toneRose
class node_operator toneIndigo
```

## Components

### Finite Simulation

- [Run coordinator](https://github.com/felipe783/problema_papai-noel/blob/main/src/main.c): `src/main.c`
- [Shared state](https://github.com/felipe783/problema_papai-noel/blob/main/src/comum.h): `src/comum.h`
- [Elf threads](https://github.com/felipe783/problema_papai-noel/blob/main/src/elfo.c): `src/elfo.c`
- [Reindeer threads](https://github.com/felipe783/problema_papai-noel/blob/main/src/rena.c): `src/rena.c`
- [Noel decisions](https://github.com/felipe783/problema_papai-noel/blob/main/src/noel.c): `src/noel.c`
- [Monotonic timing](https://github.com/felipe783/problema_papai-noel/blob/main/src/tempo.c): `src/tempo.c`
- [Run metrics](https://github.com/felipe783/problema_papai-noel/blob/main/src/metricas.c): `src/metricas.c`
- [CSV export](https://github.com/felipe783/problema_papai-noel/blob/main/src/csv.c): `src/csv.c`

### Experiment Analysis

- [Run CSV files](https://github.com/felipe783/problema_papai-noel/tree/main/dados): `dados`
- [Experiment runs](https://github.com/felipe783/problema_papai-noel/blob/main/scripts/run_experimentos.sh): `scripts/run_experimentos.sh`
- [Charts and wait table](https://github.com/felipe783/problema_papai-noel/blob/main/scripts/graficos.py): `scripts/graficos.py`

### Infinite Simulation

- [Infinite coordinator](https://github.com/felipe783/problema_papai-noel/blob/main/papai_noel_infinito/src/main.c): `papai_noel_infinito/src/main.c`
- [Infinite shared state](https://github.com/felipe783/problema_papai-noel/blob/main/papai_noel_infinito/src/comum.h): `papai_noel_infinito/src/comum.h`
- [Infinite elf threads](https://github.com/felipe783/problema_papai-noel/blob/main/papai_noel_infinito/src/elfo.c): `papai_noel_infinito/src/elfo.c`
- [Infinite reindeer threads](https://github.com/felipe783/problema_papai-noel/blob/main/papai_noel_infinito/src/rena.c): `papai_noel_infinito/src/rena.c`
- [Infinite Noel decisions](https://github.com/felipe783/problema_papai-noel/blob/main/papai_noel_infinito/src/noel.c): `papai_noel_infinito/src/noel.c`
- [Virtual clock](https://github.com/felipe783/problema_papai-noel/blob/main/papai_noel_infinito/src/relogio.c): `papai_noel_infinito/src/relogio.c`
- [JSON event output](https://github.com/felipe783/problema_papai-noel/blob/main/papai_noel_infinito/src/saida.c): `papai_noel_infinito/src/saida.c`

### Live Interface

- [Web event server](https://github.com/felipe783/problema_papai-noel/blob/main/papai_noel_infinito/servidor.py): `papai_noel_infinito/servidor.py`
- [Browser interface](https://github.com/felipe783/problema_papai-noel/blob/main/papai_noel_infinito/web/app.js): `papai_noel_infinito/web/app.js`

### Other components

- **Run operator**

## Connections

- Run operator → Run coordinator: configures run (evidence: `README.md`)
- Run coordinator → Shared state: initializes state (evidence: `src/main.c`)
- Run coordinator → Elf threads: creates threads (evidence: `src/main.c`)
- Run coordinator → Reindeer threads: creates threads (evidence: `src/main.c`)
- Run coordinator → Noel decisions: creates thread (evidence: `src/main.c`)
- Run coordinator → Monotonic timing: uses timing (evidence: `src/main.c`)
- Noel decisions → Shared state: checks and updates (evidence: `src/noel.c`)
- Noel decisions → Monotonic timing: simulates work (evidence: `src/noel.c`)
- Run coordinator → Run metrics: calculates after joins (evidence: `src/main.c`)
- Run coordinator → CSV export: exports results (evidence: `src/main.c`)
- CSV export → Run CSV files: appends CSVs (evidence: `README.md`)
- Run operator → Experiment runs: runs experiments (evidence: `README.md`)
- Experiment runs → Run coordinator: runs configurations (evidence: `README.md`)
- Run operator → Charts and wait table: generates charts (evidence: `README.md`)
- Charts and wait table → Run CSV files: reads results (evidence: `README.md`)
- Run operator → Infinite coordinator: starts simulation (evidence: `README.md`)
- Infinite coordinator → Infinite shared state: initializes state (evidence: `papai_noel_infinito/src/main.c`)
- Infinite coordinator → Infinite Noel decisions: creates thread (evidence: `papai_noel_infinito/src/main.c`)
- Infinite coordinator → Infinite elf threads: creates threads (evidence: `papai_noel_infinito/src/main.c`)
- Infinite coordinator → Infinite reindeer threads: creates threads (evidence: `papai_noel_infinito/src/main.c`)
- Infinite coordinator → Virtual clock: controls time (evidence: `papai_noel_infinito/src/main.c`)
- Infinite Noel decisions → Virtual clock: sleeps for work (evidence: `papai_noel_infinito/src/noel.c`)
- Infinite Noel decisions → JSON event output: emits events (evidence: `papai_noel_infinito/src/noel.c`)
- JSON event output → Web event server: streams events
- Web event server → Browser interface: feeds interface
