J. Rogers, SE Ohio
Architecture Design Document
1. Executive Summary
2. Design Philosophy & Core Principles
Single Source of Truth: The code executed by the engine is the same code displayed to the user.Determinism: The build process resets the environment state (e.g., in-memory databases, CPU registers) prior to execution to ensure reproducibility.Polymorphism: The Core Engine traverses the content tree but delegates execution logic to specialized Plugins based on content type.Zero-Drift: Documentation is not written; it is generated as a byproduct of successful code execution.
3. System Architecture
The Content Tree (Data Layer): A recursive directory structure containing metadata and source files.The Core Engine (Control Layer): Handles traversal, context management, layout generation, and plugin dispatch.The Plugin Registry (Logic Layer): Domain-specific handlers that execute code and return HTML fragments.
3.1 The Content Tree
{ "title": "String Literal Matching",
"type": "regex", // 'group' for folders, specific key for leaves
"description": "Matching exact character sequences.",
"order": 1,
"citations": [
{ "source": "MDN Web Docs", "url": "https://..." }
]
}
3.2 The Core Engine
Initializing the Global Context (e.g., shared database connections). Recursively walking the Content Tree. Building navigation structures (Breadcrumbs, Sidebars, TOC). Routing Leaf Nodes to the appropriate Plugin based on the type field in meta.json. Wrapping Plugin output in standard HTML templates (Headers, Footers, SEO metadata).
3.3 The Plugin System
class ContentPlugin: def execute(self, path: Path, context: Dict) -> str:
"""
Args:
path: Filesystem path to the leaf node.
context: The mutable global state dictionary.
Returns:
HTML string fragment representing the example body.
"""
pass
4. Detailed Component Specifications
4.1 Context Management (State Persistence)
Isolated Mode: Plugins reset state internally (e.g., Regex engine).Story Mode: Plugins modify a shared object in the Context (e.g., an SQLite connection), allowing Example B to query data inserted by Example A.
4.2 Standard Plugins
Input: query.sql, description.html.Context: Shared SQLite Connection object.Behavior: Executes the SQL against the shared connection.Output: Renders the SQL syntax-highlighted code block and an HTML Table of the result set (or affected row count).
Input: pattern.txt, input.txt, description.html.Context: Stateless.Behavior: Compiles the pattern and runs re.finditer against input.Output: Renders the pattern and the input text with HTML <span> injection for match highlighting.
Input: instruction.asm.Context: Dictionary simulating CPU Registers (EAX, EBX) and Stack memory.Behavior: Parses and simulates the instruction's effect on registers.Output: Visual representation of the CPU state "Before" and "After" the instruction.
4.3 Attribution & Citation Layer
5. Execution Flow
Initialization: Engine starts. Plugins are registered (SQLPlugin, RegexPlugin, PhysicsPlugin). Global Context is initialized (e.g., sqlite3.connect(':memory:')).
Traversal: Engine reads root/. Iterates through subdirectories sorted by order field.
Dispatch: If type == "group": Engine generates a Chapter Index page and recurses. If type == "sql": Engine calls SQLPlugin.execute(path, context).
Rendering: Plugin returns HTML fragment. Engine injects fragment into master_template.html. Engine writes file to docs/path/to/example.html.
Deployment: The docs/ directory is published to a static web server (e.g., GitHub Pages).
6. Extensibility
Creating a directory content/03_Physics. Implementing a PhysicsPlugin class. Registering the plugin in the Engine config.
7. Deployment & Hosting
Build Artifact: Pure static HTML/CSS.Hosting: Compatible with any static host (GitHub Pages, Netlify, S3).CI/CD: The Generator Script is intended to run within a CI pipeline (e.g., GitHub Actions) upon every commit, ensuring immediate synchronization between the repository and the live documentation site.
No comments:
Post a Comment