# stylessh/diffkit architecture

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

- Interactive diagram: https://gitdiagram.com/stylessh/diffkit
- Repository: https://github.com/stylessh/diffkit

## Overview

1. **Monorepo shape**
   - This is a Turborepo/pnpm workspace with one main application, `apps/dashboard`, plus shared UI/icon/type packages and a browser extension.
   - The architecture is centered on the dashboard app; the other packages are support libraries, not separate runtime services.

2. **Primary runtime boundary**
   - The dashboard runs on **Cloudflare Workers** using **TanStack Start** and **TanStack Router**.
   - Server code is split from client code through route files, `*.server.ts` / `*.client.ts` modules, and the worker entry at `src/entry-worker.ts`.

3. **Public vs protected app surfaces**
   - Public routes include login, setup, privacy, terms, and GitHub auth callbacks.
   - Most product functionality lives under `src/routes/_protected`, which is the authenticated shell for dashboard, repo, issue, pull request, review, and settings pages.

4. **Core domain areas**
   - The UI is organized around four main product flows: **repositories**, **pull requests**, **issues**, and **code reviews**.
   - Each has dedicated list/detail components and route entry points, with additional pages for inbox, global search, and user settings.

5. **Data access pattern**
   - The app uses **TanStack Query** on the client and **Octokit/GitHub API** on the server side for live GitHub data.
   - The `src/lib/github.*` modules are the main abstraction boundary for API access, request policy, and GitHub-specific query composition.

6. **Persistence layer**
   - Local state is stored in **Cloudflare D1** (SQLite) through **Drizzle ORM**.
   - Database migrations live under `apps/dashboard/drizzle`, and the schema is defined in `src/db/schema.ts`.
   - This layer appears to support app state, auth/session-related data, and GitHub caching/revalidation metadata.

7. **Authentication and installation model**
   - Auth is handled by **Better Auth** with a **GitHub OAuth App** for user login and a **GitHub App** for repository-scoped access.
   - The app has separate routes for OAuth auth, GitHub App authorization, and GitHub App callback handling, which makes auth a distinct subsystem from the normal dashboard pages.
   - The README indicates the GitHub App is also used for installation discovery, webhooks, and higher-scope repository actions.

8. **Cache and invalidation flow**
   - The repo has explicit GitHub caching and revalidation modules, plus docs dedicated to cache architecture.
   - The important flow is: GitHub data is fetched, cached, then invalidated or refreshed when webhooks arrive or when revalidation signals are emitted.
   - This keeps the dashboard responsive while still reacting to GitHub-side changes.

9. **Webhook and event ingestion**
   - GitHub webhooks land in `src/routes/api/webhooks/github.ts`.
   - Those events feed the cache invalidation / signal-relay path, which updates stale views and can notify open tabs or clients that data changed.

10. **UI shell and cross-cutting interaction layer**
   - Shared layout components provide the persistent dashboard chrome: top bar, side panel, tabs, mobile nav, error/loading states, and dialogs.
   - Cross-cutting interaction features include the command palette, keyboard shortcuts, filter cookies, optimistic mutations, and tab/session state.

11. **Shared component and design system layer**
   - `packages/ui` is the design system: buttons, dialogs, tables, markdown, resizable panes, sidebar, etc.
   - `packages/icons` and shared utility hooks/styles are used across the dashboard to keep the visual language consistent and reduce duplication.

12. **Browser extension integration**
   - `extensions/diffkit-redirect` is a companion browser extension, not part of the dashboard runtime.
   - Its role is to bridge GitHub pages and the DiffKit experience, which suggests the product is intended to coexist with GitHub rather than replace it.

13. **Operational concerns**
   - The repo is configured for linting, type-checking, formatting, tests, and Cloudflare deployment.
   - Environment configuration is explicit: local development requires GitHub OAuth/App secrets, webhook secret, Better Auth secret, and D1 migrations before the app runs correctly.

14. **How to think about the architecture diagram**
   - The main boxes are: browser UI, Cloudflare Worker app, GitHub API/App/OAuth, D1 database, and webhook delivery from GitHub.
   - The main arrows are: browser requests to TanStack routes, server requests to GitHub, webhook events back into the worker, and cache/revalidation signals back out to active clients.

