# hoangtuananhk56/mathstudio architecture

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

- Interactive diagram: https://gitdiagram.com/hoangtuananhk56/mathstudio
- Repository: https://github.com/hoangtuananhk56/mathstudio

## Overview

MathStudio is a Word add-in for authoring editable equations and dynamic geometry, and for reading equations, figures, or exercise pages from images. The main workflow starts in the Word taskpane or ribbon, opens an editor, then inserts content into the document. Equation conversion and Word packaging form one internal layer; geometry and OCR provide distinct authoring and input branches. Edges reflect excerpts, SOURCE INDEX references, or README statements; unsampled implementation details and uncertain wiring are omitted.

Main entry points: [`src/geometry-editor/GeometryApp.tsx`](https://github.com/hoangtuananhk56/mathstudio/blob/main/src/geometry-editor/GeometryApp.tsx) (Geometry editor), [`src/office/word.ts`](https://github.com/hoangtuananhk56/mathstudio/blob/main/src/office/word.ts) (Word document operations), [`src/core/equation.ts`](https://github.com/hoangtuananhk56/mathstudio/blob/main/src/core/equation.ts) (Equation conversion), [`src/geometry/engine.ts`](https://github.com/hoangtuananhk56/mathstudio/blob/main/src/geometry/engine.ts) (Dynamic geometry engine)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_office["Word integration"]
  node_taskpane["Taskpane<br/>[main.tsx]"]
  node_ribbon["Ribbon commands<br/>[commands.ts]"]
  node_dialog["Editor dialog<br/>[editor-dialog.ts]"]
  node_wordops["Word document operations<br/>[word.ts]"]
  node_geometryoffice["Geometry insertion<br/>[geometry.ts]"]
  node_settings[("User settings<br/>[settings.ts]")]
end

subgraph group_equations["Equation authoring"]
  node_editor["Equation editor<br/>[App.tsx]"]
  node_equation["Equation conversion<br/>[equation.ts]"]
  node_mathml["MathML to OMML<br/>[mathml-to-omml.ts]"]
  node_ooxml["Word equation packaging<br/>[ooxml.ts]"]
  node_pageooxml["Page equation packaging<br/>[page-ooxml.ts]"]
  node_mathtype["MathType conversion<br/>[docx-mathtype.ts]"]
end

subgraph group_geometry["Geometry authoring"]
  node_geoapp["Geometry editor<br/>[GeometryApp.tsx]"]
  node_textgeo["Exercise-to-figure parser<br/>[fromText.ts]"]
  node_model["Construction model<br/>[model.ts]"]
  node_engine["Dynamic geometry engine<br/>[engine.ts]"]
  node_tools["Geometry tools<br/>[tools.ts]"]
  node_render["Geometry rendering<br/>[render.ts]"]
end

subgraph group_ocr["Image recognition"]
  node_ocrpanel["Image recognition panel<br/>[OcrPanel.tsx]"]
  node_ocrclient["OCR client<br/>[client.ts]"]
  node_ocrworker["OCR worker<br/>[worker.ts]"]
  node_formula["Formula recognition<br/>[formula-model.ts]"]
  node_pageread["Exercise page reading<br/>[page.ts]"]
  node_pagelayout["Page layout analysis<br/>[page-layout.ts]"]
  node_figurebuild["Figure recognition<br/>[figure-build.ts]"]
end

node_word(("Word user"))

node_word -->|"opens add-in"| node_taskpane
node_taskpane -->|"opens editor"| node_dialog
node_taskpane -->|"exports equations"| node_wordops
node_taskpane -->|"converts documents"| node_mathtype
node_ribbon -->|"invokes operations"| node_wordops
node_ribbon -->|"opens editor"| node_dialog
node_dialog -->|"reads and inserts"| node_wordops
node_dialog -->|"opens geometry"| node_geometryoffice
node_editor -->|"renders equations"| node_equation
node_editor -->|"loads and saves"| node_settings
node_wordops -->|"builds equations"| node_equation
node_wordops -->|"reads and writes tags"| node_ooxml
node_equation -->|"converts MathML"| node_mathml
node_equation -->|"packages equations"| node_ooxml
node_pageooxml -->|"uses equation builder"| node_equation
node_pageooxml -->|"builds page package"| node_ooxml
node_geometryoffice -->|"computes construction"| node_engine
node_geometryoffice -->|"renders figure"| node_render
node_geoapp -->|"updates construction"| node_engine
node_geoapp -->|"renders construction"| node_render
node_geoapp -->|"uses tools"| node_tools
node_geoapp -->|"parses exercise text"| node_textgeo
node_engine -->|"evaluates definitions"| node_model
node_tools -->|"uses geometry values"| node_engine
node_render -->|"renders computed values"| node_engine
node_ocrpanel -->|"requests recognition"| node_ocrclient
node_ocrclient -->|"dispatches worker jobs"| node_ocrworker
node_ocrworker -->|"recognizes formulas"| node_formula
node_ocrworker -->|"reads pages"| node_pageread
node_ocrworker -->|"recognizes figures"| node_figurebuild
node_pageread -->|"plans page layout"| node_pagelayout
node_ocrpanel -->|"continues figure editing"| node_geoapp

click node_taskpane "https://github.com/hoangtuananhk56/mathstudio/blob/main/src/taskpane/main.tsx"
click node_ribbon "https://github.com/hoangtuananhk56/mathstudio/blob/main/src/commands/commands.ts"
click node_dialog "https://github.com/hoangtuananhk56/mathstudio/blob/main/src/office/editor-dialog.ts"
click node_wordops "https://github.com/hoangtuananhk56/mathstudio/blob/main/src/office/word.ts"
click node_geometryoffice "https://github.com/hoangtuananhk56/mathstudio/blob/main/src/office/geometry.ts"
click node_settings "https://github.com/hoangtuananhk56/mathstudio/blob/main/src/shared/settings.ts"
click node_editor "https://github.com/hoangtuananhk56/mathstudio/blob/main/src/editor/App.tsx"
click node_equation "https://github.com/hoangtuananhk56/mathstudio/blob/main/src/core/equation.ts"
click node_mathml "https://github.com/hoangtuananhk56/mathstudio/blob/main/src/core/mathml-to-omml.ts"
click node_ooxml "https://github.com/hoangtuananhk56/mathstudio/blob/main/src/core/ooxml.ts"
click node_pageooxml "https://github.com/hoangtuananhk56/mathstudio/blob/main/src/core/page-ooxml.ts"
click node_mathtype "https://github.com/hoangtuananhk56/mathstudio/blob/main/src/core/docx-mathtype.ts"
click node_geoapp "https://github.com/hoangtuananhk56/mathstudio/blob/main/src/geometry-editor/GeometryApp.tsx"
click node_textgeo "https://github.com/hoangtuananhk56/mathstudio/blob/main/src/geometry/fromText.ts"
click node_model "https://github.com/hoangtuananhk56/mathstudio/blob/main/src/geometry/model.ts"
click node_engine "https://github.com/hoangtuananhk56/mathstudio/blob/main/src/geometry/engine.ts"
click node_tools "https://github.com/hoangtuananhk56/mathstudio/blob/main/src/geometry/tools.ts"
click node_render "https://github.com/hoangtuananhk56/mathstudio/blob/main/src/geometry/render.ts"
click node_ocrpanel "https://github.com/hoangtuananhk56/mathstudio/blob/main/src/ocr/OcrPanel.tsx"
click node_ocrclient "https://github.com/hoangtuananhk56/mathstudio/blob/main/src/ocr/client.ts"
click node_ocrworker "https://github.com/hoangtuananhk56/mathstudio/blob/main/src/ocr/worker.ts"
click node_formula "https://github.com/hoangtuananhk56/mathstudio/blob/main/src/ocr/formula-model.ts"
click node_pageread "https://github.com/hoangtuananhk56/mathstudio/blob/main/src/ocr/page.ts"
click node_pagelayout "https://github.com/hoangtuananhk56/mathstudio/blob/main/src/ocr/page-layout.ts"
click node_figurebuild "https://github.com/hoangtuananhk56/mathstudio/blob/main/src/ocr/figure-build.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_taskpane,node_ribbon,node_dialog,node_wordops,node_geometryoffice,node_settings,node_word toneBlue
class node_editor,node_equation,node_mathml,node_ooxml,node_pageooxml,node_mathtype toneAmber
class node_geoapp,node_textgeo,node_model,node_engine,node_tools,node_render toneMint
class node_ocrpanel,node_ocrclient,node_ocrworker,node_formula,node_pageread,node_pagelayout,node_figurebuild toneRose
```

## Components

### Word integration

- [Taskpane](https://github.com/hoangtuananhk56/mathstudio/blob/main/src/taskpane/main.tsx): `src/taskpane/main.tsx`
- [Ribbon commands](https://github.com/hoangtuananhk56/mathstudio/blob/main/src/commands/commands.ts): `src/commands/commands.ts`
- [Editor dialog](https://github.com/hoangtuananhk56/mathstudio/blob/main/src/office/editor-dialog.ts): `src/office/editor-dialog.ts`
- [Word document operations](https://github.com/hoangtuananhk56/mathstudio/blob/main/src/office/word.ts): `src/office/word.ts`
- [Geometry insertion](https://github.com/hoangtuananhk56/mathstudio/blob/main/src/office/geometry.ts): `src/office/geometry.ts`
- [User settings](https://github.com/hoangtuananhk56/mathstudio/blob/main/src/shared/settings.ts): `src/shared/settings.ts`

### Equation authoring

- [Equation editor](https://github.com/hoangtuananhk56/mathstudio/blob/main/src/editor/App.tsx): `src/editor/App.tsx`
- [Equation conversion](https://github.com/hoangtuananhk56/mathstudio/blob/main/src/core/equation.ts): `src/core/equation.ts`
- [MathML to OMML](https://github.com/hoangtuananhk56/mathstudio/blob/main/src/core/mathml-to-omml.ts): `src/core/mathml-to-omml.ts`
- [Word equation packaging](https://github.com/hoangtuananhk56/mathstudio/blob/main/src/core/ooxml.ts): `src/core/ooxml.ts`
- [Page equation packaging](https://github.com/hoangtuananhk56/mathstudio/blob/main/src/core/page-ooxml.ts): `src/core/page-ooxml.ts`
- [MathType conversion](https://github.com/hoangtuananhk56/mathstudio/blob/main/src/core/docx-mathtype.ts): `src/core/docx-mathtype.ts`

### Geometry authoring

- [Geometry editor](https://github.com/hoangtuananhk56/mathstudio/blob/main/src/geometry-editor/GeometryApp.tsx): `src/geometry-editor/GeometryApp.tsx`
- [Exercise-to-figure parser](https://github.com/hoangtuananhk56/mathstudio/blob/main/src/geometry/fromText.ts): `src/geometry/fromText.ts`
- [Construction model](https://github.com/hoangtuananhk56/mathstudio/blob/main/src/geometry/model.ts): `src/geometry/model.ts`
- [Dynamic geometry engine](https://github.com/hoangtuananhk56/mathstudio/blob/main/src/geometry/engine.ts): `src/geometry/engine.ts`
- [Geometry tools](https://github.com/hoangtuananhk56/mathstudio/blob/main/src/geometry/tools.ts): `src/geometry/tools.ts`
- [Geometry rendering](https://github.com/hoangtuananhk56/mathstudio/blob/main/src/geometry/render.ts): `src/geometry/render.ts`

### Image recognition

- [Image recognition panel](https://github.com/hoangtuananhk56/mathstudio/blob/main/src/ocr/OcrPanel.tsx): `src/ocr/OcrPanel.tsx`
- [OCR client](https://github.com/hoangtuananhk56/mathstudio/blob/main/src/ocr/client.ts): `src/ocr/client.ts`
- [OCR worker](https://github.com/hoangtuananhk56/mathstudio/blob/main/src/ocr/worker.ts): `src/ocr/worker.ts`
- [Formula recognition](https://github.com/hoangtuananhk56/mathstudio/blob/main/src/ocr/formula-model.ts): `src/ocr/formula-model.ts`
- [Exercise page reading](https://github.com/hoangtuananhk56/mathstudio/blob/main/src/ocr/page.ts): `src/ocr/page.ts`
- [Page layout analysis](https://github.com/hoangtuananhk56/mathstudio/blob/main/src/ocr/page-layout.ts): `src/ocr/page-layout.ts`
- [Figure recognition](https://github.com/hoangtuananhk56/mathstudio/blob/main/src/ocr/figure-build.ts): `src/ocr/figure-build.ts`

### Other components

- **Word user**

## Connections

- Word user → Taskpane: opens add-in
- Taskpane → Editor dialog: opens editor (evidence: `src/taskpane/main.tsx`)
- Taskpane → Word document operations: exports equations (evidence: `src/taskpane/main.tsx`)
- Taskpane → MathType conversion: converts documents (evidence: `src/taskpane/main.tsx`)
- Ribbon commands → Word document operations: invokes operations (evidence: `src/commands/commands.ts`)
- Ribbon commands → Editor dialog: opens editor (evidence: `src/commands/commands.ts`)
- Editor dialog → Word document operations: reads and inserts (evidence: `src/office/editor-dialog.ts`)
- Editor dialog → Geometry insertion: opens geometry (evidence: `src/office/editor-dialog.ts`)
- Equation editor → Equation conversion: renders equations (evidence: `src/editor/App.tsx`)
- Equation editor → User settings: loads and saves (evidence: `src/editor/App.tsx`)
- Word document operations → Equation conversion: builds equations (evidence: `src/office/word.ts`)
- Word document operations → Word equation packaging: reads and writes tags (evidence: `src/office/word.ts`)
- Equation conversion → MathML to OMML: converts MathML (evidence: `src/core/equation.ts`)
- Equation conversion → Word equation packaging: packages equations (evidence: `src/core/equation.ts`)
- Page equation packaging → Equation conversion: uses equation builder (evidence: `src/core/page-ooxml.ts`)
- Page equation packaging → Word equation packaging: builds page package (evidence: `src/core/page-ooxml.ts`)
- Geometry insertion → Dynamic geometry engine: computes construction (evidence: `src/office/geometry.ts`)
- Geometry insertion → Geometry rendering: renders figure (evidence: `src/office/geometry.ts`)
- Geometry editor → Dynamic geometry engine: updates construction (evidence: `src/geometry-editor/GeometryApp.tsx`)
- Geometry editor → Geometry rendering: renders construction (evidence: `src/geometry-editor/GeometryApp.tsx`)
- Geometry editor → Geometry tools: uses tools (evidence: `src/geometry-editor/GeometryApp.tsx`)
- Geometry editor → Exercise-to-figure parser: parses exercise text (evidence: `src/geometry-editor/GeometryApp.tsx`)
- Dynamic geometry engine → Construction model: evaluates definitions (evidence: `src/geometry/engine.ts`)
- Geometry tools → Dynamic geometry engine: uses geometry values (evidence: `src/geometry/tools.ts`)
- Geometry rendering → Dynamic geometry engine: renders computed values (evidence: `src/geometry/render.ts`)
- Image recognition panel → OCR client: requests recognition (evidence: `src/ocr/OcrPanel.tsx`)
- OCR client → OCR worker: dispatches worker jobs (evidence: `src/ocr/client.ts`)
- OCR worker → Formula recognition: recognizes formulas (evidence: `src/ocr/worker.ts`)
- OCR worker → Exercise page reading: reads pages (evidence: `src/ocr/worker.ts`)
- OCR worker → Figure recognition: recognizes figures (evidence: `src/ocr/worker.ts`)
- Exercise page reading → Page layout analysis: plans page layout (evidence: `src/ocr/page.ts`)
- Image recognition panel → Geometry editor: continues figure editing (evidence: `src/geometry-editor/GeometryApp.tsx`)
