# iofficeai/officecli architecture

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

- Interactive diagram: https://gitdiagram.com/iofficeai/officecli
- Repository: https://github.com/iofficeai/officecli

## Overview

#### Purpose and entry points
OfficeCLI is a self-contained, cross-platform .NET CLI for creating, reading, modifying, validating, rendering, and batch-processing OOXML Word, Excel, and PowerPoint files without Office. Main process entry is `src/officecli/Program.cs`; command registration/parsing is centralized in `src/officecli/CommandBuilder.cs`. Distribution wrappers include `install.sh`, `install.ps1`, and the npm launcher `npm/officecli.js`.

#### Command and document dispatch
The command layer maps create/view/get/query/mutation, raw XML, batch, merge, watch, install, plugins, resident, and MCP commands to shared operations and format handlers. `src/officecli/CommandBuilder.Batch.cs` defines batch command wiring; `src/officecli/Handlers/DocumentHandlerFactory.cs` selects the handler from file type; `src/officecli/Core/IDocumentHandler.cs` is the principal format boundary.

#### Format-specific OOXML manipulation
Three large handler families implement the semantic DOM and OOXML mutations:
- Word: `src/officecli/Handlers/WordHandler.cs`, `src/officecli/Handlers/Word/WordHandler.Set.Dispatch.cs`, `src/officecli/Handlers/Word/WordBatchEmitter.cs`
- Excel: `src/officecli/Handlers/ExcelHandler.cs`, `src/officecli/Handlers/Excel/ExcelHandler.Set.cs`, `src/officecli/Handlers/Excel/ExcelBatchEmitter.cs`
- PowerPoint: `src/officecli/Handlers/PowerPointHandler.cs`, `src/officecli/Handlers/Pptx/PowerPointHandler.Mutations.cs`, `src/officecli/Handlers/Pptx/PptxBatchEmitter.cs`

Handlers expose stable path/selector-based elements, while batch emitters serialize document structure into replayable operations. Raw XML commands remain an explicit escape hatch via `src/officecli/Core/RawXmlHelper.cs`.

#### Shared document engines
Core services own cross-format capabilities: atomic package persistence (`src/officecli/Core/AtomicPackageWriter.cs`), template placeholder replacement (`src/officecli/Core/TemplateMerger.cs`), native chart construction/rendering (`src/officecli/Core/Chart/ChartHelper.cs`), Mermaid parsing/layout into editable diagrams (`src/officecli/Core/Diagram/DiagramCompiler.cs`), and Excel formula evaluation (`src/officecli/Core/Formula/FormulaEvaluator.cs`). These services are invoked by handlers rather than exposed as independent applications.

#### Rendering, preview, and quality loop
Handlers generate render inputs for a common renderer registry, producing HTML/SVG/screenshots and document issue views. Key boundary paths are `src/officecli/Core/Rendering/RendererRegistry.cs`, `src/officecli/Handlers/Rendering/BasicRenderers.cs`, and format-specific preview emitters such as `src/officecli/Handlers/Pptx/PowerPointHandler.HtmlPreview.cs`. PNG screenshot generation uses a headless-browser path (`src/officecli/Core/HtmlScreenshot.cs`). `watch` serves a local auto-refresh preview through `src/officecli/Core/Watch/WatchServer.cs`.

#### Stateful and agent-facing integration
Resident mode keeps documents in memory across CLI calls over local IPC, deferring or controlling disk flushes: `src/officecli/ResidentServer.cs`, `src/officecli/ResidentClient.cs`, `src/officecli/Core/ResidentFlushPolicy.cs`. The MCP server exposes document operations over JSON-RPC for agent clients (`src/officecli/McpServer.cs`, `src/officecli/McpInstaller.cs`). Thin Node and Python SDKs use this resident protocol: `sdk/node/index.js` and `sdk/python/officecli.py`.

#### Extensibility, contracts, and delivery
Plugin processes provide format handlers, exporters, and dump readers behind an isolated protocol: `src/officecli/Core/Plugins/PluginRegistry.cs`, `src/officecli/Core/Plugins/PluginProcess.cs`, `plugins/plugin-protocol.md`. JSON help schemas define the supported semantic command surface and are loaded at runtime from `schemas/help/` through `src/officecli/Help/SchemaHelpLoader.cs`. Builds require .NET 10 but publish self-contained native binaries via `build.sh`; release packaging targets npm, PyPI, and SDK channels through `.github/workflows/publish-npm.yml`, `.github/workflows/publish-pypi.yml`, and `.github/workflows/publish-sdk.yml`.

