# gqtien/codexion architecture

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

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

## Overview

Codexion is a pthread-based Dining Philosophers simulation: a user supplies coder counts, timing limits, compile goals, dongle cooldown, and a FIFO or EDF policy; the program runs coder threads that acquire two dongles, compile, debug, and refactor until all finish or a coder burns out. A monitor detects burnout/completion and wakes blocked workers for shutdown. The graph also shows request queues, initialization, and cleanup. Relationships are limited to the excerpts and README; unsampled implementation details are represented only where their paths are supported.

Main entry points: [`src/main.c`](https://github.com/gqtien/codexion/blob/main/src/main.c) (Simulation entry), [`src/threads/coder_routine.c`](https://github.com/gqtien/codexion/blob/main/src/threads/coder_routine.c) (Coder routine), [`src/threads/monitor.c`](https://github.com/gqtien/codexion/blob/main/src/threads/monitor.c) (Burnout monitor), [`src/dongles/acquire_dongle.c`](https://github.com/gqtien/codexion/blob/main/src/dongles/acquire_dongle.c) (Dongle acquisition)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_control["Simulation control"]
  node_arguments["Argument parsing<br/>[parse_args.c]"]
  node_entry["Simulation entry<br/>[main.c]"]
  node_initialization["State initialization"]
  node_monitor["Burnout monitor<br/>[monitor.c]"]
end

subgraph group_workers["Coder work"]
  node_coder["Coder routine<br/>[coder_routine.c]"]
end

subgraph group_resources["Dongle coordination"]
  node_dongle_order["Dongle ordering<br/>[dongle_order.c]"]
  node_acquisition["Dongle acquisition<br/>[acquire_dongle.c]"]
  node_request_queue["Wait queue<br/>[queue.c]"]
  node_scheduler["FIFO / EDF policy<br/>[scheduler.c]"]
  node_release["Dongle release<br/>[release_dongle.c]"]
end

subgraph group_support["Shared runtime"]
  node_state["Simulation state<br/>[struct.h]"]
  node_logging["Synchronized logging<br/>[log.c]"]
  node_timing["Time utilities<br/>[time.c]"]
  node_cleanup["Resource cleanup<br/>[cleanup.c]"]
end

node_user(("CLI user"))

node_user -->|"supplies settings"| node_arguments
node_arguments -->|"configures"| node_entry
node_entry -->|"initializes"| node_initialization
node_entry -->|"starts and joins"| node_coder
node_entry -->|"starts and joins"| node_monitor
node_entry -->|"cleans up"| node_cleanup
node_coder -->|"acquires"| node_acquisition
node_coder -->|"releases"| node_release
node_acquisition -->|"gets order"| node_dongle_order
node_acquisition -->|"queues requests"| node_request_queue
node_initialization -->|"selects policy"| node_scheduler
node_monitor -->|"wakes waiters"| node_entry
node_monitor -->|"checks coder state"| node_state
node_coder -->|"logs stages"| node_logging
node_coder -->|"waits between stages"| node_timing
node_monitor -->|"logs burnout"| node_logging
node_acquisition -->|"checks cooldown"| node_timing
node_release -->|"wakes queued coders"| node_request_queue

click node_arguments "https://github.com/gqtien/codexion/blob/main/src/parsing/parse_args.c"
click node_entry "https://github.com/gqtien/codexion/blob/main/src/main.c"
click node_initialization "https://github.com/gqtien/codexion/tree/main/src/init"
click node_monitor "https://github.com/gqtien/codexion/blob/main/src/threads/monitor.c"
click node_coder "https://github.com/gqtien/codexion/blob/main/src/threads/coder_routine.c"
click node_dongle_order "https://github.com/gqtien/codexion/blob/main/src/dongles/dongle_order.c"
click node_acquisition "https://github.com/gqtien/codexion/blob/main/src/dongles/acquire_dongle.c"
click node_request_queue "https://github.com/gqtien/codexion/blob/main/src/queue/queue.c"
click node_scheduler "https://github.com/gqtien/codexion/blob/main/src/queue/scheduler.c"
click node_release "https://github.com/gqtien/codexion/blob/main/src/dongles/release_dongle.c"
click node_state "https://github.com/gqtien/codexion/blob/main/includes/struct.h"
click node_logging "https://github.com/gqtien/codexion/blob/main/src/utils/log.c"
click node_timing "https://github.com/gqtien/codexion/blob/main/src/utils/time.c"
click node_cleanup "https://github.com/gqtien/codexion/blob/main/src/utils/cleanup.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_arguments,node_entry,node_initialization,node_monitor,node_user toneBlue
class node_coder toneAmber
class node_dongle_order,node_acquisition,node_request_queue,node_scheduler,node_release toneMint
class node_state,node_logging,node_timing,node_cleanup toneRose
```

## Components

### Simulation control

- [Argument parsing](https://github.com/gqtien/codexion/blob/main/src/parsing/parse_args.c): `src/parsing/parse_args.c`
- [Simulation entry](https://github.com/gqtien/codexion/blob/main/src/main.c): `src/main.c`
- [State initialization](https://github.com/gqtien/codexion/tree/main/src/init): `src/init`
- [Burnout monitor](https://github.com/gqtien/codexion/blob/main/src/threads/monitor.c): `src/threads/monitor.c`

### Coder work

- [Coder routine](https://github.com/gqtien/codexion/blob/main/src/threads/coder_routine.c): `src/threads/coder_routine.c`

### Dongle coordination

- [Dongle ordering](https://github.com/gqtien/codexion/blob/main/src/dongles/dongle_order.c): `src/dongles/dongle_order.c`
- [Dongle acquisition](https://github.com/gqtien/codexion/blob/main/src/dongles/acquire_dongle.c): `src/dongles/acquire_dongle.c`
- [Wait queue](https://github.com/gqtien/codexion/blob/main/src/queue/queue.c): `src/queue/queue.c`
- [FIFO / EDF policy](https://github.com/gqtien/codexion/blob/main/src/queue/scheduler.c): `src/queue/scheduler.c`
- [Dongle release](https://github.com/gqtien/codexion/blob/main/src/dongles/release_dongle.c): `src/dongles/release_dongle.c`

### Shared runtime

- [Simulation state](https://github.com/gqtien/codexion/blob/main/includes/struct.h): `includes/struct.h`
- [Synchronized logging](https://github.com/gqtien/codexion/blob/main/src/utils/log.c): `src/utils/log.c`
- [Time utilities](https://github.com/gqtien/codexion/blob/main/src/utils/time.c): `src/utils/time.c`
- [Resource cleanup](https://github.com/gqtien/codexion/blob/main/src/utils/cleanup.c): `src/utils/cleanup.c`

### Other components

- **CLI user**

## Connections

- CLI user → Argument parsing: supplies settings (evidence: `README.md`)
- Argument parsing → Simulation entry: configures (evidence: `src/main.c`)
- Simulation entry → State initialization: initializes (evidence: `src/main.c`)
- Simulation entry → Coder routine: starts and joins (evidence: `src/main.c`)
- Simulation entry → Burnout monitor: starts and joins (evidence: `src/main.c`)
- Simulation entry → Resource cleanup: cleans up (evidence: `src/main.c`)
- Coder routine → Dongle acquisition: acquires (evidence: `src/threads/coder_routine.c`)
- Coder routine → Dongle release: releases (evidence: `src/threads/coder_routine.c`)
- Dongle acquisition → Dongle ordering: gets order (evidence: `README.md`)
- Dongle acquisition → Wait queue: queues requests (evidence: `src/dongles/acquire_dongle.c`)
- State initialization → FIFO / EDF policy: selects policy (evidence: `src/init/init_dongles.c`)
- Burnout monitor → Simulation entry: wakes waiters (evidence: `src/threads/monitor.c`)
- Burnout monitor → Simulation state: checks coder state (evidence: `src/threads/monitor.c`)
- Coder routine → Synchronized logging: logs stages (evidence: `src/threads/coder_routine.c`)
- Coder routine → Time utilities: waits between stages (evidence: `src/threads/coder_routine.c`)
- Burnout monitor → Synchronized logging: logs burnout (evidence: `src/threads/monitor.c`)
- Dongle acquisition → Time utilities: checks cooldown (evidence: `src/dongles/acquire_dongle.c`)
- Dongle release → Wait queue: wakes queued coders (evidence: `README.md`)
