|
1 | 1 | # Architecture |
2 | 2 |
|
3 | | -High-level map of loc-counter's subsystems. Each row links to the colocated |
4 | | -CLAUDE.md that contains the full details. |
| 3 | +High-level map of loc-counter's subsystems. Each row links to the colocated CLAUDE.md that contains the full details. |
5 | 4 |
|
6 | 5 | ## Frontend (`src/lib/`) |
7 | 6 |
|
8 | 7 | Details: [`src/lib/CLAUDE.md`](../src/lib/CLAUDE.md) |
9 | 8 |
|
10 | | -| Module | Purpose | |
11 | | -|---|---| |
12 | | -| `components/` | Svelte UI — `ResultsChart`, `ResultsTable`, `ResultsSummary`, `PipelineProgress`, `RepoInput`, era-markers plugin | |
13 | | -| `git/clone.ts` | Clone/fetch via isomorphic-git + lightning-fs, abort support, staleness monitor | |
14 | | -| `git/history.ts` | Commit log grouped by date, batch fetching, `CompactOidSet` dedup | |
15 | | -| `git/count.ts` | Line counting per tree, prod/test classification, blob dedup, incremental tree diffing | |
16 | | -| `git/mailmap.ts` | `.mailmap` parsing and author normalization | |
17 | | -| `worker/` | Web Worker entry point (Comlink) — orchestrates full and incremental analysis pipelines | |
18 | | -| `types.ts` | Shared interfaces (`LanguageCount`, `DayStats`, `AnalysisResult`, `ProgressEvent`, etc.) | |
19 | | -| `languages.ts` | Language registry (~35 languages), extension mapping, inline test detection | |
20 | | -| `cache.ts` | IndexedDB results cache — LRU eviction, 500 MB limit, separate meta store | |
21 | | -| `server-cache.ts` | Shared server cache client (opt-in via `PUBLIC_SHARED_CACHE_URL`) | |
22 | | -| `url.ts` | Repo URL parsing and normalization (GitHub/GitLab/Bitbucket, owner/repo shorthand) | |
23 | | - |
24 | | -The SvelteKit app itself lives in `src/routes/` (single page) with global styles |
25 | | -in `src/app.css` (Tailwind v4 + CSS custom properties). |
| 9 | +| Module | Purpose | |
| 10 | +| ----------------- | ----------------------------------------------------------------------------------------------------------------- | |
| 11 | +| `components/` | Svelte UI — `ResultsChart`, `ResultsTable`, `ResultsSummary`, `PipelineProgress`, `RepoInput`, era-markers plugin | |
| 12 | +| `git/clone.ts` | Clone/fetch via isomorphic-git + lightning-fs, abort support, staleness monitor | |
| 13 | +| `git/history.ts` | Commit log grouped by date, batch fetching, `CompactOidSet` dedup | |
| 14 | +| `git/count.ts` | Line counting per tree, prod/test classification, blob dedup, incremental tree diffing | |
| 15 | +| `git/mailmap.ts` | `.mailmap` parsing and author normalization | |
| 16 | +| `worker/` | Web Worker entry point (Comlink) — orchestrates full and incremental analysis pipelines | |
| 17 | +| `types.ts` | Shared interfaces (`LanguageCount`, `DayStats`, `AnalysisResult`, `ProgressEvent`, etc.) | |
| 18 | +| `languages.ts` | Language registry (~35 languages), extension mapping, inline test detection | |
| 19 | +| `cache.ts` | IndexedDB results cache — LRU eviction, 500 MB limit, separate meta store | |
| 20 | +| `server-cache.ts` | Shared server cache client (opt-in via `PUBLIC_SHARED_CACHE_URL`) | |
| 21 | +| `url.ts` | Repo URL parsing and normalization (GitHub/GitLab/Bitbucket, owner/repo shorthand) | |
| 22 | + |
| 23 | +The SvelteKit app itself lives in `src/routes/` (single page) with global styles in `src/app.css` (Tailwind v4 + CSS |
| 24 | +custom properties). |
26 | 25 |
|
27 | 26 | ## CORS proxy (`cors-proxy/`) |
28 | 27 |
|
29 | 28 | Details: [`cors-proxy/CLAUDE.md`](../cors-proxy/CLAUDE.md) |
30 | 29 |
|
31 | | -| Component | Purpose | |
32 | | -|---|---| |
33 | | -| Cloudflare Worker (Hono) | Adds CORS headers, forwards bytes to git hosts (GitHub, GitLab, Bitbucket) | |
34 | | -| Rate limiting | Cloudflare edge rules + in-memory per-isolate counters | |
35 | | -| Ref caching | Caches v1 `/info/refs` responses at the edge (12 h TTL) | |
36 | | -| Shared results cache | Optional R2-backed cache for analysis results (`GET`/`PUT /cache/v1/:repoHash`) | |
| 30 | +| Component | Purpose | |
| 31 | +| ------------------------ | ------------------------------------------------------------------------------- | |
| 32 | +| Cloudflare Worker (Hono) | Adds CORS headers, forwards bytes to git hosts (GitHub, GitLab, Bitbucket) | |
| 33 | +| Rate limiting | Cloudflare edge rules + in-memory per-isolate counters | |
| 34 | +| Ref caching | Caches v1 `/info/refs` responses at the edge (12 h TTL) | |
| 35 | +| Shared results cache | Optional R2-backed cache for analysis results (`GET`/`PUT /cache/v1/:repoHash`) | |
37 | 36 |
|
38 | 37 | ## Tooling |
39 | 38 |
|
40 | | -| Directory | Purpose | |
41 | | -|---|---| |
42 | | -| `scripts/` | Go-based check runner | |
43 | | -| `tests/` | Vitest (unit) + Playwright (e2e) | |
44 | | -| `shared/` | `language-ids.ts` — single source of truth for valid language IDs, imported by both frontend and CORS proxy | |
| 39 | +| Directory | Purpose | |
| 40 | +| ---------- | ----------------------------------------------------------------------------------------------------------- | |
| 41 | +| `scripts/` | Go-based check runner | |
| 42 | +| `tests/` | Vitest (unit) + Playwright (e2e) | |
| 43 | +| `shared/` | `language-ids.ts` — single source of truth for valid language IDs, imported by both frontend and CORS proxy | |
45 | 44 |
|
46 | 45 | ## Cross-cutting patterns |
47 | 46 |
|
48 | | -- **Web Worker isolation** — All git operations and line counting run in a |
49 | | - dedicated Web Worker (via Comlink). The main thread only drives the UI. |
50 | | -- **Diff-based incremental processing** — After the first commit's full tree |
51 | | - walk, every subsequent commit uses recursive tree diffing (`diffTreesDetailed`) |
52 | | - so only changed files are re-counted. |
53 | | -- **IndexedDB caching with LRU eviction** — Analysis results are cached |
54 | | - client-side in IndexedDB with a 500 MB cap. A separate lightweight meta store |
55 | | - enables eviction and size checks without deserializing full results. |
56 | | -- **Incremental refresh** — `analyzeIncremental` fetches only new commits since |
57 | | - the last cached result and merges the new days in. |
| 47 | +- **Web Worker isolation** — All git operations and line counting run in a dedicated Web Worker (via Comlink). The main |
| 48 | + thread only drives the UI. |
| 49 | +- **Diff-based incremental processing** — After the first commit's full tree walk, every subsequent commit uses |
| 50 | + recursive tree diffing (`diffTreesDetailed`) so only changed files are re-counted. |
| 51 | +- **IndexedDB caching with LRU eviction** — Analysis results are cached client-side in IndexedDB with a 500 MB cap. A |
| 52 | + separate lightweight meta store enables eviction and size checks without deserializing full results. |
| 53 | +- **Incremental refresh** — `analyzeIncremental` fetches only new commits since the last cached result and merges the |
| 54 | + new days in. |
0 commit comments