How hozaifadev/tracking-bad-managers-salary-payment works
1. Overall shape
This is a local-only full-stack app with three main parts: a Node/Express backend, a React/Vite frontend, and a SQLite + JSON configuration layer. The backend is the system of record; the frontend is a thin UI over /api endpoints.
2. Primary runtime boundary
The app runs as two processes during development: frontend on localhost:3000 and API on localhost:3001. Vite proxies /api requests to the backend. The backend uses Node 22+ and built-in node:sqlite, so persistence is embedded rather than an external database service.
3. Backend feature boundaries
The backend is organized by domain routes:
- calendar/sync for Google Calendar ingestion and auth status
- sessions for session listing and manual overrides
- payments for payment CRUD
- reports for dashboard/monthly/export aggregations
- config for reading/writing the editable rule file
- import for non-calendar imports via ICS
- admin for maintenance-oriented endpoints
Cross-cutting error handling is centralized in middleware/errorHandler.js.
4. Ingestion flow from Google Calendar
Calendar sync is the main data-entry pipeline. A sync request provides a date range, the backend fetches events from Google Calendar, filters out all-day events, normalizes each event into a session row, and stores it in SQLite. Duplicates are avoided using the Google event id, so re-syncing is additive rather than destructive.
5. Domain logic for earnings
Earnings are not stored as raw calendar data alone; they are computed from calendar titles and the editable rules in config.json. The backend services layer contains the core business logic:
- calendarService for event/session interpretation
- calculatorService for rate and payout calculation
- balancerService and sessionSyncLogic for higher-level reconciliation/sync behavior
- reportService for aggregations used by dashboard and export
This is the key domain boundary: calendar event → categorized session → computed earnings.
6. Persistence model
SQLite holds operational data such as sessions, payments, and sync logs. The database is auto-created under backend/tracker.db, with db/database.js and db/migrations.js handling connection/setup and schema evolution. The design favors a local embedded store over external infrastructure.
7. Configuration as a separate mutable source
Business rules live in the root-level config.json, not in the database. It contains timezone, billing-cycle rules, group rates, private-course rules, and diploma milestone payouts. The settings UI writes through the API, and the backend re-reads the file on each request, so config changes are immediately reflected without a deploy or migration.
8. Payments as a parallel ledger
Payments are tracked separately from sessions. They are recorded with date, amount, and notes, and later compared against earned totals to determine what is owed. Monthly views use cumulative paid amounts through the cycle end rather than trying to auto-assign a payment to a specific salary month.
9. Reporting and export pipeline
The reports subsystem sits on top of sessions + payments + config-derived calculations. It produces:
- dashboard totals
- monthly salary-cycle breakdowns
- Excel workbook export
The export path uses exceljs, so the reporting layer is both an API aggregation layer and a file-generation boundary.
10. Frontend structure
The React app is page-driven: Dashboard, Sessions, Payments, Monthly, Sync, and Settings. Shared UI components live under components/ with a small internal design system in components/ui/. Data access is centralized in src/lib/api.js, so the pages remain presentation-focused and do not talk directly to backend internals.
11. Client-side data flow
The frontend uses TanStack Query for server-state management and React Router for page navigation. This means the browser mainly orchestrates API requests, cache updates, and local filters/sorting; the authoritative business logic remains on the server.
12. External integration boundary
The only major external dependency is Google Calendar OAuth/API. Credentials and tokens are kept in backend/credentials.json and backend/token.json respectively. The app needs internet only for auth and sync; once sessions are stored, the rest of the app works offline against SQLite.
13. Secondary import path
Besides Google Calendar, there is an ICS import service and route. That suggests a second ingestion boundary for calendar-like data, separate from the OAuth-backed sync flow, but still normalized into the same session model.
14. Legacy code boundary
The repository also contains a legacy Python CLI (main.py, src/). The README explicitly says the web app does not use it, so it should be treated as a parallel/obsolete artifact rather than part of the current runtime architecture.
Main entry points: server.js API server · database.js SQLite DB · calendar.js Calendar · reports.js Reports
Components 25
Backend
Node/Express API, domain services, and SQLite persistence.
- API server · Starts the Express app and wires routes, middleware, and persistence.
backend/server.js - Calendar · Google Calendar sync and auth-status endpoints.
backend/routes/calendar.js - Sessions · Session listing and manual override endpoints.
backend/routes/sessions.js - Payments · Payment CRUD endpoints.
backend/routes/payments.js - Reports · Dashboard, monthly, and export endpoints.
backend/routes/reports.js - Config · Read/write endpoints for editable business rules.
backend/routes/config.js - Import · ICS-based import endpoints.
backend/routes/import.js - Admin · Maintenance-oriented endpoints.
backend/routes/admin.js - Calendar logic · Interprets Google Calendar events into normalized sessions.
backend/services/calendarService.js - Earnings calc · Computes rates, payouts, and rule-based earnings.
backend/services/calculatorService.js - Sync logic · Higher-level reconciliation and session sync behavior.
backend/services/sessionSyncLogic.js - Balancer · Reconciliation helper for session and payout balancing.
backend/services/balancerService.js - Report engine · Aggregations used by dashboard, monthly views, and exports.
backend/services/reportService.js - ICS import · Parses non-Google calendar imports into the session model.
backend/services/icsImportService.js - Config reader · Reads the mutable config.json rules on demand.
backend/services/configService.js - SQLite DB · Embedded local database for sessions, payments, and sync logs.
backend/db/database.js - Migrations · Database schema creation and evolution.
backend/db/migrations.js - Error handler · Centralized API error handling.
backend/middleware/errorHandler.js
Frontend
React/Vite client that consumes the API.
- App shell · Client routing and top-level page composition.
frontend/src/App.jsx - API client · Centralized browser API wrapper for backend requests.
frontend/src/lib/api.js - Pages · Dashboard, sessions, payments, monthly, sync, and settings screens.
frontend/src/pages/Dashboard.jsx - Layout · Shared app chrome and navigation structure.
frontend/src/components/Layout.jsx - UI kit · Shared presentation components used across pages.
frontend/src/components/ui/button.jsx
Legacy
Older Python CLI and helpers kept outside the web app runtime.
- Python CLI · Older non-web entrypoint kept as a separate artifact.
main.py - Python helpers · Legacy calculation, fetch, cache, and reporting helpers.
src/calculator.py
Connections 28
- API server → Calendar: mounts
- API server → Sessions: mounts
- API server → Payments: mounts
- API server → Reports: mounts
- API server → Config: mounts
- API server → Import: mounts
- API server → Admin: mounts
- API server → Error handler: uses
- Calendar → Sync logic: sync
- Calendar → Calendar logic: normalize
- Calendar → SQLite DB: store
- Sessions → SQLite DB: read/write
- Payments → SQLite DB: read/write
- Reports → Report engine: aggregate
- Reports → Earnings calc: compute
- Config → Config reader: load rules
- Import → ICS import: parse
- Admin → SQLite DB: administer
- Sync logic → Balancer: reconcile
- Calendar logic → Earnings calc: earnings
- Report engine → SQLite DB: query
- Report engine → Config reader: rules
- App shell → Layout: renders
- App shell → Pages: routes
- Pages → API client: fetches
- Layout → UI kit: uses
- Pages → UI kit: uses
- Python CLI → Python helpers: uses