How shubanms/opus works
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: db.js IndexedDB system of record · router.jsx Route workflows · workoutActions.js Workout completion · index.js Shared fitness / RPG core
Components 22
Web PWA
- Vite / React entry
src/main.jsx - Route workflows · Selects workout, planning, progress, profile, and settings pages.
src/router.jsx - App shell · Shared layout, navigation, modals, and error recovery.
src/components/layout/AppLayout.jsx - Workout execution
src/pages/WorkoutPage.jsx - Set and rest logging
src/components/workout/SetLogger.jsx - Workout completion · Persists history and triggers downstream calculations.
src/utils/workoutActions.js - Templates and planning
src/pages/TemplatesPage.jsx - Routine generator
src/components/template/RoutineGeneratorModal.jsx - Routine calculations
src/utils/routineGenerator.js - Session state
src/store/workoutStore.js - Progress insights · Composes local records into page-ready progress models.
src/hooks/useProgress.js
Local Data & Domain
- IndexedDB system of record · All user data remains device-local.
src/db/db.js - Schema migrations
src/db/migrations.js - Data recovery and transfer · Supports recovery, reset, import, and export without a server.
src/components/DbRecovery.jsx - Shared fitness / RPG core · Reusable session, progression, achievements, quests, overload, volume, PR, and recap rules.
packages/core/src/index.js - Workout session rules
packages/core/src/workoutSession.js - RPG progression rules
packages/core/src/rpg.js
Mobile Runtime
- React Native client · Parallel client with native integrations.
apps/mobile/App.js - Native local database
apps/mobile/native/db.js - Android Capacitor shell
android/app/src/main/java/com/shubanms/opus/MainActivity.java
Delivery
- Web build configuration · Builds the PWA for the GitHub Pages /opus/ base path.
vite.config.js - GitHub Pages deployment · Deploys from main.
.github/workflows/deploy.yml
Connections 22
- 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