# ggwarrior001/digital-debt-tracker architecture

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

- Interactive diagram: https://gitdiagram.com/ggwarrior001/digital-debt-tracker
- Repository: https://github.com/ggwarrior001/digital-debt-tracker

## Overview

1. **Repository shape**
   - This repo contains a full-stack subscription tracker with a clear client/server split under `subtrackr/`.
   - The root-level `server-v2.js`, `App-v2.jsx`, and `App-v2.css` look like standalone “v2” entry files, while the main implementation lives in `subtrackr/backend` and `subtrackr/frontend`.

2. **Primary runtime boundaries**
   - **Frontend:** React 18 app in `subtrackr/frontend`.
   - **Backend:** Node.js + Express API in `subtrackr/backend`.
   - **Persistence:** SQLite database accessed by the backend.
   - The browser never talks to the database directly; all state changes go through the API.

3. **Frontend application structure**
   - `src/pages` defines the major screens: `AuthPage`, `Dashboard`, and `Analytics`.
   - `src/components` holds the UI building blocks, including subscription cards, modals, onboarding flow, and analytics panels.
   - `src/context` provides cross-cutting UI state for dark mode and toasts.
   - `src/hooks` encapsulate data fetching and derived behaviors like subscriptions, analytics, and debouncing.

4. **Frontend data layer**
   - `src/api/client.js` is the HTTP client boundary to the backend.
   - The custom hooks (`useSubscriptions`, `useAnalytics`) likely wrap server calls and caching/refresh behavior, with the README indicating TanStack Query-style optimistic updates and transparent 401 retry.
   - UI components consume hook data rather than calling the API directly, which keeps the page layer thin.

5. **Backend request pipeline**
   - `src/routes/auth.js`, `subscriptions.js`, and `analytics.js` define the API surface.
   - Requests pass through middleware in `src/middleware`: authentication, rate limiting, and validation.
   - Validation is schema-driven through `src/schemas/subscription.js`, suggesting Zod-style request contracts at the route boundary.

6. **Authentication subsystem**
   - The auth route set handles signup, login, refresh, and logout.
   - `src/utils/tokens.js` centralizes token creation/rotation logic.
   - `src/middleware/auth.js` protects subscription and analytics endpoints, enforcing the access-token boundary before any data access.

7. **Subscription management subsystem**
   - The subscriptions route is the core CRUD path for recurring charges.
   - Data likely flows from form/modal UI → API client → authenticated `/api/subscriptions` endpoints → DB client.
   - The README indicates support for pagination, filtering, sorting, status changes, billing-cycle normalization, and soft lifecycle states like paused/cancelled.

8. **Analytics subsystem**
   - `src/routes/analytics.js` exposes aggregated spending data, trends, category breakdowns, and “insights.”
   - `src/utils/analytics.js` appears to compute derived values from raw subscription records rather than storing precomputed metrics.
   - This is a read-heavy boundary: the frontend dashboard and analytics page consume aggregated results from the backend.

9. **Database layer**
   - `src/db/client.js` is the SQLite connection/access layer.
   - `src/db/migrations.js` suggests schema initialization and upgrades are managed in code.
   - The backend owns all persistence concerns, including indexing and data shape evolution, which keeps the frontend storage-agnostic.

10. **Onboarding and seeded demo data**
   - The backend exposes onboarding-related endpoints for demo seeding and completion tracking.
   - The frontend `OnboardingWizard` guides first-time users, likely invoking these endpoints to create starter records and flip onboarding state.
   - This is a distinct workflow from normal subscription CRUD and acts as an activation path into the main dashboard.

11. **Cross-cutting UI systems**
   - `DarkModeContext` persists theme preference in the browser.
   - `ToastContext` and UI components under `components/ui` provide transient feedback, confirmation, loading skeletons, and modal interactions.
   - These are frontend-only concerns and do not affect backend state, but they shape the user-facing interaction model.

12. **Operational and security boundaries**
   - The backend is designed around JWT auth with access/refresh token separation, request size limits, and rate limiting.
   - Environment configuration is required for secrets, CORS origin, and database path.
   - In architecture terms, the important edge is: browser → authenticated API → validated middleware → DB, with no direct client access to persistence.

13. **What to draw in an architecture diagram**
   - Place the React app on the left, the Express API in the middle, and SQLite on the right.
   - Show separate API lanes for auth, subscriptions, analytics, and onboarding.
   - Add middleware as a gate in front of protected routes, and show analytics as a read-only aggregation path over subscription data.
   - Represent the frontend contexts/hooks/components as internal client layers rather than separate services.