Main entry points: [`src/officecli/CommandBuilder.cs`](https://github.com/iofficeai/officecli/blob/main/src/officecli/CommandBuilder.cs) (Command builder), [`src/officecli/Core/Rendering/RendererRegistry.cs`](https://github.com/iofficeai/officecli/blob/main/src/officecli/Core/Rendering/RendererRegistry.cs) (Renderer registry), [`src/officecli/Core/IDocumentHandler.cs`](https://github.com/iofficeai/officecli/blob/main/src/officecli/Core/IDocumentHandler.cs) (Document handler contract), [`src/officecli/Handlers/WordHandler.cs`](https://github.com/iofficeai/officecli/blob/main/src/officecli/Handlers/WordHandler.cs) (Word handler)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_cli["CLI &amp; Contracts"]
  node_program["CLI entry<br/>dotnet entry point<br/>[Program.cs]"]
  node_commands["Command builder<br/>command parsing<br/>[CommandBuilder.cs]"]
  node_help["Help schemas<br/>runtime contracts"]
end

subgraph group_formats["OOXML Handlers"]
  node_factory["Handler factory<br/>format dispatch"]
  node_handler_contract["Document handler contract<br/>format boundary"]
  node_word["Word handler<br/>DOCX semantic DOM<br/>[WordHandler.cs]"]
  node_excel["Excel handler<br/>XLSX semantic DOM<br/>[ExcelHandler.cs]"]
  node_powerpoint["PowerPoint handler<br/>PPTX semantic DOM"]
end

subgraph group_core["Shared Engines"]
  node_raw_xml["Raw XML helper<br/>OOXML escape hatch<br/>[RawXmlHelper.cs]"]
  node_package_writer["Atomic package writer<br/>package persistence"]
  node_document_engines["Document engines<br/>cross-format services<br/>[TemplateMerger.cs]"]
  node_render_registry["Renderer registry<br/>render dispatch"]
  node_renderers["Basic renderers<br/>HTML/SVG renderers<br/>[BasicRenderers.cs]"]
  node_screenshots["HTML screenshots<br/>headless browser rendering<br/>[HtmlScreenshot.cs]"]
  node_watch["Watch server<br/>local preview server<br/>[WatchServer.cs]"]
end

subgraph group_integration["Stateful &amp; External Access"]
  node_resident["Resident server<br/>local IPC service<br/>[ResidentServer.cs]"]
  node_mcp["MCP server<br/>JSON-RPC server<br/>[McpServer.cs]"]
  node_plugins["Plugin registry<br/>isolated extension host<br/>[PluginRegistry.cs]"]
  node_sdks["Node &amp; Python SDKs<br/>client SDKs<br/>[index.js]"]
end

subgraph group_delivery["Distribution"]
  node_release["Release channels<br/>packaging workflows<br/>[publish-npm.yml]"]
end

node_program -->|"starts"| node_commands
node_commands -->|"loads help"| node_help
node_commands -->|"dispatches document commands"| node_factory
node_factory -->|"selects implementation"| node_handler_contract
node_handler_contract -->|"implemented by"| node_word
node_handler_contract -->|"implemented by"| node_excel
node_handler_contract -->|"implemented by"| node_powerpoint
node_commands -->|"raw XML commands"| node_raw_xml
node_word -->|"uses"| node_document_engines
node_excel -->|"uses"| node_document_engines
node_powerpoint -->|"uses"| node_document_engines
node_word -->|"persists packages"| node_package_writer
node_excel -->|"persists packages"| node_package_writer
node_powerpoint -->|"persists packages"| node_package_writer
node_word -->|"supplies render input"| node_render_registry
node_excel -->|"supplies render input"| node_render_registry
node_powerpoint -->|"supplies render input"| node_render_registry
node_render_registry -->|"selects renderer"| node_renderers
node_renderers -->|"HTML to PNG"| node_screenshots
node_commands -->|"watch command"| node_watch
node_watch -->|"refreshes previews"| node_render_registry
node_commands -->|"resident command"| node_resident
node_sdks -->|"local IPC"| node_resident
node_commands -->|"MCP command"| node_mcp
node_commands -->|"loads extensions"| node_plugins
node_release -.->|"packages CLI"| node_program

click node_program "https://github.com/iofficeai/officecli/blob/main/src/officecli/Program.cs"
click node_commands "https://github.com/iofficeai/officecli/blob/main/src/officecli/CommandBuilder.cs"
click node_help "https://github.com/iofficeai/officecli/blob/main/src/officecli/Help/SchemaHelpLoader.cs"
click node_factory "https://github.com/iofficeai/officecli/blob/main/src/officecli/Handlers/DocumentHandlerFactory.cs"
click node_handler_contract "https://github.com/iofficeai/officecli/blob/main/src/officecli/Core/IDocumentHandler.cs"
click node_word "https://github.com/iofficeai/officecli/blob/main/src/officecli/Handlers/WordHandler.cs"
click node_excel "https://github.com/iofficeai/officecli/blob/main/src/officecli/Handlers/ExcelHandler.cs"
click node_powerpoint "https://github.com/iofficeai/officecli/blob/main/src/officecli/Handlers/PowerPointHandler.cs"
click node_raw_xml "https://github.com/iofficeai/officecli/blob/main/src/officecli/Core/RawXmlHelper.cs"
click node_package_writer "https://github.com/iofficeai/officecli/blob/main/src/officecli/Core/AtomicPackageWriter.cs"
click node_document_engines "https://github.com/iofficeai/officecli/blob/main/src/officecli/Core/TemplateMerger.cs"
click node_render_registry "https://github.com/iofficeai/officecli/blob/main/src/officecli/Core/Rendering/RendererRegistry.cs"
click node_renderers "https://github.com/iofficeai/officecli/blob/main/src/officecli/Handlers/Rendering/BasicRenderers.cs"
click node_screenshots "https://github.com/iofficeai/officecli/blob/main/src/officecli/Core/HtmlScreenshot.cs"
click node_watch "https://github.com/iofficeai/officecli/blob/main/src/officecli/Core/Watch/WatchServer.cs"
click node_resident "https://github.com/iofficeai/officecli/blob/main/src/officecli/ResidentServer.cs"
click node_mcp "https://github.com/iofficeai/officecli/blob/main/src/officecli/McpServer.cs"
click node_plugins "https://github.com/iofficeai/officecli/blob/main/src/officecli/Core/Plugins/PluginRegistry.cs"
click node_sdks "https://github.com/iofficeai/officecli/blob/main/sdk/node/index.js"
click node_release "https://github.com/iofficeai/officecli/blob/main/.github/workflows/publish-npm.yml"

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_program,node_commands,node_help toneBlue
class node_factory,node_handler_contract,node_word,node_excel,node_powerpoint toneAmber
class node_raw_xml,node_package_writer,node_document_engines,node_render_registry,node_renderers,node_screenshots,node_watch toneMint
class node_resident,node_mcp,node_plugins,node_sdks toneRose
class node_release toneIndigo
```

## Components

### CLI & Contracts

- [CLI entry](https://github.com/iofficeai/officecli/blob/main/src/officecli/Program.cs): dotnet entry point · `src/officecli/Program.cs`
- [Command builder](https://github.com/iofficeai/officecli/blob/main/src/officecli/CommandBuilder.cs): command parsing · Registers document, batch, watch, plugin, resident, and MCP commands. · `src/officecli/CommandBuilder.cs`
- [Help schemas](https://github.com/iofficeai/officecli/blob/main/src/officecli/Help/SchemaHelpLoader.cs): runtime contracts · Loads the semantic command surface from JSON schemas. · `src/officecli/Help/SchemaHelpLoader.cs`

### OOXML Handlers

- [Handler factory](https://github.com/iofficeai/officecli/blob/main/src/officecli/Handlers/DocumentHandlerFactory.cs): format dispatch · `src/officecli/Handlers/DocumentHandlerFactory.cs`
- [Document handler contract](https://github.com/iofficeai/officecli/blob/main/src/officecli/Core/IDocumentHandler.cs): format boundary · `src/officecli/Core/IDocumentHandler.cs`
- [Word handler](https://github.com/iofficeai/officecli/blob/main/src/officecli/Handlers/WordHandler.cs): DOCX semantic DOM · Supports selector-based mutations and batch emission. · `src/officecli/Handlers/WordHandler.cs`
- [Excel handler](https://github.com/iofficeai/officecli/blob/main/src/officecli/Handlers/ExcelHandler.cs): XLSX semantic DOM · Supports selector-based mutations and batch emission. · `src/officecli/Handlers/ExcelHandler.cs`
- [PowerPoint handler](https://github.com/iofficeai/officecli/blob/main/src/officecli/Handlers/PowerPointHandler.cs): PPTX semantic DOM · Supports mutations, batch emission, and preview output. · `src/officecli/Handlers/PowerPointHandler.cs`

### Shared Engines

- [Raw XML helper](https://github.com/iofficeai/officecli/blob/main/src/officecli/Core/RawXmlHelper.cs): OOXML escape hatch · `src/officecli/Core/RawXmlHelper.cs`
- [Atomic package writer](https://github.com/iofficeai/officecli/blob/main/src/officecli/Core/AtomicPackageWriter.cs): package persistence · `src/officecli/Core/AtomicPackageWriter.cs`
- [Document engines](https://github.com/iofficeai/officecli/blob/main/src/officecli/Core/TemplateMerger.cs): cross-format services · Template merge, charts, diagrams, and formula evaluation invoked by handlers. · `src/officecli/Core/TemplateMerger.cs`
- [Renderer registry](https://github.com/iofficeai/officecli/blob/main/src/officecli/Core/Rendering/RendererRegistry.cs): render dispatch · `src/officecli/Core/Rendering/RendererRegistry.cs`
- [Basic renderers](https://github.com/iofficeai/officecli/blob/main/src/officecli/Handlers/Rendering/BasicRenderers.cs): HTML/SVG renderers · Produces render and issue-view outputs. · `src/officecli/Handlers/Rendering/BasicRenderers.cs`
- [HTML screenshots](https://github.com/iofficeai/officecli/blob/main/src/officecli/Core/HtmlScreenshot.cs): headless browser rendering · Generates PNG screenshots from HTML previews. · `src/officecli/Core/HtmlScreenshot.cs`
- [Watch server](https://github.com/iofficeai/officecli/blob/main/src/officecli/Core/Watch/WatchServer.cs): local preview server · Serves auto-refresh document previews. · `src/officecli/Core/Watch/WatchServer.cs`

### Stateful & External Access

- [Resident server](https://github.com/iofficeai/officecli/blob/main/src/officecli/ResidentServer.cs): local IPC service · Keeps documents in memory and controls disk flushes. · `src/officecli/ResidentServer.cs`
- [MCP server](https://github.com/iofficeai/officecli/blob/main/src/officecli/McpServer.cs): JSON-RPC server · Exposes document operations to agent clients. · `src/officecli/McpServer.cs`
- [Plugin registry](https://github.com/iofficeai/officecli/blob/main/src/officecli/Core/Plugins/PluginRegistry.cs): isolated extension host · Discovers external format handlers, exporters, and dump readers. · `src/officecli/Core/Plugins/PluginRegistry.cs`
- [Node & Python SDKs](https://github.com/iofficeai/officecli/blob/main/sdk/node/index.js): client SDKs · Use the resident protocol. · `sdk/node/index.js`

### Distribution

- [Release channels](https://github.com/iofficeai/officecli/blob/main/.github/workflows/publish-npm.yml): packaging workflows · Publishes npm, PyPI, and SDK distributions. · `.github/workflows/publish-npm.yml`

## Connections

- CLI entry → Command builder: starts
- Command builder → Help schemas: loads help
- Command builder → Handler factory: dispatches document commands
- Handler factory → Document handler contract: selects implementation
- Document handler contract → Word handler: implemented by
- Document handler contract → Excel handler: implemented by
- Document handler contract → PowerPoint handler: implemented by
- Command builder → Raw XML helper: raw XML commands
- Word handler → Document engines: uses
- Excel handler → Document engines: uses
- PowerPoint handler → Document engines: uses
- Word handler → Atomic package writer: persists packages
- Excel handler → Atomic package writer: persists packages
- PowerPoint handler → Atomic package writer: persists packages
- Word handler → Renderer registry: supplies render input
- Excel handler → Renderer registry: supplies render input
- PowerPoint handler → Renderer registry: supplies render input
- Renderer registry → Basic renderers: selects renderer
- Basic renderers → HTML screenshots: HTML to PNG
- Command builder → Watch server: watch command
- Watch server → Renderer registry: refreshes previews
- Command builder → Resident server: resident command
- Node & Python SDKs → Resident server: local IPC
- Command builder → MCP server: MCP command
- Command builder → Plugin registry: loads extensions
- Release channels → CLI entry: packages CLI
