How ggwarrior001/digital-debt-tracker works
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: server.js Express server · App.jsx App shell · middleware Middleware · subscriptions.js Subs routes
Components 19
Root v2
Standalone entry files at the repository root.
Frontend
React client application.
- App shell · Main frontend composition root and screen switcher.
subtrackr/frontend/src/App.jsx - API client · Browser-to-backend request layer and token handling boundary.
subtrackr/frontend/src/api/client.js - Pages · Primary app screens for auth, dashboard, and analytics.
subtrackr/frontend/src/pages - Components · Subscription cards, modals, onboarding, and analytics panels.
subtrackr/frontend/src/components - Hooks · Subscription and analytics fetching plus derived client behavior.
subtrackr/frontend/src/hooks - UI context · Cross-cutting theme and toast state for the client.
subtrackr/frontend/src/context
Backend
Express API and server-side logic.
- Express server · Backend runtime entry that mounts middleware and routes.
subtrackr/backend/server.js - Auth routes · Signup, login, refresh, logout, and onboarding-related auth flows.
subtrackr/backend/src/routes/auth.js - Subs routes · CRUD and lifecycle endpoints for subscriptions.
subtrackr/backend/src/routes/subscriptions.js - Analytics routes · Aggregated spending, trends, category breakdowns, and insights.
subtrackr/backend/src/routes/analytics.js - Middleware · Authentication, rate limiting, and request validation boundary.
subtrackr/backend/src/middleware - Schemas · Request validation contracts for subscription payloads.
subtrackr/backend/src/schemas/subscription.js - Tokens · JWT creation, rotation, and refresh token support.
subtrackr/backend/src/utils/tokens.js - Analytics utils · Server-side computation of aggregates and insights from raw subscription data.
subtrackr/backend/src/utils/analytics.js
Persistence
SQLite database layer.
- DB client · SQLite connection and query access layer.
subtrackr/backend/src/db/client.js - Migrations · Database initialization and schema evolution logic.
subtrackr/backend/src/db/migrations.js
Connections 23
- 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.