# monapdx/modular-markup-language architecture

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

- Interactive diagram: https://gitdiagram.com/monapdx/modular-markup-language
- Repository: https://github.com/monapdx/modular-markup-language

## Overview

#### Purpose and Entry Points

Modular Markup Language (MML) is a meaning-first plain-text markup language. It parses MML source into a structured document tree, semantically validates that tree, and compiles it to HTML.

Primary programmatic entry point: `src/index.js`. Browser demo entry point: `index.html`. The public language contract is documented in `DOCS/SPEC.md`, with registered semantics and nesting rules in `DOCS/TAGS.md` and `DOCS/DEPENDENCIES.md`.

#### Language Grammar and Normalization

`src/grammar.js` is the authoritative recognition layer for tags, shorthand aliases, attributes, and inline quoted values. It determines whether an input line is markup or must remain literal text, preserving the “text wins” boundary.

Relevant paths:
- `src/grammar.js`
- `DOCS/SHORTHAND.md`
- `DOCS/TAGS.md`

#### Parse Stage: Source to AST

`src/parser.js` converts line-oriented MML into an AST. It supports opening-tag-only authoring, explicit optional close tags, inferred/implicit closure when later tags or content change context, merged consecutive text, and ignored blank content lines.

The parser consumes grammar-normalized tag information and produces the tree consumed by validation and compilation; it should not be conflated with semantic enforcement.

Relevant paths:
- `src/parser.js`
- `src/grammar.js`
- `src/index.js`

#### Semantic Validation Stage

`src/validator.js` validates parent/child eligibility, required children, and cross-node schema invariants after parsing. It covers core semantic models such as arguments/claims/evidence, timelines and date ranges, calendars and event-day validity, comparison variants, shared-trait groups, media, and ebook structure.

Validation is a distinct boundary: syntactically parseable input may still be semantically invalid.

Relevant paths:
- `src/validator.js`
- `DOCS/DEPENDENCIES.md`
- `DOCS/SPEC.md`

#### HTML Compilation and Specialized Rendering

`src/compiler.js` transforms valid AST nodes into HTML, emitting explicit closing tags and rendering specialized output such as calendar tables, heading IDs, and generated tables of contents. It is the primary output-target layer and owns presentation-oriented HTML generation rather than the parser or validator.

Relevant paths:
- `src/compiler.js`
- `src/index.js`
- `index.html`

#### Ebook Schema and TOC Generation

Ebook support is a specialized schema layered on the common AST: an `ebook` requires content and can declare metadata, cover media, TOC, styles, and JavaScript. `toc` is declarative; headings within ebook content drive generated navigation. Web-only style/script tags are relevant to HTML export but not plain-text export.

Relevant paths:
- `src/ebook-schema.js`
- `src/ebook.js`
- `src/compiler.js`

#### Runtime, Delivery, and Documentation Export

The implementation is JavaScript/Node.js, with npm-based test execution (`package.json`, `tests/run-tests.js`). The root HTML file provides a browser-facing parser/validator/compiler demo. Documentation is maintained as source Markdown under `DOCS/` and has checked-in HTML output under `export/`; Node scripts support that documentation export and local serving workflow.

Relevant paths:
- `package.json`
- `index.html`
- `scripts/build-notes-html.mjs`
- `scripts/notes-server.mjs`
- `export/index.html`

