# shubanms/opus architecture

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

- Interactive diagram: https://gitdiagram.com/shubanms/opus
- Repository: https://github.com/shubanms/opus

## Overview

#### Purpose and Product Boundary
OPUS is an offline-first gym-tracking PWA with RPG progression. The primary product is a browser application; user workout, health, planning, and progression data remains device-local in IndexedDB, with import/export rather than a cloud backend. A parallel React Native mobile client and Android Capacitor shell are present.
Paths: `src/main.jsx`, `src/db/db.js`, `apps/mobile/App.js`

#### Web Application Entry and Navigation
Vite boots React from `src/main.jsx`; routing selects page-level workflows such as workout execution, templates, progress, profile, and settings. Shared layout, navigation, modal hosting, and error recovery form the UI shell around routes.
Paths: `src/main.jsx`, `src/router.jsx`, `src/components/layout/AppLayout.jsx`

#### Persistent Data and Integrity Boundary
Dexie/IndexedDB is the system of record. Schema evolution is isolated in migrations; feature hooks and action utilities should be the boundary between UI and persisted records. Data recovery, reset, import/export, and derived record recalculation are important because no server can restore state.
Paths: `src/db/db.js`, `src/db/migrations.js`, `src/components/DbRecovery.jsx`

#### Workout Execution Pipeline
The active-workout flow selects exercises, logs sets and rest, supports supersets/reordering, and completes through an end-workout transition. Completion persists workout history and drives downstream personal-record, volume, XP, quest, and snapshot calculations.
Paths: `src/pages/WorkoutPage.jsx`, `src/components/workout/SetLogger.jsx`, `src/utils/workoutActions.js`

#### Planning and Exercise Domain
Exercises, reusable templates, generated routines, and weekly planning provide inputs to the workout pipeline. Planning logic is split between UI orchestration and deterministic domain calculations; initial exercise data is seeded locally.
Paths: `src/pages/TemplatesPage.jsx`, `src/components/template/RoutineGeneratorModal.jsx`, `src/utils/routineGenerator.js`

#### Shared Fitness and RPG Domain Logic
`packages/core` is the reusable pure-domain package for workout-session rules, progression, achievements, quests, overload, volume, PRs, and recap calculations. The web app also has corresponding `src/utils` modules, so synchronization or intentional divergence between these two logic layers is a key maintenance boundary.
Paths: `packages/core/src/index.js`, `packages/core/src/workoutSession.js`, `packages/core/src/rpg.js`

#### State, Insights, and Native Integrations
Zustand stores hold UI/session/settings state; hooks compose persisted data into page-ready models for progress, recovery, quests, RPG state, and reminders. The web uses browser/PWA capabilities, while the mobile client adds local database access, notifications, haptics, sharing, sound, widgets, and export adapters.
Paths: `src/store/workoutStore.js`, `src/hooks/useProgress.js`, `apps/mobile/native/db.js`

#### Delivery Runtimes and Infrastructure
Web runtime: React 18, Vite, Tailwind, React Router, Dexie, Zustand, Recharts, PWA support, and html2canvas. Deployment is GitHub Pages under `/opus/`, triggered on `main`. Mobile runtime is React Native, with Android Gradle/Capacitor artifacts and APK/release workflows. No application server or external data service is indicated.
Paths: `vite.config.js`, `.github/workflows/deploy.yml`, `android/app/src/main/java/com/shubanms/opus/MainActivity.java`

