# Hackatime architecture guide This is a map of current ownership and invariants, not a proposed design. Follow the linked source when behavior and this summary disagree. ## Sources of truth and derived state | Domain | Source of truth | Derived / disposable state | | --- | --- | --- | | Identity | `users`, `email_addresses`, provider IDs and encrypted provider tokens | Session cookie | | Coding activity | Non-deleted `heartbeats` | Durations, dashboard/profile payloads, rollups, leaderboards, streaks, Rails caches | | Heartbeat project identity | `heartbeats.project` | Project lists and project statistics | | Per-user project settings | `project_repo_mappings` keyed by project name | Discovery retry/coalescing cache keys | | Repository identity | Shared `repositories` row (`url`, host, owner, name) | Stars, languages, homepage, commit count, sync timestamps, imported commits | | Async work | Pending/scheduled `good_jobs` rows and their serialized arguments | Finished execution history, process records, cron history and enqueue cache keys, subject to retention policy | Do not write a rollup, duration, profile statistic, or cache as though it were primary data. Change its input or the derivation, invalidate it, and let it be rebuilt. ## 1. Rails request and Inertia/Svelte UI flow 1. Routes dispatch to Rails controllers. Browser controllers inherit [`ApplicationController`](app/controllers/application_controller.rb), which supplies session identity, lockout enforcement, no-store headers, error reporting, PaperTrail attribution, and the user's time zone. 2. Inertia controllers inherit [`InertiaController`](app/controllers/inertia_controller.rb). It shares layout props (navigation, flash, theme, CSRF token, footer and impersonation state) on every Inertia response. Controllers select a page with `render inertia: "Directory/Page", props: ...`; server props are the request's serialized boundary, not a second model layer. 3. [`inertia.ts`](app/javascript/entrypoints/inertia.ts) resolves that name to `app/javascript/pages/Directory/Page.svelte` and wraps pages in `AppLayout.svelte`. Inertia ``, `