# topnomen/codexion architecture

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

- Interactive diagram: https://gitdiagram.com/topnomen/codexion
- Repository: https://github.com/topnomen/codexion

## Overview

Codexion is a POSIX-threaded simulation in which coders repeatedly acquire shared dongles, compile, debug, and refactor until everyone completes or a burnout deadline stops the run. The graph follows startup through argument parsing and initialization into worker and monitor threads, then shows scheduling, synchronization, and logging responsibilities. The README documents key guarantees and capabilities; some implementation files were not excerpted, so uncertain internal calls are omitted or marked unverified.

Main entry points: [`coder.c`](https://github.com/topnomen/codexion/blob/main/coder.c) (Coder loop), [`main.c`](https://github.com/topnomen/codexion/blob/main/main.c) (Program entry), [`init.c`](https://github.com/topnomen/codexion/blob/main/init.c) (Simulation setup), [`init_alloc.c`](https://github.com/topnomen/codexion/blob/main/init_alloc.c) (Array allocation)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_startup["Startup"]
  node_entry["Program entry<br/>[main.c]"]
  node_arguments["Argument parsing<br/>[parse.c]"]
  node_simulation_init["Simulation setup<br/>[init.c]"]
  node_array_init["Array allocation<br/>[init_alloc.c]"]
  node_init_helpers["Resource initialization<br/>[init_utils.c]"]
  node_dongle_init["Dongle setup<br/>[init.c]"]
  node_coder_init["Coder setup<br/>[init.c]"]
end

subgraph group_runtime["Coder runtime"]
  node_worker["Coder loop<br/>[coder.c]"]
  node_pair_acquire["Pair acquisition<br/>[coder_pair.c]"]
  node_compile_state["Compile tracking<br/>[coder_pair.c]"]
  node_compile_phase["Compile phase<br/>[coder.c]"]
  node_debug_phase["Debug phase<br/>[coder.c]"]
  node_refactor_phase["Refactor phase<br/>[coder.c]"]
end

subgraph group_scheduling["Dongle scheduling"]
  node_dongle_wait["Priority wait queue<br/>[dongle_wait.c]"]
  node_dongle_ops["Dongle operations<br/>[dongle.c]"]
  node_heap_core["Heap ordering<br/>[heap.c]"]
  node_heap_ops["Heap operations<br/>[heap_ops.c]"]
end

subgraph group_coordination["Coordination"]
  node_monitor["Burnout monitor<br/>[monitor.c]"]
  node_burnout_report["Burnout reporting<br/>[burnout.c]"]
  node_stop_control["Stop coordination<br/>[coder_sync.c]"]
  node_logging["Serialized logging<br/>[log.c]"]
  node_simulation_types["Simulation state<br/>[codexion.h]"]
end

node_user(("Operator"))

node_user -->|"runs"| node_entry
node_entry -->|"parses"| node_arguments
node_entry -->|"initializes"| node_simulation_init
node_simulation_init -->|"allocates"| node_array_init
node_array_init -->|"initializes"| node_dongle_init
node_array_init -->|"initializes"| node_coder_init
node_simulation_init -.->|"uses"| node_init_helpers
node_entry -->|"starts threads"| node_worker
node_entry -->|"starts monitor"| node_monitor
node_worker -->|"acquires pair"| node_pair_acquire
node_pair_acquire -->|"takes and releases"| node_dongle_ops
node_dongle_ops -.->|"waits for access"| node_dongle_wait
node_dongle_wait -->|"updates queue"| node_heap_ops
node_heap_ops -->|"orders waiters"| node_heap_core
node_worker -->|"runs compile"| node_compile_phase
node_compile_phase -->|"starts and completes"| node_compile_state
node_worker -->|"runs debug"| node_debug_phase
node_worker -->|"runs refactor"| node_refactor_phase
node_compile_state -->|"checks completion"| node_stop_control
node_monitor -.->|"reports burnout"| node_burnout_report
node_monitor -.->|"requests stop"| node_stop_control
node_worker -->|"checks stop"| node_stop_control
node_worker -->|"logs state"| node_logging
node_simulation_init -->|"uses state"| node_simulation_types

click node_entry "https://github.com/topnomen/codexion/blob/main/main.c"
click node_arguments "https://github.com/topnomen/codexion/blob/main/parse.c"
click node_simulation_init "https://github.com/topnomen/codexion/blob/main/init.c"
click node_array_init "https://github.com/topnomen/codexion/blob/main/init_alloc.c"
click node_init_helpers "https://github.com/topnomen/codexion/blob/main/init_utils.c"
click node_dongle_init "https://github.com/topnomen/codexion/blob/main/init.c"
click node_coder_init "https://github.com/topnomen/codexion/blob/main/init.c"
click node_worker "https://github.com/topnomen/codexion/blob/main/coder.c"
click node_pair_acquire "https://github.com/topnomen/codexion/blob/main/coder_pair.c"
click node_compile_state "https://github.com/topnomen/codexion/blob/main/coder_pair.c"
click node_compile_phase "https://github.com/topnomen/codexion/blob/main/coder.c"
click node_debug_phase "https://github.com/topnomen/codexion/blob/main/coder.c"
click node_refactor_phase "https://github.com/topnomen/codexion/blob/main/coder.c"
click node_monitor "https://github.com/topnomen/codexion/blob/main/monitor.c"
click node_burnout_report "https://github.com/topnomen/codexion/blob/main/burnout.c"
click node_stop_control "https://github.com/topnomen/codexion/blob/main/coder_sync.c"
click node_logging "https://github.com/topnomen/codexion/blob/main/log.c"
click node_dongle_wait "https://github.com/topnomen/codexion/blob/main/dongle_wait.c"
click node_dongle_ops "https://github.com/topnomen/codexion/blob/main/dongle.c"
click node_heap_core "https://github.com/topnomen/codexion/blob/main/heap.c"
click node_heap_ops "https://github.com/topnomen/codexion/blob/main/heap_ops.c"
click node_simulation_types "https://github.com/topnomen/codexion/blob/main/codexion.h"

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_entry,node_arguments,node_simulation_init,node_array_init,node_init_helpers,node_dongle_init,node_coder_init toneBlue
class node_worker,node_pair_acquire,node_compile_state,node_compile_phase,node_debug_phase,node_refactor_phase toneAmber
class node_dongle_wait,node_dongle_ops,node_heap_core,node_heap_ops toneMint
class node_monitor,node_burnout_report,node_stop_control,node_logging,node_simulation_types toneRose
class node_user toneIndigo
```

## Components

### Startup

- [Program entry](https://github.com/topnomen/codexion/blob/main/main.c): `main.c`
- [Argument parsing](https://github.com/topnomen/codexion/blob/main/parse.c): `parse.c`
- [Simulation setup](https://github.com/topnomen/codexion/blob/main/init.c): `init.c`
- [Array allocation](https://github.com/topnomen/codexion/blob/main/init_alloc.c): `init_alloc.c`
- [Resource initialization](https://github.com/topnomen/codexion/blob/main/init_utils.c): `init_utils.c`
- [Dongle setup](https://github.com/topnomen/codexion/blob/main/init.c): `init.c`
- [Coder setup](https://github.com/topnomen/codexion/blob/main/init.c): `init.c`

### Coder runtime

- [Coder loop](https://github.com/topnomen/codexion/blob/main/coder.c): `coder.c`
- [Pair acquisition](https://github.com/topnomen/codexion/blob/main/coder_pair.c): `coder_pair.c`
- [Compile tracking](https://github.com/topnomen/codexion/blob/main/coder_pair.c): `coder_pair.c`
- [Compile phase](https://github.com/topnomen/codexion/blob/main/coder.c): `coder.c`
- [Debug phase](https://github.com/topnomen/codexion/blob/main/coder.c): `coder.c`
- [Refactor phase](https://github.com/topnomen/codexion/blob/main/coder.c): `coder.c`

### Dongle scheduling

- [Priority wait queue](https://github.com/topnomen/codexion/blob/main/dongle_wait.c): `dongle_wait.c`
- [Dongle operations](https://github.com/topnomen/codexion/blob/main/dongle.c): `dongle.c`
- [Heap ordering](https://github.com/topnomen/codexion/blob/main/heap.c): `heap.c`
- [Heap operations](https://github.com/topnomen/codexion/blob/main/heap_ops.c): `heap_ops.c`

### Coordination

- [Burnout monitor](https://github.com/topnomen/codexion/blob/main/monitor.c): `monitor.c`
- [Burnout reporting](https://github.com/topnomen/codexion/blob/main/burnout.c): `burnout.c`
- [Stop coordination](https://github.com/topnomen/codexion/blob/main/coder_sync.c): `coder_sync.c`
- [Serialized logging](https://github.com/topnomen/codexion/blob/main/log.c): `log.c`
- [Simulation state](https://github.com/topnomen/codexion/blob/main/codexion.h): `codexion.h`

### Other components

- **Operator**

## Connections

- Operator → Program entry: runs (evidence: `README.md`)
- Program entry → Argument parsing: parses (evidence: `main.c`)
- Program entry → Simulation setup: initializes (evidence: `main.c`)
- Simulation setup → Array allocation: allocates (evidence: `init.c`)
- Array allocation → Dongle setup: initializes (evidence: `init_alloc.c`)
- Array allocation → Coder setup: initializes (evidence: `init_alloc.c`)
- Simulation setup → Resource initialization: uses
- Program entry → Coder loop: starts threads (evidence: `main.c`)
- Program entry → Burnout monitor: starts monitor (evidence: `main.c`)
- Coder loop → Pair acquisition: acquires pair (evidence: `coder.c`)
- Pair acquisition → Dongle operations: takes and releases (evidence: `coder_pair.c`)
- Dongle operations → Priority wait queue: waits for access
- Priority wait queue → Heap operations: updates queue (evidence: `dongle_wait.c`)
- Heap operations → Heap ordering: orders waiters (evidence: `heap_ops.c`)
- Coder loop → Compile phase: runs compile (evidence: `coder.c`)
- Compile phase → Compile tracking: starts and completes (evidence: `coder.c`)
- Coder loop → Debug phase: runs debug (evidence: `coder.c`)
- Coder loop → Refactor phase: runs refactor (evidence: `coder.c`)
- Compile tracking → Stop coordination: checks completion (evidence: `coder_sync.c`)
- Burnout monitor → Burnout reporting: reports burnout
- Burnout monitor → Stop coordination: requests stop
- Coder loop → Stop coordination: checks stop (evidence: `coder.c`)
- Coder loop → Serialized logging: logs state (evidence: `coder.c`)
- Simulation setup → Simulation state: uses state (evidence: `init.c`)
