Purpose
This page explains Ceradoc’s architecture, including the data flow pipeline and layer structure. Understanding the architecture helps you use Ceradoc effectively and extend it when needed.
Data Flow Pipeline
Ceradoc processes documents through a hub-and-spoke pipeline:
┌─────────────┐
│ Input │
│ (adoc/md/ │
│ html/docx) │
└─────┬───────┘
│
▼
┌─────────────┐
│ Parser │
│ (format- │
│ specific) │
└─────┬───────┘
│
▼
┌─────────────┐
│ ToCoreModel │
│ Transformer │
└─────┬───────┘
│
▼
┌─────────────┐
│ CoreModel │
│ Hub │
└─────┬───────┘
│
┌───────────┴───────────┐
▼ ▼
┌──────────┐ ┌──────────┐
│FromCore │ │ Query / │
│ Model │ │ Validate │
│Transform │ │ / Edit │
└────┬─────┘ └──────────┘
│
▼
┌──────────┐
│Serialize │
│ Output │
│(adoc/md/ │
│ html) │
└──────────┘Pipeline Stages
-
Input - Text or file is received (AsciiDoc, Markdown, HTML, or DOCX)
-
Parser - Format-specific parser produces a format model tree
-
ToCoreModel - Transforms format model into canonical CoreModel
-
CoreModel - Hub representation; can be queried, validated, or edited
-
FromCoreModel - Transforms CoreModel to a target format model
-
Serialize - Produces output text
DOCX Pipeline
DOCX files follow a specialized path through Uniword:
DOCX file → Uniword::DocumentFactory.from_file → OOXML model tree (Uniword::Wordprocessingml::*) → Ceradoc::Docx::Transform::ToCoreModel (rule-based dispatch) → CoreModel tree (canonical hub) → FromCoreModel (AsciiDoc or Markdown) → Format model tree → Serializer → .adoc or .md file
The DOCX transform uses a rule registry with priority-based dispatch. Each OOXML element type has a dedicated rule class that produces a typed CoreModel node. Style-based semantic detection (headings, lists, quotes) is handled by StyleResolver and NumberingResolver.
Layer Structure
Ceradoc is organized into logical layers:
Parser Layer
Location: lib/ceradoc/parser/
Parses AsciiDoc text using Parslet parsing expressions. This layer produces an AST that represents the syntactic structure of the input.
Transformer Layer
Location: lib/ceradoc/transformer.rb
Converts the AST into Model objects. This is where syntactic structures become semantic document elements.
Model Layer
Location: lib/ceradoc/model/
Defines the document structure as Ruby objects. All model elements inherit from Ceradoc::Model::Base.
Model Class Hierarchy
┌─────────────────────────┐
│ Ceradoc::Model::Base │
│ (All Model classes │
│ inherit from Base) │
└───────────────┬─────────────┘
│
┌───────────────────┴───────────────┐
│ │
┌─────────┴────────┐ ┌──────────────┴─────────────┐
│ │ │ │
┌───┴──┐ ┌───┴──┐ │ ┌──────┴──────┐ ┌──────┴──────┐
│Block│ │List │ │ │ Section │ │ Inline │
│ │ │ │ │ │ │ │ │
└───┬──┘ └───┬──┘ │ └──────┬──────┘ └──────────────┘
│ │ │ │
│ ┌─────────┴─────│──────────┘
│ │ │
│ ┌───┴────────┐ ┌──┴──────────┐
│ │ │ │ │
└───┴──Paragraph│ │Ordered │
│Unordered │ │Definition │
│ │ │ │
└────────────┘ └─────────────┘Key Design Principles
Related Documentation
-
Parsing Layer - Detailed parser documentation
-
Transformation Layer - Transformer explanation
-
Document Model - Model class details
-
Serialization - Serializer architecture
Bibliography
-
Parslet - Parsing expression grammar library
-
lutaml-model - Model definition library