Main entry points: [`src/grammar.js`](https://github.com/monapdx/modular-markup-language/blob/main/src/grammar.js) (Grammar normalization), [`src/validator.js`](https://github.com/monapdx/modular-markup-language/blob/main/src/validator.js) (Semantic validator), [`src/index.js`](https://github.com/monapdx/modular-markup-language/blob/main/src/index.js) (Public API), [`src/compiler.js`](https://github.com/monapdx/modular-markup-language/blob/main/src/compiler.js) (HTML compiler)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_language["Language contract"]
  node_spec["Language specification<br/>language contract<br/>[SPEC.md]"]
  node_tags["Tag semantics<br/>tag registry<br/>[TAGS.md]"]
  node_shorthand["Shorthand rules<br/>grammar reference<br/>[SHORTHAND.md]"]
  node_dependencies["Semantic dependencies<br/>validation rules<br/>[DEPENDENCIES.md]"]
end

subgraph group_pipeline["MML processing pipeline"]
  node_mml_source["MML source<br/>input"]
  node_api["Public API<br/>JavaScript entry<br/>[index.js]"]
  node_grammar["Grammar normalization<br/>recognition layer<br/>[grammar.js]"]
  node_parser["AST parser<br/>parse stage<br/>[parser.js]"]
  node_ast["Document AST<br/>structured tree"]
  node_validator["Semantic validator<br/>validation stage<br/>[validator.js]"]
  node_valid_ast["Valid AST<br/>validated tree"]
  node_compiler["HTML compiler<br/>output stage<br/>[compiler.js]"]
  node_html["HTML output<br/>compiled document"]
end

subgraph group_ebook["Ebook rendering"]
  node_ebook_schema["Ebook schema<br/>specialized schema<br/>[ebook-schema.js]"]
  node_ebook["Ebook support<br/>ebook model<br/>[ebook.js]"]
end

subgraph group_delivery["Delivery and docs"]
  node_browser_demo["Browser demo<br/>browser entry<br/>[index.html]"]
  node_npm{{"Node/npm runtime<br/>[package.json]"}}
  node_docs_build["Documentation export<br/>Node build script"]
  node_docs_server["Documentation server<br/>Node server script<br/>[notes-server.mjs]"]
  node_exported_docs["Exported documentation<br/>HTML export<br/>[index.html]"]
end

node_mml_source -->|"submitted to"| node_api
node_api -->|"normalizes lines"| node_grammar
node_grammar -->|"recognized tags"| node_parser
node_parser -->|"produces"| node_ast
node_ast -->|"validates"| node_validator
node_validator -->|"accepts"| node_valid_ast
node_valid_ast -->|"compiles"| node_compiler
node_compiler -->|"emits"| node_html
node_spec -.->|"defines syntax"| node_grammar
node_tags -.->|"defines tags"| node_grammar
node_shorthand -.->|"defines aliases"| node_grammar
node_dependencies -.->|"defines constraints"| node_validator
node_tags -.->|"defines nesting"| node_validator
node_ebook_schema -->|"extends validation"| node_validator
node_ebook_schema -->|"defines model"| node_ebook
node_ebook -->|"supplies TOC rendering"| node_compiler
node_browser_demo -->|"uses"| node_api
node_npm -->|"runs"| node_docs_build
node_npm -->|"runs"| node_docs_server
node_docs_build -->|"generates"| node_exported_docs
node_docs_server -->|"serves"| node_exported_docs

click node_api "https://github.com/monapdx/modular-markup-language/blob/main/src/index.js"
click node_grammar "https://github.com/monapdx/modular-markup-language/blob/main/src/grammar.js"
click node_parser "https://github.com/monapdx/modular-markup-language/blob/main/src/parser.js"
click node_validator "https://github.com/monapdx/modular-markup-language/blob/main/src/validator.js"
click node_compiler "https://github.com/monapdx/modular-markup-language/blob/main/src/compiler.js"
click node_spec "https://github.com/monapdx/modular-markup-language/blob/main/DOCS/SPEC.md"
click node_tags "https://github.com/monapdx/modular-markup-language/blob/main/DOCS/TAGS.md"
click node_shorthand "https://github.com/monapdx/modular-markup-language/blob/main/DOCS/SHORTHAND.md"
click node_dependencies "https://github.com/monapdx/modular-markup-language/blob/main/DOCS/DEPENDENCIES.md"
click node_ebook_schema "https://github.com/monapdx/modular-markup-language/blob/main/src/ebook-schema.js"
click node_ebook "https://github.com/monapdx/modular-markup-language/blob/main/src/ebook.js"
click node_browser_demo "https://github.com/monapdx/modular-markup-language/blob/main/index.html"
click node_npm "https://github.com/monapdx/modular-markup-language/blob/main/package.json"
click node_docs_build "https://github.com/monapdx/modular-markup-language/blob/main/scripts/build-notes-html.mjs"
click node_docs_server "https://github.com/monapdx/modular-markup-language/blob/main/scripts/notes-server.mjs"
click node_exported_docs "https://github.com/monapdx/modular-markup-language/blob/main/export/index.html"

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_spec,node_tags,node_shorthand,node_dependencies toneBlue
class node_mml_source,node_api,node_grammar,node_parser,node_ast,node_validator,node_valid_ast,node_compiler,node_html toneAmber
class node_ebook_schema,node_ebook toneMint
class node_browser_demo,node_npm,node_docs_build,node_docs_server,node_exported_docs toneRose
```

## Components

### Language contract

- [Language specification](https://github.com/monapdx/modular-markup-language/blob/main/DOCS/SPEC.md): language contract · Public MML language contract. · `DOCS/SPEC.md`
- [Tag semantics](https://github.com/monapdx/modular-markup-language/blob/main/DOCS/TAGS.md): tag registry · Registered tags and nesting rules. · `DOCS/TAGS.md`
- [Shorthand rules](https://github.com/monapdx/modular-markup-language/blob/main/DOCS/SHORTHAND.md): grammar reference · `DOCS/SHORTHAND.md`
- [Semantic dependencies](https://github.com/monapdx/modular-markup-language/blob/main/DOCS/DEPENDENCIES.md): validation rules · Required-child and cross-node semantic rules. · `DOCS/DEPENDENCIES.md`

### MML processing pipeline

- **MML source**: input · Line-oriented meaning-first markup.
- [Public API](https://github.com/monapdx/modular-markup-language/blob/main/src/index.js): JavaScript entry · Programmatic parse, validation, and compilation entry point. · `src/index.js`
- [Grammar normalization](https://github.com/monapdx/modular-markup-language/blob/main/src/grammar.js): recognition layer · Recognizes tags, aliases, attributes, and literal-text boundary. · `src/grammar.js`
- [AST parser](https://github.com/monapdx/modular-markup-language/blob/main/src/parser.js): parse stage · Builds a tree with inferred closure and merged text. · `src/parser.js`
- **Document AST**: structured tree · Common representation shared by validation and output.
- [Semantic validator](https://github.com/monapdx/modular-markup-language/blob/main/src/validator.js): validation stage · Enforces nesting, required children, and cross-node invariants. · `src/validator.js`
- **Valid AST**: validated tree
- [HTML compiler](https://github.com/monapdx/modular-markup-language/blob/main/src/compiler.js): output stage · Generates HTML, closing tags, heading IDs, tables, and TOCs. · `src/compiler.js`
- **HTML output**: compiled document

### Ebook rendering

- [Ebook schema](https://github.com/monapdx/modular-markup-language/blob/main/src/ebook-schema.js): specialized schema · Defines ebook content, metadata, cover, TOC, styles, and scripts. · `src/ebook-schema.js`
- [Ebook support](https://github.com/monapdx/modular-markup-language/blob/main/src/ebook.js): ebook model · Uses ebook headings to supply declarative TOC navigation. · `src/ebook.js`

### Delivery and docs

- [Browser demo](https://github.com/monapdx/modular-markup-language/blob/main/index.html): browser entry · Interactive parser, validator, and compiler delivery. · `index.html`
- [Node/npm runtime](https://github.com/monapdx/modular-markup-language/blob/main/package.json): runtime · Runs implementation, tests, and documentation scripts. · `package.json`
- [Documentation export](https://github.com/monapdx/modular-markup-language/blob/main/scripts/build-notes-html.mjs): Node build script · Builds checked-in HTML from Markdown documentation. · `scripts/build-notes-html.mjs`
- [Documentation server](https://github.com/monapdx/modular-markup-language/blob/main/scripts/notes-server.mjs): Node server script · Serves local documentation workflow. · `scripts/notes-server.mjs`
- [Exported documentation](https://github.com/monapdx/modular-markup-language/blob/main/export/index.html): HTML export · `export/index.html`

## Connections

- MML source → Public API: submitted to
- Public API → Grammar normalization: normalizes lines
- Grammar normalization → AST parser: recognized tags
- AST parser → Document AST: produces
- Document AST → Semantic validator: validates
- Semantic validator → Valid AST: accepts
- Valid AST → HTML compiler: compiles
- HTML compiler → HTML output: emits
- Language specification → Grammar normalization: defines syntax
- Tag semantics → Grammar normalization: defines tags
- Shorthand rules → Grammar normalization: defines aliases
- Semantic dependencies → Semantic validator: defines constraints
- Tag semantics → Semantic validator: defines nesting
- Ebook schema → Semantic validator: extends validation
- Ebook schema → Ebook support: defines model
- Ebook support → HTML compiler: supplies TOC rendering
- Browser demo → Public API: uses
- Node/npm runtime → Documentation export: runs
- Node/npm runtime → Documentation server: runs
- Documentation export → Exported documentation: generates
- Documentation server → Exported documentation: serves
