# 4mun4jmudin/web-surat-copilot architecture

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

- Interactive diagram: https://gitdiagram.com/4mun4jmudin/web-surat-copilot
- Repository: https://github.com/4mun4jmudin/web-surat-copilot

## Overview

AI Document Builder is a browser-based document editor and school-letter administration system. Its main document workflow takes user topics through AI-assisted outlining and section drafting, validates a structured document model, then renders or safely patches a Word file for preview and export. Separate product branches handle quality checks, formal outgoing-letter numbering and verification, role-based approvals, and workspace synchronization. The README documents several capabilities whose UI or implementation was not sampled; those are represented at supported directory paths, with uncertain links omitted.

Main entry points: [`js/main.js`](https://github.com/4mun4jmudin/web-surat-copilot/blob/main/js/main.js) (App bootstrap), [`js/ui/editor.js`](https://github.com/4mun4jmudin/web-surat-copilot/blob/main/js/ui/editor.js) (Document editor), [`js/ai/client.js`](https://github.com/4mun4jmudin/web-surat-copilot/blob/main/js/ai/client.js) (AI client), [`js/ui/outgoingLettersView.js`](https://github.com/4mun4jmudin/web-surat-copilot/blob/main/js/ui/outgoingLettersView.js) (Outgoing letters)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["Application UI"]
  node_app["App bootstrap<br/>[main.js]"]
  node_editor["Document editor<br/>[editor.js]"]
  node_aiui["AI workflow UI<br/>[aiView.js]"]
  node_preview["Document preview<br/>[preview.js]"]
  node_patchui["Patch editor UI<br/>[patchView.js]"]
  node_checksui["Quality checks UI<br/>[consistencyView.js]"]
end

subgraph group_content["Document creation"]
  node_state[("Project state<br/>[state.js]")]
  node_schema["Model validation<br/>[schema.js]"]
  node_aiclient["AI client<br/>[client.js]"]
  node_prompts["AI prompts<br/>[prompts.js]"]
  node_renderer["DOCX renderer<br/>[render.js]"]
  node_patcher["Safe DOCX patcher<br/>[patch.js]"]
  node_quality["Consistency checks<br/>[consistency.js]"]
end

subgraph group_letters["School letters"]
  node_outgoing["Outgoing letters"]
  node_letterdata["Letter numbering<br/>[numbering.js]"]
  node_verification["Letter verification<br/>[verification.js]"]
end

subgraph group_collaboration["Access and sync"]
  node_permissions["Role permissions<br/>[permissions.js]"]
  node_livesync["Live sync<br/>[liveSync.js]"]
  node_workspaceclient["Workspace client<br/>[workspaceClient.js]"]
end

subgraph group_services["Backend services"]
  node_workspaceapi["Workspace API<br/>[workspace.mjs]"]
  node_store[("Workspace storage<br/>[workspaceStore.mjs]")]
  node_aiapi["AI proxy<br/>[ai.js]"]
  node_verifyapi["Verification API<br/>[verify-letter.mjs]"]
end

node_user(("User"))
node_browser[("Browser storage")]
node_aiprovider["AI provider"]

node_user -->|"uses"| node_app
node_app -->|"loads"| node_editor
node_app -->|"loads"| node_aiui
node_app -->|"loads"| node_outgoing
node_aiui -->|"requests drafting"| node_aiclient
node_aiclient -->|"builds prompts"| node_prompts
node_aiclient -->|"reads system key"| node_state
node_aiclient -.->|"calls proxy"| node_aiapi
node_aiapi -.->|"forwards requests"| node_aiprovider
node_aiui -->|"validates model"| node_schema
node_editor -->|"updates project"| node_state
node_state -->|"persists locally"| node_browser
node_editor -->|"exports DOCX"| node_renderer
node_app -->|"renders document"| node_renderer
node_preview -->|"renders preview"| node_renderer
node_patchui -->|"patches upload"| node_patcher
node_editor -->|"checks consistency"| node_quality
node_checksui -->|"runs checks"| node_quality
node_outgoing -->|"formats numbers"| node_letterdata
node_outgoing -->|"verifies letters"| node_verification
node_outgoing -->|"checks access"| node_permissions
node_verification -->|"registers status"| node_verifyapi
node_livesync -->|"polls updates"| node_workspaceclient
node_state -->|"saves changes"| node_workspaceclient
node_workspaceclient -.->|"sends requests"| node_workspaceapi
node_workspaceapi -->|"uses storage"| node_store

click node_app "https://github.com/4mun4jmudin/web-surat-copilot/blob/main/js/main.js"
click node_editor "https://github.com/4mun4jmudin/web-surat-copilot/blob/main/js/ui/editor.js"
click node_aiui "https://github.com/4mun4jmudin/web-surat-copilot/blob/main/js/ui/aiView.js"
click node_preview "https://github.com/4mun4jmudin/web-surat-copilot/blob/main/js/ui/preview.js"
click node_patchui "https://github.com/4mun4jmudin/web-surat-copilot/blob/main/js/ui/patchView.js"
click node_checksui "https://github.com/4mun4jmudin/web-surat-copilot/blob/main/js/ui/consistencyView.js"
click node_state "https://github.com/4mun4jmudin/web-surat-copilot/blob/main/js/state.js"
click node_schema "https://github.com/4mun4jmudin/web-surat-copilot/blob/main/js/model/schema.js"
click node_aiclient "https://github.com/4mun4jmudin/web-surat-copilot/blob/main/js/ai/client.js"
click node_prompts "https://github.com/4mun4jmudin/web-surat-copilot/blob/main/js/ai/prompts.js"
click node_renderer "https://github.com/4mun4jmudin/web-surat-copilot/blob/main/js/docx/render.js"
click node_patcher "https://github.com/4mun4jmudin/web-surat-copilot/blob/main/js/docx/patch.js"
click node_quality "https://github.com/4mun4jmudin/web-surat-copilot/blob/main/js/checks/consistency.js"
click node_outgoing "https://github.com/4mun4jmudin/web-surat-copilot/blob/main/js/ui/outgoingLettersView.js"
click node_letterdata "https://github.com/4mun4jmudin/web-surat-copilot/blob/main/js/letters/numbering.js"
click node_verification "https://github.com/4mun4jmudin/web-surat-copilot/blob/main/js/letters/verification.js"
click node_permissions "https://github.com/4mun4jmudin/web-surat-copilot/blob/main/js/auth/permissions.js"
click node_livesync "https://github.com/4mun4jmudin/web-surat-copilot/blob/main/js/sync/liveSync.js"
click node_workspaceclient "https://github.com/4mun4jmudin/web-surat-copilot/blob/main/js/sync/workspaceClient.js"
click node_workspaceapi "https://github.com/4mun4jmudin/web-surat-copilot/blob/main/netlify/functions/workspace.mjs"
click node_store "https://github.com/4mun4jmudin/web-surat-copilot/blob/main/netlify/functions/_lib/workspaceStore.mjs"
click node_aiapi "https://github.com/4mun4jmudin/web-surat-copilot/blob/main/functions/api/ai.js"
click node_verifyapi "https://github.com/4mun4jmudin/web-surat-copilot/blob/main/netlify/functions/verify-letter.mjs"

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_aiui,node_preview,node_patchui,node_checksui,node_user toneBlue
class node_state,node_schema,node_aiclient,node_prompts,node_renderer,node_patcher,node_quality,node_browser toneAmber
class node_outgoing,node_letterdata,node_verification toneMint
class node_permissions,node_livesync,node_workspaceclient toneRose
class node_workspaceapi,node_store,node_aiapi,node_verifyapi,node_aiprovider toneIndigo
```

## Components

### Application UI

- [App bootstrap](https://github.com/4mun4jmudin/web-surat-copilot/blob/main/js/main.js): `js/main.js`
- [Document editor](https://github.com/4mun4jmudin/web-surat-copilot/blob/main/js/ui/editor.js): `js/ui/editor.js`
- [AI workflow UI](https://github.com/4mun4jmudin/web-surat-copilot/blob/main/js/ui/aiView.js): `js/ui/aiView.js`
- [Document preview](https://github.com/4mun4jmudin/web-surat-copilot/blob/main/js/ui/preview.js): `js/ui/preview.js`
- [Patch editor UI](https://github.com/4mun4jmudin/web-surat-copilot/blob/main/js/ui/patchView.js): `js/ui/patchView.js`
- [Quality checks UI](https://github.com/4mun4jmudin/web-surat-copilot/blob/main/js/ui/consistencyView.js): `js/ui/consistencyView.js`

### Document creation

- [Project state](https://github.com/4mun4jmudin/web-surat-copilot/blob/main/js/state.js): `js/state.js`
- [Model validation](https://github.com/4mun4jmudin/web-surat-copilot/blob/main/js/model/schema.js): `js/model/schema.js`
- [AI client](https://github.com/4mun4jmudin/web-surat-copilot/blob/main/js/ai/client.js): `js/ai/client.js`
- [AI prompts](https://github.com/4mun4jmudin/web-surat-copilot/blob/main/js/ai/prompts.js): `js/ai/prompts.js`
- [DOCX renderer](https://github.com/4mun4jmudin/web-surat-copilot/blob/main/js/docx/render.js): `js/docx/render.js`
- [Safe DOCX patcher](https://github.com/4mun4jmudin/web-surat-copilot/blob/main/js/docx/patch.js): `js/docx/patch.js`
- [Consistency checks](https://github.com/4mun4jmudin/web-surat-copilot/blob/main/js/checks/consistency.js): `js/checks/consistency.js`

### School letters

- [Outgoing letters](https://github.com/4mun4jmudin/web-surat-copilot/blob/main/js/ui/outgoingLettersView.js): `js/ui/outgoingLettersView.js`
- [Letter numbering](https://github.com/4mun4jmudin/web-surat-copilot/blob/main/js/letters/numbering.js): `js/letters/numbering.js`
- [Letter verification](https://github.com/4mun4jmudin/web-surat-copilot/blob/main/js/letters/verification.js): `js/letters/verification.js`

### Access and sync

- [Role permissions](https://github.com/4mun4jmudin/web-surat-copilot/blob/main/js/auth/permissions.js): `js/auth/permissions.js`
- [Live sync](https://github.com/4mun4jmudin/web-surat-copilot/blob/main/js/sync/liveSync.js): `js/sync/liveSync.js`
- [Workspace client](https://github.com/4mun4jmudin/web-surat-copilot/blob/main/js/sync/workspaceClient.js): `js/sync/workspaceClient.js`

### Backend services

- [Workspace API](https://github.com/4mun4jmudin/web-surat-copilot/blob/main/netlify/functions/workspace.mjs): `netlify/functions/workspace.mjs`
- [Workspace storage](https://github.com/4mun4jmudin/web-surat-copilot/blob/main/netlify/functions/_lib/workspaceStore.mjs): `netlify/functions/_lib/workspaceStore.mjs`
- [AI proxy](https://github.com/4mun4jmudin/web-surat-copilot/blob/main/functions/api/ai.js): `functions/api/ai.js`
- [Verification API](https://github.com/4mun4jmudin/web-surat-copilot/blob/main/netlify/functions/verify-letter.mjs): `netlify/functions/verify-letter.mjs`

### Other components

- **User**
- **Browser storage**
- **AI provider**

## Connections

- User → App bootstrap: uses
- App bootstrap → Document editor: loads (evidence: `js/main.js`)
- App bootstrap → AI workflow UI: loads (evidence: `js/main.js`)
- App bootstrap → Outgoing letters: loads (evidence: `js/main.js`)
- AI workflow UI → AI client: requests drafting
- AI client → AI prompts: builds prompts (evidence: `js/ai/client.js`)
- AI client → Project state: reads system key (evidence: `js/ai/client.js`)
- AI client → AI proxy: calls proxy
- AI proxy → AI provider: forwards requests
- AI workflow UI → Model validation: validates model
- Document editor → Project state: updates project
- Project state → Browser storage: persists locally
- Document editor → DOCX renderer: exports DOCX
- App bootstrap → DOCX renderer: renders document (evidence: `js/main.js`)
- Document preview → DOCX renderer: renders preview (evidence: `js/ui/preview.js`)
- Patch editor UI → Safe DOCX patcher: patches upload
- Document editor → Consistency checks: checks consistency
- Quality checks UI → Consistency checks: runs checks
- Outgoing letters → Letter numbering: formats numbers (evidence: `js/ui/outgoingLettersView.js`)
- Outgoing letters → Letter verification: verifies letters (evidence: `js/ui/outgoingLettersView.js`)
- Outgoing letters → Role permissions: checks access (evidence: `js/ui/outgoingLettersView.js`)
- Letter verification → Verification API: registers status (evidence: `js/letters/verification.js`)
- Live sync → Workspace client: polls updates (evidence: `js/sync/liveSync.js`)
- Project state → Workspace client: saves changes (evidence: `js/state.js`)
- Workspace client → Workspace API: sends requests
- Workspace API → Workspace storage: uses storage (evidence: `netlify/functions/workspace.mjs`)
