# loganzartman/tuicalc architecture

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

- Interactive diagram: https://gitdiagram.com/loganzartman/tuicalc
- Repository: https://github.com/loganzartman/tuicalc

## Overview

tuicalc is a four-function terminal calculator. Its principal workflow is terminal mouse/keyboard input into calculator state, followed by formatted display rendering. The separate layout module computes geometry, hit-tests controls, and renders styled boxes. The README documents mouse interaction and keyboard input; layout behavior is supported by sampled source, while the JSON layout contents were not sampled.

Main entry points: [`calc.py`](https://github.com/loganzartman/tuicalc/blob/master/calc.py) (Calculator app), [`layout.py`](https://github.com/loganzartman/tuicalc/blob/master/layout.py) (Layout engine), [`layout.json`](https://github.com/loganzartman/tuicalc/blob/master/layout.json) (UI layout)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["Calculator app"]
  node_app["Calculator app<br/>[calc.py]"]
  node_input["Input handling<br/>[calc.py]"]
  node_state["Calculator state<br/>[calc.py]"]
  node_display["Formatted display<br/>[calc.py]"]
end

subgraph group_layout["Terminal layout"]
  node_layoutdata["UI layout<br/>[layout.json]"]
  node_layoutengine["Layout engine<br/>[layout.py]"]
  node_geometry["Geometry and hit tests<br/>[layout.py]"]
  node_renderer["Screen renderer<br/>[layout.py]"]
end

node_user(("User"))
node_terminal["Terminal UI"]
node_termpixels["termpixels"]

node_user -->|"interacts"| node_terminal
node_terminal -->|"delivers input"| node_input
node_app -->|"loads"| node_layoutdata
node_app -->|"computes layout"| node_layoutengine
node_app -->|"hit-tests"| node_geometry
node_input -->|"updates"| node_state
node_app -->|"formats value"| node_display
node_display -->|"sets text"| node_layoutengine
node_layoutengine -->|"computes positions"| node_geometry
node_layoutengine -->|"renders layout"| node_renderer
node_renderer -->|"draws screen"| node_terminal
node_app -->|"uses app and screen"| node_termpixels

click node_app "https://github.com/loganzartman/tuicalc/blob/master/calc.py"
click node_input "https://github.com/loganzartman/tuicalc/blob/master/calc.py"
click node_state "https://github.com/loganzartman/tuicalc/blob/master/calc.py"
click node_display "https://github.com/loganzartman/tuicalc/blob/master/calc.py"
click node_layoutdata "https://github.com/loganzartman/tuicalc/blob/master/layout.json"
click node_layoutengine "https://github.com/loganzartman/tuicalc/blob/master/layout.py"
click node_geometry "https://github.com/loganzartman/tuicalc/blob/master/layout.py"
click node_renderer "https://github.com/loganzartman/tuicalc/blob/master/layout.py"

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_app,node_input,node_state,node_display,node_user,node_terminal toneBlue
class node_layoutdata,node_layoutengine,node_geometry,node_renderer toneAmber
class node_termpixels toneIndigo
```

## Components

### Calculator app

- [Calculator app](https://github.com/loganzartman/tuicalc/blob/master/calc.py): `calc.py`
- [Input handling](https://github.com/loganzartman/tuicalc/blob/master/calc.py): `calc.py`
- [Calculator state](https://github.com/loganzartman/tuicalc/blob/master/calc.py): `calc.py`
- [Formatted display](https://github.com/loganzartman/tuicalc/blob/master/calc.py): `calc.py`

### Terminal layout

- [UI layout](https://github.com/loganzartman/tuicalc/blob/master/layout.json): `layout.json`
- [Layout engine](https://github.com/loganzartman/tuicalc/blob/master/layout.py): `layout.py`
- [Geometry and hit tests](https://github.com/loganzartman/tuicalc/blob/master/layout.py): `layout.py`
- [Screen renderer](https://github.com/loganzartman/tuicalc/blob/master/layout.py): `layout.py`

### Other components

- **User**
- **Terminal UI**
- **termpixels**

## Connections

- User → Terminal UI: interacts
- Terminal UI → Input handling: delivers input
- Calculator app → UI layout: loads
- Calculator app → Layout engine: computes layout
- Calculator app → Geometry and hit tests: hit-tests
- Input handling → Calculator state: updates
- Calculator app → Formatted display: formats value
- Formatted display → Layout engine: sets text
- Layout engine → Geometry and hit tests: computes positions
- Layout engine → Screen renderer: renders layout
- Screen renderer → Terminal UI: draws screen
- Calculator app → termpixels: uses app and screen
