One Codebase, Five Targets: Inside go-pptx's Architecture

go-pptx Tech Blog · Part 10: Architecture Evolution and Cross-Platform Delivery — v2 Layering, engine, CLI, and WASM

Series: go-pptx Tech Blog (10 parts)
Baseline: v2.4.4
Keywords: ADR-030, facade convergence, engine, archlint, ECMA-376 generation pipeline, API tiers, CLI, WASM, cross-build

1. v1's architectural problem: facade and implementation entangled

v1's module root was both the "public facade" and the "implementation itself":

  • 63 non-test files, over 20,000 lines;
  • Presentation + Slide had more than 100 methods;
  • Public types and business implementation were 100% in the same package;
  • CLI, WASM, and IR each attached to the facade, prone to implementation drift;
  • Refactoring the implementation inevitably touched public signatures.

This was fine early in the project, but by v2 the bottleneck was obvious: the public API is frozen, yet the implementation needs to evolve freely. So ADR-030 came about.

2. ADR-030: A layered meta-repository

2.1 Target layout

go-pptx/ ├── go.mod / LICENSE / README.md # meta-repo root (no .go files) ├── pptx/ # public facade (the only package imported externally) ├── internal/ │ ├── document/ # domain logic │ │ ├── model/ style/ geometry/ text/ media/ table/ │ ├── opc/ xmlstore/ # transport/storage layer │ ├── ooxml/ + ooxml/schema/ # format layer (read-only projection) │ ├── engine/ # orchestration layer │ ├── ir/ # read-only IR + semantic diff │ ├── chart/ bind/ editplan/ ... # feature subsystems │ └── archlint/ # dependency-direction validation ├── cmd/pptx cmd/pptx_check # thin entry points ├── wasm/check wasm/site # browser side ├── render/ # public rendering contract (no implementation) ├── testdata/corpus/ # corpus index and public golden samples └── docs/ # ADRs, design, release notes 

Key changes:

  • The module root no longer has package pptx files;
  • The only official import path becomes github.com/F31/go-pptx/v2/pptx;
  • All implementation moves down into internal/, protected by Go language-level privacy;
  • The public facade holds only stable types and thin delegation.

This is a one-time breaking change (import path migration), in exchange for long-term implementation freedom.

2.2 Six key mechanisms

  1. Thin facade, thick domain: pptx/ holds only stable types and thin delegation; business logic lives in internal/document.
  2. OOXML type generation (read-only only): generate typed structures from the ECMA-376 XSD, replacing hand-written parsing.
  3. Tests travel with packages: code and tests migrate together, so coverage is naturally correct by package ownership.
  4. Unidirectional dependencies, enforced by CI: build a dependency-rule check with the std-lib, without introducing external arch-lint tools.
  5. cmd/wasm share the engine: CLI and WASM no longer each write their own set.
  6. Module root becomes a meta-repository: structural pressure drops to zero, and future file growth is distributed across subdomain packages.

3. engine: the shared core of CLI and WASM

internal/engine carries read-only orchestration:

  • Inspect: full IR projection;
  • Validate: structural validation + diagnostic grading;
  • Capability: six-dimensional capability manifest;
  • ProjectIR: facade → IR adapter.

Its constraints:

  • Depends only on the facade and the read-only IR;
  • Performs no I/O;
  • Is unaware of flag / exit code / stdout;
  • The caller is responsible for opening input and the output form.

This way CLI and WASM get the same source of truth, and there is no drift where "the CLI says supported, WASM says something else."

