# jd862/cubestats architecture

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

- Interactive diagram: https://gitdiagram.com/jd862/cubestats
- Repository: https://github.com/jd862/cubestats

## Overview

Cubestats is an offline-first cubing tracker with optional hosted accounts and sync. Its main workflow is importing solve data, organizing sessions, and viewing statistics; users can also train algorithms and optionally connect WCA results or sign in to sync. The graph preserves the documented feature branches, but several client modules were not excerpted, so their internal calls are left unclaimed. Solid edges are based on shown code or README statements; dashed edges indicate documented or likely integration whose exact call site was not shown.

Main entry points: [`app.js`](https://github.com/jd862/cubestats/blob/main/app.js) (App and sessions), [`trainer.js`](https://github.com/jd862/cubestats/blob/main/trainer.js) (Alg trainer), [`manager.js`](https://github.com/jd862/cubestats/blob/main/manager.js) (Session manager), [`api`](https://github.com/jd862/cubestats/tree/main/api) (Account and data routes)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Solve tracking"]
  node_app["App and sessions<br/>[app.js]"]
  node_import["Solve import<br/>[import.js]"]
  node_manager["Session manager<br/>[manager.js]"]
  node_browserdb[("Browser storage<br/>[app.js]")]
end

subgraph group_analytics["Statistics"]
  node_stats["Statistics<br/>[stats.js]"]
  node_comparison["Solve comparison<br/>[compare.js]"]
  node_wcaresults["WCA results<br/>[wca.js]"]
end

subgraph group_training["Algorithm trainer"]
  node_trainer["Alg trainer<br/>[trainer.js]"]
  node_algorithms["Algorithm sets<br/>[algs.js]"]
  node_alternates["Alternate algs<br/>[alts.js]"]
  node_cube["Cube model<br/>[cube.js]"]
end

subgraph group_identity["Accounts and sync"]
  node_sync["Cloud sync<br/>[sync.js]"]
  node_api["Account and data routes"]
  node_authlib["Auth and Redis helpers<br/>[_lib.js]"]
end

node_cubers(("Cubers"))
node_wca{{"WCA service"}}
node_redis[("Upstash Redis")]
node_wcaauth{{"WCA OAuth"}}

node_cubers -->|"use"| node_app
node_cubers -->|"import solves"| node_import
node_app -.->|"parses imports"| node_import
node_app -->|"reads and writes"| node_browserdb
node_manager -->|"saves sessions"| node_app
node_manager -->|"calculates averages"| node_stats
node_manager -->|"uses event data"| node_wcaresults
node_cubers -->|"manage sessions"| node_manager
node_cubers -->|"view statistics"| node_stats
node_app -->|"uses summaries"| node_stats
node_cubers -.->|"compare solves"| node_comparison
node_app -->|"uses WCA data"| node_wcaresults
node_wcaresults -->|"downloads results"| node_wca
node_cubers -->|"practice algorithms"| node_trainer
node_trainer -.->|"drills cases"| node_algorithms
node_trainer -.->|"uses alternatives"| node_alternates
node_trainer -.->|"uses cube model"| node_cube
node_cubers -->|"sign in and sync"| node_sync
node_sync -->|"exchanges data"| node_api
node_api -->|"uses shared handlers"| node_authlib
node_authlib -->|"reads and writes"| node_redis
node_api -->|"OAuth sign-in"| node_wcaauth
node_wcaauth -->|"returns authorization"| node_api

click node_app "https://github.com/jd862/cubestats/blob/main/app.js"
click node_import "https://github.com/jd862/cubestats/blob/main/import.js"
click node_manager "https://github.com/jd862/cubestats/blob/main/manager.js"
click node_browserdb "https://github.com/jd862/cubestats/blob/main/app.js"
click node_stats "https://github.com/jd862/cubestats/blob/main/stats.js"
click node_comparison "https://github.com/jd862/cubestats/blob/main/compare.js"
click node_wcaresults "https://github.com/jd862/cubestats/blob/main/wca.js"
click node_trainer "https://github.com/jd862/cubestats/blob/main/trainer.js"
click node_algorithms "https://github.com/jd862/cubestats/blob/main/algs.js"
click node_alternates "https://github.com/jd862/cubestats/blob/main/alts.js"
click node_cube "https://github.com/jd862/cubestats/blob/main/cube.js"
click node_sync "https://github.com/jd862/cubestats/blob/main/sync.js"
click node_api "https://github.com/jd862/cubestats/tree/main/api"
click node_authlib "https://github.com/jd862/cubestats/blob/main/api/_lib.js"

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_import,node_manager,node_browserdb toneBlue
class node_stats,node_comparison,node_wcaresults,node_redis toneAmber
class node_trainer,node_algorithms,node_alternates,node_cube toneMint
class node_sync,node_api,node_authlib toneRose
class node_cubers,node_wca,node_wcaauth toneIndigo
```

## Components

### Solve tracking

- [App and sessions](https://github.com/jd862/cubestats/blob/main/app.js): `app.js`
- [Solve import](https://github.com/jd862/cubestats/blob/main/import.js): `import.js`
- [Session manager](https://github.com/jd862/cubestats/blob/main/manager.js): `manager.js`
- [Browser storage](https://github.com/jd862/cubestats/blob/main/app.js): `app.js`

### Statistics

- [Statistics](https://github.com/jd862/cubestats/blob/main/stats.js): `stats.js`
- [Solve comparison](https://github.com/jd862/cubestats/blob/main/compare.js): `compare.js`
- [WCA results](https://github.com/jd862/cubestats/blob/main/wca.js): `wca.js`

### Algorithm trainer

- [Alg trainer](https://github.com/jd862/cubestats/blob/main/trainer.js): `trainer.js`
- [Algorithm sets](https://github.com/jd862/cubestats/blob/main/algs.js): `algs.js`
- [Alternate algs](https://github.com/jd862/cubestats/blob/main/alts.js): `alts.js`
- [Cube model](https://github.com/jd862/cubestats/blob/main/cube.js): `cube.js`

### Accounts and sync

- [Cloud sync](https://github.com/jd862/cubestats/blob/main/sync.js): `sync.js`
- [Account and data routes](https://github.com/jd862/cubestats/tree/main/api): `api`
- [Auth and Redis helpers](https://github.com/jd862/cubestats/blob/main/api/_lib.js): `api/_lib.js`

### Other components

- **Cubers**
- **WCA service**
- **Upstash Redis**
- **WCA OAuth**

## Connections

- Cubers → App and sessions: use (evidence: `README.md`)
- Cubers → Solve import: import solves (evidence: `README.md`)
- App and sessions → Solve import: parses imports
- App and sessions → Browser storage: reads and writes (evidence: `app.js`)
- Session manager → App and sessions: saves sessions (evidence: `manager.js`)
- Session manager → Statistics: calculates averages (evidence: `manager.js`)
- Session manager → WCA results: uses event data (evidence: `manager.js`)
- Cubers → Session manager: manage sessions (evidence: `README.md`)
- Cubers → Statistics: view statistics (evidence: `README.md`)
- App and sessions → Statistics: uses summaries (evidence: `app.js`)
- Cubers → Solve comparison: compare solves
- App and sessions → WCA results: uses WCA data (evidence: `app.js`)
- WCA results → WCA service: downloads results (evidence: `README.md`)
- Cubers → Alg trainer: practice algorithms (evidence: `README.md`)
- Alg trainer → Algorithm sets: drills cases
- Alg trainer → Alternate algs: uses alternatives
- Alg trainer → Cube model: uses cube model
- Cubers → Cloud sync: sign in and sync (evidence: `README.md`)
- Cloud sync → Account and data routes: exchanges data (evidence: `README.md`)
- Account and data routes → Auth and Redis helpers: uses shared handlers (evidence: `api/data.js`)
- Auth and Redis helpers → Upstash Redis: reads and writes (evidence: `api/_lib.js`)
- Account and data routes → WCA OAuth: OAuth sign-in (evidence: `api/wca.js`)
- WCA OAuth → Account and data routes: returns authorization (evidence: `api/wca-callback.js`)
