# mha963/loctex architecture

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

- Interactive diagram: https://gitdiagram.com/mha963/loctex
- Repository: https://github.com/mha963/loctex

## Overview

LocTex is an offline-first LaTeX research studio. Users manage a project, edit TeX and assets, compile to PDF, inspect diagnostics, and use SyncTeX to move between source and output; optional local AI assists with chat and repairs. The backend also persists project state and supports ZIP exchange and snapshots. The graph follows documented capabilities and visible imports/calls; some feature internals were not sampled, so uncertain links are omitted or marked dashed.

Main entry points: [`src/App.tsx`](https://github.com/mha963/loctex/blob/main/src/App.tsx) (Studio Shell), [`server/index.ts`](https://github.com/mha963/loctex/blob/main/server/index.ts) (HTTP API), [`src/services/api.ts`](https://github.com/mha963/loctex/blob/main/src/services/api.ts) (API Client), [`server/compiler/tectonic-runner.ts`](https://github.com/mha963/loctex/blob/main/server/compiler/tectonic-runner.ts) (TeX Compiler)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_workspace["Writing Workspace"]
  node_app["Studio Shell<br/>[App.tsx]"]
  node_dashboard["Project Dashboard"]
  node_editor["LaTeX Editor<br/>[EditorPane.tsx]"]
  node_toolbar["Editor Toolbar<br/>[HeaderPill.tsx]"]
  node_format["TeX Formatting<br/>[latex-format.ts]"]
  node_stats["Document Statistics<br/>[latex-stats.ts]"]
end

subgraph group_project["Projects and Assets"]
  node_assets["Asset Preview"]
  node_sidebar["File Explorer<br/>[Sidebar.tsx]"]
  node_modals["Project Dialogs<br/>[Modals.tsx]"]
  node_zip["ZIP Exchange<br/>[zip-service.ts]"]
end

subgraph group_compile["Compile and Review"]
  node_compiler["TeX Compiler<br/>[tectonic-runner.ts]"]
  node_parser["Error Parser<br/>[error-parser.ts]"]
  node_diagnostics["Diagnostic Drawer"]
  node_pdf["PDF Canvas<br/>[PdfCanvas.tsx]"]
  node_synctex["SyncTeX Parser<br/>[synctex-parser.ts]"]
end

subgraph group_assistant["AI Copilot"]
  node_aiui["Copilot Chat<br/>[QwenChatDrawer.tsx]"]
  node_ai["AI Service<br/>[ollama-service.ts]"]
end

subgraph group_backend["Local Backend"]
  node_api["API Client<br/>[api.ts]"]
  node_server["HTTP API<br/>[index.ts]"]
  node_database[("SQLite Store<br/>[database.ts]")]
end

node_writer(("Writer"))
node_ollama{{"Ollama Runtime"}}
node_tex{{"Local TeX Tools"}}

node_writer -->|"uses"| node_app
node_app -->|"renders"| node_dashboard
node_app -->|"renders"| node_editor
node_app -->|"renders"| node_toolbar
node_app -->|"selects preview"| node_assets
node_app -->|"renders"| node_pdf
node_app -->|"requests data"| node_api
node_editor -->|"formats text"| node_format
node_toolbar -->|"displays stats"| node_stats
node_app -->|"renders"| node_sidebar
node_app -->|"renders"| node_modals
node_app -->|"renders"| node_diagnostics
node_app -->|"renders"| node_aiui
node_aiui -->|"sends chat"| node_api
node_api -->|"calls HTTP routes"| node_server
node_server -->|"reads and writes"| node_database
node_server -->|"dispatches compile"| node_compiler
node_server -->|"dispatches AI"| node_ai
node_server -->|"imports archives"| node_zip
node_server -->|"uses parser"| node_synctex
node_compiler -->|"parses diagnostics"| node_parser
node_app -.->|"imports and exports"| node_zip
node_server -.->|"stores snapshots"| node_database
node_compiler -.->|"runs local tools"| node_tex
node_ai -.->|"queries locally"| node_ollama
node_pdf -.->|"jumps to source"| node_synctex
node_diagnostics -.->|"requests repair"| node_api

click node_app "https://github.com/mha963/loctex/blob/main/src/App.tsx"
click node_dashboard "https://github.com/mha963/loctex/blob/main/src/components/ProjectsDashboard.tsx"
click node_editor "https://github.com/mha963/loctex/blob/main/src/components/EditorPane.tsx"
click node_toolbar "https://github.com/mha963/loctex/blob/main/src/components/HeaderPill.tsx"
click node_format "https://github.com/mha963/loctex/blob/main/src/utils/latex-format.ts"
click node_stats "https://github.com/mha963/loctex/blob/main/src/utils/latex-stats.ts"
click node_assets "https://github.com/mha963/loctex/blob/main/src/components/AssetPreviewPane.tsx"
click node_sidebar "https://github.com/mha963/loctex/blob/main/src/components/Sidebar.tsx"
click node_modals "https://github.com/mha963/loctex/blob/main/src/components/Modals.tsx"
click node_api "https://github.com/mha963/loctex/blob/main/src/services/api.ts"
click node_server "https://github.com/mha963/loctex/blob/main/server/index.ts"
click node_database "https://github.com/mha963/loctex/blob/main/server/db/database.ts"
click node_compiler "https://github.com/mha963/loctex/blob/main/server/compiler/tectonic-runner.ts"
click node_parser "https://github.com/mha963/loctex/blob/main/server/compiler/error-parser.ts"
click node_diagnostics "https://github.com/mha963/loctex/blob/main/src/components/DiagnosticDrawer.tsx"
click node_pdf "https://github.com/mha963/loctex/blob/main/src/components/PdfCanvas.tsx"
click node_synctex "https://github.com/mha963/loctex/blob/main/server/services/synctex-parser.ts"
click node_zip "https://github.com/mha963/loctex/blob/main/server/services/zip-service.ts"
click node_aiui "https://github.com/mha963/loctex/blob/main/src/components/QwenChatDrawer.tsx"
click node_ai "https://github.com/mha963/loctex/blob/main/server/services/ollama-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,node_dashboard,node_editor,node_toolbar,node_format,node_stats toneBlue
class node_assets,node_sidebar,node_modals,node_zip toneAmber
class node_compiler,node_parser,node_diagnostics,node_pdf,node_synctex toneMint
class node_aiui,node_ai toneRose
class node_api,node_server,node_database,node_writer,node_ollama,node_tex toneIndigo
```

## Components

### Writing Workspace

- [Studio Shell](https://github.com/mha963/loctex/blob/main/src/App.tsx): `src/App.tsx`
- [Project Dashboard](https://github.com/mha963/loctex/blob/main/src/components/ProjectsDashboard.tsx): `src/components/ProjectsDashboard.tsx`
- [LaTeX Editor](https://github.com/mha963/loctex/blob/main/src/components/EditorPane.tsx): `src/components/EditorPane.tsx`
- [Editor Toolbar](https://github.com/mha963/loctex/blob/main/src/components/HeaderPill.tsx): `src/components/HeaderPill.tsx`
- [TeX Formatting](https://github.com/mha963/loctex/blob/main/src/utils/latex-format.ts): `src/utils/latex-format.ts`
- [Document Statistics](https://github.com/mha963/loctex/blob/main/src/utils/latex-stats.ts): `src/utils/latex-stats.ts`

### Projects and Assets

- [Asset Preview](https://github.com/mha963/loctex/blob/main/src/components/AssetPreviewPane.tsx): `src/components/AssetPreviewPane.tsx`
- [File Explorer](https://github.com/mha963/loctex/blob/main/src/components/Sidebar.tsx): `src/components/Sidebar.tsx`
- [Project Dialogs](https://github.com/mha963/loctex/blob/main/src/components/Modals.tsx): `src/components/Modals.tsx`
- [ZIP Exchange](https://github.com/mha963/loctex/blob/main/server/services/zip-service.ts): `server/services/zip-service.ts`

### Compile and Review

- [TeX Compiler](https://github.com/mha963/loctex/blob/main/server/compiler/tectonic-runner.ts): `server/compiler/tectonic-runner.ts`
- [Error Parser](https://github.com/mha963/loctex/blob/main/server/compiler/error-parser.ts): `server/compiler/error-parser.ts`
- [Diagnostic Drawer](https://github.com/mha963/loctex/blob/main/src/components/DiagnosticDrawer.tsx): `src/components/DiagnosticDrawer.tsx`
- [PDF Canvas](https://github.com/mha963/loctex/blob/main/src/components/PdfCanvas.tsx): `src/components/PdfCanvas.tsx`
- [SyncTeX Parser](https://github.com/mha963/loctex/blob/main/server/services/synctex-parser.ts): `server/services/synctex-parser.ts`

### AI Copilot

- [Copilot Chat](https://github.com/mha963/loctex/blob/main/src/components/QwenChatDrawer.tsx): `src/components/QwenChatDrawer.tsx`
- [AI Service](https://github.com/mha963/loctex/blob/main/server/services/ollama-service.ts): `server/services/ollama-service.ts`

### Local Backend

- [API Client](https://github.com/mha963/loctex/blob/main/src/services/api.ts): `src/services/api.ts`
- [HTTP API](https://github.com/mha963/loctex/blob/main/server/index.ts): `server/index.ts`
- [SQLite Store](https://github.com/mha963/loctex/blob/main/server/db/database.ts): `server/db/database.ts`

### Other components

- **Writer**
- **Ollama Runtime**
- **Local TeX Tools**

## Connections

- Writer → Studio Shell: uses (evidence: `README.md`)
- Studio Shell → Project Dashboard: renders (evidence: `src/App.tsx`)
- Studio Shell → LaTeX Editor: renders (evidence: `src/App.tsx`)
- Studio Shell → Editor Toolbar: renders (evidence: `src/App.tsx`)
- Studio Shell → Asset Preview: selects preview (evidence: `src/App.tsx`)
- Studio Shell → PDF Canvas: renders (evidence: `src/App.tsx`)
- Studio Shell → API Client: requests data (evidence: `src/App.tsx`)
- LaTeX Editor → TeX Formatting: formats text (evidence: `src/components/EditorPane.tsx`)
- Editor Toolbar → Document Statistics: displays stats (evidence: `src/components/HeaderPill.tsx`)
- Studio Shell → File Explorer: renders (evidence: `src/App.tsx`)
- Studio Shell → Project Dialogs: renders (evidence: `src/App.tsx`)
- Studio Shell → Diagnostic Drawer: renders (evidence: `src/App.tsx`)
- Studio Shell → Copilot Chat: renders (evidence: `src/App.tsx`)
- Copilot Chat → API Client: sends chat (evidence: `src/services/api.ts`)
- API Client → HTTP API: calls HTTP routes (evidence: `src/services/api.ts`)
- HTTP API → SQLite Store: reads and writes (evidence: `server/index.ts`)
- HTTP API → TeX Compiler: dispatches compile (evidence: `server/index.ts`)
- HTTP API → AI Service: dispatches AI (evidence: `server/index.ts`)
- HTTP API → ZIP Exchange: imports archives (evidence: `server/index.ts`)
- HTTP API → SyncTeX Parser: uses parser (evidence: `server/index.ts`)
- TeX Compiler → Error Parser: parses diagnostics (evidence: `server/compiler/tectonic-runner.ts`)
- Studio Shell → ZIP Exchange: imports and exports (evidence: `README.md`)
- HTTP API → SQLite Store: stores snapshots (evidence: `README.md`)
- TeX Compiler → Local TeX Tools: runs local tools (evidence: `README.md`)
- AI Service → Ollama Runtime: queries locally (evidence: `README.md`)
- PDF Canvas → SyncTeX Parser: jumps to source (evidence: `README.md`)
- Diagnostic Drawer → API Client: requests repair (evidence: `README.md`)
