# samflipppy/rubric architecture

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

- Interactive diagram: https://gitdiagram.com/samflipppy/rubric
- Repository: https://github.com/samflipppy/rubric

## Overview

1. **Repository shape: two deployable surfaces.** This repo is split into a `web` frontend and `functions` backend, deployed together through Firebase Hosting + Cloud Functions Gen 2. The product is a linear PR-review app, not a generic CRUD system.

2. **Frontend boundary.** `web/` is a React 19 + Vite + TypeScript app styled with Tailwind. It uses URL params and local React state for navigation/state instead of a router or global store, which keeps the app centered on a single review session rather than persistent user accounts.

3. **Frontend screen flow.** The UI is organized around five pages: `Home`, `Brief`, `Review`, `Ask`, and `Decide`. That maps directly to the product’s four-phase review flow plus the landing page. Navigation is intentionally linear: orient, answer questions, optionally ask follow-ups, then make a final decision.

4. **Frontend component roles.** `QuestionCard`, `DiffView`, `TierBadge`, `ProgressBar`, and `LoadingSequence` make up the core review experience. The important architectural point is that the UI renders AI-produced questions alongside code slices, so the frontend is not just displaying text; it is presenting evidence and reviewer judgments side by side.

5. **Frontend data plumbing.** `web/src/lib/api.ts` is the client boundary to the backend. `github.ts` parses PR URLs / repo metadata, `nav.ts` handles screen transitions, and `audit.ts` assembles the final review transcript for copy-out. This means the browser holds the session state and the review artifact; there is no server-side persistence.

6. **Backend boundary.** `functions/` is a Genkit-based Firebase Functions service running on Node 20. The backend is organized around flows rather than ad hoc endpoints: `generateBrief`, `generateRubric`, and `answerPRQuestion`, plus a plain `listPRs` HTTPS entry point for loading open PRs on the home screen.

7. **Backend orchestration model.** Each flow uses `ai.defineFlow` with Zod schemas for input/output validation. That implies strict typed boundaries between the web app, the orchestration layer, and the model outputs. The backend is designed to be deterministic in structure even though it calls an LLM for content generation.

8. **LLM and model configuration.** `functions/src/genkit.ts` centralizes the Genkit instance and the model constant, using Vertex AI Gemini 2.5 Flash-lite. The model choice is treated as infrastructure, not scattered configuration, which makes the model swap a single-point change.

9. **GitHub as the source of truth.** `functions/src/tools/github.ts` encapsulates GitHub REST API access and diff/PR fetching. The system reviews public PRs without auth by default, with optional `GITHUB_TOKEN` support. The raw GitHub diff is the authoritative input that all AI outputs must be checked against.

10. **Fabrication guard as a core boundary.** The key trust mechanism is that embedded code snippets in rubric questions and chat answers are substring-verified against the real GitHub diff after generation. Anything not present in the diff is dropped before reaching the reviewer. Architecturally, this turns the backend into a generate-then-verify pipeline rather than “trust the model” text generation.

11. **Schema layer.** `functions/src/schemas/` contains separate Zod models for PR metadata, brief output, rubric output, review decisions, and ask/chat payloads. This makes the content pipeline explicit: PR data in, structured brief/rubric/question answers out, with the review transcript assembled from validated pieces.

12. **End-to-end data flow.** A reviewer opens a PR in the browser, the frontend requests PR data and review artifacts from Firebase Functions, the backend fetches GitHub diff context, Genkit generates a brief and rubric, the UI presents questions and evidence, optional follow-up answers are generated with the same verification guard, and the final decision is kept client-side for copy-to-clipboard review text.

13. **What is deliberately absent.** There is no Firestore, no auth, no multi-user collaboration, no posting comments back to GitHub, and no streaming or analytics. That means the architecture is optimized for a single-session demo-style review workflow with minimal backend state and a strong trust boundary around generated evidence.

14. **Deployment topology.** The frontend is served from Firebase Hosting, and the backend functions live in the same Firebase project (`rubric-216`). Local development mirrors the split: the frontend points at the deployed functions URL, while backend flows can be tested directly against live GitHub PRs.

