# erdos/stencil architecture

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

- Interactive diagram: https://gitdiagram.com/erdos/stencil
- Repository: https://github.com/erdos/stencil

## Overview

Stencil is a JVM template engine that fills Word and PowerPoint OOXML documents. The main workflow accepts a template and data, prepares the template, evaluates expressions and dynamic content, then writes the rendered document; Java and Clojure APIs and a standalone service/CLI provide entry points. The README documents functions, fragments, HTML, images, links, and table manipulation. Some Clojure processing and service internals were not sampled, so those capability links are shown as unverified rather than asserted calls.

Main entry points: [`src/stencil/process.clj`](https://github.com/erdos/stencil/blob/master/src/stencil/process.clj) (Document processing), [`java-src/io/github/erdos/stencil/PreparedTemplate.java`](https://github.com/erdos/stencil/blob/master/java-src/io/github/erdos/stencil/PreparedTemplate.java) (Prepared template), [`java-src/io/github/erdos/stencil/API.java`](https://github.com/erdos/stencil/blob/master/java-src/io/github/erdos/stencil/API.java) (Java API), [`java-src/io/github/erdos/stencil/Main.java`](https://github.com/erdos/stencil/blob/master/java-src/io/github/erdos/stencil/Main.java) (CLI entry)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interfaces["Entry Points"]
  node_java_api["Java API<br/>[API.java]"]
  node_clj_api["Clojure API<br/>[api.clj]"]
  node_cli["CLI entry<br/>[Main.java]"]
  node_cli_args["CLI arguments<br/>[ArgsParser.java]"]
  node_stencil_args["Stencil options"]
  node_standalone["Standalone runner"]
end

subgraph group_preparation["Template Preparation"]
  node_factory["Native factory"]
  node_dir_watch["Directory watcher"]
  node_file_helper["File handling<br/>[FileHelper.java]"]
  node_prepared["Prepared template"]
  node_template_data["Template data<br/>[TemplateData.java]"]
  node_variables["Template variables"]
end

subgraph group_engine["Rendering Engine"]
  node_process["Document processing<br/>[process.clj]"]
  node_grammar["Expression grammar<br/>[grammar.clj]"]
  node_evaluation["Expression evaluation<br/>[eval.clj]"]
  node_functions["Template functions"]
  node_ooxml_model["OOXML model<br/>[model.clj]"]
  node_ooxml["OOXML handling<br/>[ooxml.clj]"]
end

subgraph group_features["Document Features"]
  node_html["HTML content<br/>[html.clj]"]
  node_images["Images<br/>[images.clj]"]
  node_links["Links<br/>[links.clj]"]
  node_tables["Table editing<br/>[table.clj]"]
  node_fragments["Document fragments<br/>[fragments.clj]"]
end

subgraph group_delivery["Output and Service"]
  node_evaluated["Evaluated document"]
  node_service["Rendering service<br/>[service.clj]"]
  node_output(("Document output"))
end

node_user(("Template author"))

node_user -->|"supplies template"| node_java_api
node_user -->|"runs rendering"| node_cli
node_cli -->|"parses options"| node_stencil_args
node_stencil_args -->|"configures parser"| node_cli_args
node_cli -->|"starts runner"| node_standalone
node_standalone -->|"uses API"| node_java_api
node_java_api -->|"prepares template"| node_factory
node_factory -.->|"creates prepared"| node_prepared
node_dir_watch -->|"delegates preparation"| node_factory
node_java_api -->|"renders template"| node_prepared
node_prepared -->|"consumes data"| node_template_data
node_prepared -->|"uses evaluator"| node_functions
node_prepared -->|"produces document"| node_evaluated
node_prepared -->|"exposes variables"| node_variables
node_clj_api -.->|"invokes processing"| node_process
node_process -.->|"parses expressions"| node_grammar
node_process -.->|"evaluates expressions"| node_evaluation
node_evaluation -.->|"dispatches functions"| node_functions
node_process -.->|"transforms document"| node_ooxml_model
node_ooxml_model -.->|"handles OOXML"| node_ooxml
node_process -.->|"supports HTML"| node_html
node_process -.->|"replaces images"| node_images
node_process -.->|"replaces links"| node_links
node_process -.->|"edits tables"| node_tables
node_process -.->|"includes fragments"| node_fragments
node_evaluated -->|"writes document"| node_output
node_user -.->|"submits job"| node_service

click node_java_api "https://github.com/erdos/stencil/blob/master/java-src/io/github/erdos/stencil/API.java"
click node_clj_api "https://github.com/erdos/stencil/blob/master/src/stencil/api.clj"
click node_cli "https://github.com/erdos/stencil/blob/master/java-src/io/github/erdos/stencil/Main.java"
click node_cli_args "https://github.com/erdos/stencil/blob/master/java-src/io/github/erdos/stencil/standalone/ArgsParser.java"
click node_stencil_args "https://github.com/erdos/stencil/blob/master/java-src/io/github/erdos/stencil/standalone/StencilArgsParser.java"
click node_standalone "https://github.com/erdos/stencil/blob/master/java-src/io/github/erdos/stencil/standalone/StandaloneApplication.java"
click node_factory "https://github.com/erdos/stencil/blob/master/java-src/io/github/erdos/stencil/impl/NativeTemplateFactory.java"
click node_dir_watch "https://github.com/erdos/stencil/blob/master/java-src/io/github/erdos/stencil/impl/DirWatcherTemplateFactory.java"
click node_file_helper "https://github.com/erdos/stencil/blob/master/java-src/io/github/erdos/stencil/impl/FileHelper.java"
click node_prepared "https://github.com/erdos/stencil/blob/master/java-src/io/github/erdos/stencil/PreparedTemplate.java"
click node_template_data "https://github.com/erdos/stencil/blob/master/java-src/io/github/erdos/stencil/TemplateData.java"
click node_variables "https://github.com/erdos/stencil/blob/master/java-src/io/github/erdos/stencil/TemplateVariables.java"
click node_process "https://github.com/erdos/stencil/blob/master/src/stencil/process.clj"
click node_grammar "https://github.com/erdos/stencil/blob/master/src/stencil/grammar.clj"
click node_evaluation "https://github.com/erdos/stencil/blob/master/src/stencil/eval.clj"
click node_functions "https://github.com/erdos/stencil/blob/master/java-src/io/github/erdos/stencil/functions/FunctionEvaluator.java"
click node_ooxml_model "https://github.com/erdos/stencil/blob/master/src/stencil/model.clj"
click node_ooxml "https://github.com/erdos/stencil/blob/master/src/stencil/ooxml.clj"
click node_html "https://github.com/erdos/stencil/blob/master/src/stencil/postprocess/html.clj"
click node_images "https://github.com/erdos/stencil/blob/master/src/stencil/postprocess/images.clj"
click node_links "https://github.com/erdos/stencil/blob/master/src/stencil/postprocess/links.clj"
click node_tables "https://github.com/erdos/stencil/blob/master/src/stencil/postprocess/table.clj"
click node_fragments "https://github.com/erdos/stencil/blob/master/src/stencil/postprocess/fragments.clj"
click node_evaluated "https://github.com/erdos/stencil/blob/master/java-src/io/github/erdos/stencil/EvaluatedDocument.java"
click node_service "https://github.com/erdos/stencil/blob/master/service/src/stencil/service.clj"

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_java_api,node_clj_api,node_cli,node_cli_args,node_stencil_args,node_standalone toneBlue
class node_factory,node_dir_watch,node_file_helper,node_prepared,node_template_data,node_variables toneAmber
class node_process,node_grammar,node_evaluation,node_functions,node_ooxml_model,node_ooxml toneMint
class node_html,node_images,node_links,node_tables,node_fragments toneRose
class node_evaluated,node_service,node_output,node_user toneIndigo
```

## Components

### Entry Points

- [Java API](https://github.com/erdos/stencil/blob/master/java-src/io/github/erdos/stencil/API.java): `java-src/io/github/erdos/stencil/API.java`
- [Clojure API](https://github.com/erdos/stencil/blob/master/src/stencil/api.clj): `src/stencil/api.clj`
- [CLI entry](https://github.com/erdos/stencil/blob/master/java-src/io/github/erdos/stencil/Main.java): `java-src/io/github/erdos/stencil/Main.java`
- [CLI arguments](https://github.com/erdos/stencil/blob/master/java-src/io/github/erdos/stencil/standalone/ArgsParser.java): `java-src/io/github/erdos/stencil/standalone/ArgsParser.java`
- [Stencil options](https://github.com/erdos/stencil/blob/master/java-src/io/github/erdos/stencil/standalone/StencilArgsParser.java): `java-src/io/github/erdos/stencil/standalone/StencilArgsParser.java`
- [Standalone runner](https://github.com/erdos/stencil/blob/master/java-src/io/github/erdos/stencil/standalone/StandaloneApplication.java): `java-src/io/github/erdos/stencil/standalone/StandaloneApplication.java`

### Template Preparation

- [Native factory](https://github.com/erdos/stencil/blob/master/java-src/io/github/erdos/stencil/impl/NativeTemplateFactory.java): `java-src/io/github/erdos/stencil/impl/NativeTemplateFactory.java`
- [Directory watcher](https://github.com/erdos/stencil/blob/master/java-src/io/github/erdos/stencil/impl/DirWatcherTemplateFactory.java): `java-src/io/github/erdos/stencil/impl/DirWatcherTemplateFactory.java`
- [File handling](https://github.com/erdos/stencil/blob/master/java-src/io/github/erdos/stencil/impl/FileHelper.java): `java-src/io/github/erdos/stencil/impl/FileHelper.java`
- [Prepared template](https://github.com/erdos/stencil/blob/master/java-src/io/github/erdos/stencil/PreparedTemplate.java): `java-src/io/github/erdos/stencil/PreparedTemplate.java`
- [Template data](https://github.com/erdos/stencil/blob/master/java-src/io/github/erdos/stencil/TemplateData.java): `java-src/io/github/erdos/stencil/TemplateData.java`
- [Template variables](https://github.com/erdos/stencil/blob/master/java-src/io/github/erdos/stencil/TemplateVariables.java): `java-src/io/github/erdos/stencil/TemplateVariables.java`

### Rendering Engine

- [Document processing](https://github.com/erdos/stencil/blob/master/src/stencil/process.clj): `src/stencil/process.clj`
- [Expression grammar](https://github.com/erdos/stencil/blob/master/src/stencil/grammar.clj): `src/stencil/grammar.clj`
- [Expression evaluation](https://github.com/erdos/stencil/blob/master/src/stencil/eval.clj): `src/stencil/eval.clj`
- [Template functions](https://github.com/erdos/stencil/blob/master/java-src/io/github/erdos/stencil/functions/FunctionEvaluator.java): `java-src/io/github/erdos/stencil/functions/FunctionEvaluator.java`
- [OOXML model](https://github.com/erdos/stencil/blob/master/src/stencil/model.clj): `src/stencil/model.clj`
- [OOXML handling](https://github.com/erdos/stencil/blob/master/src/stencil/ooxml.clj): `src/stencil/ooxml.clj`

### Document Features

- [HTML content](https://github.com/erdos/stencil/blob/master/src/stencil/postprocess/html.clj): `src/stencil/postprocess/html.clj`
- [Images](https://github.com/erdos/stencil/blob/master/src/stencil/postprocess/images.clj): `src/stencil/postprocess/images.clj`
- [Links](https://github.com/erdos/stencil/blob/master/src/stencil/postprocess/links.clj): `src/stencil/postprocess/links.clj`
- [Table editing](https://github.com/erdos/stencil/blob/master/src/stencil/postprocess/table.clj): `src/stencil/postprocess/table.clj`
- [Document fragments](https://github.com/erdos/stencil/blob/master/src/stencil/postprocess/fragments.clj): `src/stencil/postprocess/fragments.clj`

### Output and Service

- [Evaluated document](https://github.com/erdos/stencil/blob/master/java-src/io/github/erdos/stencil/EvaluatedDocument.java): `java-src/io/github/erdos/stencil/EvaluatedDocument.java`
- [Rendering service](https://github.com/erdos/stencil/blob/master/service/src/stencil/service.clj): `service/src/stencil/service.clj`
- **Document output**

### Other components

- **Template author**

## Connections

- Template author → Java API: supplies template (evidence: `README.md`)
- Template author → CLI entry: runs rendering (evidence: `README.md`)
- CLI entry → Stencil options: parses options (evidence: `java-src/io/github/erdos/stencil/Main.java`)
- Stencil options → CLI arguments: configures parser (evidence: `java-src/io/github/erdos/stencil/standalone/StencilArgsParser.java`)
- CLI entry → Standalone runner: starts runner (evidence: `java-src/io/github/erdos/stencil/Main.java`)
- Standalone runner → Java API: uses API (evidence: `java-src/io/github/erdos/stencil/standalone/StandaloneApplication.java`)
- Java API → Native factory: prepares template (evidence: `java-src/io/github/erdos/stencil/API.java`)
- Native factory → Prepared template: creates prepared
- Directory watcher → Native factory: delegates preparation (evidence: `java-src/io/github/erdos/stencil/impl/DirWatcherTemplateFactory.java`)
- Java API → Prepared template: renders template (evidence: `java-src/io/github/erdos/stencil/API.java`)
- Prepared template → Template data: consumes data (evidence: `java-src/io/github/erdos/stencil/PreparedTemplate.java`)
- Prepared template → Template functions: uses evaluator (evidence: `java-src/io/github/erdos/stencil/PreparedTemplate.java`)
- Prepared template → Evaluated document: produces document (evidence: `java-src/io/github/erdos/stencil/PreparedTemplate.java`)
- Prepared template → Template variables: exposes variables (evidence: `java-src/io/github/erdos/stencil/PreparedTemplate.java`)
- Clojure API → Document processing: invokes processing
- Document processing → Expression grammar: parses expressions
- Document processing → Expression evaluation: evaluates expressions
- Expression evaluation → Template functions: dispatches functions
- Document processing → OOXML model: transforms document
- OOXML model → OOXML handling: handles OOXML
- Document processing → HTML content: supports HTML (evidence: `README.md`)
- Document processing → Images: replaces images (evidence: `README.md`)
- Document processing → Links: replaces links (evidence: `README.md`)
- Document processing → Table editing: edits tables (evidence: `README.md`)
- Document processing → Document fragments: includes fragments
- Evaluated document → Document output: writes document (evidence: `java-src/io/github/erdos/stencil/EvaluatedDocument.java`)
- Template author → Rendering service: submits job (evidence: `README.md`)
