# termcavetw/openlawtw architecture

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

- Interactive diagram: https://gitdiagram.com/termcavetw/openlawtw
- Repository: https://github.com/termcavetw/openlawtw

## Overview

openlawtw is a Taiwanese building-regulations lookup and reading workspace, not a legal-advice system. The main user flow is to search regulations or source documents, open a result in the law reader, and inspect article text, citations, rulings, and official sources. The workspace also supports case evidence, sharing, version history, coverage exploration, an interactive law universe, and optional offline data. The README documents capabilities beyond the sampled excerpts; those links are cited to it, while implementation details are limited to indexed references and shown source.

Main entry points: [`app/page.tsx`](https://github.com/termcavetw/openlawtw/blob/main/app/page.tsx) (Workspace Shell), [`components/law-reader.tsx`](https://github.com/termcavetw/openlawtw/blob/main/components/law-reader.tsx) (Law Reader), [`lib/data-client.ts`](https://github.com/termcavetw/openlawtw/blob/main/lib/data-client.ts) (Data Client), [`components/rulings.tsx`](https://github.com/termcavetw/openlawtw/blob/main/components/rulings.tsx) (Rulings Browser)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_workspace["Workspace"]
  node_workspace["Workspace Shell<br/>[page.tsx]"]
  node_casebook["Casebook<br/>[casebook.tsx]"]
  node_sharing["Reference Sharing"]
end

subgraph group_lookup["Search and Sources"]
  node_searchui["Search Results<br/>[search-results.tsx]"]
  node_search["Search Engine<br/>[search.ts]"]
end

subgraph group_reading["Legal Reading"]
  node_navigation["Law Navigation<br/>[law-navigation.tsx]"]
  node_lawportal["Law Portal<br/>[law-portal.tsx]"]
  node_lawreader["Law Reader<br/>[law-reader.tsx]"]
  node_inlinepreview["Inline Citation Preview"]
  node_documents["Document Reading"]
  node_supplements["Article Supplements"]
end

subgraph group_research["Research Tools"]
  node_rulings["Rulings Browser<br/>[rulings.tsx]"]
  node_rulingpreview["Ruling Preview<br/>[ruling-preview.tsx]"]
  node_coverage["Coverage Checklist"]
  node_universe["Law Universe<br/>[law-universe.tsx]"]
  node_version["Version Evidence"]
end

subgraph group_data["Data Services"]
  node_datafetch["Data Client<br/>[data-client.ts]"]
  node_catalog[("Law Catalog<br/>[catalog.ts]")]
  node_types["Legal Data Model<br/>[law-types.ts]"]
  node_offline["Offline Packs<br/>[offline-packs.tsx]"]
end

node_reader(("User"))

node_reader -->|"opens"| node_workspace
node_workspace -->|"hosts"| node_casebook
node_workspace -->|"hosts"| node_sharing
node_workspace -->|"shows"| node_searchui
node_searchui -->|"selects result"| node_navigation
node_workspace -->|"searches"| node_search
node_search -->|"uses candidates"| node_datafetch
node_datafetch -->|"loads records"| node_types
node_catalog -->|"types records"| node_types
node_workspace -->|"opens laws"| node_lawportal
node_lawportal -->|"reads coverage"| node_catalog
node_lawreader -->|"loads law data"| node_datafetch
node_lawreader -->|"renders documents"| node_documents
node_lawreader -->|"loads supplements"| node_supplements
node_lawreader -.->|"shows citations"| node_inlinepreview
node_workspace -->|"reads laws"| node_lawreader
node_workspace -->|"opens rulings"| node_rulings
node_rulings -->|"loads ruling data"| node_datafetch
node_rulings -->|"saves evidence"| node_casebook
node_rulings -->|"shares references"| node_sharing
node_rulingpreview -->|"loads preview"| node_datafetch
node_workspace -->|"explores coverage"| node_coverage
node_coverage -->|"checks regions"| node_catalog
node_workspace -->|"explores relations"| node_universe
node_universe -->|"loads law data"| node_datafetch
node_lawreader -->|"shows history"| node_version
node_workspace -->|"manages downloads"| node_offline

click node_workspace "https://github.com/termcavetw/openlawtw/blob/main/app/page.tsx"
click node_casebook "https://github.com/termcavetw/openlawtw/blob/main/components/casebook.tsx"
click node_sharing "https://github.com/termcavetw/openlawtw/blob/main/components/reference-share.tsx"
click node_searchui "https://github.com/termcavetw/openlawtw/blob/main/components/search-results.tsx"
click node_search "https://github.com/termcavetw/openlawtw/blob/main/lib/search.ts"
click node_datafetch "https://github.com/termcavetw/openlawtw/blob/main/lib/data-client.ts"
click node_catalog "https://github.com/termcavetw/openlawtw/blob/main/lib/catalog.ts"
click node_types "https://github.com/termcavetw/openlawtw/blob/main/lib/law-types.ts"
click node_navigation "https://github.com/termcavetw/openlawtw/blob/main/components/law-navigation.tsx"
click node_lawportal "https://github.com/termcavetw/openlawtw/blob/main/components/law-portal.tsx"
click node_lawreader "https://github.com/termcavetw/openlawtw/blob/main/components/law-reader.tsx"
click node_inlinepreview "https://github.com/termcavetw/openlawtw/blob/main/components/legal-inline-preview.tsx"
click node_documents "https://github.com/termcavetw/openlawtw/blob/main/components/document-reader.tsx"
click node_supplements "https://github.com/termcavetw/openlawtw/blob/main/components/article-supplements.tsx"
click node_rulings "https://github.com/termcavetw/openlawtw/blob/main/components/rulings.tsx"
click node_rulingpreview "https://github.com/termcavetw/openlawtw/blob/main/components/ruling-preview.tsx"
click node_coverage "https://github.com/termcavetw/openlawtw/blob/main/components/coverage-checklist.tsx"
click node_universe "https://github.com/termcavetw/openlawtw/blob/main/components/law-universe.tsx"
click node_version "https://github.com/termcavetw/openlawtw/blob/main/components/version-evidence.tsx"
click node_offline "https://github.com/termcavetw/openlawtw/blob/main/components/offline-packs.tsx"

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_workspace,node_casebook,node_sharing,node_reader toneBlue
class node_searchui,node_search toneAmber
class node_navigation,node_lawportal,node_lawreader,node_inlinepreview,node_documents,node_supplements toneMint
class node_rulings,node_rulingpreview,node_coverage,node_universe,node_version toneRose
class node_datafetch,node_catalog,node_types,node_offline toneIndigo
```

## Components

### Workspace

- [Workspace Shell](https://github.com/termcavetw/openlawtw/blob/main/app/page.tsx): `app/page.tsx`
- [Casebook](https://github.com/termcavetw/openlawtw/blob/main/components/casebook.tsx): `components/casebook.tsx`
- [Reference Sharing](https://github.com/termcavetw/openlawtw/blob/main/components/reference-share.tsx): `components/reference-share.tsx`

### Search and Sources

- [Search Results](https://github.com/termcavetw/openlawtw/blob/main/components/search-results.tsx): `components/search-results.tsx`
- [Search Engine](https://github.com/termcavetw/openlawtw/blob/main/lib/search.ts): `lib/search.ts`

### Legal Reading

- [Law Navigation](https://github.com/termcavetw/openlawtw/blob/main/components/law-navigation.tsx): `components/law-navigation.tsx`
- [Law Portal](https://github.com/termcavetw/openlawtw/blob/main/components/law-portal.tsx): `components/law-portal.tsx`
- [Law Reader](https://github.com/termcavetw/openlawtw/blob/main/components/law-reader.tsx): `components/law-reader.tsx`
- [Inline Citation Preview](https://github.com/termcavetw/openlawtw/blob/main/components/legal-inline-preview.tsx): `components/legal-inline-preview.tsx`
- [Document Reading](https://github.com/termcavetw/openlawtw/blob/main/components/document-reader.tsx): `components/document-reader.tsx`
- [Article Supplements](https://github.com/termcavetw/openlawtw/blob/main/components/article-supplements.tsx): `components/article-supplements.tsx`

### Research Tools

- [Rulings Browser](https://github.com/termcavetw/openlawtw/blob/main/components/rulings.tsx): `components/rulings.tsx`
- [Ruling Preview](https://github.com/termcavetw/openlawtw/blob/main/components/ruling-preview.tsx): `components/ruling-preview.tsx`
- [Coverage Checklist](https://github.com/termcavetw/openlawtw/blob/main/components/coverage-checklist.tsx): `components/coverage-checklist.tsx`
- [Law Universe](https://github.com/termcavetw/openlawtw/blob/main/components/law-universe.tsx): `components/law-universe.tsx`
- [Version Evidence](https://github.com/termcavetw/openlawtw/blob/main/components/version-evidence.tsx): `components/version-evidence.tsx`

### Data Services

- [Data Client](https://github.com/termcavetw/openlawtw/blob/main/lib/data-client.ts): `lib/data-client.ts`
- [Law Catalog](https://github.com/termcavetw/openlawtw/blob/main/lib/catalog.ts): `lib/catalog.ts`
- [Legal Data Model](https://github.com/termcavetw/openlawtw/blob/main/lib/law-types.ts): `lib/law-types.ts`
- [Offline Packs](https://github.com/termcavetw/openlawtw/blob/main/components/offline-packs.tsx): `components/offline-packs.tsx`

### Other components

- **User**

## Connections

- User → Workspace Shell: opens (evidence: `README.md`)
- Workspace Shell → Casebook: hosts (evidence: `app/page.tsx`)
- Workspace Shell → Reference Sharing: hosts (evidence: `app/page.tsx`)
- Workspace Shell → Search Results: shows (evidence: `app/page.tsx`)
- Search Results → Law Navigation: selects result (evidence: `components/search-results.tsx`)
- Workspace Shell → Search Engine: searches (evidence: `README.md`)
- Search Engine → Data Client: uses candidates (evidence: `lib/data-client.ts`)
- Data Client → Legal Data Model: loads records (evidence: `lib/data-client.ts`)
- Law Catalog → Legal Data Model: types records (evidence: `lib/catalog.ts`)
- Workspace Shell → Law Portal: opens laws (evidence: `app/page.tsx`)
- Law Portal → Law Catalog: reads coverage (evidence: `components/law-portal.tsx`)
- Law Reader → Data Client: loads law data (evidence: `components/law-reader.tsx`)
- Law Reader → Document Reading: renders documents (evidence: `components/law-reader.tsx`)
- Law Reader → Article Supplements: loads supplements (evidence: `components/law-reader.tsx`)
- Law Reader → Inline Citation Preview: shows citations
- Workspace Shell → Law Reader: reads laws (evidence: `README.md`)
- Workspace Shell → Rulings Browser: opens rulings (evidence: `README.md`)
- Rulings Browser → Data Client: loads ruling data (evidence: `components/rulings.tsx`)
- Rulings Browser → Casebook: saves evidence (evidence: `components/rulings.tsx`)
- Rulings Browser → Reference Sharing: shares references (evidence: `components/rulings.tsx`)
- Ruling Preview → Data Client: loads preview (evidence: `components/ruling-preview.tsx`)
- Workspace Shell → Coverage Checklist: explores coverage (evidence: `README.md`)
- Coverage Checklist → Law Catalog: checks regions (evidence: `components/coverage-checklist.tsx`)
- Workspace Shell → Law Universe: explores relations (evidence: `app/page.tsx`)
- Law Universe → Data Client: loads law data (evidence: `components/law-universe.tsx`)
- Law Reader → Version Evidence: shows history (evidence: `components/law-reader.tsx`)
- Workspace Shell → Offline Packs: manages downloads (evidence: `README.md`)
