# terzogode/philosophers architecture

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

- Interactive diagram: https://gitdiagram.com/terzogode/philosophers
- Repository: https://github.com/terzogode/philosophers

## Overview

Philo is a command-line dining-philosophers simulation. The workflow validates numeric arguments, configures shared state, starts philosopher threads and a monitor, then runs each philosopher through eating, sleeping, and thinking until a death or meal limit ends the simulation. Mutexes coordinate fork access and shared state; synchronized output and time helpers support the runtime. The README is empty, so documented capabilities beyond the sampled implementation cannot be assessed; edges reflect only shown calls.

Main entry points: [`philo/utils.c`](https://github.com/terzogode/philosophers/blob/main/philo/utils.c) (Join and cleanup), [`philo/main.c`](https://github.com/terzogode/philosophers/blob/main/philo/main.c) (CLI entry), [`philo/init.c`](https://github.com/terzogode/philosophers/blob/main/philo/init.c) (Table and thread setup), [`philo/monitor.c`](https://github.com/terzogode/philosophers/blob/main/philo/monitor.c) (Death and meal monitor)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_input["Input and setup"]
  node_entry["CLI entry<br/>[main.c]"]
  node_validation["Argument checks<br/>[check.c]"]
  node_configuration["Table and thread setup<br/>[init.c]"]
  node_shared["Simulation state<br/>[philo.h]"]
end

subgraph group_simulation["Simulation runtime"]
  node_coordinator["Run coordinator<br/>[main.c]"]
  node_philosopher["Philosopher routine<br/>[routine.c]"]
  node_actions["Eat sleep think<br/>[actions.c]"]
  node_monitor["Death and meal monitor<br/>[monitor.c]"]
end

subgraph group_support["Synchronization and support"]
  node_forks["Fork mutexes<br/>[fork_mutex.c]"]
  node_output["Action output<br/>[print.c]"]
  node_time["Time utilities<br/>[time_utils.c]"]
  node_utilities["Join and cleanup<br/>[utils.c]"]
end

node_user(("CLI user"))

node_user -->|"provides arguments"| node_entry
node_entry -->|"validates arguments"| node_validation
node_entry -->|"sets table"| node_configuration
node_entry -->|"starts simulation"| node_coordinator
node_coordinator -->|"initializes threads"| node_configuration
node_coordinator -->|"starts and joins"| node_monitor
node_coordinator -->|"joins philosophers"| node_utilities
node_entry -->|"cleans up"| node_utilities
node_configuration -->|"sets state"| node_shared
node_configuration -->|"reads clock"| node_time
node_configuration -->|"creates threads"| node_philosopher
node_philosopher -->|"runs actions"| node_actions
node_philosopher -->|"releases forks"| node_forks
node_philosopher -->|"handles solo case"| node_utilities
node_actions -->|"locks forks"| node_forks
node_actions -->|"waits and timestamps"| node_time
node_actions -->|"prints actions"| node_output
node_forks -->|"prints fork events"| node_output
node_forks -->|"checks deadline"| node_monitor
node_monitor -->|"checks meal count"| node_utilities
node_monitor -->|"reads clock"| node_time
node_output -->|"checks deadline"| node_monitor
node_output -->|"timestamps events"| node_time
node_utilities -->|"prints solo case"| node_output
node_utilities -->|"waits solo philosopher"| node_time

click node_entry "https://github.com/terzogode/philosophers/blob/main/philo/main.c"
click node_validation "https://github.com/terzogode/philosophers/blob/main/philo/check.c"
click node_configuration "https://github.com/terzogode/philosophers/blob/main/philo/init.c"
click node_shared "https://github.com/terzogode/philosophers/blob/main/philo/philo.h"
click node_coordinator "https://github.com/terzogode/philosophers/blob/main/philo/main.c"
click node_philosopher "https://github.com/terzogode/philosophers/blob/main/philo/routine.c"
click node_actions "https://github.com/terzogode/philosophers/blob/main/philo/actions.c"
click node_monitor "https://github.com/terzogode/philosophers/blob/main/philo/monitor.c"
click node_forks "https://github.com/terzogode/philosophers/blob/main/philo/fork_mutex.c"
click node_output "https://github.com/terzogode/philosophers/blob/main/philo/print.c"
click node_time "https://github.com/terzogode/philosophers/blob/main/philo/time_utils.c"
click node_utilities "https://github.com/terzogode/philosophers/blob/main/philo/utils.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_entry,node_validation,node_configuration,node_shared,node_user toneBlue
class node_coordinator,node_philosopher,node_actions,node_monitor toneAmber
class node_forks,node_output,node_time,node_utilities toneMint
```

## Components

### Input and setup

- [CLI entry](https://github.com/terzogode/philosophers/blob/main/philo/main.c): `philo/main.c`
- [Argument checks](https://github.com/terzogode/philosophers/blob/main/philo/check.c): `philo/check.c`
- [Table and thread setup](https://github.com/terzogode/philosophers/blob/main/philo/init.c): `philo/init.c`
- [Simulation state](https://github.com/terzogode/philosophers/blob/main/philo/philo.h): `philo/philo.h`

### Simulation runtime

- [Run coordinator](https://github.com/terzogode/philosophers/blob/main/philo/main.c): `philo/main.c`
- [Philosopher routine](https://github.com/terzogode/philosophers/blob/main/philo/routine.c): `philo/routine.c`
- [Eat sleep think](https://github.com/terzogode/philosophers/blob/main/philo/actions.c): `philo/actions.c`
- [Death and meal monitor](https://github.com/terzogode/philosophers/blob/main/philo/monitor.c): `philo/monitor.c`

### Synchronization and support

- [Fork mutexes](https://github.com/terzogode/philosophers/blob/main/philo/fork_mutex.c): `philo/fork_mutex.c`
- [Action output](https://github.com/terzogode/philosophers/blob/main/philo/print.c): `philo/print.c`
- [Time utilities](https://github.com/terzogode/philosophers/blob/main/philo/time_utils.c): `philo/time_utils.c`
- [Join and cleanup](https://github.com/terzogode/philosophers/blob/main/philo/utils.c): `philo/utils.c`

### Other components

- **CLI user**

## Connections

- CLI user → CLI entry: provides arguments
- CLI entry → Argument checks: validates arguments (evidence: `philo/main.c`)
- CLI entry → Table and thread setup: sets table (evidence: `philo/main.c`)
- CLI entry → Run coordinator: starts simulation (evidence: `philo/main.c`)
- Run coordinator → Table and thread setup: initializes threads (evidence: `philo/main.c`)
- Run coordinator → Death and meal monitor: starts and joins (evidence: `philo/main.c`)
- Run coordinator → Join and cleanup: joins philosophers (evidence: `philo/main.c`)
- CLI entry → Join and cleanup: cleans up (evidence: `philo/main.c`)
- Table and thread setup → Simulation state: sets state (evidence: `philo/init.c`)
- Table and thread setup → Time utilities: reads clock (evidence: `philo/init.c`)
- Table and thread setup → Philosopher routine: creates threads (evidence: `philo/init.c`)
- Philosopher routine → Eat sleep think: runs actions (evidence: `philo/routine.c`)
- Philosopher routine → Fork mutexes: releases forks (evidence: `philo/routine.c`)
- Philosopher routine → Join and cleanup: handles solo case (evidence: `philo/routine.c`)
- Eat sleep think → Fork mutexes: locks forks (evidence: `philo/actions.c`)
- Eat sleep think → Time utilities: waits and timestamps (evidence: `philo/actions.c`)
- Eat sleep think → Action output: prints actions (evidence: `philo/actions.c`)
- Fork mutexes → Action output: prints fork events (evidence: `philo/fork_mutex.c`)
- Fork mutexes → Death and meal monitor: checks deadline (evidence: `philo/fork_mutex.c`)
- Death and meal monitor → Join and cleanup: checks meal count (evidence: `philo/monitor.c`)
- Death and meal monitor → Time utilities: reads clock (evidence: `philo/monitor.c`)
- Action output → Death and meal monitor: checks deadline (evidence: `philo/print.c`)
- Action output → Time utilities: timestamps events (evidence: `philo/print.c`)
- Join and cleanup → Action output: prints solo case (evidence: `philo/utils.c`)
- Join and cleanup → Time utilities: waits solo philosopher (evidence: `philo/utils.c`)
