# ajarallah/matn architecture

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

- Interactive diagram: https://gitdiagram.com/ajarallah/matn
- Repository: https://github.com/ajarallah/matn

## Overview

Matn is a local Arabic-first Markdown reader. The main workflow is: a reader opens a file, folder, or stdin through the CLI; a local HTTP server serves the browser reader and workspace content; rendering and navigation features support reading; optional reader state is persisted separately. The README also documents book navigation, link health, exports, and other reader capabilities. Some browser-side wiring and server routes were not sampled, so those relationships are omitted or marked unverified.

Main entry points: [`src/server.mjs`](https://github.com/ajarallah/matn/blob/main/src/server.mjs) (Local HTTP server), [`src/index.html`](https://github.com/ajarallah/matn/blob/main/src/index.html) (Browser reader), [`src/link-core.cjs`](https://github.com/ajarallah/matn/blob/main/src/link-core.cjs) (Links and health), [`bin/matn.mjs`](https://github.com/ajarallah/matn/blob/main/bin/matn.mjs) (CLI)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Launch and serving"]
  node_cli["CLI<br/>[matn.mjs]"]
  node_stdin["Stdin session<br/>[stdin-session.mjs]"]
  node_server["Local HTTP server<br/>[server.mjs]"]
end

subgraph group_reading["Reading and content"]
  node_browser["Browser reader<br/>[index.html]"]
  node_render["Markdown rendering<br/>[render-core.cjs]"]
  node_worker["Large-file rendering<br/>[render-worker.js]"]
  node_annotations["Annotations"]
end

subgraph group_workspace["Workspace navigation"]
  node_workspace_files["Markdown file rules<br/>[markdown-files.cjs]"]
  node_search["Search and indexing<br/>[search-core.cjs]"]
  node_links["Links and health<br/>[link-core.cjs]"]
  node_books["Book navigation<br/>[book-core.cjs]"]
end

subgraph group_reader_state["Reader state and actions"]
  node_state_actions["State actions<br/>[state-actions.cjs]"]
  node_state_store[("Persistent state<br/>[state-store.mjs]")]
  node_platform["File actions"]
end

node_reader(("Reader"))

node_reader -->|"opens content"| node_cli
node_cli -->|"creates session"| node_stdin
node_cli -->|"starts server"| node_server
node_server -->|"serves reader"| node_browser
node_browser -.->|"requests content"| node_server
node_server -->|"uses core"| node_render
node_browser -.->|"renders content"| node_render
node_browser -.->|"dispatches large files"| node_worker
node_browser -.->|"supports annotations"| node_annotations
node_server -->|"uses rules"| node_workspace_files
node_server -->|"indexes and searches"| node_search
node_server -->|"checks links"| node_links
node_links -->|"uses normalization"| node_search
node_links -->|"uses render rules"| node_render
node_links -->|"uses filename rules"| node_workspace_files
node_server -->|"supports book navigation"| node_books
node_browser -.->|"navigates chapters"| node_books
node_server -->|"reads and updates"| node_state_store
node_state_store -->|"applies actions"| node_state_actions
node_server -->|"runs file actions"| node_platform
node_browser -.->|"persists reader state"| node_state_store

click node_cli "https://github.com/ajarallah/matn/blob/main/bin/matn.mjs"
click node_stdin "https://github.com/ajarallah/matn/blob/main/src/stdin-session.mjs"
click node_server "https://github.com/ajarallah/matn/blob/main/src/server.mjs"
click node_browser "https://github.com/ajarallah/matn/blob/main/src/index.html"
click node_render "https://github.com/ajarallah/matn/blob/main/src/render-core.cjs"
click node_worker "https://github.com/ajarallah/matn/blob/main/src/render-worker.js"
click node_annotations "https://github.com/ajarallah/matn/blob/main/src/annotation-core.cjs"
click node_workspace_files "https://github.com/ajarallah/matn/blob/main/src/markdown-files.cjs"
click node_search "https://github.com/ajarallah/matn/blob/main/src/search-core.cjs"
click node_links "https://github.com/ajarallah/matn/blob/main/src/link-core.cjs"
click node_books "https://github.com/ajarallah/matn/blob/main/src/book-core.cjs"
click node_state_actions "https://github.com/ajarallah/matn/blob/main/src/state-actions.cjs"
click node_state_store "https://github.com/ajarallah/matn/blob/main/src/state-store.mjs"
click node_platform "https://github.com/ajarallah/matn/blob/main/src/platform-actions.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_cli,node_stdin,node_server toneBlue
class node_browser,node_render,node_worker,node_annotations toneAmber
class node_workspace_files,node_search,node_links,node_books toneMint
class node_state_actions,node_state_store,node_platform toneRose
class node_reader toneIndigo
```

## Components

### Launch and serving

- [CLI](https://github.com/ajarallah/matn/blob/main/bin/matn.mjs): `bin/matn.mjs`
- [Stdin session](https://github.com/ajarallah/matn/blob/main/src/stdin-session.mjs): `src/stdin-session.mjs`
- [Local HTTP server](https://github.com/ajarallah/matn/blob/main/src/server.mjs): `src/server.mjs`

### Reading and content

- [Browser reader](https://github.com/ajarallah/matn/blob/main/src/index.html): `src/index.html`
- [Markdown rendering](https://github.com/ajarallah/matn/blob/main/src/render-core.cjs): `src/render-core.cjs`
- [Large-file rendering](https://github.com/ajarallah/matn/blob/main/src/render-worker.js): `src/render-worker.js`
- [Annotations](https://github.com/ajarallah/matn/blob/main/src/annotation-core.cjs): `src/annotation-core.cjs`

### Workspace navigation

- [Markdown file rules](https://github.com/ajarallah/matn/blob/main/src/markdown-files.cjs): `src/markdown-files.cjs`
- [Search and indexing](https://github.com/ajarallah/matn/blob/main/src/search-core.cjs): `src/search-core.cjs`
- [Links and health](https://github.com/ajarallah/matn/blob/main/src/link-core.cjs): `src/link-core.cjs`
- [Book navigation](https://github.com/ajarallah/matn/blob/main/src/book-core.cjs): `src/book-core.cjs`

### Reader state and actions

- [State actions](https://github.com/ajarallah/matn/blob/main/src/state-actions.cjs): `src/state-actions.cjs`
- [Persistent state](https://github.com/ajarallah/matn/blob/main/src/state-store.mjs): `src/state-store.mjs`
- [File actions](https://github.com/ajarallah/matn/blob/main/src/platform-actions.mjs): `src/platform-actions.mjs`

### Other components

- **Reader**

## Connections

- Reader → CLI: opens content (evidence: `README.md`)
- CLI → Stdin session: creates session (evidence: `bin/matn.mjs`)
- CLI → Local HTTP server: starts server (evidence: `bin/matn.mjs`)
- Local HTTP server → Browser reader: serves reader (evidence: `src/server.mjs`)
- Browser reader → Local HTTP server: requests content
- Local HTTP server → Markdown rendering: uses core (evidence: `src/server.mjs`)
- Browser reader → Markdown rendering: renders content
- Browser reader → Large-file rendering: dispatches large files
- Browser reader → Annotations: supports annotations
- Local HTTP server → Markdown file rules: uses rules (evidence: `src/server.mjs`)
- Local HTTP server → Search and indexing: indexes and searches (evidence: `src/server.mjs`)
- Local HTTP server → Links and health: checks links (evidence: `src/server.mjs`)
- Links and health → Search and indexing: uses normalization (evidence: `src/link-core.cjs`)
- Links and health → Markdown rendering: uses render rules (evidence: `src/link-core.cjs`)
- Links and health → Markdown file rules: uses filename rules (evidence: `src/link-core.cjs`)
- Local HTTP server → Book navigation: supports book navigation (evidence: `src/server.mjs`)
- Browser reader → Book navigation: navigates chapters
- Local HTTP server → Persistent state: reads and updates (evidence: `src/server.mjs`)
- Persistent state → State actions: applies actions (evidence: `src/state-store.mjs`)
- Local HTTP server → File actions: runs file actions (evidence: `src/server.mjs`)
- Browser reader → Persistent state: persists reader state
