# bpinh0/pinhos architecture

> Architecture diagram of the GitHub repository bpinh0/pinhos, 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/bpinh0/pinhos
- Repository: https://github.com/bpinh0/pinhos

## Overview

PinhOS is a MicroPython operating system for PicoCalc-style cyberdecks. The principal workflow starts at boot, initializes board and persistent runtime services, then enters the launcher/UI loop; users select apps, settings, or tools, with app execution handled by the sandbox. Separate capability branches provide Wi-Fi and NTP, the secured browser IDE, themes, swap, and field tooling. The graph uses README and SOURCE INDEX relationships; unsampled implementation details are not inferred beyond those references.

Main entry points: [`main.py`](https://github.com/bpinh0/pinhos/blob/main/main.py) (Boot and runtime), [`ui/menu.py`](https://github.com/bpinh0/pinhos/blob/main/ui/menu.py) (Launcher and settings), [`boards/base.py`](https://github.com/bpinh0/pinhos/blob/main/boards/base.py) (Board interface), [`web/server.py`](https://github.com/bpinh0/pinhos/blob/main/web/server.py) (WebPortal server)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Runtime services"]
  node_main["Boot and runtime<br/>[main.py]"]
  node_config[("Configuration<br/>[config.py]")]
  node_logger["Crash logging<br/>[logger.py]"]
  node_sandbox["App sandbox<br/>[sandbox.py]"]
  node_swap[("Cooperative swap<br/>[swap.py]")]
  node_memory["Heap diagnostics<br/>[memutil.py]"]
  node_theme["Theme engine<br/>[theme.py]"]
end

subgraph group_hardware["Hardware abstraction"]
  node_hal["Board interface<br/>[base.py]"]
  node_picocalc["PicoCalc driver<br/>[picocalc.py]"]
end

subgraph group_interface["User interface"]
  node_launcher["Launcher and settings<br/>[menu.py]"]
  node_desktop["Desktop home<br/>[desktop.py]"]
  node_engine["Dual-UI engine<br/>[engine.py]"]
  node_gui["GUI renderer<br/>[gui.py]"]
  node_tui["TUI renderer<br/>[tui.py]"]
  node_widgets["Shared widgets<br/>[widgets.py]"]
end

subgraph group_connectivity["Connectivity and web"]
  node_wifi["Wi-Fi and NTP<br/>[wifi.py]"]
  node_sync["GitHub sync<br/>[sync.py]"]
  node_web["WebPortal server<br/>[server.py]"]
  node_webui["Browser IDE<br/>[app.js]"]
end

subgraph group_capabilities["Apps and field tools"]
  node_apps["User applications"]
  node_editor["On-device editor<br/>[editor.py]"]
  node_shell["CLI shell<br/>[shell.py]"]
  node_shellcmds["Shell commands<br/>[_shell_cmds.py]"]
  node_files["File commander<br/>[files.py]"]
  node_nettools["Network probes<br/>[net_tools.py]"]
  node_sysmon["System monitor<br/>[sysmon.py]"]
  node_uart["UART console<br/>[uart_term.py]"]
end

node_user(("Device user"))
node_network(("Wi-Fi network"))

node_user -->|"powers on"| node_main
node_main -->|"initializes"| node_hal
node_picocalc -->|"implements"| node_hal
node_main -->|"loads settings"| node_config
node_main -->|"initializes"| node_logger
node_main -->|"enters"| node_launcher
node_main -->|"initializes"| node_theme
node_main -->|"initializes"| node_engine
node_launcher -->|"launches apps"| node_sandbox
node_launcher -->|"manages app state"| node_swap
node_launcher -->|"configures network"| node_wifi
node_launcher -->|"offers sync"| node_sync
node_launcher -->|"starts portal"| node_web
node_launcher -->|"shows home"| node_desktop
node_desktop -->|"reads settings"| node_config
node_desktop -->|"renders with"| node_widgets
node_desktop -->|"reads usage"| node_swap
node_desktop -->|"reads status"| node_wifi
node_engine -->|"dispatches"| node_gui
node_engine -->|"dispatches"| node_tui
node_engine -->|"uses palette"| node_theme
node_gui -->|"renders"| node_widgets
node_tui -->|"renders"| node_widgets
node_theme -->|"sets palette"| node_hal
node_sandbox -->|"checks heap"| node_memory
node_swap -->|"uses storage settings"| node_config
node_swap -->|"checks heap"| node_memory
node_wifi -->|"persists settings"| node_config
node_wifi -->|"connects"| node_network
node_sync -->|"uses connectivity"| node_wifi
node_sync -->|"syncs themes"| node_theme
node_web -->|"uses connectivity"| node_wifi
node_web -->|"reads settings"| node_config
node_web -->|"writes web log"| node_logger
node_web -->|"launches apps"| node_sandbox
node_webui -->|"calls API"| node_web
node_user -->|"selects app"| node_apps
node_shell -->|"dispatches commands"| node_shellcmds
node_shell -->|"opens editor"| node_editor
node_files -->|"edits files"| node_editor
node_shell -->|"uses board input"| node_hal
node_editor -->|"uses board interface"| node_hal
node_nettools -->|"uses board interface"| node_hal
node_sysmon -->|"checks heap"| node_memory
node_uart -->|"routes serial"| node_hal

click node_main "https://github.com/bpinh0/pinhos/blob/main/main.py"
click node_config "https://github.com/bpinh0/pinhos/blob/main/core/config.py"
click node_logger "https://github.com/bpinh0/pinhos/blob/main/core/logger.py"
click node_sandbox "https://github.com/bpinh0/pinhos/blob/main/core/sandbox.py"
click node_swap "https://github.com/bpinh0/pinhos/blob/main/core/swap.py"
click node_memory "https://github.com/bpinh0/pinhos/blob/main/core/memutil.py"
click node_theme "https://github.com/bpinh0/pinhos/blob/main/core/theme.py"
click node_hal "https://github.com/bpinh0/pinhos/blob/main/boards/base.py"
click node_picocalc "https://github.com/bpinh0/pinhos/blob/main/boards/picocalc.py"
click node_launcher "https://github.com/bpinh0/pinhos/blob/main/ui/menu.py"
click node_desktop "https://github.com/bpinh0/pinhos/blob/main/ui/desktop.py"
click node_engine "https://github.com/bpinh0/pinhos/blob/main/ui/engine.py"
click node_gui "https://github.com/bpinh0/pinhos/blob/main/ui/gui.py"
click node_tui "https://github.com/bpinh0/pinhos/blob/main/ui/tui.py"
click node_widgets "https://github.com/bpinh0/pinhos/blob/main/ui/widgets.py"
click node_wifi "https://github.com/bpinh0/pinhos/blob/main/net/wifi.py"
click node_sync "https://github.com/bpinh0/pinhos/blob/main/net/sync.py"
click node_web "https://github.com/bpinh0/pinhos/blob/main/web/server.py"
click node_webui "https://github.com/bpinh0/pinhos/blob/main/web/static/app.js"
click node_apps "https://github.com/bpinh0/pinhos/tree/main/apps"
click node_editor "https://github.com/bpinh0/pinhos/blob/main/tools/editor.py"
click node_shell "https://github.com/bpinh0/pinhos/blob/main/tools/shell.py"
click node_shellcmds "https://github.com/bpinh0/pinhos/blob/main/tools/_shell_cmds.py"
click node_files "https://github.com/bpinh0/pinhos/blob/main/tools/files.py"
click node_nettools "https://github.com/bpinh0/pinhos/blob/main/tools/net_tools.py"
click node_sysmon "https://github.com/bpinh0/pinhos/blob/main/tools/sysmon.py"
click node_uart "https://github.com/bpinh0/pinhos/blob/main/tools/uart_term.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_main,node_config,node_logger,node_sandbox,node_swap,node_memory,node_theme,node_user toneBlue
class node_hal,node_picocalc toneAmber
class node_launcher,node_desktop,node_engine,node_gui,node_tui,node_widgets toneMint
class node_wifi,node_sync,node_web,node_webui toneRose
class node_apps,node_editor,node_shell,node_shellcmds,node_files,node_nettools,node_sysmon,node_uart,node_network toneIndigo
```

## Components

### Runtime services

- [Boot and runtime](https://github.com/bpinh0/pinhos/blob/main/main.py): `main.py`
- [Configuration](https://github.com/bpinh0/pinhos/blob/main/core/config.py): `core/config.py`
- [Crash logging](https://github.com/bpinh0/pinhos/blob/main/core/logger.py): `core/logger.py`
- [App sandbox](https://github.com/bpinh0/pinhos/blob/main/core/sandbox.py): `core/sandbox.py`
- [Cooperative swap](https://github.com/bpinh0/pinhos/blob/main/core/swap.py): `core/swap.py`
- [Heap diagnostics](https://github.com/bpinh0/pinhos/blob/main/core/memutil.py): `core/memutil.py`
- [Theme engine](https://github.com/bpinh0/pinhos/blob/main/core/theme.py): `core/theme.py`

### Hardware abstraction

- [Board interface](https://github.com/bpinh0/pinhos/blob/main/boards/base.py): `boards/base.py`
- [PicoCalc driver](https://github.com/bpinh0/pinhos/blob/main/boards/picocalc.py): `boards/picocalc.py`

### User interface

- [Launcher and settings](https://github.com/bpinh0/pinhos/blob/main/ui/menu.py): `ui/menu.py`
- [Desktop home](https://github.com/bpinh0/pinhos/blob/main/ui/desktop.py): `ui/desktop.py`
- [Dual-UI engine](https://github.com/bpinh0/pinhos/blob/main/ui/engine.py): `ui/engine.py`
- [GUI renderer](https://github.com/bpinh0/pinhos/blob/main/ui/gui.py): `ui/gui.py`
- [TUI renderer](https://github.com/bpinh0/pinhos/blob/main/ui/tui.py): `ui/tui.py`
- [Shared widgets](https://github.com/bpinh0/pinhos/blob/main/ui/widgets.py): `ui/widgets.py`

### Connectivity and web

- [Wi-Fi and NTP](https://github.com/bpinh0/pinhos/blob/main/net/wifi.py): `net/wifi.py`
- [GitHub sync](https://github.com/bpinh0/pinhos/blob/main/net/sync.py): `net/sync.py`
- [WebPortal server](https://github.com/bpinh0/pinhos/blob/main/web/server.py): `web/server.py`
- [Browser IDE](https://github.com/bpinh0/pinhos/blob/main/web/static/app.js): `web/static/app.js`

### Apps and field tools

- [User applications](https://github.com/bpinh0/pinhos/tree/main/apps): `apps`
- [On-device editor](https://github.com/bpinh0/pinhos/blob/main/tools/editor.py): `tools/editor.py`
- [CLI shell](https://github.com/bpinh0/pinhos/blob/main/tools/shell.py): `tools/shell.py`
- [Shell commands](https://github.com/bpinh0/pinhos/blob/main/tools/_shell_cmds.py): `tools/_shell_cmds.py`
- [File commander](https://github.com/bpinh0/pinhos/blob/main/tools/files.py): `tools/files.py`
- [Network probes](https://github.com/bpinh0/pinhos/blob/main/tools/net_tools.py): `tools/net_tools.py`
- [System monitor](https://github.com/bpinh0/pinhos/blob/main/tools/sysmon.py): `tools/sysmon.py`
- [UART console](https://github.com/bpinh0/pinhos/blob/main/tools/uart_term.py): `tools/uart_term.py`

### Other components

- **Device user**
- **Wi-Fi network**

## Connections

- Device user → Boot and runtime: powers on
- Boot and runtime → Board interface: initializes (evidence: `main.py`)
- PicoCalc driver → Board interface: implements (evidence: `boards/picocalc.py`)
- Boot and runtime → Configuration: loads settings (evidence: `main.py`)
- Boot and runtime → Crash logging: initializes (evidence: `main.py`)
- Boot and runtime → Launcher and settings: enters (evidence: `main.py`)
- Boot and runtime → Theme engine: initializes (evidence: `main.py`)
- Boot and runtime → Dual-UI engine: initializes (evidence: `main.py`)
- Launcher and settings → App sandbox: launches apps (evidence: `ui/menu.py`)
- Launcher and settings → Cooperative swap: manages app state (evidence: `ui/menu.py`)
- Launcher and settings → Wi-Fi and NTP: configures network (evidence: `ui/menu.py`)
- Launcher and settings → GitHub sync: offers sync (evidence: `ui/menu.py`)
- Launcher and settings → WebPortal server: starts portal (evidence: `ui/menu.py`)
- Launcher and settings → Desktop home: shows home
- Desktop home → Configuration: reads settings (evidence: `ui/desktop.py`)
- Desktop home → Shared widgets: renders with (evidence: `ui/desktop.py`)
- Desktop home → Cooperative swap: reads usage (evidence: `ui/desktop.py`)
- Desktop home → Wi-Fi and NTP: reads status (evidence: `ui/desktop.py`)
- Dual-UI engine → GUI renderer: dispatches (evidence: `ui/engine.py`)
- Dual-UI engine → TUI renderer: dispatches (evidence: `ui/engine.py`)
- Dual-UI engine → Theme engine: uses palette (evidence: `ui/engine.py`)
- GUI renderer → Shared widgets: renders (evidence: `ui/gui.py`)
- TUI renderer → Shared widgets: renders (evidence: `ui/tui.py`)
- Theme engine → Board interface: sets palette (evidence: `core/theme.py`)
- App sandbox → Heap diagnostics: checks heap (evidence: `core/sandbox.py`)
- Cooperative swap → Configuration: uses storage settings (evidence: `core/swap.py`)
- Cooperative swap → Heap diagnostics: checks heap (evidence: `core/swap.py`)
- Wi-Fi and NTP → Configuration: persists settings (evidence: `net/wifi.py`)
- Wi-Fi and NTP → Wi-Fi network: connects
- GitHub sync → Wi-Fi and NTP: uses connectivity (evidence: `net/sync.py`)
- GitHub sync → Theme engine: syncs themes (evidence: `net/sync.py`)
- WebPortal server → Wi-Fi and NTP: uses connectivity (evidence: `web/server.py`)
- WebPortal server → Configuration: reads settings (evidence: `web/server.py`)
- WebPortal server → Crash logging: writes web log (evidence: `web/server.py`)
- WebPortal server → App sandbox: launches apps (evidence: `web/server.py`)
- Browser IDE → WebPortal server: calls API
- Device user → User applications: selects app
- CLI shell → Shell commands: dispatches commands (evidence: `tools/shell.py`)
- CLI shell → On-device editor: opens editor (evidence: `tools/shell.py`)
- File commander → On-device editor: edits files (evidence: `tools/files.py`)
- CLI shell → Board interface: uses board input (evidence: `tools/shell.py`)
- On-device editor → Board interface: uses board interface (evidence: `tools/editor.py`)
- Network probes → Board interface: uses board interface (evidence: `tools/net_tools.py`)
- System monitor → Heap diagnostics: checks heap (evidence: `tools/sysmon.py`)
- UART console → Board interface: routes serial (evidence: `tools/uart_term.py`)
