# pair-code/wordcraft architecture

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

- Interactive diagram: https://gitdiagram.com/pair-code/wordcraft
- Repository: https://github.com/pair-code/wordcraft

## Overview

Wordcraft is an LLM-assisted story editor. Writers use editor and sidebar controls to request generation or rewriting, review alternatives, and apply text to the document; they can also save documents and use chat or starred results. Its domain stages are operation selection and state capture, context- and operation-specific prompt construction, Gemini generation and parsing, then editor updates. The graph preserves documented capabilities, but several runtime links are based on README statements because their implementation files were not sampled.

Main entry points: [`app/components/sidebar_right.ts`](https://github.com/pair-code/wordcraft/blob/main/app/components/sidebar_right.ts) (Writing sidebar), [`app/core/operations/operation.ts`](https://github.com/pair-code/wordcraft/blob/main/app/core/operations/operation.ts) (Operation steps), [`app/components/app.ts`](https://github.com/pair-code/wordcraft/blob/main/app/components/app.ts) (Application shell), [`app/models/model.ts`](https://github.com/pair-code/wordcraft/blob/main/app/models/model.ts) (Model abstraction)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ui["Writing interface"]
  node_app_ui["Application shell<br/>[app.ts]"]
  node_editor_ui["Text editor view<br/>[text_editor.ts]"]
  node_sidebar["Writing sidebar<br/>[sidebar_right.ts]"]
  node_operation_ui["Operation controls<br/>[operations.ts]"]
  node_choices_ui["Choice review<br/>[choices.ts]"]
  node_chat_ui["Writing chat<br/>[chat.ts]"]
  node_starred_ui["Starred results<br/>[starred.ts]"]
end

subgraph group_runtime["Operations and services"]
  node_operations_service["Operation dispatcher"]
  node_operation_types["Writing operations"]
  node_operation_flow["Operation steps<br/>[operation.ts]"]
  node_operation_data["Operation data processing<br/>[processor.ts]"]
end

subgraph group_generation["Prompt and generation"]
  node_context["Few-shot context<br/>[index.ts]"]
  node_model_service["Model service<br/>[model_service.ts]"]
  node_model["Model abstraction<br/>[model.ts]"]
  node_gemini["Gemini prompts and parsing<br/>[index.ts]"]
  node_gemini_api["Gemini API client<br/>[api.ts]"]
end

subgraph group_state["Document and state"]
  node_editor_service["Editor state and edits"]
  node_document_store["Document persistence"]
  node_local_storage[("Browser storage")]
  node_sentences["Sentence analysis"]
end

node_writer(("Writer"))
node_gemini_service(("Gemini"))

node_writer -->|"uses"| node_app_ui
node_app_ui -->|"renders"| node_editor_ui
node_app_ui -->|"renders"| node_sidebar
node_sidebar -->|"renders"| node_operation_ui
node_sidebar -->|"renders"| node_choices_ui
node_sidebar -->|"renders"| node_chat_ui
node_sidebar -->|"renders"| node_starred_ui
node_writer -.->|"requests writing"| node_operations_service
node_operations_service -->|"dispatches"| node_operation_types
node_operation_types -->|"uses lifecycle"| node_operation_flow
node_operation_flow -->|"processes input"| node_operation_data
node_operation_flow -->|"requests generation"| node_model_service
node_model_service -.->|"uses model"| node_model
node_model -->|"uses examples"| node_context
node_model -->|"delegates prompts"| node_gemini
node_gemini -->|"calls"| node_gemini_api
node_gemini_api -.->|"queries"| node_gemini_service
node_operation_flow -.->|"updates text"| node_editor_service
node_editor_ui -.->|"edits document"| node_editor_service
node_app_ui -->|"saves documents"| node_document_store
node_document_store -.->|"persists state"| node_local_storage
node_operation_flow -.->|"uses boundaries"| node_sentences

click node_app_ui "https://github.com/pair-code/wordcraft/blob/main/app/components/app.ts"
click node_editor_ui "https://github.com/pair-code/wordcraft/blob/main/app/components/text_editor.ts"
click node_sidebar "https://github.com/pair-code/wordcraft/blob/main/app/components/sidebar_right.ts"
click node_operation_ui "https://github.com/pair-code/wordcraft/blob/main/app/components/operations.ts"
click node_choices_ui "https://github.com/pair-code/wordcraft/blob/main/app/components/choices.ts"
click node_chat_ui "https://github.com/pair-code/wordcraft/blob/main/app/components/chat.ts"
click node_starred_ui "https://github.com/pair-code/wordcraft/blob/main/app/components/starred.ts"
click node_operations_service "https://github.com/pair-code/wordcraft/blob/main/app/core/services/operations_service.ts"
click node_operation_types "https://github.com/pair-code/wordcraft/tree/main/app/core/operations"
click node_operation_flow "https://github.com/pair-code/wordcraft/blob/main/app/core/operations/operation.ts"
click node_operation_data "https://github.com/pair-code/wordcraft/blob/main/app/core/operation_data/processor.ts"
click node_context "https://github.com/pair-code/wordcraft/blob/main/app/context/index.ts"
click node_model_service "https://github.com/pair-code/wordcraft/blob/main/app/core/services/model_service.ts"
click node_model "https://github.com/pair-code/wordcraft/blob/main/app/models/model.ts"
click node_gemini "https://github.com/pair-code/wordcraft/blob/main/app/models/gemini/index.ts"
click node_gemini_api "https://github.com/pair-code/wordcraft/blob/main/app/models/gemini/api.ts"
click node_editor_service "https://github.com/pair-code/wordcraft/blob/main/app/core/services/text_editor_service.ts"
click node_document_store "https://github.com/pair-code/wordcraft/blob/main/app/core/services/document_store_service.ts"
click node_local_storage "https://github.com/pair-code/wordcraft/blob/main/app/core/services/local_storage_service.ts"
click node_sentences "https://github.com/pair-code/wordcraft/blob/main/app/core/services/sentences_service.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_ui,node_editor_ui,node_sidebar,node_operation_ui,node_choices_ui,node_chat_ui,node_starred_ui toneBlue
class node_operations_service,node_operation_types,node_operation_flow,node_operation_data toneAmber
class node_context,node_model_service,node_model,node_gemini,node_gemini_api toneMint
class node_editor_service,node_document_store,node_local_storage,node_sentences toneRose
class node_writer,node_gemini_service toneIndigo
```

## Components

### Writing interface

- [Application shell](https://github.com/pair-code/wordcraft/blob/main/app/components/app.ts): `app/components/app.ts`
- [Text editor view](https://github.com/pair-code/wordcraft/blob/main/app/components/text_editor.ts): `app/components/text_editor.ts`
- [Writing sidebar](https://github.com/pair-code/wordcraft/blob/main/app/components/sidebar_right.ts): `app/components/sidebar_right.ts`
- [Operation controls](https://github.com/pair-code/wordcraft/blob/main/app/components/operations.ts): `app/components/operations.ts`
- [Choice review](https://github.com/pair-code/wordcraft/blob/main/app/components/choices.ts): `app/components/choices.ts`
- [Writing chat](https://github.com/pair-code/wordcraft/blob/main/app/components/chat.ts): `app/components/chat.ts`
- [Starred results](https://github.com/pair-code/wordcraft/blob/main/app/components/starred.ts): `app/components/starred.ts`

### Operations and services

- [Operation dispatcher](https://github.com/pair-code/wordcraft/blob/main/app/core/services/operations_service.ts): `app/core/services/operations_service.ts`
- [Writing operations](https://github.com/pair-code/wordcraft/tree/main/app/core/operations): `app/core/operations`
- [Operation steps](https://github.com/pair-code/wordcraft/blob/main/app/core/operations/operation.ts): `app/core/operations/operation.ts`
- [Operation data processing](https://github.com/pair-code/wordcraft/blob/main/app/core/operation_data/processor.ts): `app/core/operation_data/processor.ts`

### Prompt and generation

- [Few-shot context](https://github.com/pair-code/wordcraft/blob/main/app/context/index.ts): `app/context/index.ts`
- [Model service](https://github.com/pair-code/wordcraft/blob/main/app/core/services/model_service.ts): `app/core/services/model_service.ts`
- [Model abstraction](https://github.com/pair-code/wordcraft/blob/main/app/models/model.ts): `app/models/model.ts`
- [Gemini prompts and parsing](https://github.com/pair-code/wordcraft/blob/main/app/models/gemini/index.ts): `app/models/gemini/index.ts`
- [Gemini API client](https://github.com/pair-code/wordcraft/blob/main/app/models/gemini/api.ts): `app/models/gemini/api.ts`

### Document and state

- [Editor state and edits](https://github.com/pair-code/wordcraft/blob/main/app/core/services/text_editor_service.ts): `app/core/services/text_editor_service.ts`
- [Document persistence](https://github.com/pair-code/wordcraft/blob/main/app/core/services/document_store_service.ts): `app/core/services/document_store_service.ts`
- [Browser storage](https://github.com/pair-code/wordcraft/blob/main/app/core/services/local_storage_service.ts): `app/core/services/local_storage_service.ts`
- [Sentence analysis](https://github.com/pair-code/wordcraft/blob/main/app/core/services/sentences_service.ts): `app/core/services/sentences_service.ts`

### Other components

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

## Connections

- Writer → Application shell: uses
- Application shell → Text editor view: renders (evidence: `app/components/app.ts`)
- Application shell → Writing sidebar: renders (evidence: `app/components/app.ts`)
- Writing sidebar → Operation controls: renders (evidence: `app/components/sidebar_right.ts`)
- Writing sidebar → Choice review: renders (evidence: `app/components/sidebar_right.ts`)
- Writing sidebar → Writing chat: renders (evidence: `app/components/sidebar_right.ts`)
- Writing sidebar → Starred results: renders (evidence: `app/components/sidebar_right.ts`)
- Writer → Operation dispatcher: requests writing
- Operation dispatcher → Writing operations: dispatches (evidence: `app/core/services/operations_service.ts`)
- Writing operations → Operation steps: uses lifecycle (evidence: `app/core/operations/operation.ts`)
- Operation steps → Operation data processing: processes input (evidence: `app/core/operations/operation.ts`)
- Operation steps → Model service: requests generation (evidence: `app/core/operations/operation.ts`)
- Model service → Model abstraction: uses model
- Model abstraction → Few-shot context: uses examples (evidence: `app/models/model.ts`)
- Model abstraction → Gemini prompts and parsing: delegates prompts (evidence: `app/models/gemini/index.ts`)
- Gemini prompts and parsing → Gemini API client: calls (evidence: `app/models/gemini/index.ts`)
- Gemini API client → Gemini: queries
- Operation steps → Editor state and edits: updates text
- Text editor view → Editor state and edits: edits document
- Application shell → Document persistence: saves documents (evidence: `app/components/app.ts`)
- Document persistence → Browser storage: persists state (evidence: `app/core/services/local_storage_service.ts`)
- Operation steps → Sentence analysis: uses boundaries
