# nschaefer1/jockle architecture

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

- Interactive diagram: https://gitdiagram.com/nschaefer1/jockle
- Repository: https://github.com/nschaefer1/jockle

## Overview

1. **Overall shape**
   - Jockle is a **Windows desktop app** packaged around a **Python host process** and a **HTML/CSS/JavaScript UI** rendered inside **PyWebview**.
   - The repository is organized as a small desktop shell plus a local application backend and a file-based database layer.

2. **Application entry and runtime boundary**
   - `main.py` is the launch point.
   - It likely creates the webview window, wires the backend object into the frontend, and starts the app lifecycle.
   - This is the key boundary: **native Python runtime on one side, browser-like UI on the other**.

3. **Frontend subsystem**
   - `frontend/html/` contains the screens: `characters.html`, `inventory.html`, and a sub-screen for creating inventories.
   - `frontend/css/global.css` provides shared styling.
   - `frontend/js/router.js` suggests a client-side screen/navigation layer, while `inventory.js` and `inventory_sub/new_inventory.js` handle page-specific interaction logic.
   - The frontend is static and local; it does not appear to be a public web app.

4. **Frontend-to-backend interaction**
   - The JavaScript layer acts as the **interaction middleware** for user actions.
   - UI events likely call into the Python backend through the PyWebview bridge rather than via HTTP over a network.
   - That separation matters for the architecture: UI is presentation and event handling, while Python owns state, persistence, and business rules.

5. **Backend API layer**
   - `backend/api.py` is the main backend interface exposed to the frontend.
   - `backend/base_api.py` and the `backend/api_requests/` package split behavior by operation type: `get.py`, `post.py`, `put.py`, `patch.py`, and `delete.py`.
   - This indicates a request-dispatch pattern where frontend actions are mapped to CRUD-style handlers.

6. **Application/domain management**
   - `managers/main_app.py` appears to coordinate higher-level app behavior, likely campaign/character/inventory workflows.
   - This layer is the likely place where the app’s business logic lives: selecting campaigns, managing characters, and updating inventory state.
   - It acts as a bridge between the API surface and the lower-level data layer.

7. **Persistence and database access**
   - `managers/db_manager.py` centralizes access to the local database.
   - The app uses **SQLite**, consistent with the README’s “local relational database” goal.
   - SQL is stored separately under `sql/`, which cleanly divides schema/query definitions from Python code.

8. **Database design and seed data**
   - `sql/create_dim.sql` and `sql/create_ft.sql` suggest a **dimensional / fact-style schema** rather than a simple flat schema.
   - The CSV seed files under `sql/csv_seeds/` provide initial data for characters, inventories, and inventory statistics.
   - Additional query files in `sql/inventory/` indicate dedicated SQL for inventory views or lookup operations.

9. **Static rules and game-specific data**
   - `data/static_carry_cap.json` likely stores encumbrance/carry-capacity rules used by the inventory system.
   - The included `Encumbrance Math.tex` / `.pdf` reinforce that inventory weight/encumbrance is a meaningful domain rule, not just incidental data.
   - This suggests a small rules/data layer separate from the database.

10. **Asset and icon subsystem**
   - `frontend/assets/icons/` is organized by content type: accessories, armor, items, misc, weapons, and custom.
   - `managers/icon_manager.py` likely maps inventory items or categories to the correct icon asset.
   - This keeps UI rendering independent from business logic and avoids hardcoding file paths in the frontend.

11. **Shared models and return contracts**
   - `models/api_response.py` and `models/db_return.py` define structured outputs for backend calls and database operations.
   - These models are the contract boundary between backend services and the frontend caller, helping standardize success/error payloads.

12. **Utility layer**
   - `utils/file_utils.py`, `json_utils.py`, and `logging_utils.py` provide cross-cutting support functions.
   - These are infrastructure helpers rather than domain logic, likely used by both backend services and managers.

13. **Primary data flow**
   - User opens the desktop app → PyWebview loads local HTML/CSS/JS → frontend navigation selects a screen → JS calls backend methods → backend routes to the correct request handler or manager → database and static data are read/updated → structured response returns to the UI → UI refreshes.

14. **Key architectural boundaries**
   - **Presentation boundary:** frontend HTML/CSS/JS.
   - **Application logic boundary:** backend API and managers.
   - **Persistence boundary:** SQLite via SQL scripts and the DB manager.
   - **Static content boundary:** icons and JSON rule data.
   - The repo is intentionally split so UI, rules, and storage can evolve independently as campaign and inventory features expand.