Main entry points: [`subtrackr/backend/server.js`](https://github.com/ggwarrior001/digital-debt-tracker/blob/main/subtrackr/backend/server.js) (Express server), [`subtrackr/frontend/src/App.jsx`](https://github.com/ggwarrior001/digital-debt-tracker/blob/main/subtrackr/frontend/src/App.jsx) (App shell), [`subtrackr/backend/src/middleware`](https://github.com/ggwarrior001/digital-debt-tracker/tree/main/subtrackr/backend/src/middleware) (Middleware), [`subtrackr/backend/src/routes/subscriptions.js`](https://github.com/ggwarrior001/digital-debt-tracker/blob/main/subtrackr/backend/src/routes/subscriptions.js) (Subs routes)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_group_root["Root v2"]
  node_node_root_app["App v2<br/>legacy entry<br/>[App-v2.jsx]"]
  node_node_root_style["App CSS<br/>legacy styles<br/>[App-v2.css]"]
  node_node_root_server["Server v2<br/>legacy entry<br/>[server-v2.js]"]
end

subgraph group_group_frontend["Frontend"]
  node_node_client_app["App shell<br/>react shell<br/>[App.jsx]"]
  node_node_client_api["API client<br/>http boundary<br/>[client.js]"]
  node_node_client_pages["Pages<br/>screens"]
  node_node_client_components["Components<br/>ui modules"]
  node_node_client_hooks["Hooks"]
  node_node_client_context["UI context<br/>state context"]
end

subgraph group_group_backend["Backend"]
  node_node_backend_server["Express server<br/>api host<br/>[server.js]"]
  node_node_backend_auth_routes["Auth routes<br/>route set<br/>[auth.js]"]
  node_node_backend_sub_routes["Subs routes<br/>route set<br/>[subscriptions.js]"]
  node_node_backend_analytics_routes["Analytics routes<br/>route set<br/>[analytics.js]"]
  node_node_backend_middleware["Middleware<br/>request gates"]
  node_node_backend_schema["Schemas<br/>contracts<br/>[subscription.js]"]
  node_node_backend_tokens["Tokens<br/>auth utils<br/>[tokens.js]"]
  node_node_backend_analytics_utils["Analytics utils<br/>derived metrics<br/>[analytics.js]"]
end

subgraph group_group_storage["Persistence"]
  node_node_backend_db_client[("DB client<br/>sqlite access<br/>[client.js]")]
  node_node_backend_db_migrations["Migrations<br/>schema ops<br/>[migrations.js]"]
end

node_node_root_app -.->|"alternate entry"| node_node_client_app
node_node_root_server -.->|"alternate entry"| node_node_backend_server
node_node_client_app -->|"renders"| node_node_client_pages
node_node_client_app -->|"uses"| node_node_client_components
node_node_client_app -->|"provides"| node_node_client_context
node_node_client_pages -->|"consumes"| node_node_client_hooks
node_node_client_pages -->|"composes"| node_node_client_components
node_node_client_hooks -->|"calls"| node_node_client_api
node_node_client_components -->|"submit via"| node_node_client_api
node_node_client_api -->|"HTTP requests"| node_node_backend_server
node_node_backend_server -->|"mounts"| node_node_backend_middleware
node_node_backend_server -->|"routes"| node_node_backend_auth_routes
node_node_backend_server -->|"routes"| node_node_backend_sub_routes
node_node_backend_server -->|"routes"| node_node_backend_analytics_routes
node_node_backend_auth_routes -->|"uses"| node_node_backend_tokens
node_node_backend_sub_routes -->|"validates"| node_node_backend_schema
node_node_backend_sub_routes -->|"reads/writes"| node_node_backend_db_client
node_node_backend_analytics_routes -->|"derives"| node_node_backend_analytics_utils
node_node_backend_analytics_routes -->|"reads"| node_node_backend_db_client
node_node_backend_middleware -->|"protects"| node_node_backend_auth_routes
node_node_backend_middleware -->|"protects"| node_node_backend_sub_routes
node_node_backend_middleware -->|"protects"| node_node_backend_analytics_routes
node_node_backend_db_migrations -->|"initializes"| node_node_backend_db_client

click node_node_root_app "https://github.com/ggwarrior001/digital-debt-tracker/blob/main/App-v2.jsx"
click node_node_root_style "https://github.com/ggwarrior001/digital-debt-tracker/blob/main/App-v2.css"
click node_node_root_server "https://github.com/ggwarrior001/digital-debt-tracker/blob/main/server-v2.js"
click node_node_client_app "https://github.com/ggwarrior001/digital-debt-tracker/blob/main/subtrackr/frontend/src/App.jsx"
click node_node_client_api "https://github.com/ggwarrior001/digital-debt-tracker/blob/main/subtrackr/frontend/src/api/client.js"
click node_node_client_pages "https://github.com/ggwarrior001/digital-debt-tracker/tree/main/subtrackr/frontend/src/pages"
click node_node_client_components "https://github.com/ggwarrior001/digital-debt-tracker/tree/main/subtrackr/frontend/src/components"
click node_node_client_hooks "https://github.com/ggwarrior001/digital-debt-tracker/tree/main/subtrackr/frontend/src/hooks"
click node_node_client_context "https://github.com/ggwarrior001/digital-debt-tracker/tree/main/subtrackr/frontend/src/context"
click node_node_backend_server "https://github.com/ggwarrior001/digital-debt-tracker/blob/main/subtrackr/backend/server.js"
click node_node_backend_auth_routes "https://github.com/ggwarrior001/digital-debt-tracker/blob/main/subtrackr/backend/src/routes/auth.js"
click node_node_backend_sub_routes "https://github.com/ggwarrior001/digital-debt-tracker/blob/main/subtrackr/backend/src/routes/subscriptions.js"
click node_node_backend_analytics_routes "https://github.com/ggwarrior001/digital-debt-tracker/blob/main/subtrackr/backend/src/routes/analytics.js"
click node_node_backend_middleware "https://github.com/ggwarrior001/digital-debt-tracker/tree/main/subtrackr/backend/src/middleware"
click node_node_backend_schema "https://github.com/ggwarrior001/digital-debt-tracker/blob/main/subtrackr/backend/src/schemas/subscription.js"
click node_node_backend_tokens "https://github.com/ggwarrior001/digital-debt-tracker/blob/main/subtrackr/backend/src/utils/tokens.js"
click node_node_backend_analytics_utils "https://github.com/ggwarrior001/digital-debt-tracker/blob/main/subtrackr/backend/src/utils/analytics.js"
click node_node_backend_db_client "https://github.com/ggwarrior001/digital-debt-tracker/blob/main/subtrackr/backend/src/db/client.js"
click node_node_backend_db_migrations "https://github.com/ggwarrior001/digital-debt-tracker/blob/main/subtrackr/backend/src/db/migrations.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_node_root_app,node_node_root_style,node_node_root_server toneBlue
class node_node_client_app,node_node_client_api,node_node_client_pages,node_node_client_components,node_node_client_hooks,node_node_client_context toneAmber
class node_node_backend_server,node_node_backend_auth_routes,node_node_backend_sub_routes,node_node_backend_analytics_routes,node_node_backend_middleware,node_node_backend_schema,node_node_backend_tokens,node_node_backend_analytics_utils toneMint
class node_node_backend_db_client,node_node_backend_db_migrations toneRose
```

## Components

### Root v2

Standalone entry files at the repository root.

- [App v2](https://github.com/ggwarrior001/digital-debt-tracker/blob/main/App-v2.jsx): legacy entry · Standalone React entry point at the repository root. · `App-v2.jsx`
- [App CSS](https://github.com/ggwarrior001/digital-debt-tracker/blob/main/App-v2.css): legacy styles · Standalone styling companion for the root v2 app. · `App-v2.css`
- [Server v2](https://github.com/ggwarrior001/digital-debt-tracker/blob/main/server-v2.js): legacy entry · Standalone server entry point at the repository root. · `server-v2.js`

### Frontend

React client application.

- [App shell](https://github.com/ggwarrior001/digital-debt-tracker/blob/main/subtrackr/frontend/src/App.jsx): react shell · Main frontend composition root and screen switcher. · `subtrackr/frontend/src/App.jsx`
- [API client](https://github.com/ggwarrior001/digital-debt-tracker/blob/main/subtrackr/frontend/src/api/client.js): http boundary · Browser-to-backend request layer and token handling boundary. · `subtrackr/frontend/src/api/client.js`
- [Pages](https://github.com/ggwarrior001/digital-debt-tracker/tree/main/subtrackr/frontend/src/pages): screens · Primary app screens for auth, dashboard, and analytics. · `subtrackr/frontend/src/pages`
- [Components](https://github.com/ggwarrior001/digital-debt-tracker/tree/main/subtrackr/frontend/src/components): ui modules · Subscription cards, modals, onboarding, and analytics panels. · `subtrackr/frontend/src/components`
- [Hooks](https://github.com/ggwarrior001/digital-debt-tracker/tree/main/subtrackr/frontend/src/hooks): data hooks · Subscription and analytics fetching plus derived client behavior. · `subtrackr/frontend/src/hooks`
- [UI context](https://github.com/ggwarrior001/digital-debt-tracker/tree/main/subtrackr/frontend/src/context): state context · Cross-cutting theme and toast state for the client. · `subtrackr/frontend/src/context`

### Backend

Express API and server-side logic.

- [Express server](https://github.com/ggwarrior001/digital-debt-tracker/blob/main/subtrackr/backend/server.js): api host · Backend runtime entry that mounts middleware and routes. · `subtrackr/backend/server.js`
- [Auth routes](https://github.com/ggwarrior001/digital-debt-tracker/blob/main/subtrackr/backend/src/routes/auth.js): route set · Signup, login, refresh, logout, and onboarding-related auth flows. · `subtrackr/backend/src/routes/auth.js`
- [Subs routes](https://github.com/ggwarrior001/digital-debt-tracker/blob/main/subtrackr/backend/src/routes/subscriptions.js): route set · CRUD and lifecycle endpoints for subscriptions. · `subtrackr/backend/src/routes/subscriptions.js`
- [Analytics routes](https://github.com/ggwarrior001/digital-debt-tracker/blob/main/subtrackr/backend/src/routes/analytics.js): route set · Aggregated spending, trends, category breakdowns, and insights. · `subtrackr/backend/src/routes/analytics.js`
- [Middleware](https://github.com/ggwarrior001/digital-debt-tracker/tree/main/subtrackr/backend/src/middleware): request gates · Authentication, rate limiting, and request validation boundary. · `subtrackr/backend/src/middleware`
- [Schemas](https://github.com/ggwarrior001/digital-debt-tracker/blob/main/subtrackr/backend/src/schemas/subscription.js): contracts · Request validation contracts for subscription payloads. · `subtrackr/backend/src/schemas/subscription.js`
- [Tokens](https://github.com/ggwarrior001/digital-debt-tracker/blob/main/subtrackr/backend/src/utils/tokens.js): auth utils · JWT creation, rotation, and refresh token support. · `subtrackr/backend/src/utils/tokens.js`
- [Analytics utils](https://github.com/ggwarrior001/digital-debt-tracker/blob/main/subtrackr/backend/src/utils/analytics.js): derived metrics · Server-side computation of aggregates and insights from raw subscription data. · `subtrackr/backend/src/utils/analytics.js`

### Persistence

SQLite database layer.

- [DB client](https://github.com/ggwarrior001/digital-debt-tracker/blob/main/subtrackr/backend/src/db/client.js): sqlite access · SQLite connection and query access layer. · `subtrackr/backend/src/db/client.js`
- [Migrations](https://github.com/ggwarrior001/digital-debt-tracker/blob/main/subtrackr/backend/src/db/migrations.js): schema ops · Database initialization and schema evolution logic. · `subtrackr/backend/src/db/migrations.js`

## Connections

- App v2 → App shell: alternate entry · Root v2 app is a parallel client entry.
- Server v2 → Express server: alternate entry · Root v2 server is a parallel backend entry.
- App shell → Pages: renders · App shell composes the major screens.
- App shell → Components: uses · App shell and pages assemble shared UI building blocks.
- App shell → UI context: provides · Theme and toast state are shared across the client.
- Pages → Hooks: consumes · Screens rely on hooks for subscription and analytics data.
- Pages → Components: composes · Pages render cards, modals, onboarding, and insights UI.
- Hooks → API client: calls · Hooks delegate server communication to the HTTP client.
- Components → API client: submit via · Interactive flows ultimately go through the API client.
- API client → Express server: HTTP requests · Browser traffic is sent to the backend API.
- Express server → Middleware: mounts · Requests pass through shared middleware before routes.
- Express server → Auth routes: routes · Auth endpoints are exposed through the API host.
- Express server → Subs routes: routes · Subscription endpoints are exposed through the API host.
- Express server → Analytics routes: routes · Analytics endpoints are exposed through the API host.
- Auth routes → Tokens: uses · Auth flow centralizes token creation and rotation.
- Subs routes → Schemas: validates · Subscription requests are schema-checked at the boundary.
- Subs routes → DB client: reads/writes · Subscription CRUD persists through SQLite.
- Analytics routes → Analytics utils: derives · Analytics endpoints compute aggregates from stored subscriptions.
- Analytics routes → DB client: reads · Analytics reads subscription data from SQLite.
- Middleware → Auth routes: protects · Authentication gates guarded auth-related flows where needed.
- Middleware → Subs routes: protects · Protected subscription endpoints require middleware checks.
- Middleware → Analytics routes: protects · Protected analytics endpoints require middleware checks.
- Migrations → DB client: initializes · Migrations shape the SQLite schema used by the client.
