# hectordev2/js-ppt-generate architecture

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

- Interactive diagram: https://gitdiagram.com/hectordev2/js-ppt-generate
- Repository: https://github.com/hectordev2/js-ppt-generate

## Overview

1. **What this repo is**
   - `js-ppt-generate` is a browser-only presentation generator. It has no backend and runs entirely in the client.
   - The core architectural split is between two entry points: **JSON mode** (`index.html` → `src/main.ts`) and **JS mode** (`js.html` → `src/main-js.ts`).

2. **Two independent inputs, one shared output system**
   - JSON mode accepts a declarative presentation schema.
   - JS mode executes user-authored `pptxgenjs` code in the browser.
   - Both modes converge on the same downstream capabilities: generate PPTX, generate PDF, and render a visual preview.

3. **Shared internal representation**
   - JSON mode does not render directly from the input schema. It first normalizes and validates into a **Document Node Tree (DNT)**.
   - The DNT is the main architectural boundary: everything after it is format-specific rendering, not input-specific parsing.

4. **JSON mode pipeline**
   - `src/parser.ts` handles parse → normalize → validate → compile.
   - `src/schema/types.ts` defines the presentation schema and element types.
   - `src/schema/validator.ts` enforces structure and type guards.
   - `src/engine/runtime.ts` turns schema elements into positioned, styled document nodes using layout rules and theme defaults.

5. **JS mode pipeline**
   - `src/modes/library.ts` provides the browser execution environment for `pptxgenjs`, including a `require("pptxgenjs")` polyfill and interception of `writeFile()`.
   - Instead of downloading immediately, the created presentation instance is captured so the app can reuse it for export and preview.
   - This mode bypasses the DNT compiler and works from the `pptxgenjs` object model directly.

6. **Rendering outputs are separate adapters**
   - `src/renderers/pptx.ts` converts DNT into PPTX using PptxGenJS.
   - `src/renderers/pdf.ts` converts DNT into PDF using jsPDF.
   - `src/renderers/html.ts` converts DNT into HTML for the JSON-mode preview.
   - In JS mode, `src/lib/pptx-to-pdf.ts` handles PDF creation from the captured `pptxgenjs` instance.

7. **Preview is a shared UI concern, but with two data sources**
   - JSON mode preview is generated from the DNT via HTML rendering.
   - JS mode preview is generated by `src/modes/js-preview.ts`, which inspects internal `pptxgenjs` slide objects and turns them into HTML.
   - The preview subsystem is intentionally decoupled from export generation so the same slide content can be shown without requiring file output.

8. **Layout, theming, and styling**
   - `src/engine/theme.ts` defines the built-in themes and color/style resolution.
   - `src/engine/runtime.ts` applies layout behavior such as placement, grid positioning, and default sizing.
   - Style resolution is hierarchical: element styles override theme defaults, and tokens like `accent` or `background` are resolved centrally.

9. **Editor and runtime ergonomics**
   - `src/editor/setup.ts` wires up Monaco Editor and its workers, which suggests the app includes in-browser code editing for both JSON and JS modes.
   - `src/state.ts` and `src/types.ts` hold shared app state, logs, and processing status that support compile/execute feedback in the UI.

10. **Sample content and app bootstrap**
   - `src/lib/samples.ts` provides example presentations, likely used to seed the editor or demonstrate the pipeline in both modes.
   - `src/main.ts` and `src/main-js.ts` are the two bootstraps that connect editor input, compilation/execution, rendering, export, and preview.
   - `index.html` and `js.html` are the mode-specific shells that select which pipeline is active.

11. **Technology boundaries that matter**
   - The app is TypeScript-first, built with Vite, and uses vanilla HTML/CSS for the UI.
   - Presentation generation depends on **PptxGenJS**; PDF export uses **jsPDF**.
   - Because everything runs in the browser, the key architecture constraint is managing execution safely and converting internal structures into preview/export artifacts without server-side services.