internal/engine is the only explicit exception to internal/* → pptx, because it needs the facade's public handles. This exception is registered in internal/archlint, not "let through casually."

4. archlint: turning dependency direction into a test

internal/archlint uses the standard library (go/parser / go list) to check:

  • internal/* must not import pptx in reverse (engine is the exception);
  • Except for engine, internal/* must not import internal/engine;
  • New packages must be registered;
  • Cross-layer imports must conform to the rules.

It runs via go test, so no extra CI tool is needed. This fits the project's "zero extra CI dependencies" policy.

The value is that the architecture diagram is not a drawing in documentation, but a constraint that makes CI fail. New packages silently going unchecked, or internal packages depending on the facade in reverse, both turn red immediately.

5. ECMA-376 generation pipeline: read-only projection, never touching the write path

5.1 What is generated

scripts/gen/schema generates Go types from the ECMA-376 Part 4 Transitional XSD:

  • 26 XSDs;
  • 8 namespaces, 7,300+ lines;
  • Generates read-only projection types in internal/ooxml/schema.

5.2 Why read-only

This is a hard constraint of ADR-030:

Generated types may only be used for read-only projection and must not enter the write path.

The reason is straightforward: encoding/xml round-tripping does not guarantee:

  • Attribute order;
  • Namespace prefix selection;
  • Self-closing form;
  • Whitespace.

Once generated types participate in writing, the three byte-level fidelity pieces of evidence immediately become invalid:

  • Empty change set → byte-identical;
  • TestSavePlanUnchangedIsB1;
  • ext-0024 single-Run replacement with a 1-byte difference.

So the write path is always:

xmlstore span patch + byte copy of unmodified Parts 

Generated types are used only for the read-side projection of internal/ooxml (slides / notes / timing / chart), for the engine to build the IR and auditing.

5.3 Pitfalls of the input source

ECMA-376 has two schema sets, Strict and Transitional. What the project needs is Part 4 Transitional (schemas.openxmlformats.org), not Part 1 Strict (purl.oclc.org). If this detail is gotten wrong, the generated types will not match real PPTX files.

6. API stability tiers: making upgrades predictable

6.1 Three-tier labels

Label Commitment
// Stable: Backward compatible, additive only, no breaks; behavior may be tightened but not loosened
API (default) Fields may be adjusted before v2.x is locked
// Deprecated: Retained for at least two minor versions, with a replacement entry point

Error codes / error types are Stable by default — error codes are a hard constraint of the compatibility contract.

6.2 Golden-sample gate

pptx/api_surface_test.go freezes the public surface into assertions. Counts for v2.4.4:

Item Count
Public API types 221
// Stable: paragraphs 73
Stable symbols 96
Stable methods 183
Exported methods 207
Top-level functions 44
Error sentinels 17
Constants 164

These numbers are not "marketing language," but a contract that test failures will block.

7. CLI: 9 subcommands, unified exit codes

pptx inspect deck.pptx pptx validate deck.pptx pptx replace --old Q3 --new Q4 --output out.pptx deck.pptx pptx bind --data data.json --output out.pptx template.pptx pptx narrate --manifest tracks.json --output narrated.pptx deck.pptx pptx timing-plan deck.pptx pptx export-ir --output deck.ir.json deck.pptx pptx capability pptx diff old.pptx new.pptx 

Exit codes:

Code Meaning
0 success
1 runtime / I/O error
2 usage error
3 capability / validation error
4 resource limit

CLI design principles:

  • JSON is written to stdout; progress/error summaries are written to stderr;
  • Read-only commands reject --output by default;
  • Write commands require --output, and overwriting requires --overwrite;
  • --help goes to stdout + exit 0; argument errors go to stderr + exit 2.

8. WASM: files never leave the device

8.1 Capabilities

wasm/check exposes three pure functions:

wasm/check.Inspect(ctx, pptxBytes, fileName) // IR projection JSON wasm/check.Validate(ctx, pptxBytes, fileName) // validation diagnostics JSON wasm/check.Capability(fileName) // capability manifest JSON 
  • Input exists only in wasm linear memory;
  • No filesystem writes;
  • No network access;
  • Returns JSON strings, convenient for consumption at the JS boundary.

8.2 Offline static page

wasm/site/ contains:

  • check.html
  • check.js
  • pptx_check.wasm generated by the build script
  • wasm_exec.js copied from GOROOT by the build script

Opening check.html directly in a modern browser is enough to use it; no server, no CDN, no backend needed.

Use cases:

  • Audits where client files cannot be uploaded, such as in law firms/healthcare/finance;
  • Client-side pre-checks before upload;
  • Capability confirmation in offline environments.

8.3 Build

GOOS=js GOARCH=wasm go build -o wasm/site/pptx_check.wasm ./cmd/pptx_check # or (also copies wasm_exec.js) bash scripts/check_wasm.sh 

9. Cross-build: five target classes

CI validates on every push/PR:

Target Purpose
js/wasm browser-side read-only check
wasip1/wasm WASI sandbox container
darwin/arm64 Apple Silicon
linux/arm64 ARM servers
windows/amd64 Windows server/desktop

All with CGO_ENABLED=0, no C toolchain dependency, and statically linkable into containers.

macOS/Windows also run the native test matrix (Go 1.24 / 1.27), avoiding "only Linux can pass."

10. Rendering contract: define the interface, don't pretend to implement

The render subpackage defines:

  • Renderer
  • RenderOptions
  • RenderCapabilities
  • RenderedSlide
  • RenderAll

But has no implementation. In Capability, the rendering.native status is Untested, and the documentation explicitly states "the interface has landed, but the implementation has not been scoped."

This is a deliberate boundary:

  • Native rendering would introduce heavy dependencies such as fonts, shaping, and layout;
  • It is not suitable to cram into the core SDK;
  • Third-party adapters can implement the interface, but must declare the capability scope;
  • Any preview capability must be labeled "limited preview" and must not be used to prove visual consistency with PowerPoint.

11. Roadmap and known limitations

11.1 Explicitly not done for now

  • Native rendering;
  • Writing of encryption/signature/OLE;
  • Full animation editing/playback evaluation;
  • In-place saving of source files;
  • Covering all OOXML features.

11.2 Evolution direction

  • 2.x patch line: coverage converging toward 90%, bug fixes, golden-sample guard reinforcement;
  • 2.1.x: the Open series adds ctx (a signature-level change, requiring an ADR + transition period);
  • 2.2.x: experimental capabilities are promoted or deprecated based on usage; deeper extraction within internal proceeds as triggered;
  • 3.0 (if started): native rendering scoped as an independent project.

11.3 Evolution principles

  • Do not break Stable;
  • API additions are the default;
  • Architectural pressure is split according to trigger conditions (merge-conflict hotspots / third-party extension needs / compile-time bottlenecks).

12. Ten-part retrospective

This series moves from "why do it" to "how to evolve":

  1. Overview: purpose, goals, architecture, competitors, capabilities;
  2. Byte-level fidelity: xmlstore + SpanPatch + B1;
  3. OPC and transactions: lazy indexing, budgets, SavePlan, atomic save;
  4. Object model and handles: cross-Run text, STALE-GUARD, monotonic IDs;
  5. Chart subsystem: 9 chart types, combination charts, workbooks, canonical;
  6. Media and auto-narration: pure Go probing, playback tree, timing plan;
  7. Template binding: plan/apply, zero residue;
  8. Read-only audit: IR, semantic diff, Capability;
  9. Quality engineering: corpus, golden samples, coverage, fuzz, L3;
  10. Architecture evolution and cross-platform: layering, engine, archlint, CLI, WASM.

If you had to summarize go-pptx's design philosophy in one sentence:

Treat "modifying a document" as a verifiable transaction: touch only the bytes you should, leave no half-finished product on failure, and state the capability boundaries clearly.

13. References and further reading

  • Repository: github.com/F31/go-pptx
  • Module: github.com/F31/go-pptx/v2
  • Facade: github.com/F31/go-pptx/v2/pptx
  • Documentation:
    • README.zh.md
    • docs/architecture-current.md
    • docs/go-pptx-技术白皮书-v2.0.md
    • docs/adr/ (ADR-014 to ADR-096)
    • docs/api-reference.md
    • CHANGELOG.md

Series navigation: ← Part 9: Quality Engineering · Back to Part 1: Overview