Main entry points: [`apps/dashboard/src/components`](https://github.com/stylessh/diffkit/tree/main/apps/dashboard/src/components) (Product views), [`apps/dashboard/src/router.tsx`](https://github.com/stylessh/diffkit/blob/main/apps/dashboard/src/router.tsx) (App router), [`apps/dashboard/src/components/layouts`](https://github.com/stylessh/diffkit/tree/main/apps/dashboard/src/components/layouts) (Dashboard shell), [`apps/dashboard/src/lib/github.server.ts`](https://github.com/stylessh/diffkit/blob/main/apps/dashboard/src/lib/github.server.ts) (GitHub core)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_group_app["Dashboard app"]
  node_node_worker["Worker entry<br/>Cloudflare Worker<br/>[entry-worker.ts]"]
  node_node_router["App router<br/>TanStack Start<br/>[router.tsx]"]
  node_node_public_routes["Public routes<br/>route surface"]
  node_node_protected_routes["Protected shell<br/>authenticated routes"]
  node_node_api_routes["API routes<br/>server endpoints"]
  node_node_layout_shell["Dashboard shell<br/>ui shell"]
  node_node_product_views["Product views<br/>domain UI"]
  node_node_repo_views["Repo flow<br/>repository UI"]
  node_node_issue_views["Issue flow<br/>issue UI"]
  node_node_pull_views["PR flow<br/>pull request UI"]
  node_node_review_views["Review flow<br/>code review UI"]
  node_node_data_client["Query client<br/>TanStack Query<br/>[query-client.tsx]"]
  node_node_github_core["GitHub core<br/>GitHub API layer<br/>[github.server.ts]"]
  node_node_github_cache["GitHub cache<br/>cache/revalidation<br/>[github-cache.ts]"]
  node_node_signal_relay["Signal relay<br/>broadcast stream"]
  node_node_auth["Auth system<br/>Better Auth<br/>[auth.server.ts]"]
  node_node_db[("D1 database<br/>Drizzle schema<br/>[schema.ts]")]
end

subgraph group_group_packages["Shared packages"]
  node_node_ui_kit["UI kit<br/>design system"]
  node_node_icons["Icons"]
end

subgraph group_group_extension["Browser extension"]
  node_node_extension["DiffKit extension<br/>browser extension"]
end

subgraph group_group_docs_ops["Docs and ops"]
  node_node_cache_docs["Cache docs<br/>architecture docs"]
end

node_node_worker -->|"boots"| node_node_router
node_node_router -->|"serves"| node_node_public_routes
node_node_router -->|"serves"| node_node_protected_routes
node_node_router -->|"serves"| node_node_api_routes
node_node_protected_routes -->|"composes"| node_node_layout_shell
node_node_protected_routes -->|"renders"| node_node_product_views
node_node_product_views -->|"includes"| node_node_repo_views
node_node_product_views -->|"includes"| node_node_issue_views
node_node_product_views -->|"includes"| node_node_pull_views
node_node_product_views -->|"includes"| node_node_review_views
node_node_product_views -->|"uses"| node_node_ui_kit
node_node_layout_shell -->|"uses"| node_node_ui_kit
node_node_layout_shell -->|"uses"| node_node_icons
node_node_layout_shell -->|"subscribes"| node_node_signal_relay
node_node_product_views -->|"queries"| node_node_data_client
node_node_data_client -->|"fetches"| node_node_github_core
node_node_github_core -->|"checks access"| node_node_auth
node_node_github_core -->|"reads/writes"| node_node_db
node_node_github_core -->|"caches"| node_node_github_cache
node_node_github_cache -->|"invalidates"| node_node_signal_relay
node_node_api_routes -->|"handles"| node_node_auth
node_node_api_routes -->|"ingests webhooks"| node_node_signal_relay
node_node_auth -->|"persists"| node_node_db
node_node_signal_relay -->|"pushes"| node_node_data_client
node_node_extension -->|"extends"| node_node_product_views
node_node_cache_docs -.->|"describes"| node_node_github_cache

click node_node_worker "https://github.com/stylessh/diffkit/blob/main/apps/dashboard/src/entry-worker.ts"
click node_node_router "https://github.com/stylessh/diffkit/blob/main/apps/dashboard/src/router.tsx"
click node_node_public_routes "https://github.com/stylessh/diffkit/tree/main/apps/dashboard/src/routes"
click node_node_protected_routes "https://github.com/stylessh/diffkit/tree/main/apps/dashboard/src/routes/_protected"
click node_node_api_routes "https://github.com/stylessh/diffkit/tree/main/apps/dashboard/src/routes/api"
click node_node_layout_shell "https://github.com/stylessh/diffkit/tree/main/apps/dashboard/src/components/layouts"
click node_node_product_views "https://github.com/stylessh/diffkit/tree/main/apps/dashboard/src/components"
click node_node_repo_views "https://github.com/stylessh/diffkit/tree/main/apps/dashboard/src/components/repo"
click node_node_issue_views "https://github.com/stylessh/diffkit/tree/main/apps/dashboard/src/components/issues"
click node_node_pull_views "https://github.com/stylessh/diffkit/tree/main/apps/dashboard/src/components/pulls"
click node_node_review_views "https://github.com/stylessh/diffkit/tree/main/apps/dashboard/src/components/pulls/review"
click node_node_data_client "https://github.com/stylessh/diffkit/blob/main/apps/dashboard/src/lib/query-client.tsx"
click node_node_github_core "https://github.com/stylessh/diffkit/blob/main/apps/dashboard/src/lib/github.server.ts"
click node_node_github_cache "https://github.com/stylessh/diffkit/blob/main/apps/dashboard/src/lib/github-cache.ts"
click node_node_signal_relay "https://github.com/stylessh/diffkit/blob/main/apps/dashboard/src/lib/signal-relay.server.ts"
click node_node_auth "https://github.com/stylessh/diffkit/blob/main/apps/dashboard/src/lib/auth.server.ts"
click node_node_db "https://github.com/stylessh/diffkit/blob/main/apps/dashboard/src/db/schema.ts"
click node_node_ui_kit "https://github.com/stylessh/diffkit/tree/main/packages/ui/src/components"
click node_node_icons "https://github.com/stylessh/diffkit/tree/main/packages/icons/src"
click node_node_extension "https://github.com/stylessh/diffkit/tree/main/extensions/diffkit-redirect"
click node_node_cache_docs "https://github.com/stylessh/diffkit/blob/main/docs/github-cache-architecture.md"

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_worker,node_node_router,node_node_public_routes,node_node_protected_routes,node_node_api_routes,node_node_layout_shell,node_node_product_views,node_node_repo_views,node_node_issue_views,node_node_pull_views,node_node_review_views,node_node_data_client,node_node_github_core,node_node_github_cache,node_node_signal_relay,node_node_auth,node_node_db toneBlue
class node_node_ui_kit,node_node_icons toneAmber
class node_node_extension toneMint
class node_node_cache_docs toneRose
```

## Components

### Dashboard app

Primary Cloudflare Worker application, routes, UI, and data layers.

- [Worker entry](https://github.com/stylessh/diffkit/blob/main/apps/dashboard/src/entry-worker.ts): Cloudflare Worker · Runtime entrypoint for the dashboard app. · `apps/dashboard/src/entry-worker.ts`
- [App router](https://github.com/stylessh/diffkit/blob/main/apps/dashboard/src/router.tsx): TanStack Start · Route tree and application wiring. · `apps/dashboard/src/router.tsx`
- [Public routes](https://github.com/stylessh/diffkit/tree/main/apps/dashboard/src/routes): route surface · Login, setup, legal pages, and auth callbacks. · `apps/dashboard/src/routes`
- [Protected shell](https://github.com/stylessh/diffkit/tree/main/apps/dashboard/src/routes/_protected): authenticated routes · Signed-in dashboard surface for product workflows. · `apps/dashboard/src/routes/_protected`
- [API routes](https://github.com/stylessh/diffkit/tree/main/apps/dashboard/src/routes/api): server endpoints · Auth, GitHub App, and webhook entrypoints. · `apps/dashboard/src/routes/api`
- [Dashboard shell](https://github.com/stylessh/diffkit/tree/main/apps/dashboard/src/components/layouts): ui shell · Persistent chrome, nav, dialogs, loading, and error states. · `apps/dashboard/src/components/layouts`
- [Product views](https://github.com/stylessh/diffkit/tree/main/apps/dashboard/src/components): domain UI · Repository, issue, pull request, review, inbox, and settings screens. · `apps/dashboard/src/components`
- [Repo flow](https://github.com/stylessh/diffkit/tree/main/apps/dashboard/src/components/repo): repository UI · Repository overview, file tree, activity, and code explorer. · `apps/dashboard/src/components/repo`
- [Issue flow](https://github.com/stylessh/diffkit/tree/main/apps/dashboard/src/components/issues): issue UI · Issue lists, detail pages, labels, and new issue composer. · `apps/dashboard/src/components/issues`
- [PR flow](https://github.com/stylessh/diffkit/tree/main/apps/dashboard/src/components/pulls): pull request UI · Pull request lists, detail pages, and merge/review helpers. · `apps/dashboard/src/components/pulls`
- [Review flow](https://github.com/stylessh/diffkit/tree/main/apps/dashboard/src/components/pulls/review): code review UI · Review diffs, file trees, and submit interactions. · `apps/dashboard/src/components/pulls/review`
- [Query client](https://github.com/stylessh/diffkit/blob/main/apps/dashboard/src/lib/query-client.tsx): TanStack Query · Client-side cache, hydration, and mutation boundary. · `apps/dashboard/src/lib/query-client.tsx`
- [GitHub core](https://github.com/stylessh/diffkit/blob/main/apps/dashboard/src/lib/github.server.ts): GitHub API layer · Server-side GitHub request composition, access policy, and helpers. · `apps/dashboard/src/lib/github.server.ts`
- [GitHub cache](https://github.com/stylessh/diffkit/blob/main/apps/dashboard/src/lib/github-cache.ts): cache/revalidation · Caching policy and refresh coordination for GitHub data. · `apps/dashboard/src/lib/github-cache.ts`
- [Signal relay](https://github.com/stylessh/diffkit/blob/main/apps/dashboard/src/lib/signal-relay.server.ts): broadcast stream · Revalidation and change signals pushed to active clients. · `apps/dashboard/src/lib/signal-relay.server.ts`
- [Auth system](https://github.com/stylessh/diffkit/blob/main/apps/dashboard/src/lib/auth.server.ts): Better Auth · OAuth login, GitHub App authorization, and auth runtime glue. · `apps/dashboard/src/lib/auth.server.ts`
- [D1 database](https://github.com/stylessh/diffkit/blob/main/apps/dashboard/src/db/schema.ts): Drizzle schema · SQLite persistence for app state, sessions, and cache metadata. · `apps/dashboard/src/db/schema.ts`

### Shared packages

Workspace libraries reused by the dashboard and extension.

- [UI kit](https://github.com/stylessh/diffkit/tree/main/packages/ui/src/components): design system · Shared UI primitives for buttons, dialogs, tables, markdown, layout, and editing. · `packages/ui/src/components`
- [Icons](https://github.com/stylessh/diffkit/tree/main/packages/icons/src): shared icons · Reusable icon set used across the workspace. · `packages/icons/src`

### Browser extension

Companion extension that bridges GitHub pages into DiffKit.

- [DiffKit extension](https://github.com/stylessh/diffkit/tree/main/extensions/diffkit-redirect): browser extension · Companion extension that integrates GitHub pages with DiffKit. · `extensions/diffkit-redirect`

### Docs and ops

Architecture notes and repository operations support.

- [Cache docs](https://github.com/stylessh/diffkit/blob/main/docs/github-cache-architecture.md): architecture docs · Design notes for GitHub cache and invalidation behavior. · `docs/github-cache-architecture.md`

## Connections

- Worker entry → App router: boots · The Cloudflare Worker starts the application router.
- App router → Public routes: serves · Routes unauthenticated pages and auth callbacks.
- App router → Protected shell: serves · Routes the authenticated dashboard shell and product pages.
- App router → API routes: serves · Exposes auth, GitHub App, and webhook endpoints.
- Protected shell → Dashboard shell: composes · Protected pages share the persistent dashboard shell.
- Protected shell → Product views: renders · Route pages mount the main product screens.
- Product views → Repo flow: includes · Repository experience covers overview and file navigation.
- Product views → Issue flow: includes · Issue experience covers lists, detail, and creation.
- Product views → PR flow: includes · Pull request experience covers lists and detail pages.
- Product views → Review flow: includes · Review experience handles diffs and submissions.
- Product views → UI kit: uses · Domain screens are built from shared design-system primitives.
- Dashboard shell → UI kit: uses · Shell chrome is assembled from shared UI components.
- Dashboard shell → Icons: uses · Navigation and chrome use shared icons.
- Dashboard shell → Signal relay: subscribes · Shell can react to live revalidation and change signals.
- Product views → Query client: queries · Client views read and mutate data through TanStack Query.
- Query client → GitHub core: fetches · Client data ultimately resolves to GitHub-backed server access.
- GitHub core → Auth system: checks access · GitHub requests depend on user and installation authorization.
- GitHub core → D1 database: reads/writes · GitHub state and cache metadata are tracked in D1.
- GitHub core → GitHub cache: caches · Requests flow through cache and request policy layers.
- GitHub cache → Signal relay: invalidates · Cache refresh events emit signals for live clients.
- API routes → Auth system: handles · Auth routes manage login and GitHub authorization.
- API routes → Signal relay: ingests webhooks · GitHub webhook events trigger invalidation and relay paths.
- Auth system → D1 database: persists · Auth state and related records are stored in D1.
- Signal relay → Query client: pushes · Open clients can react to revalidation and refresh signals.
- DiffKit extension → Product views: extends · The browser extension bridges GitHub pages to the product experience.
- Cache docs → GitHub cache: describes · Documentation explains cache and invalidation architecture.
