1. Every format goes through one canonical Document, with plugins at the edges
Context
The service handles UTF-8 Markdown only, and each operation (VitePress formatting, AI enhancement, translation) is a separate flow with its own route, service and response shape. The roadmap (#91) adds input formats (PDF, Office, HTML, images), processing steps (summary, rewrite, structured extraction) and output formats (DOCX, PDF, JSON). Wired as they are, each format would multiply the routes, and each new step would have to handle each format.
The alternatives considered:
- Keep one flow per operation, adding formats inside each. Cheapest today; every new step costs one change per format, and every format one change per step.
- Convert everything to Markdown at the edge and keep Markdown strings inside. Simple, but it loses what Markdown cannot hold (page numbers for citations, table cells, image positions), which the extraction and RAG steps need.
- One canonical
Document(source, metadata, ordered blocks with their provenance) between extractors, processors and exporters.
Decision
Every input is extracted into one canonical Document; processing steps take a Document and produce an Artifact; exporters write an artifact out in one format. Extractor, Processor and Exporter are ports (typing.Protocol), implemented by plugins registered through entry_points. The domain imports no web framework, HTTP client or LLM SDK. A pipeline is a declarative, validated list of steps and exports.
The current behavior becomes plugins without changing the public routes: a markdown extractor, vitepress-format, enhance and translate processors, and a vitepress exporter (#84).
Consequences
- A new format is one extractor or one exporter, and every processor works on it at once; a new processor works on every format.
- The
Documentmodel becomes the contract every plugin depends on: changing it is costly, so it starts small (the blocks defined in the repository'sGLOSSARY.md) and grows by optional fields. - Markdown-specific steps (VitePress containers, frontmatter) must go through
Document.to_markdown()or keep raw Markdown blocks, which adds a conversion the current code does not have. - Long pipelines lead to background jobs (#86): the request/response routes stay for short documents.