# duoleshi/0606-klb architecture

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

- Interactive diagram: https://gitdiagram.com/duoleshi/0606-klb
- Repository: https://github.com/duoleshi/0606-klb

## Overview

This is a Next.js application for AI-assisted review of high-risk construction plans. The main workflow uploads a PDF, extracts text (using OCR when needed), identifies relevant engineering specialties, matches standards from the knowledge base, generates a structured AI review, and saves the result for later retrieval. Separate features expose review history, standards documents, authentication, and OCR testing. The principal processing calls are visible in the review and PDF-parser excerpts; some page-to-API connections are documented or implied but not shown in the sampled code.

Main entry points: [`app/api/review/route.ts`](https://github.com/duoleshi/0606-klb/blob/main/app/api/review/route.ts) (Review orchestrator), [`lib/pdf-parser.ts`](https://github.com/duoleshi/0606-klb/blob/main/lib/pdf-parser.ts) (PDF extraction), [`components/landing/hero.tsx`](https://github.com/duoleshi/0606-klb/blob/main/components/landing/hero.tsx) (Review workspace), [`lib/db.ts`](https://github.com/duoleshi/0606-klb/blob/main/lib/db.ts) (Review records)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_experience["User experience"]
  node_landing["Review workspace<br/>[hero.tsx]"]
  node_upload["File selection<br/>[file-upload.tsx]"]
  node_report["Report editor<br/>[review-result.tsx]"]
  node_history_ui["History views<br/>[page.tsx]"]
  node_regulations_ui["Standards browser<br/>[page.tsx]"]
end

subgraph group_review["Review processing"]
  node_review_api["Review orchestrator<br/>[route.ts]"]
  node_pdf["PDF extraction<br/>[pdf-parser.ts]"]
  node_specialty["Specialty matching<br/>[knowledge-base.ts]"]
  node_standards["Knowledge context<br/>[knowledge-base.ts]"]
  node_ocr_test["OCR test endpoint<br/>[route.ts]"]
end

subgraph group_records["Records and standards"]
  node_history_api["History endpoints<br/>[route.ts]"]
  node_history_item_api["Record endpoint<br/>[route.ts]"]
  node_records_store[("Review records<br/>[db.ts]")]
  node_regulations_api["Standards endpoint<br/>[route.ts]"]
end

subgraph group_identity["Identity and integrations"]
  node_ai["AI review service"]
  node_mineru["MinerU OCR"]
  node_baidu["Baidu OCR"]
  node_tesseract["Tesseract OCR"]
  node_auth_ui["Sign-in and registration<br/>[page.tsx]"]
  node_auth_api["Registration endpoint<br/>[route.ts]"]
  node_supabase[("Supabase identity<br/>[server.ts]")]
end

node_user(("Plan reviewer"))
node_browser(("Web browser"))

node_user -->|"uploads plan"| node_landing
node_landing -->|"selects file"| node_upload
node_landing -.->|"submits for review"| node_review_api
node_review_api -->|"parses document"| node_pdf
node_review_api -->|"matches knowledge"| node_specialty
node_specialty -->|"returns context"| node_standards
node_review_api -.->|"requests analysis"| node_ai
node_pdf -.->|"uses OCR"| node_mineru
node_pdf -.->|"uses OCR"| node_baidu
node_pdf -.->|"uses OCR"| node_tesseract
node_review_api -->|"saves result"| node_records_store
node_review_api -->|"gets user ID"| node_supabase
node_landing -.->|"shows result"| node_report
node_user -->|"views history"| node_history_ui
node_history_ui -.->|"loads records"| node_history_api
node_history_api -->|"reads records"| node_records_store
node_history_item_api -->|"reads or deletes"| node_records_store
node_user -->|"browses standards"| node_regulations_ui
node_regulations_ui -.->|"loads documents"| node_regulations_api
node_user -.->|"signs in"| node_auth_ui
node_auth_ui -.->|"authenticates"| node_supabase
node_auth_api -.->|"registers user"| node_supabase
node_browser -->|"tests OCR"| node_ocr_test
node_ocr_test -->|"parses upload"| node_pdf

click node_landing "https://github.com/duoleshi/0606-klb/blob/main/components/landing/hero.tsx"
click node_upload "https://github.com/duoleshi/0606-klb/blob/main/components/file-upload.tsx"
click node_report "https://github.com/duoleshi/0606-klb/blob/main/components/review-result.tsx"
click node_history_ui "https://github.com/duoleshi/0606-klb/blob/main/app/history/page.tsx"
click node_regulations_ui "https://github.com/duoleshi/0606-klb/blob/main/app/regulations/page.tsx"
click node_review_api "https://github.com/duoleshi/0606-klb/blob/main/app/api/review/route.ts"
click node_pdf "https://github.com/duoleshi/0606-klb/blob/main/lib/pdf-parser.ts"
click node_specialty "https://github.com/duoleshi/0606-klb/blob/main/lib/knowledge-base.ts"
click node_standards "https://github.com/duoleshi/0606-klb/blob/main/lib/knowledge-base.ts"
click node_history_api "https://github.com/duoleshi/0606-klb/blob/main/app/api/history/route.ts"
click node_history_item_api "https://github.com/duoleshi/0606-klb/blob/main/app/api/history/%5Bid%5D/route.ts"
click node_records_store "https://github.com/duoleshi/0606-klb/blob/main/lib/db.ts"
click node_regulations_api "https://github.com/duoleshi/0606-klb/blob/main/app/api/regulations/route.ts"
click node_ocr_test "https://github.com/duoleshi/0606-klb/blob/main/app/api/ocr-test/route.ts"
click node_auth_ui "https://github.com/duoleshi/0606-klb/blob/main/app/login/page.tsx"
click node_auth_api "https://github.com/duoleshi/0606-klb/blob/main/app/api/auth/register/route.ts"
click node_supabase "https://github.com/duoleshi/0606-klb/blob/main/lib/supabase/server.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_landing,node_upload,node_report,node_history_ui,node_regulations_ui,node_user,node_browser toneBlue
class node_review_api,node_pdf,node_specialty,node_standards,node_ocr_test toneAmber
class node_history_api,node_history_item_api,node_records_store,node_regulations_api toneMint
class node_ai,node_mineru,node_baidu,node_tesseract,node_auth_ui,node_auth_api,node_supabase toneRose
```

## Components

### User experience

- [Review workspace](https://github.com/duoleshi/0606-klb/blob/main/components/landing/hero.tsx): `components/landing/hero.tsx`
- [File selection](https://github.com/duoleshi/0606-klb/blob/main/components/file-upload.tsx): `components/file-upload.tsx`
- [Report editor](https://github.com/duoleshi/0606-klb/blob/main/components/review-result.tsx): `components/review-result.tsx`
- [History views](https://github.com/duoleshi/0606-klb/blob/main/app/history/page.tsx): `app/history/page.tsx`
- [Standards browser](https://github.com/duoleshi/0606-klb/blob/main/app/regulations/page.tsx): `app/regulations/page.tsx`

### Review processing

- [Review orchestrator](https://github.com/duoleshi/0606-klb/blob/main/app/api/review/route.ts): `app/api/review/route.ts`
- [PDF extraction](https://github.com/duoleshi/0606-klb/blob/main/lib/pdf-parser.ts): `lib/pdf-parser.ts`
- [Specialty matching](https://github.com/duoleshi/0606-klb/blob/main/lib/knowledge-base.ts): `lib/knowledge-base.ts`
- [Knowledge context](https://github.com/duoleshi/0606-klb/blob/main/lib/knowledge-base.ts): `lib/knowledge-base.ts`
- [OCR test endpoint](https://github.com/duoleshi/0606-klb/blob/main/app/api/ocr-test/route.ts): `app/api/ocr-test/route.ts`

### Records and standards

- [History endpoints](https://github.com/duoleshi/0606-klb/blob/main/app/api/history/route.ts): `app/api/history/route.ts`
- [Record endpoint](https://github.com/duoleshi/0606-klb/blob/main/app/api/history/%5Bid%5D/route.ts): `app/api/history/[id]/route.ts`
- [Review records](https://github.com/duoleshi/0606-klb/blob/main/lib/db.ts): `lib/db.ts`
- [Standards endpoint](https://github.com/duoleshi/0606-klb/blob/main/app/api/regulations/route.ts): `app/api/regulations/route.ts`

### Identity and integrations

- **AI review service**
- **MinerU OCR**
- **Baidu OCR**
- **Tesseract OCR**
- [Sign-in and registration](https://github.com/duoleshi/0606-klb/blob/main/app/login/page.tsx): `app/login/page.tsx`
- [Registration endpoint](https://github.com/duoleshi/0606-klb/blob/main/app/api/auth/register/route.ts): `app/api/auth/register/route.ts`
- [Supabase identity](https://github.com/duoleshi/0606-klb/blob/main/lib/supabase/server.ts): `lib/supabase/server.ts`

### Other components

- **Plan reviewer**
- **Web browser**

## Connections

- Plan reviewer → Review workspace: uploads plan (evidence: `README.md`)
- Review workspace → File selection: selects file (evidence: `components/landing/hero.tsx`)
- Review workspace → Review orchestrator: submits for review
- Review orchestrator → PDF extraction: parses document (evidence: `app/api/review/route.ts`)
- Review orchestrator → Specialty matching: matches knowledge (evidence: `app/api/review/route.ts`)
- Specialty matching → Knowledge context: returns context (evidence: `app/api/review/route.ts`)
- Review orchestrator → AI review service: requests analysis
- PDF extraction → MinerU OCR: uses OCR (evidence: `lib/pdf-parser.ts`)
- PDF extraction → Baidu OCR: uses OCR (evidence: `lib/pdf-parser.ts`)
- PDF extraction → Tesseract OCR: uses OCR (evidence: `lib/pdf-parser.ts`)
- Review orchestrator → Review records: saves result (evidence: `app/api/review/route.ts`)
- Review orchestrator → Supabase identity: gets user ID (evidence: `app/api/review/route.ts`)
- Review workspace → Report editor: shows result (evidence: `components/landing/hero.tsx`)
- Plan reviewer → History views: views history (evidence: `README.md`)
- History views → History endpoints: loads records
- History endpoints → Review records: reads records (evidence: `app/api/history/route.ts`)
- Record endpoint → Review records: reads or deletes (evidence: `app/api/history/[id]/route.ts`)
- Plan reviewer → Standards browser: browses standards (evidence: `README.md`)
- Standards browser → Standards endpoint: loads documents
- Plan reviewer → Sign-in and registration: signs in
- Sign-in and registration → Supabase identity: authenticates
- Registration endpoint → Supabase identity: registers user
- Web browser → OCR test endpoint: tests OCR
- OCR test endpoint → PDF extraction: parses upload (evidence: `app/api/ocr-test/route.ts`)
