# energyshifter8/v-1-13-bankers-algorithm architecture

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

- Interactive diagram: https://gitdiagram.com/energyshifter8/v-1-13-bankers-algorithm
- Repository: https://github.com/energyshifter8/v-1-13-bankers-algorithm

## Overview

This repository implements a Banker's Algorithm command-line simulator and a browser UI for editing resource states, submitting commands, and inspecting safety results. The UI sends commands through a local Python HTTP server to the C executable; C owns all algorithmic decisions and returns JSON state and safety traces. The graph and stepper render those results, while the CLI also exposes resource requests/releases, state editing, and deadlock detection. The main call and data paths are evidenced by README statements and sampled source; unsampled UI details are represented at subsystem level.

Main entry points: [`src/ui/static/js/app.js`](https://github.com/energyshifter8/v-1-13-bankers-algorithm/blob/main/src/ui/static/js/app.js) (UI controls), [`src/core/main.c`](https://github.com/energyshifter8/v-1-13-bankers-algorithm/blob/main/src/core/main.c) (CLI driver), [`src/ui/server.py`](https://github.com/energyshifter8/v-1-13-bankers-algorithm/blob/main/src/ui/server.py) (Local web server), [`src/ui/static/js/api.js`](https://github.com/energyshifter8/v-1-13-bankers-algorithm/blob/main/src/ui/static/js/api.js) (HTTP API client)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_cli["CLI and commands"]
  node_cli_driver["CLI driver<br/>[main.c]"]
end

subgraph group_engine["Banker engine"]
  node_bank_state["Resource state<br/>[banker.h]"]
  node_bank_algorithms["Banker algorithms<br/>[banker.c]"]
  node_json_output["JSON output<br/>[json.c]"]
end

subgraph group_web["Browser UI"]
  node_browser_app["UI controls<br/>[app.js]"]
  node_api_client["HTTP API client<br/>[api.js]"]
  node_web_server["Local web server<br/>[server.py]"]
  node_resource_graph["Resource graph<br/>[graph.js]"]
  node_safety_stepper["Safety stepper<br/>[stepper.js]"]
  node_static_ui["UI page and styles<br/>[index.html]"]
end

node_user(("Operator"))
node_web_user(("UI operator"))

node_user -->|"enters commands"| node_cli_driver
node_cli_driver -->|"requests safety operations"| node_bank_algorithms
node_bank_algorithms -->|"updates state"| node_bank_state
node_cli_driver -->|"serializes responses"| node_json_output
node_json_output -->|"encodes state and trace"| node_bank_state
node_web_user -->|"edits and submits"| node_browser_app
node_browser_app -->|"calls API methods"| node_api_client
node_api_client -->|"sends HTTP requests"| node_web_server
node_web_server -->|"forwards commands"| node_cli_driver
node_cli_driver -->|"returns JSON lines"| node_web_server
node_web_server -->|"returns API responses"| node_api_client
node_browser_app -->|"renders resource state"| node_resource_graph
node_browser_app -->|"builds safety frames"| node_safety_stepper
node_browser_app -.->|"uses page elements"| node_static_ui
node_web_server -->|"serves static UI"| node_static_ui

click node_cli_driver "https://github.com/energyshifter8/v-1-13-bankers-algorithm/blob/main/src/core/main.c"
click node_bank_state "https://github.com/energyshifter8/v-1-13-bankers-algorithm/blob/main/src/core/banker.h"
click node_bank_algorithms "https://github.com/energyshifter8/v-1-13-bankers-algorithm/blob/main/src/core/banker.c"
click node_json_output "https://github.com/energyshifter8/v-1-13-bankers-algorithm/blob/main/src/core/json.c"
click node_browser_app "https://github.com/energyshifter8/v-1-13-bankers-algorithm/blob/main/src/ui/static/js/app.js"
click node_api_client "https://github.com/energyshifter8/v-1-13-bankers-algorithm/blob/main/src/ui/static/js/api.js"
click node_web_server "https://github.com/energyshifter8/v-1-13-bankers-algorithm/blob/main/src/ui/server.py"
click node_resource_graph "https://github.com/energyshifter8/v-1-13-bankers-algorithm/blob/main/src/ui/static/js/graph.js"
click node_safety_stepper "https://github.com/energyshifter8/v-1-13-bankers-algorithm/blob/main/src/ui/static/js/stepper.js"
click node_static_ui "https://github.com/energyshifter8/v-1-13-bankers-algorithm/blob/main/src/ui/static/index.html"

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_cli_driver,node_web_user toneBlue
class node_bank_state,node_bank_algorithms,node_json_output toneAmber
class node_browser_app,node_api_client,node_web_server,node_resource_graph,node_safety_stepper,node_static_ui toneMint
class node_user toneIndigo
```

## Components

### CLI and commands

- [CLI driver](https://github.com/energyshifter8/v-1-13-bankers-algorithm/blob/main/src/core/main.c): `src/core/main.c`

### Banker engine

- [Resource state](https://github.com/energyshifter8/v-1-13-bankers-algorithm/blob/main/src/core/banker.h): `src/core/banker.h`
- [Banker algorithms](https://github.com/energyshifter8/v-1-13-bankers-algorithm/blob/main/src/core/banker.c): `src/core/banker.c`
- [JSON output](https://github.com/energyshifter8/v-1-13-bankers-algorithm/blob/main/src/core/json.c): `src/core/json.c`

### Browser UI

- [UI controls](https://github.com/energyshifter8/v-1-13-bankers-algorithm/blob/main/src/ui/static/js/app.js): `src/ui/static/js/app.js`
- [HTTP API client](https://github.com/energyshifter8/v-1-13-bankers-algorithm/blob/main/src/ui/static/js/api.js): `src/ui/static/js/api.js`
- [Local web server](https://github.com/energyshifter8/v-1-13-bankers-algorithm/blob/main/src/ui/server.py): `src/ui/server.py`
- [Resource graph](https://github.com/energyshifter8/v-1-13-bankers-algorithm/blob/main/src/ui/static/js/graph.js): `src/ui/static/js/graph.js`
- [Safety stepper](https://github.com/energyshifter8/v-1-13-bankers-algorithm/blob/main/src/ui/static/js/stepper.js): `src/ui/static/js/stepper.js`
- [UI page and styles](https://github.com/energyshifter8/v-1-13-bankers-algorithm/blob/main/src/ui/static/index.html): `src/ui/static/index.html`

### Other components

- **Operator**
- **UI operator**

## Connections

- Operator → CLI driver: enters commands (evidence: `README.md`)
- CLI driver → Banker algorithms: requests safety operations (evidence: `README.md`)
- Banker algorithms → Resource state: updates state (evidence: `src/core/banker.c`)
- CLI driver → JSON output: serializes responses (evidence: `src/core/main.c`)
- JSON output → Resource state: encodes state and trace (evidence: `src/core/json.c`)
- UI operator → UI controls: edits and submits (evidence: `README.md`)
- UI controls → HTTP API client: calls API methods (evidence: `src/ui/static/js/app.js`)
- HTTP API client → Local web server: sends HTTP requests (evidence: `src/ui/static/js/api.js`)
- Local web server → CLI driver: forwards commands (evidence: `src/ui/server.py`)
- CLI driver → Local web server: returns JSON lines (evidence: `src/ui/server.py`)
- Local web server → HTTP API client: returns API responses (evidence: `src/ui/server.py`)
- UI controls → Resource graph: renders resource state (evidence: `src/ui/static/js/app.js`)
- UI controls → Safety stepper: builds safety frames (evidence: `src/ui/static/js/app.js`)
- UI controls → UI page and styles: uses page elements
- Local web server → UI page and styles: serves static UI (evidence: `src/ui/server.py`)