12. **How to diagram it**
   - A good architecture diagram should show:
     - two entry points feeding two input pipelines,
     - a shared presentation runtime/preview layer,
     - separate adapters for PPTX, PDF, and HTML output,
     - and a clear boundary between input parsing/execution and output rendering.
   - The main “join point” is the captured document model: DNT for JSON mode, captured `pptxgenjs` state for JS mode.

Main entry points: [`src/main.ts`](https://github.com/hectordev2/js-ppt-generate/blob/main/src/main.ts) (Main boot), [`src/engine/runtime.ts`](https://github.com/hectordev2/js-ppt-generate/blob/main/src/engine/runtime.ts) (Layout runtime), [`src/main-js.ts`](https://github.com/hectordev2/js-ppt-generate/blob/main/src/main-js.ts) (JS boot), [`src/parser.ts`](https://github.com/hectordev2/js-ppt-generate/blob/main/src/parser.ts) (Parser)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Entry shells"]
  node_index_html["index.html<br/>shell<br/>[index.html]"]
  node_js_html["js.html<br/>shell<br/>[js.html]"]
  node_main_ts["Main boot<br/>bootstrap<br/>[main.ts]"]
  node_main_js_ts["JS boot<br/>bootstrap<br/>[main-js.ts]"]
end

subgraph group_json["JSON mode"]
  node_parser_ts["Parser<br/>compile pipeline<br/>[parser.ts]"]
  node_schema_types_ts["Schema types<br/>[types.ts]"]
  node_schema_validator_ts["Validator<br/>schema guard<br/>[validator.ts]"]
end

subgraph group_js["JS mode"]
  node_library_ts["Pptx library<br/>execution env<br/>[library.ts]"]
  node_js_preview_ts["JS preview<br/>preview adapter<br/>[js-preview.ts]"]
end

subgraph group_shared["Shared core"]
  node_runtime_ts["Layout runtime<br/>document engine<br/>[runtime.ts]"]
  node_theme_ts["Theme system<br/>[theme.ts]"]
  node_samples_ts["Samples<br/>content fixtures<br/>[samples.ts]"]
  node_state_ts["App state<br/>[state.ts]"]
  node_editor_setup_ts["Editor setup<br/>editor wiring<br/>[setup.ts]"]
end

subgraph group_outputs["Output adapters"]
  node_pptx_renderer_ts["PPTX renderer<br/>export adapter<br/>[pptx.ts]"]
  node_pdf_renderer_ts["PDF renderer<br/>export adapter<br/>[pdf.ts]"]
  node_html_renderer_ts["HTML renderer<br/>preview adapter<br/>[html.ts]"]
  node_pptx_to_pdf_ts["PPTX to PDF<br/>export adapter<br/>[pptx-to-pdf.ts]"]
end

node_index_html -->|"loads"| node_main_ts
node_js_html -->|"loads"| node_main_js_ts
node_main_ts -->|"uses"| node_editor_setup_ts
node_main_ts -->|"seeds"| node_samples_ts
node_main_ts -->|"parses"| node_parser_ts
node_parser_ts -->|"reads"| node_schema_types_ts
node_parser_ts -->|"validates"| node_schema_validator_ts
node_parser_ts -->|"compiles"| node_runtime_ts
node_runtime_ts -->|"resolves"| node_theme_ts
node_runtime_ts -->|"previews"| node_html_renderer_ts
node_runtime_ts -->|"exports"| node_pptx_renderer_ts
node_runtime_ts -->|"exports"| node_pdf_renderer_ts
node_main_js_ts -->|"uses"| node_editor_setup_ts
node_main_js_ts -->|"executes"| node_library_ts
node_library_ts -->|"captures"| node_pptx_to_pdf_ts
node_library_ts -->|"inspects"| node_js_preview_ts
node_main_ts -->|"updates"| node_state_ts
node_main_js_ts -->|"updates"| node_state_ts
node_editor_setup_ts -->|"reports"| node_state_ts
node_samples_ts -.->|"demonstrates"| node_main_js_ts

click node_index_html "https://github.com/hectordev2/js-ppt-generate/blob/main/index.html"
click node_js_html "https://github.com/hectordev2/js-ppt-generate/blob/main/js.html"
click node_main_ts "https://github.com/hectordev2/js-ppt-generate/blob/main/src/main.ts"
click node_main_js_ts "https://github.com/hectordev2/js-ppt-generate/blob/main/src/main-js.ts"
click node_parser_ts "https://github.com/hectordev2/js-ppt-generate/blob/main/src/parser.ts"
click node_schema_types_ts "https://github.com/hectordev2/js-ppt-generate/blob/main/src/schema/types.ts"
click node_schema_validator_ts "https://github.com/hectordev2/js-ppt-generate/blob/main/src/schema/validator.ts"
click node_runtime_ts "https://github.com/hectordev2/js-ppt-generate/blob/main/src/engine/runtime.ts"
click node_theme_ts "https://github.com/hectordev2/js-ppt-generate/blob/main/src/engine/theme.ts"
click node_library_ts "https://github.com/hectordev2/js-ppt-generate/blob/main/src/modes/library.ts"
click node_js_preview_ts "https://github.com/hectordev2/js-ppt-generate/blob/main/src/modes/js-preview.ts"
click node_pptx_renderer_ts "https://github.com/hectordev2/js-ppt-generate/blob/main/src/renderers/pptx.ts"
click node_pdf_renderer_ts "https://github.com/hectordev2/js-ppt-generate/blob/main/src/renderers/pdf.ts"
click node_html_renderer_ts "https://github.com/hectordev2/js-ppt-generate/blob/main/src/renderers/html.ts"
click node_pptx_to_pdf_ts "https://github.com/hectordev2/js-ppt-generate/blob/main/src/lib/pptx-to-pdf.ts"
click node_samples_ts "https://github.com/hectordev2/js-ppt-generate/blob/main/src/lib/samples.ts"
click node_state_ts "https://github.com/hectordev2/js-ppt-generate/blob/main/src/state.ts"
click node_editor_setup_ts "https://github.com/hectordev2/js-ppt-generate/blob/main/src/editor/setup.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_index_html,node_js_html,node_main_ts,node_main_js_ts toneBlue
class node_parser_ts,node_schema_types_ts,node_schema_validator_ts toneAmber
class node_library_ts,node_js_preview_ts toneMint
class node_runtime_ts,node_theme_ts,node_samples_ts,node_state_ts,node_editor_setup_ts toneRose
class node_pptx_renderer_ts,node_pdf_renderer_ts,node_html_renderer_ts,node_pptx_to_pdf_ts toneIndigo
```

## Components

### Entry shells

Mode-specific HTML entry points and bootstraps.

- [index.html](https://github.com/hectordev2/js-ppt-generate/blob/main/index.html): shell · JSON-mode browser entry shell. · `index.html`
- [js.html](https://github.com/hectordev2/js-ppt-generate/blob/main/js.html): shell · JS-mode browser entry shell. · `js.html`
- [Main boot](https://github.com/hectordev2/js-ppt-generate/blob/main/src/main.ts): bootstrap · Wires JSON mode UI, parsing, preview, and export. · `src/main.ts`
- [JS boot](https://github.com/hectordev2/js-ppt-generate/blob/main/src/main-js.ts): bootstrap · Wires JS mode UI, execution capture, preview, and export. · `src/main-js.ts`

### JSON mode

Declarative presentation pipeline.

- [Parser](https://github.com/hectordev2/js-ppt-generate/blob/main/src/parser.ts): compile pipeline · Parse, normalize, validate, and compile JSON input. · `src/parser.ts`
- [Schema types](https://github.com/hectordev2/js-ppt-generate/blob/main/src/schema/types.ts): schema · Presentation schema and element type definitions. · `src/schema/types.ts`
- [Validator](https://github.com/hectordev2/js-ppt-generate/blob/main/src/schema/validator.ts): schema guard · Structural validation and type guards for JSON presentations. · `src/schema/validator.ts`

### JS mode

Browser-executed pptxgenjs pipeline.

- [Pptx library](https://github.com/hectordev2/js-ppt-generate/blob/main/src/modes/library.ts): execution env · Browser execution environment for pptxgenjs with require polyfill and write interception. · `src/modes/library.ts`
- [JS preview](https://github.com/hectordev2/js-ppt-generate/blob/main/src/modes/js-preview.ts): preview adapter · Turns captured pptxgenjs slide objects into HTML preview output. · `src/modes/js-preview.ts`

### Shared core

Runtime, state, editor, and sample data shared across modes.

- [Layout runtime](https://github.com/hectordev2/js-ppt-generate/blob/main/src/engine/runtime.ts): document engine · Builds positioned document nodes from schema elements using layout and theme rules. · `src/engine/runtime.ts`
- [Theme system](https://github.com/hectordev2/js-ppt-generate/blob/main/src/engine/theme.ts): theme · Built-in themes and centralized style/token resolution. · `src/engine/theme.ts`
- [Samples](https://github.com/hectordev2/js-ppt-generate/blob/main/src/lib/samples.ts): content fixtures · Example presentations used to seed or demonstrate the editor. · `src/lib/samples.ts`
- [App state](https://github.com/hectordev2/js-ppt-generate/blob/main/src/state.ts): state · Shared processing status, logs, and UI state. · `src/state.ts`
- [Editor setup](https://github.com/hectordev2/js-ppt-generate/blob/main/src/editor/setup.ts): editor wiring · Monaco editor and worker setup for browser editing. · `src/editor/setup.ts`

### Output adapters

Format-specific export and preview renderers.

- [PPTX renderer](https://github.com/hectordev2/js-ppt-generate/blob/main/src/renderers/pptx.ts): export adapter · Converts the document node tree into PptxGenJS output. · `src/renderers/pptx.ts`
- [PDF renderer](https://github.com/hectordev2/js-ppt-generate/blob/main/src/renderers/pdf.ts): export adapter · Converts the document node tree into PDF output via jsPDF. · `src/renderers/pdf.ts`
- [HTML renderer](https://github.com/hectordev2/js-ppt-generate/blob/main/src/renderers/html.ts): preview adapter · Renders the document node tree as HTML for JSON-mode preview. · `src/renderers/html.ts`
- [PPTX to PDF](https://github.com/hectordev2/js-ppt-generate/blob/main/src/lib/pptx-to-pdf.ts): export adapter · Creates PDF from captured pptxgenjs presentation in JS mode. · `src/lib/pptx-to-pdf.ts`

## Connections

- index.html → Main boot: loads · JSON mode shell loads the JSON-mode bootstrap.
- js.html → JS boot: loads · JS mode shell loads the JS-mode bootstrap.
- Main boot → Editor setup: uses · Bootstraps browser editing in JSON mode.
- Main boot → Samples: seeds · Sample presentations can initialize the JSON editor.
- Main boot → Parser: parses · JSON mode compiles user schema into the document node tree.
- Parser → Schema types: reads · Parser relies on the presentation schema definitions.
- Parser → Validator: validates · Parser delegates structural checks and guards.
- Parser → Layout runtime: compiles · Normalization feeds the layout/runtime compiler.
- Layout runtime → Theme system: resolves · Runtime applies theme defaults and token resolution.
- Layout runtime → HTML renderer: previews · JSON-mode preview is rendered from the DNT as HTML.
- Layout runtime → PPTX renderer: exports · The shared DNT is exported to PPTX.
- Layout runtime → PDF renderer: exports · The shared DNT is exported to PDF.
- JS boot → Editor setup: uses · Bootstraps browser editing in JS mode.
- JS boot → Pptx library: executes · JS mode runs user code inside the browser library environment.
- Pptx library → PPTX to PDF: captures · Intercepted presentation instance is reused for PDF creation.
- Pptx library → JS preview: inspects · Captured pptxgenjs slide objects drive JS-mode preview.
- Main boot → App state: updates · JSON-mode processing status and logs are stored in shared app state.
- JS boot → App state: updates · JS-mode processing status and logs are stored in shared app state.
- Editor setup → App state: reports · Editor/runtime feedback flows through shared state.
- Samples → JS boot: demonstrates · Sample content can seed JS mode as well as JSON mode.