Main entry points: [`src/db/db.js`](https://github.com/shubanms/opus/blob/main/src/db/db.js) (IndexedDB system of record), [`src/router.jsx`](https://github.com/shubanms/opus/blob/main/src/router.jsx) (Route workflows), [`src/utils/workoutActions.js`](https://github.com/shubanms/opus/blob/main/src/utils/workoutActions.js) (Workout completion), [`packages/core/src/index.js`](https://github.com/shubanms/opus/blob/main/packages/core/src/index.js) (Shared fitness / RPG core)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Web PWA"]
  node_web_entry["Vite / React entry<br/>web entry<br/>[main.jsx]"]
  node_router["Route workflows<br/>router<br/>[router.jsx]"]
  node_ui_shell["App shell<br/>UI shell<br/>[AppLayout.jsx]"]
  node_workout_page["Workout execution<br/>page workflow<br/>[WorkoutPage.jsx]"]
  node_set_logger["Set and rest logging<br/>workout UI<br/>[SetLogger.jsx]"]
  node_workout_actions["Workout completion<br/>action layer<br/>[workoutActions.js]"]
  node_planning["Templates and planning<br/>planning UI<br/>[TemplatesPage.jsx]"]
  node_routine_modal["Routine generator<br/>planning UI"]
  node_routine_logic["Routine calculations<br/>domain logic"]
  node_workout_store["Session state<br/>Zustand store<br/>[workoutStore.js]"]
  node_progress_hook["Progress insights<br/>data hook<br/>[useProgress.js]"]
end

subgraph group_data["Local Data &amp; Domain"]
  node_indexeddb[("IndexedDB system of record<br/>Dexie database<br/>[db.js]")]
  node_migrations["Schema migrations<br/>data migration<br/>[migrations.js]"]
  node_recovery["Data recovery and transfer<br/>recovery UI<br/>[DbRecovery.jsx]"]
  node_core_api["Shared fitness / RPG core<br/>pure domain package<br/>[index.js]"]
  node_session_rules["Workout session rules<br/>core module<br/>[workoutSession.js]"]
  node_rpg_rules["RPG progression rules<br/>core module<br/>[rpg.js]"]
end

subgraph group_mobile["Mobile Runtime"]
  node_mobile_app["React Native client<br/>mobile app<br/>[App.js]"]
  node_mobile_db[("Native local database<br/>mobile data adapter<br/>[db.js]")]
  node_android_shell["Android Capacitor shell<br/>Android entry<br/>[MainActivity.java]"]
end

subgraph group_delivery["Delivery"]
  node_vite["Web build configuration<br/>Vite config<br/>[vite.config.js]"]
  node_deploy["GitHub Pages deployment<br/>CI workflow<br/>[deploy.yml]"]
end

node_web_entry -->|"boots"| node_router
node_router -->|"renders within"| node_ui_shell
node_router -->|"selects"| node_workout_page
node_router -->|"selects"| node_planning
node_workout_page -->|"uses"| node_set_logger
node_set_logger -->|"updates"| node_workout_store
node_workout_page -->|"completes through"| node_workout_actions
node_workout_actions -->|"writes history"| node_indexeddb
node_workout_actions -->|"calculates"| node_core_api
node_planning -->|"opens"| node_routine_modal
node_routine_modal -->|"generates with"| node_routine_logic
node_planning -->|"reads and saves plans"| node_indexeddb
node_progress_hook -->|"derives from"| node_indexeddb
node_migrations -->|"evolves schema"| node_indexeddb
node_recovery -->|"recovers and transfers"| node_indexeddb
node_core_api -->|"exports"| node_session_rules
node_core_api -->|"exports"| node_rpg_rules
node_workout_actions -.->|"must stay aligned with"| node_core_api
node_mobile_app -->|"uses"| node_mobile_db
node_android_shell -->|"hosts"| node_mobile_app
node_vite -->|"builds"| node_web_entry
node_deploy -->|"deploys build"| node_vite

click node_web_entry "https://github.com/shubanms/opus/blob/main/src/main.jsx"
click node_router "https://github.com/shubanms/opus/blob/main/src/router.jsx"
click node_ui_shell "https://github.com/shubanms/opus/blob/main/src/components/layout/AppLayout.jsx"
click node_workout_page "https://github.com/shubanms/opus/blob/main/src/pages/WorkoutPage.jsx"
click node_set_logger "https://github.com/shubanms/opus/blob/main/src/components/workout/SetLogger.jsx"
click node_workout_actions "https://github.com/shubanms/opus/blob/main/src/utils/workoutActions.js"
click node_planning "https://github.com/shubanms/opus/blob/main/src/pages/TemplatesPage.jsx"
click node_routine_modal "https://github.com/shubanms/opus/blob/main/src/components/template/RoutineGeneratorModal.jsx"
click node_routine_logic "https://github.com/shubanms/opus/blob/main/src/utils/routineGenerator.js"
click node_workout_store "https://github.com/shubanms/opus/blob/main/src/store/workoutStore.js"
click node_progress_hook "https://github.com/shubanms/opus/blob/main/src/hooks/useProgress.js"
click node_indexeddb "https://github.com/shubanms/opus/blob/main/src/db/db.js"
click node_migrations "https://github.com/shubanms/opus/blob/main/src/db/migrations.js"
click node_recovery "https://github.com/shubanms/opus/blob/main/src/components/DbRecovery.jsx"
click node_core_api "https://github.com/shubanms/opus/blob/main/packages/core/src/index.js"
click node_session_rules "https://github.com/shubanms/opus/blob/main/packages/core/src/workoutSession.js"
click node_rpg_rules "https://github.com/shubanms/opus/blob/main/packages/core/src/rpg.js"
click node_mobile_app "https://github.com/shubanms/opus/blob/main/apps/mobile/App.js"
click node_mobile_db "https://github.com/shubanms/opus/blob/main/apps/mobile/native/db.js"
click node_android_shell "https://github.com/shubanms/opus/blob/main/android/app/src/main/java/com/shubanms/opus/MainActivity.java"
click node_vite "https://github.com/shubanms/opus/blob/main/vite.config.js"
click node_deploy "https://github.com/shubanms/opus/blob/main/.github/workflows/deploy.yml"

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_web_entry,node_router,node_ui_shell,node_workout_page,node_set_logger,node_workout_actions,node_planning,node_routine_modal,node_routine_logic,node_workout_store,node_progress_hook toneBlue
class node_indexeddb,node_migrations,node_recovery,node_core_api,node_session_rules,node_rpg_rules toneAmber
class node_mobile_app,node_mobile_db,node_android_shell toneMint
class node_vite,node_deploy toneRose
```

## Components

### Web PWA

- [Vite / React entry](https://github.com/shubanms/opus/blob/main/src/main.jsx): web entry · `src/main.jsx`
- [Route workflows](https://github.com/shubanms/opus/blob/main/src/router.jsx): router · Selects workout, planning, progress, profile, and settings pages. · `src/router.jsx`
- [App shell](https://github.com/shubanms/opus/blob/main/src/components/layout/AppLayout.jsx): UI shell · Shared layout, navigation, modals, and error recovery. · `src/components/layout/AppLayout.jsx`
- [Workout execution](https://github.com/shubanms/opus/blob/main/src/pages/WorkoutPage.jsx): page workflow · `src/pages/WorkoutPage.jsx`
- [Set and rest logging](https://github.com/shubanms/opus/blob/main/src/components/workout/SetLogger.jsx): workout UI · `src/components/workout/SetLogger.jsx`
- [Workout completion](https://github.com/shubanms/opus/blob/main/src/utils/workoutActions.js): action layer · Persists history and triggers downstream calculations. · `src/utils/workoutActions.js`
- [Templates and planning](https://github.com/shubanms/opus/blob/main/src/pages/TemplatesPage.jsx): planning UI · `src/pages/TemplatesPage.jsx`
- [Routine generator](https://github.com/shubanms/opus/blob/main/src/components/template/RoutineGeneratorModal.jsx): planning UI · `src/components/template/RoutineGeneratorModal.jsx`
- [Routine calculations](https://github.com/shubanms/opus/blob/main/src/utils/routineGenerator.js): domain logic · `src/utils/routineGenerator.js`
- [Session state](https://github.com/shubanms/opus/blob/main/src/store/workoutStore.js): Zustand store · `src/store/workoutStore.js`
- [Progress insights](https://github.com/shubanms/opus/blob/main/src/hooks/useProgress.js): data hook · Composes local records into page-ready progress models. · `src/hooks/useProgress.js`

### Local Data & Domain

- [IndexedDB system of record](https://github.com/shubanms/opus/blob/main/src/db/db.js): Dexie database · All user data remains device-local. · `src/db/db.js`
- [Schema migrations](https://github.com/shubanms/opus/blob/main/src/db/migrations.js): data migration · `src/db/migrations.js`
- [Data recovery and transfer](https://github.com/shubanms/opus/blob/main/src/components/DbRecovery.jsx): recovery UI · Supports recovery, reset, import, and export without a server. · `src/components/DbRecovery.jsx`
- [Shared fitness / RPG core](https://github.com/shubanms/opus/blob/main/packages/core/src/index.js): pure domain package · Reusable session, progression, achievements, quests, overload, volume, PR, and recap rules. · `packages/core/src/index.js`
- [Workout session rules](https://github.com/shubanms/opus/blob/main/packages/core/src/workoutSession.js): core module · `packages/core/src/workoutSession.js`
- [RPG progression rules](https://github.com/shubanms/opus/blob/main/packages/core/src/rpg.js): core module · `packages/core/src/rpg.js`

### Mobile Runtime

- [React Native client](https://github.com/shubanms/opus/blob/main/apps/mobile/App.js): mobile app · Parallel client with native integrations. · `apps/mobile/App.js`
- [Native local database](https://github.com/shubanms/opus/blob/main/apps/mobile/native/db.js): mobile data adapter · `apps/mobile/native/db.js`
- [Android Capacitor shell](https://github.com/shubanms/opus/blob/main/android/app/src/main/java/com/shubanms/opus/MainActivity.java): Android entry · `android/app/src/main/java/com/shubanms/opus/MainActivity.java`

### Delivery

- [Web build configuration](https://github.com/shubanms/opus/blob/main/vite.config.js): Vite config · Builds the PWA for the GitHub Pages /opus/ base path. · `vite.config.js`
- [GitHub Pages deployment](https://github.com/shubanms/opus/blob/main/.github/workflows/deploy.yml): CI workflow · Deploys from main. · `.github/workflows/deploy.yml`

## Connections

- Vite / React entry → Route workflows: boots
- Route workflows → App shell: renders within
- Route workflows → Workout execution: selects
- Route workflows → Templates and planning: selects
- Workout execution → Set and rest logging: uses
- Set and rest logging → Session state: updates
- Workout execution → Workout completion: completes through
- Workout completion → IndexedDB system of record: writes history
- Workout completion → Shared fitness / RPG core: calculates
- Templates and planning → Routine generator: opens
- Routine generator → Routine calculations: generates with
- Templates and planning → IndexedDB system of record: reads and saves plans
- Progress insights → IndexedDB system of record: derives from
- Schema migrations → IndexedDB system of record: evolves schema
- Data recovery and transfer → IndexedDB system of record: recovers and transfers
- Shared fitness / RPG core → Workout session rules: exports
- Shared fitness / RPG core → RPG progression rules: exports
- Workout completion → Shared fitness / RPG core: must stay aligned with
- React Native client → Native local database: uses
- Android Capacitor shell → React Native client: hosts
- Web build configuration → Vite / React entry: builds
- GitHub Pages deployment → Web build configuration: deploys build