Main entry points: [`web/src/App.tsx`](https://github.com/samflipppy/rubric/blob/main/web/src/App.tsx) (Web app), [`web/src/pages/Review.tsx`](https://github.com/samflipppy/rubric/blob/main/web/src/pages/Review.tsx) (Review), [`functions/src/flows/generateBrief.ts`](https://github.com/samflipppy/rubric/blob/main/functions/src/flows/generateBrief.ts) (Brief flow), [`functions/src/flows/generateRubric.ts`](https://github.com/samflipppy/rubric/blob/main/functions/src/flows/generateRubric.ts) (Rubric flow)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Web app"]
  node_web_app["Web app<br/>react-vite-ui<br/>[App.tsx]"]
  node_home_page["Home<br/>landing page<br/>[Home.tsx]"]
  node_brief_page["Brief<br/>review step<br/>[Brief.tsx]"]
  node_review_page["Review<br/>[Review.tsx]"]
  node_ask_page["Ask<br/>follow-up step<br/>[Ask.tsx]"]
  node_decide_page["Decide<br/>final step<br/>[Decide.tsx]"]
  node_question_card["Question card<br/>review component<br/>[QuestionCard.tsx]"]
  node_diff_view["Diff view<br/>evidence viewer<br/>[DiffView.tsx]"]
  node_progress_bar["Progress<br/>ui indicator<br/>[ProgressBar.tsx]"]
  node_tier_badge["Tier badge<br/>judgment badge<br/>[TierBadge.tsx]"]
  node_loading_sequence["Loading<br/>ui state"]
  node_api_client["API client<br/>backend boundary<br/>[api.ts]"]
  node_nav_state["Nav state<br/>session state<br/>[nav.ts]"]
  node_audit_builder["Audit builder<br/>transcript assembler<br/>[audit.ts]"]
  node_github_parse["GitHub parser<br/>pr metadata<br/>[github.ts]"]
end

subgraph group_backend["Functions"]
  node_functions_entry["Functions API<br/>firebase functions<br/>[index.ts]"]
  node_genkit_core["Genkit core<br/>llm runtime<br/>[genkit.ts]"]
  node_github_tools["GitHub tools<br/>integration adapter<br/>[github.ts]"]
  node_flows["AI flows<br/>orchestration<br/>[generateBrief.ts]"]
  node_brief_flow["Brief flow<br/>[generateBrief.ts]"]
  node_rubric_flow["Rubric flow<br/>[generateRubric.ts]"]
  node_answer_flow["Answer flow"]
end

subgraph group_shared["Shared flow"]
  node_hosting["Firebase Hosting<br/>deployment<br/>[firebase.json]"]
  node_schemas["Schemas<br/>zod contracts<br/>[index.ts]"]
  node_review_schemas["Review schemas<br/>zod models<br/>[review.ts]"]
  node_pr_schemas["PR schemas<br/>zod models<br/>[pr.ts]"]
end

node_hosting -->|"serves"| node_web_app
node_web_app -->|"navigates"| node_home_page
node_web_app -->|"navigates"| node_brief_page
node_web_app -->|"navigates"| node_review_page
node_web_app -->|"navigates"| node_ask_page
node_web_app -->|"navigates"| node_decide_page
node_review_page -->|"renders"| node_question_card
node_review_page -->|"renders"| node_diff_view
node_review_page -->|"shows"| node_progress_bar
node_review_page -->|"shows"| node_tier_badge
node_web_app -->|"uses"| node_loading_sequence
node_nav_state -->|"drives"| node_web_app
node_github_parse -->|"feeds"| node_api_client
node_audit_builder -->|"feeds"| node_decide_page
node_api_client -->|"calls"| node_functions_entry
node_functions_entry -->|"invokes"| node_brief_flow
node_functions_entry -->|"invokes"| node_rubric_flow
node_functions_entry -->|"invokes"| node_answer_flow
node_brief_flow -->|"uses"| node_genkit_core
node_rubric_flow -->|"uses"| node_genkit_core
node_answer_flow -->|"uses"| node_genkit_core
node_brief_flow -->|"reads"| node_github_tools
node_rubric_flow -->|"reads"| node_github_tools
node_answer_flow -->|"reads"| node_github_tools
node_brief_flow -->|"validates"| node_schemas
node_rubric_flow -->|"validates"| node_schemas
node_answer_flow -->|"validates"| node_schemas
node_schemas -->|"includes"| node_review_schemas
node_schemas -->|"includes"| node_pr_schemas
node_rubric_flow -->|"produces"| node_question_card
node_brief_flow -->|"produces"| node_brief_page
node_answer_flow -->|"produces"| node_ask_page

click node_hosting "https://github.com/samflipppy/rubric/blob/main/firebase.json"
click node_web_app "https://github.com/samflipppy/rubric/blob/main/web/src/App.tsx"
click node_home_page "https://github.com/samflipppy/rubric/blob/main/web/src/pages/Home.tsx"
click node_brief_page "https://github.com/samflipppy/rubric/blob/main/web/src/pages/Brief.tsx"
click node_review_page "https://github.com/samflipppy/rubric/blob/main/web/src/pages/Review.tsx"
click node_ask_page "https://github.com/samflipppy/rubric/blob/main/web/src/pages/Ask.tsx"
click node_decide_page "https://github.com/samflipppy/rubric/blob/main/web/src/pages/Decide.tsx"
click node_question_card "https://github.com/samflipppy/rubric/blob/main/web/src/components/QuestionCard.tsx"
click node_diff_view "https://github.com/samflipppy/rubric/blob/main/web/src/components/DiffView.tsx"
click node_progress_bar "https://github.com/samflipppy/rubric/blob/main/web/src/components/ProgressBar.tsx"
click node_tier_badge "https://github.com/samflipppy/rubric/blob/main/web/src/components/TierBadge.tsx"
click node_loading_sequence "https://github.com/samflipppy/rubric/blob/main/web/src/components/LoadingSequence.tsx"
click node_api_client "https://github.com/samflipppy/rubric/blob/main/web/src/lib/api.ts"
click node_nav_state "https://github.com/samflipppy/rubric/blob/main/web/src/lib/nav.ts"
click node_audit_builder "https://github.com/samflipppy/rubric/blob/main/web/src/lib/audit.ts"
click node_github_parse "https://github.com/samflipppy/rubric/blob/main/web/src/lib/github.ts"
click node_functions_entry "https://github.com/samflipppy/rubric/blob/main/functions/src/index.ts"
click node_genkit_core "https://github.com/samflipppy/rubric/blob/main/functions/src/genkit.ts"
click node_github_tools "https://github.com/samflipppy/rubric/blob/main/functions/src/tools/github.ts"
click node_flows "https://github.com/samflipppy/rubric/blob/main/functions/src/flows/generateBrief.ts"
click node_brief_flow "https://github.com/samflipppy/rubric/blob/main/functions/src/flows/generateBrief.ts"
click node_rubric_flow "https://github.com/samflipppy/rubric/blob/main/functions/src/flows/generateRubric.ts"
click node_answer_flow "https://github.com/samflipppy/rubric/blob/main/functions/src/flows/answerPRQuestion.ts"
click node_schemas "https://github.com/samflipppy/rubric/blob/main/functions/src/schemas/index.ts"
click node_review_schemas "https://github.com/samflipppy/rubric/blob/main/functions/src/schemas/review.ts"
click node_pr_schemas "https://github.com/samflipppy/rubric/blob/main/functions/src/schemas/pr.ts"

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_web_app,node_home_page,node_brief_page,node_review_page,node_ask_page,node_decide_page,node_question_card,node_diff_view,node_progress_bar,node_tier_badge,node_loading_sequence,node_api_client,node_nav_state,node_audit_builder,node_github_parse toneBlue
class node_functions_entry,node_genkit_core,node_github_tools,node_flows,node_brief_flow,node_rubric_flow,node_answer_flow toneAmber
class node_hosting,node_schemas,node_review_schemas,node_pr_schemas toneMint
```

## Components

### Web app

React/Vite frontend for the linear review session

- [Web app](https://github.com/samflipppy/rubric/blob/main/web/src/App.tsx): react-vite-ui · React 19 single-session PR review interface · `web/src/App.tsx`
- [Home](https://github.com/samflipppy/rubric/blob/main/web/src/pages/Home.tsx): landing page · Entry point for opening a PR review session · `web/src/pages/Home.tsx`
- [Brief](https://github.com/samflipppy/rubric/blob/main/web/src/pages/Brief.tsx): review step · Shows the generated summary before the detailed review · `web/src/pages/Brief.tsx`
- [Review](https://github.com/samflipppy/rubric/blob/main/web/src/pages/Review.tsx): review step · Primary screen for questions, evidence, and judgments · `web/src/pages/Review.tsx`
- [Ask](https://github.com/samflipppy/rubric/blob/main/web/src/pages/Ask.tsx): follow-up step · Collects and presents follow-up questions or answers · `web/src/pages/Ask.tsx`
- [Decide](https://github.com/samflipppy/rubric/blob/main/web/src/pages/Decide.tsx): final step · Captures the final review decision and copyable transcript · `web/src/pages/Decide.tsx`
- [Question card](https://github.com/samflipppy/rubric/blob/main/web/src/components/QuestionCard.tsx): review component · Renders AI questions with evidence and reviewer response space · `web/src/components/QuestionCard.tsx`
- [Diff view](https://github.com/samflipppy/rubric/blob/main/web/src/components/DiffView.tsx): evidence viewer · Shows PR code slices alongside generated review content · `web/src/components/DiffView.tsx`
- [Progress](https://github.com/samflipppy/rubric/blob/main/web/src/components/ProgressBar.tsx): ui indicator · Shows where the reviewer is in the linear flow · `web/src/components/ProgressBar.tsx`
- [Tier badge](https://github.com/samflipppy/rubric/blob/main/web/src/components/TierBadge.tsx): judgment badge · Displays review severity or confidence tier · `web/src/components/TierBadge.tsx`
- [Loading](https://github.com/samflipppy/rubric/blob/main/web/src/components/LoadingSequence.tsx): ui state · Animated loading state during generation and fetches · `web/src/components/LoadingSequence.tsx`
- [API client](https://github.com/samflipppy/rubric/blob/main/web/src/lib/api.ts): backend boundary · Frontend calls to Firebase Functions and review data loading · `web/src/lib/api.ts`
- [Nav state](https://github.com/samflipppy/rubric/blob/main/web/src/lib/nav.ts): session state · URL-param and local state transitions between review screens · `web/src/lib/nav.ts`
- [Audit builder](https://github.com/samflipppy/rubric/blob/main/web/src/lib/audit.ts): transcript assembler · Builds the final review transcript for copy-out · `web/src/lib/audit.ts`
- [GitHub parser](https://github.com/samflipppy/rubric/blob/main/web/src/lib/github.ts): pr metadata · Parses PR URLs and repo metadata on the client · `web/src/lib/github.ts`

### Functions

Genkit-backed Firebase Functions orchestration

- [Functions API](https://github.com/samflipppy/rubric/blob/main/functions/src/index.ts): firebase functions · Cloud Functions Gen 2 entrypoints exposed to the web app · `functions/src/index.ts`
- [Genkit core](https://github.com/samflipppy/rubric/blob/main/functions/src/genkit.ts): llm runtime · Central Genkit instance and model selection · `functions/src/genkit.ts`
- [GitHub tools](https://github.com/samflipppy/rubric/blob/main/functions/src/tools/github.ts): integration adapter · GitHub REST access and diff retrieval as source of truth · `functions/src/tools/github.ts`
- [AI flows](https://github.com/samflipppy/rubric/blob/main/functions/src/flows/generateBrief.ts): orchestration · Structured generation flows for brief, rubric, and follow-up answers · `functions/src/flows/generateBrief.ts`
- [Brief flow](https://github.com/samflipppy/rubric/blob/main/functions/src/flows/generateBrief.ts): flow · Generates the concise PR brief from GitHub context · `functions/src/flows/generateBrief.ts`
- [Rubric flow](https://github.com/samflipppy/rubric/blob/main/functions/src/flows/generateRubric.ts): flow · Generates structured review questions and tiers · `functions/src/flows/generateRubric.ts`
- [Answer flow](https://github.com/samflipppy/rubric/blob/main/functions/src/flows/answerPRQuestion.ts): flow · Generates follow-up answers under the same verification rules · `functions/src/flows/answerPRQuestion.ts`

### Shared flow

Data contracts and integration boundaries

- [Firebase Hosting](https://github.com/samflipppy/rubric/blob/main/firebase.json): deployment · Serves the web app in Firebase project rubic-216 · `firebase.json`
- [Schemas](https://github.com/samflipppy/rubric/blob/main/functions/src/schemas/index.ts): zod contracts · Structured input/output models for PRs, briefs, rubrics, reviews, and asks · `functions/src/schemas/index.ts`
- [Review schemas](https://github.com/samflipppy/rubric/blob/main/functions/src/schemas/review.ts): zod models · Decision and transcript payload models · `functions/src/schemas/review.ts`
- [PR schemas](https://github.com/samflipppy/rubric/blob/main/functions/src/schemas/pr.ts): zod models · Pull request metadata and diff context models · `functions/src/schemas/pr.ts`

## Connections

- Firebase Hosting → Web app: serves · Firebase Hosting delivers the frontend bundle
- Web app → Home: navigates · Session begins on the landing page
- Web app → Brief: navigates · Moves into the brief stage
- Web app → Review: navigates · Moves into the main review stage
- Web app → Ask: navigates · Moves into the follow-up question stage
- Web app → Decide: navigates · Moves into the final decision stage
- Review → Question card: renders · Shows AI questions and reviewer prompts
- Review → Diff view: renders · Displays supporting code evidence beside the question
- Review → Progress: shows · Tracks linear progress through the session
- Review → Tier badge: shows · Marks review tier or priority
- Web app → Loading: uses · Displays generation/loading states
- Nav state → Web app: drives · Controls screen transitions from URL and local state
- GitHub parser → API client: feeds · Parsed PR info is used to request backend data
- Audit builder → Decide: feeds · Assembles the final transcript shown for copy-out
- API client → Functions API: calls · Frontend requests PR data and generated artifacts
- Functions API → Brief flow: invokes · Entrypoint exposes brief generation
- Functions API → Rubric flow: invokes · Entrypoint exposes rubric generation
- Functions API → Answer flow: invokes · Entrypoint exposes follow-up answer generation
- Brief flow → Genkit core: uses · Flow runs through the centralized Genkit runtime
- Rubric flow → Genkit core: uses · Flow runs through the centralized Genkit runtime
- Answer flow → Genkit core: uses · Flow runs through the centralized Genkit runtime
- Brief flow → GitHub tools: reads · Uses GitHub diff and PR context as input
- Rubric flow → GitHub tools: reads · Uses GitHub diff and PR context as input
- Answer flow → GitHub tools: reads · Uses GitHub diff and PR context as input
- Brief flow → Schemas: validates · Structured brief inputs and outputs are schema-checked
- Rubric flow → Schemas: validates · Structured rubric inputs and outputs are schema-checked
- Answer flow → Schemas: validates · Structured follow-up inputs and outputs are schema-checked
- Schemas → Review schemas: includes · Review decision and transcript contracts
- Schemas → PR schemas: includes · PR metadata and context contracts
- Rubric flow → Question card: produces · Generated questions feed the review UI
- Brief flow → Brief: produces · Generated brief feeds the brief screen
- Answer flow → Ask: produces · Follow-up answers feed the ask screen