Main entry points: [`backend/api.py`](https://github.com/nschaefer1/jockle/blob/main/backend/api.py) (API facade), [`managers/main_app.py`](https://github.com/nschaefer1/jockle/blob/main/managers/main_app.py) (Main app), [`frontend/js/router.js`](https://github.com/nschaefer1/jockle/blob/main/frontend/js/router.js) (Router), [`frontend/js/inventory.js`](https://github.com/nschaefer1/jockle/blob/main/frontend/js/inventory.js) (Inventory JS)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_grp_runtime["Desktop runtime"]
  node_main_py["main.py<br/>entrypoint<br/>[main.py]"]
  node_frontend_router["Router<br/>ui navigation<br/>[router.js]"]
  node_frontend_inventory_js["Inventory JS<br/>ui behavior<br/>[inventory.js]"]
  node_frontend_new_inventory_js["New Inventory JS<br/>ui behavior<br/>[new_inventory.js]"]
  node_frontend_chars_html["Characters UI<br/>screen<br/>[characters.html]"]
  node_frontend_inventory_html["Inventory UI<br/>screen<br/>[inventory.html]"]
  node_frontend_new_inventory_html["New Inventory UI<br/>screen<br/>[new_inventory.html]"]
end

subgraph group_grp_backend["Backend logic"]
  node_backend_api["API facade<br/>backend api<br/>[api.py]"]
  node_backend_base_api["Base API<br/>api base<br/>[base_api.py]"]
  node_backend_requests["CRUD handlers<br/>request handlers"]
  node_main_app["Main app<br/>orchestration<br/>[main_app.py]"]
end

subgraph group_grp_data["Data layer"]
  node_db_manager[("DB manager<br/>persistence access<br/>[db_manager.py]")]
  node_sql_scripts["SQL scripts<br/>schema/query assets"]
  node_static_rules["Carry rules<br/>domain data"]
end

subgraph group_grp_shared["Shared support"]
  node_icon_manager["Icon manager<br/>asset mapping<br/>[icon_manager.py]"]
  node_models_contracts["Response models<br/>contracts"]
  node_utils["Utilities<br/>support"]
end

node_main_py -->|"loads UI"| node_frontend_router
node_main_py -->|"injects backend"| node_backend_api
node_frontend_router -->|"navigates"| node_frontend_inventory_js
node_frontend_router -->|"shows"| node_frontend_chars_html
node_frontend_router -->|"shows"| node_frontend_inventory_html
node_frontend_inventory_js -->|"opens flow"| node_frontend_new_inventory_js
node_frontend_inventory_html -->|"binds"| node_frontend_inventory_js
node_frontend_new_inventory_html -->|"binds"| node_frontend_new_inventory_js
node_frontend_inventory_js -->|"calls"| node_backend_api
node_frontend_new_inventory_js -->|"calls"| node_backend_api
node_backend_api -->|"extends"| node_backend_base_api
node_backend_api -->|"dispatches"| node_backend_requests
node_backend_requests -->|"orchestrates"| node_main_app
node_main_app -->|"persists"| node_db_manager
node_db_manager -->|"executes"| node_sql_scripts
node_main_app -->|"applies rules"| node_static_rules
node_main_app -->|"resolves assets"| node_icon_manager
node_backend_api -->|"returns"| node_models_contracts
node_db_manager -->|"returns"| node_models_contracts
node_backend_api -->|"uses"| node_utils
node_main_app -->|"uses"| node_utils

click node_main_py "https://github.com/nschaefer1/jockle/blob/main/main.py"
click node_frontend_router "https://github.com/nschaefer1/jockle/blob/main/frontend/js/router.js"
click node_frontend_inventory_js "https://github.com/nschaefer1/jockle/blob/main/frontend/js/inventory.js"
click node_frontend_new_inventory_js "https://github.com/nschaefer1/jockle/blob/main/frontend/js/inventory_sub/new_inventory.js"
click node_frontend_chars_html "https://github.com/nschaefer1/jockle/blob/main/frontend/html/characters.html"
click node_frontend_inventory_html "https://github.com/nschaefer1/jockle/blob/main/frontend/html/inventory.html"
click node_frontend_new_inventory_html "https://github.com/nschaefer1/jockle/blob/main/frontend/html/inventory_sub/new_inventory.html"
click node_backend_api "https://github.com/nschaefer1/jockle/blob/main/backend/api.py"
click node_backend_base_api "https://github.com/nschaefer1/jockle/blob/main/backend/base_api.py"
click node_backend_requests "https://github.com/nschaefer1/jockle/tree/main/backend/api_requests"
click node_main_app "https://github.com/nschaefer1/jockle/blob/main/managers/main_app.py"
click node_db_manager "https://github.com/nschaefer1/jockle/blob/main/managers/db_manager.py"
click node_sql_scripts "https://github.com/nschaefer1/jockle/tree/main/sql"
click node_static_rules "https://github.com/nschaefer1/jockle/blob/main/data/static_carry_cap.json"
click node_icon_manager "https://github.com/nschaefer1/jockle/blob/main/managers/icon_manager.py"
click node_models_contracts "https://github.com/nschaefer1/jockle/tree/main/models"
click node_utils "https://github.com/nschaefer1/jockle/tree/main/utils"

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_py,node_frontend_router,node_frontend_inventory_js,node_frontend_new_inventory_js,node_frontend_chars_html,node_frontend_inventory_html,node_frontend_new_inventory_html toneBlue
class node_backend_api,node_backend_base_api,node_backend_requests,node_main_app toneAmber
class node_db_manager,node_sql_scripts,node_static_rules toneMint
class node_icon_manager,node_models_contracts,node_utils toneRose
```

## Components

### Desktop runtime

Native Python host and local web UI boundary.

- [main.py](https://github.com/nschaefer1/jockle/blob/main/main.py): entrypoint · Launches the desktop app and starts the PyWebview lifecycle. · `main.py`
- [Router](https://github.com/nschaefer1/jockle/blob/main/frontend/js/router.js): ui navigation · Client-side screen switching and page coordination. · `frontend/js/router.js`
- [Inventory JS](https://github.com/nschaefer1/jockle/blob/main/frontend/js/inventory.js): ui behavior · Inventory screen interactions and frontend event handling. · `frontend/js/inventory.js`
- [New Inventory JS](https://github.com/nschaefer1/jockle/blob/main/frontend/js/inventory_sub/new_inventory.js): ui behavior · Create-inventory subflow logic. · `frontend/js/inventory_sub/new_inventory.js`
- [Characters UI](https://github.com/nschaefer1/jockle/blob/main/frontend/html/characters.html): screen · Character-focused HTML view. · `frontend/html/characters.html`
- [Inventory UI](https://github.com/nschaefer1/jockle/blob/main/frontend/html/inventory.html): screen · Primary inventory HTML view. · `frontend/html/inventory.html`
- [New Inventory UI](https://github.com/nschaefer1/jockle/blob/main/frontend/html/inventory_sub/new_inventory.html): screen · Inventory creation sub-screen. · `frontend/html/inventory_sub/new_inventory.html`

### Backend logic

API surface, request handlers, and app orchestration.

- [API facade](https://github.com/nschaefer1/jockle/blob/main/backend/api.py): backend api · Main interface exposed to the frontend bridge. · `backend/api.py`
- [Base API](https://github.com/nschaefer1/jockle/blob/main/backend/base_api.py): api base · Shared API behavior and dispatch support. · `backend/base_api.py`
- [CRUD handlers](https://github.com/nschaefer1/jockle/tree/main/backend/api_requests): request handlers · Operation-specific backend request modules. · `backend/api_requests`
- [Main app](https://github.com/nschaefer1/jockle/blob/main/managers/main_app.py): orchestration · Coordinates app workflows and domain operations. · `managers/main_app.py`

### Data layer

Database access, SQL assets, and static rule data.

- [DB manager](https://github.com/nschaefer1/jockle/blob/main/managers/db_manager.py): persistence access · Centralized SQLite access and query execution. · `managers/db_manager.py`
- [SQL scripts](https://github.com/nschaefer1/jockle/tree/main/sql): schema/query assets · Schema, fact/dimension setup, and inventory queries. · `sql`
- [Carry rules](https://github.com/nschaefer1/jockle/blob/main/data/static_carry_cap.json): domain data · Static encumbrance and carry-capacity rule data. · `data/static_carry_cap.json`

### Shared support

Contracts, utilities, and asset mapping used across layers.

- [Icon manager](https://github.com/nschaefer1/jockle/blob/main/managers/icon_manager.py): asset mapping · Resolves item and category icons for the UI. · `managers/icon_manager.py`
- [Response models](https://github.com/nschaefer1/jockle/tree/main/models): contracts · Structured backend and database return types. · `models`
- [Utilities](https://github.com/nschaefer1/jockle/tree/main/utils): support · File, JSON, and logging helpers used across the app. · `utils`

## Connections

- main.py → Router: loads UI · The desktop host initializes the local webview UI.
- main.py → API facade: injects backend · The Python host exposes backend methods to the frontend bridge.
- Router → Inventory JS: navigates · Router selects the inventory screen behavior.
- Router → Characters UI: shows · Router switches to the characters view.
- Router → Inventory UI: shows · Router switches to the inventory view.
- Inventory JS → New Inventory JS: opens flow · Inventory interactions lead into the create-inventory subflow.
- Inventory UI → Inventory JS: binds · Inventory page markup is driven by its page script.
- New Inventory UI → New Inventory JS: binds · Create-inventory markup is driven by its page script.
- Inventory JS → API facade: calls · User actions are sent through the PyWebview bridge.
- New Inventory JS → API facade: calls · Inventory creation actions invoke backend methods.
- API facade → Base API: extends · The main API builds on shared API dispatch behavior.
- API facade → CRUD handlers: dispatches · API calls are routed to CRUD-style request modules.
- CRUD handlers → Main app: orchestrates · Request handlers delegate app workflows to the main application layer.
- Main app → DB manager: persists · Application logic reads and writes through the database manager.
- DB manager → SQL scripts: executes · SQL definitions and inventory queries back the persistence layer.
- Main app → Carry rules: applies rules · Business logic uses carry-capacity and encumbrance data.
- Main app → Icon manager: resolves assets · Domain objects are mapped to UI icons through the asset manager.
- API facade → Response models: returns · Backend responses are normalized through shared models.
- DB manager → Response models: returns · Database operations use structured return contracts.
- API facade → Utilities: uses · Backend layers rely on shared file, JSON, and logging helpers.
- Main app → Utilities: uses · Application orchestration uses common helper functions.
