# tnerson/c-wildwater architecture

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

- Interactive diagram: https://gitdiagram.com/tnerson/c-wildwater
- Repository: https://github.com/tnerson/c-wildwater

## Overview

C-Wildwater summarizes water-distribution data through two user-facing modes: histogram reports for plant volumes and leak analysis for a selected plant. The documented shell script provides the command interface and launches the C program. In histogram mode, the program reads data into a plant index and generates ranked reports; in leak mode, it parses records, builds a distribution tree and computes losses. Source excerpts support these runtime relationships; the shell-to-program handoff and command capabilities are documented in the README.

Main entry points: [`codeC/src/main.c`](https://github.com/tnerson/c-wildwater/blob/main/codeC/src/main.c) (C entry point), [`c-wildwater.sh`](https://github.com/tnerson/c-wildwater/blob/main/c-wildwater.sh) (Shell launcher), [`codeC/src/usine_arbre.c`](https://github.com/tnerson/c-wildwater/blob/main/codeC/src/usine_arbre.c) (Leak AVL index), [`codeC/src/histo.c`](https://github.com/tnerson/c-wildwater/blob/main/codeC/src/histo.c) (Read histogram data)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interface["Command interface"]
  node_shell["Shell launcher<br/>[c-wildwater.sh]"]
  node_program["C entry point<br/>[main.c]"]
end

subgraph group_histograms["Volume reports"]
  node_hist_read["Read histogram data<br/>[histo.c]"]
  node_hist_rank["Rank volume values<br/>[histo.c]"]
  node_hist_reports["Histogram reports<br/>[histo.c]"]
end

subgraph group_leaks["Leak analysis"]
  node_leak_parse["Parse leak records<br/>[usine_arbre.c]"]
  node_leak_tree["Distribution tree<br/>[usine_arbre.c]"]
  node_leak_calc["Calculate losses<br/>[usine_arbre.c]"]
  node_leak_report["Leak result<br/>[usine_arbre.c]"]
end

subgraph group_indexing["In-memory indexes"]
  node_plant_index["Plant AVL index<br/>[avl.c]"]
  node_leak_index["Leak AVL index<br/>[usine_arbre.c]"]
end

node_user(("User"))
node_dataset["Input data"]

node_user -->|"runs command"| node_shell
node_dataset -->|"provides input"| node_shell
node_shell -->|"launches"| node_program
node_program -->|"calls"| node_hist_read
node_hist_read -->|"inserts and searches"| node_plant_index
node_program -->|"calls report mode"| node_hist_rank
node_hist_rank -->|"writes ranked reports"| node_hist_reports
node_program -->|"parses input lines"| node_leak_parse
node_program -->|"adds parsed records"| node_leak_index
node_leak_parse -->|"constructs nodes"| node_leak_tree
node_leak_tree -->|"indexes nodes"| node_leak_index
node_program -->|"requests loss total"| node_leak_calc
node_leak_calc -->|"searches plant tree"| node_leak_index
node_program -->|"prints and saves result"| node_leak_report

click node_shell "https://github.com/tnerson/c-wildwater/blob/main/c-wildwater.sh"
click node_program "https://github.com/tnerson/c-wildwater/blob/main/codeC/src/main.c"
click node_hist_read "https://github.com/tnerson/c-wildwater/blob/main/codeC/src/histo.c"
click node_plant_index "https://github.com/tnerson/c-wildwater/blob/main/codeC/src/avl.c"
click node_hist_rank "https://github.com/tnerson/c-wildwater/blob/main/codeC/src/histo.c"
click node_hist_reports "https://github.com/tnerson/c-wildwater/blob/main/codeC/src/histo.c"
click node_leak_parse "https://github.com/tnerson/c-wildwater/blob/main/codeC/src/usine_arbre.c"
click node_leak_tree "https://github.com/tnerson/c-wildwater/blob/main/codeC/src/usine_arbre.c"
click node_leak_index "https://github.com/tnerson/c-wildwater/blob/main/codeC/src/usine_arbre.c"
click node_leak_calc "https://github.com/tnerson/c-wildwater/blob/main/codeC/src/usine_arbre.c"
click node_leak_report "https://github.com/tnerson/c-wildwater/blob/main/codeC/src/usine_arbre.c"

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_shell,node_program,node_user toneBlue
class node_hist_read,node_hist_rank,node_hist_reports toneAmber
class node_leak_parse,node_leak_tree,node_leak_calc,node_leak_report toneMint
class node_plant_index,node_leak_index toneRose
class node_dataset toneIndigo
```

## Components

### Command interface

- [Shell launcher](https://github.com/tnerson/c-wildwater/blob/main/c-wildwater.sh): `c-wildwater.sh`
- [C entry point](https://github.com/tnerson/c-wildwater/blob/main/codeC/src/main.c): `codeC/src/main.c`

### Volume reports

- [Read histogram data](https://github.com/tnerson/c-wildwater/blob/main/codeC/src/histo.c): `codeC/src/histo.c`
- [Rank volume values](https://github.com/tnerson/c-wildwater/blob/main/codeC/src/histo.c): `codeC/src/histo.c`
- [Histogram reports](https://github.com/tnerson/c-wildwater/blob/main/codeC/src/histo.c): `codeC/src/histo.c`

### Leak analysis

- [Parse leak records](https://github.com/tnerson/c-wildwater/blob/main/codeC/src/usine_arbre.c): `codeC/src/usine_arbre.c`
- [Distribution tree](https://github.com/tnerson/c-wildwater/blob/main/codeC/src/usine_arbre.c): `codeC/src/usine_arbre.c`
- [Calculate losses](https://github.com/tnerson/c-wildwater/blob/main/codeC/src/usine_arbre.c): `codeC/src/usine_arbre.c`
- [Leak result](https://github.com/tnerson/c-wildwater/blob/main/codeC/src/usine_arbre.c): `codeC/src/usine_arbre.c`

### In-memory indexes

- [Plant AVL index](https://github.com/tnerson/c-wildwater/blob/main/codeC/src/avl.c): `codeC/src/avl.c`
- [Leak AVL index](https://github.com/tnerson/c-wildwater/blob/main/codeC/src/usine_arbre.c): `codeC/src/usine_arbre.c`

### Other components

- **User**
- **Input data**

## Connections

- User → Shell launcher: runs command (evidence: `README.md`)
- Input data → Shell launcher: provides input (evidence: `README.md`)
- Shell launcher → C entry point: launches (evidence: `README.md`)
- C entry point → Read histogram data: calls (evidence: `codeC/src/main.c`)
- Read histogram data → Plant AVL index: inserts and searches (evidence: `codeC/src/histo.c`)
- C entry point → Rank volume values: calls report mode (evidence: `codeC/src/main.c`)
- Rank volume values → Histogram reports: writes ranked reports (evidence: `codeC/src/histo.c`)
- C entry point → Parse leak records: parses input lines (evidence: `codeC/src/main.c`)
- C entry point → Leak AVL index: adds parsed records (evidence: `codeC/src/main.c`)
- Parse leak records → Distribution tree: constructs nodes (evidence: `codeC/src/usine_arbre.c`)
- Distribution tree → Leak AVL index: indexes nodes (evidence: `codeC/src/usine_arbre.c`)
- C entry point → Calculate losses: requests loss total (evidence: `codeC/src/main.c`)
- Calculate losses → Leak AVL index: searches plant tree (evidence: `codeC/src/usine_arbre.c`)
- C entry point → Leak result: prints and saves result (evidence: `codeC/src/main.c`)
