# dhwjdgh1122/writing-demo architecture

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

- Interactive diagram: https://gitdiagram.com/dhwjdgh1122/writing-demo
- Repository: https://github.com/dhwjdgh1122/writing-demo

## Overview

This is a Korean sentence-correction web demo: users select text, request correction candidates, compare changes, optionally read explanations, and apply a candidate. The browser also supports reruns, local correction history, and optional activity logging/export. The server validates correction and explanation requests, delegates model work through a provider interface, and currently supports Gemini. The graph reflects the sampled imports and calls plus README-documented behavior; the browser-to-server HTTP connection is shown as unverified because the API implementation excerpt was not provided.

Main entry points: [`client/src/App.tsx`](https://github.com/dhwjdgh1122/writing-demo/blob/main/client/src/App.tsx) (Workspace app), [`server/llm/gemini.ts`](https://github.com/dhwjdgh1122/writing-demo/blob/main/server/llm/gemini.ts) (Gemini adapter), [`server/app.ts`](https://github.com/dhwjdgh1122/writing-demo/blob/main/server/app.ts) (API server), [`client/src/components/CandidateCard.tsx`](https://github.com/dhwjdgh1122/writing-demo/blob/main/client/src/components/CandidateCard.tsx) (Candidate card)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_workspace["Writing workspace"]
  node_app["Workspace app<br/>[App.tsx]"]
  node_editor["Editor state<br/>[editor.ts]"]
  node_api["Browser API<br/>[api.ts]"]
  node_results["Candidate results"]
  node_candidate["Candidate card<br/>[CandidateCard.tsx]"]
  node_rerun["Rerun controls<br/>[RerunControls.tsx]"]
  node_selection["Selection helpers<br/>[selectionAnchor.ts]"]
  node_reveal["Text reveal<br/>[revealTextRange.ts]"]
end

subgraph group_records["Local records"]
  node_historyhook["History hook<br/>[useHistory.ts]"]
  node_historyview["History panel<br/>[HistoryPanel.tsx]"]
  node_history["Correction history<br/>[history.ts]"]
  node_activityhook["Activity hook<br/>[useActivity.ts]"]
  node_activityview["Activity panel<br/>[ActivityPanel.tsx]"]
  node_activity["Activity controller<br/>[activity.ts]"]
  node_browserstore[("Browser storage")]
end

subgraph group_service["Correction service"]
  node_server["API server<br/>[app.ts]"]
  node_provider["Provider contract<br/>[provider.ts]"]
  node_config["Provider config<br/>[config.ts]"]
  node_gemini["Gemini adapter<br/>[gemini.ts]"]
  node_prompt["Model prompts<br/>[prompt.ts]"]
  node_explanationparse["Explanation parsing"]
end

subgraph group_shared["Shared domain logic"]
  node_contracts["Request contracts<br/>[contracts.ts]"]
  node_changes["Explanation changes"]
  node_expressiondiff["Expression diff<br/>[expression-diff.ts]"]
  node_clientdiff["Display diff<br/>[diff.ts]"]
end

node_writer(("Writer"))
node_geminiservice["Gemini API"]

node_writer -->|"uses"| node_app
node_app -->|"updates"| node_editor
node_app -->|"requests correction"| node_api
node_app -->|"renders"| node_results
node_app -->|"renders"| node_rerun
node_app -->|"uses"| node_selection
node_app -->|"uses"| node_reveal
node_app -->|"uses"| node_historyhook
node_app -->|"uses"| node_activityhook
node_results -->|"requests explanations"| node_api
node_results -->|"renders"| node_candidate
node_candidate -->|"uses"| node_clientdiff
node_candidate -->|"uses"| node_changes
node_historyhook -->|"uses"| node_history
node_historyview -->|"reads"| node_history
node_historyview -->|"renders"| node_candidate
node_activityhook -->|"creates controller"| node_activity
node_activityview -->|"uses"| node_activityhook
node_activity -->|"reads records"| node_history
node_activityhook -->|"reads and writes"| node_browserstore
node_api -.->|"sends HTTP requests"| node_server
node_server -->|"validates requests"| node_contracts
node_server -->|"delegates generation"| node_provider
node_server -->|"uses configured provider"| node_gemini
node_config -->|"configures"| node_provider
node_config -->|"configures"| node_gemini
node_gemini -->|"builds prompts"| node_prompt
node_gemini -->|"parses explanations"| node_explanationparse
node_gemini -->|"adds change data"| node_changes
node_gemini -->|"calls model"| node_geminiservice
node_changes -->|"groups expressions"| node_expressiondiff

click node_app "https://github.com/dhwjdgh1122/writing-demo/blob/main/client/src/App.tsx"
click node_editor "https://github.com/dhwjdgh1122/writing-demo/blob/main/client/src/state/editor.ts"
click node_api "https://github.com/dhwjdgh1122/writing-demo/blob/main/client/src/lib/api.ts"
click node_results "https://github.com/dhwjdgh1122/writing-demo/blob/main/client/src/components/CorrectionResults.tsx"
click node_candidate "https://github.com/dhwjdgh1122/writing-demo/blob/main/client/src/components/CandidateCard.tsx"
click node_rerun "https://github.com/dhwjdgh1122/writing-demo/blob/main/client/src/components/RerunControls.tsx"
click node_selection "https://github.com/dhwjdgh1122/writing-demo/blob/main/client/src/lib/selectionAnchor.ts"
click node_reveal "https://github.com/dhwjdgh1122/writing-demo/blob/main/client/src/lib/revealTextRange.ts"
click node_historyhook "https://github.com/dhwjdgh1122/writing-demo/blob/main/client/src/hooks/useHistory.ts"
click node_historyview "https://github.com/dhwjdgh1122/writing-demo/blob/main/client/src/components/HistoryPanel.tsx"
click node_history "https://github.com/dhwjdgh1122/writing-demo/blob/main/client/src/lib/history.ts"
click node_activityhook "https://github.com/dhwjdgh1122/writing-demo/blob/main/client/src/hooks/useActivity.ts"
click node_activityview "https://github.com/dhwjdgh1122/writing-demo/blob/main/client/src/components/ActivityPanel.tsx"
click node_activity "https://github.com/dhwjdgh1122/writing-demo/blob/main/client/src/lib/activity.ts"
click node_server "https://github.com/dhwjdgh1122/writing-demo/blob/main/server/app.ts"
click node_provider "https://github.com/dhwjdgh1122/writing-demo/blob/main/server/llm/provider.ts"
click node_config "https://github.com/dhwjdgh1122/writing-demo/blob/main/server/llm/config.ts"
click node_gemini "https://github.com/dhwjdgh1122/writing-demo/blob/main/server/llm/gemini.ts"
click node_prompt "https://github.com/dhwjdgh1122/writing-demo/blob/main/server/llm/prompt.ts"
click node_explanationparse "https://github.com/dhwjdgh1122/writing-demo/blob/main/server/llm/parse-explanations.ts"
click node_contracts "https://github.com/dhwjdgh1122/writing-demo/blob/main/shared/contracts.ts"
click node_changes "https://github.com/dhwjdgh1122/writing-demo/blob/main/shared/explanation-changes.ts"
click node_expressiondiff "https://github.com/dhwjdgh1122/writing-demo/blob/main/shared/expression-diff.ts"
click node_clientdiff "https://github.com/dhwjdgh1122/writing-demo/blob/main/client/src/lib/diff.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_app,node_editor,node_api,node_results,node_candidate,node_rerun,node_selection,node_reveal toneBlue
class node_historyhook,node_historyview,node_history,node_activityhook,node_activityview,node_activity,node_browserstore toneAmber
class node_server,node_provider,node_config,node_gemini,node_prompt,node_explanationparse,node_geminiservice toneMint
class node_contracts,node_changes,node_expressiondiff,node_clientdiff toneRose
class node_writer toneIndigo
```

## Components

### Writing workspace

- [Workspace app](https://github.com/dhwjdgh1122/writing-demo/blob/main/client/src/App.tsx): `client/src/App.tsx`
- [Editor state](https://github.com/dhwjdgh1122/writing-demo/blob/main/client/src/state/editor.ts): `client/src/state/editor.ts`
- [Browser API](https://github.com/dhwjdgh1122/writing-demo/blob/main/client/src/lib/api.ts): `client/src/lib/api.ts`
- [Candidate results](https://github.com/dhwjdgh1122/writing-demo/blob/main/client/src/components/CorrectionResults.tsx): `client/src/components/CorrectionResults.tsx`
- [Candidate card](https://github.com/dhwjdgh1122/writing-demo/blob/main/client/src/components/CandidateCard.tsx): `client/src/components/CandidateCard.tsx`
- [Rerun controls](https://github.com/dhwjdgh1122/writing-demo/blob/main/client/src/components/RerunControls.tsx): `client/src/components/RerunControls.tsx`
- [Selection helpers](https://github.com/dhwjdgh1122/writing-demo/blob/main/client/src/lib/selectionAnchor.ts): `client/src/lib/selectionAnchor.ts`
- [Text reveal](https://github.com/dhwjdgh1122/writing-demo/blob/main/client/src/lib/revealTextRange.ts): `client/src/lib/revealTextRange.ts`

### Local records

- [History hook](https://github.com/dhwjdgh1122/writing-demo/blob/main/client/src/hooks/useHistory.ts): `client/src/hooks/useHistory.ts`
- [History panel](https://github.com/dhwjdgh1122/writing-demo/blob/main/client/src/components/HistoryPanel.tsx): `client/src/components/HistoryPanel.tsx`
- [Correction history](https://github.com/dhwjdgh1122/writing-demo/blob/main/client/src/lib/history.ts): `client/src/lib/history.ts`
- [Activity hook](https://github.com/dhwjdgh1122/writing-demo/blob/main/client/src/hooks/useActivity.ts): `client/src/hooks/useActivity.ts`
- [Activity panel](https://github.com/dhwjdgh1122/writing-demo/blob/main/client/src/components/ActivityPanel.tsx): `client/src/components/ActivityPanel.tsx`
- [Activity controller](https://github.com/dhwjdgh1122/writing-demo/blob/main/client/src/lib/activity.ts): `client/src/lib/activity.ts`
- **Browser storage**

### Correction service

- [API server](https://github.com/dhwjdgh1122/writing-demo/blob/main/server/app.ts): `server/app.ts`
- [Provider contract](https://github.com/dhwjdgh1122/writing-demo/blob/main/server/llm/provider.ts): `server/llm/provider.ts`
- [Provider config](https://github.com/dhwjdgh1122/writing-demo/blob/main/server/llm/config.ts): `server/llm/config.ts`
- [Gemini adapter](https://github.com/dhwjdgh1122/writing-demo/blob/main/server/llm/gemini.ts): `server/llm/gemini.ts`
- [Model prompts](https://github.com/dhwjdgh1122/writing-demo/blob/main/server/llm/prompt.ts): `server/llm/prompt.ts`
- [Explanation parsing](https://github.com/dhwjdgh1122/writing-demo/blob/main/server/llm/parse-explanations.ts): `server/llm/parse-explanations.ts`

### Shared domain logic

- [Request contracts](https://github.com/dhwjdgh1122/writing-demo/blob/main/shared/contracts.ts): `shared/contracts.ts`
- [Explanation changes](https://github.com/dhwjdgh1122/writing-demo/blob/main/shared/explanation-changes.ts): `shared/explanation-changes.ts`
- [Expression diff](https://github.com/dhwjdgh1122/writing-demo/blob/main/shared/expression-diff.ts): `shared/expression-diff.ts`
- [Display diff](https://github.com/dhwjdgh1122/writing-demo/blob/main/client/src/lib/diff.ts): `client/src/lib/diff.ts`

### Other components

- **Writer**
- **Gemini API**

## Connections

- Writer → Workspace app: uses (evidence: `README.md`)
- Workspace app → Editor state: updates (evidence: `client/src/App.tsx`)
- Workspace app → Browser API: requests correction (evidence: `client/src/App.tsx`)
- Workspace app → Candidate results: renders (evidence: `client/src/App.tsx`)
- Workspace app → Rerun controls: renders (evidence: `client/src/App.tsx`)
- Workspace app → Selection helpers: uses (evidence: `client/src/App.tsx`)
- Workspace app → Text reveal: uses (evidence: `client/src/App.tsx`)
- Workspace app → History hook: uses (evidence: `client/src/App.tsx`)
- Workspace app → Activity hook: uses (evidence: `client/src/App.tsx`)
- Candidate results → Browser API: requests explanations (evidence: `client/src/components/CorrectionResults.tsx`)
- Candidate results → Candidate card: renders (evidence: `client/src/components/CorrectionResults.tsx`)
- Candidate card → Display diff: uses (evidence: `client/src/components/CandidateCard.tsx`)
- Candidate card → Explanation changes: uses (evidence: `client/src/components/CandidateCard.tsx`)
- History hook → Correction history: uses (evidence: `client/src/hooks/useHistory.ts`)
- History panel → Correction history: reads (evidence: `client/src/components/HistoryPanel.tsx`)
- History panel → Candidate card: renders (evidence: `client/src/components/HistoryPanel.tsx`)
- Activity hook → Activity controller: creates controller (evidence: `client/src/hooks/useActivity.ts`)
- Activity panel → Activity hook: uses (evidence: `client/src/components/ActivityPanel.tsx`)
- Activity controller → Correction history: reads records (evidence: `client/src/lib/activity.ts`)
- Activity hook → Browser storage: reads and writes (evidence: `client/src/hooks/useActivity.ts`)
- Browser API → API server: sends HTTP requests
- API server → Request contracts: validates requests (evidence: `server/app.ts`)
- API server → Provider contract: delegates generation (evidence: `server/app.ts`)
- API server → Gemini adapter: uses configured provider
- Provider config → Provider contract: configures (evidence: `server/llm/config.ts`)
- Provider config → Gemini adapter: configures (evidence: `server/llm/config.ts`)
- Gemini adapter → Model prompts: builds prompts (evidence: `server/llm/gemini.ts`)
- Gemini adapter → Explanation parsing: parses explanations (evidence: `server/llm/gemini.ts`)
- Gemini adapter → Explanation changes: adds change data (evidence: `server/llm/gemini.ts`)
- Gemini adapter → Gemini API: calls model (evidence: `README.md`)
- Explanation changes → Expression diff: groups expressions (evidence: `shared/explanation-changes.ts`)
