<?xml version="1.0" encoding="UTF-8"?>
<xao-docs>
  <site name="XaoDocs" product="Xao" version="1.0.0-dev" homepage="https://xao.ndx.au" repo="https://github.com/ndx-au/Xao" examples-repo="https://github.com/ndx-au/xao-example-apps"/>
  <request slug="architecture" theme="atlas" path="/xml/architecture" xml-url="/xml/architecture"/>
  <themes>
    <theme id="atlas" name="Atlas" tagline="Three-column reference desk with persistent sidebar and sticky page outline" audience="API and framework developers browsing across sections" structure="3-column grid: left navigation sidebar, center article, right on-this-page outline" css="/assets/atlas.css" active="true"/>
    <theme id="folio" name="Folio" tagline="Editorial journal spread with XPath-grouped numbered chapters and collapsible library" audience="Architects and evaluators reading long-form conceptual chapters" structure="Editorial cover header, collapsible library drawer, and sibling-grouped numbered chapter sections" css="/assets/folio.css" active="false"/>
    <theme id="console" name="Console" tagline="Operations dashboard with telemetry strip and collapsible H2 module accordions" audience="SREs, operators, and runtime engineers scanning sections quickly" structure="Command header, telemetry bar, compact nav rail, and expandable &lt;details&gt; module accordions" css="/assets/console.css" active="false"/>
    <theme id="reader" name="Reader (A11y)" tagline="WCAG AAA single-column linear reader with upfront summary, numbered TOC, and zero JS" audience="Screen reader users, keyboard-only navigation, and low-vision / cognitive accessibility" structure="Multi-landmark skip links, upfront document summary, inline numbered TOC, figure-wrapped code blocks, directory after article, zero JS" css="/assets/reader.css" active="false"/>
    <theme id="handbook" name="Handbook" tagline="Single-column print-ready technical specification sheet with metadata ledger" audience="Technical reviewers, auditors, and print/PDF export workflows" structure="Single-column specification document with &lt;dl&gt; metadata ledger, numbered outline, and print stylesheet" css="/assets/handbook.css" active="false"/>
  </themes>
  <navigation>
    <section name="Start Here">
      <item slug="index" title="Xao Documentation" description="XML Application Objects for PHP 8 and PHC — zero-dependency XML content aggregation and XSLT 3.0 presentation." order="1" active="false"/>
      <item slug="getting-started" title="Getting Started" description="Set up PHC, autoload Xao with zero Composer packages, transform your first DomDoc with XSLT 3.0, and run phc serve." order="2" active="false"/>
    </section>
    <section name="Core Concepts">
      <item slug="architecture" title="Architecture &amp; XML Aggregation" description="How Xao builds a unified XML conglomeration document from databases, Markdown, and domain objects before delegating presentation to XSLT 3.0." order="3" active="true"/>
      <item slug="xslt-themes" title="XSLT 3.0 Themes vs CSS Skins" description="Why XSLT themes are structurally and semantically richer than CSS-only themes — including accessibility-first DOM transformations." order="4" active="false"/>
    </section>
    <section name="Framework Reference">
      <item slug="core-api" title="Core API Reference" description="Reference for Xao\\Runtime, Xao\\XaoRoot, Xao\\DomDoc, Xao\\DomFactory, Xao\\AppDoc, Xao\\Http\\Response, and Xao\\Exceptions." order="5" active="false"/>
      <item slug="database-aggregation" title="Database Aggregation (DbToXml)" description="Convert PDO queries, PDOStatement results, and PHP iterables directly into structured DomDoc XML fragments under PHC." order="6" active="false"/>
      <item slug="markdown-aggregation" title="Markdown Aggregation" description="Convert CommonMark and GFM into CommonMark XML 1.0 natively in PHC via comrak and graft it into Xao DomDoc trees." order="7" active="false"/>
      <item slug="xslt-drivers" title="XSLT 3.0 Drivers" description="Pluggable XsltDriverInterface strategies: PhcNativeXsltDriver (default in-process), SaxonHttpDriver (HTTP/distributed), and ClientSideXslDriver." order="8" active="false"/>
    </section>
    <section name="Operations &amp; Runtime">
      <item slug="phc-runtime" title="PHC Runtime &amp; Compatibility" description="Running Xao on PHC in isolate and worker modes, sandbox defaults, worker-safe autoloading, and P00–P05 compatibility findings." order="9" active="false"/>
      <item slug="security" title="Security Model" description="XXE rejection, realpath containment, strict slug allowlists, CSRF guards, gated debug output, and PHC sandbox enforcement." order="10" active="false"/>
    </section>
    <section name="Examples &amp; Design">
      <item slug="reference-apps" title="Reference Applications" description="Comparing Xao's built-in SQLite PDO catalog reference app with XaoDocs, the flat-file Markdown multi-theme CMS." order="11" active="false"/>
      <item slug="adr-0001-phc-xee-xslt" title="ADR 0001 &amp; Roadmap" description="Architecture Decision Record for pure-Rust xee-xslt in PHC plus the Xao v1.0.0 milestone and phase roadmap (M0–M3, P00–P06)." order="12" active="false"/>
    </section>
  </navigation>
  <page slug="architecture" title="Architecture &amp; XML Aggregation" description="How Xao builds a unified XML conglomeration document from databases, Markdown, and domain objects before delegating presentation to XSLT 3.0." section="Core Concepts" audience="Application architects and backend developers" status="stable" words="311" reading-minutes="2" source-file="content/architecture.md">
    <tags>
      <tag>architecture</tag>
      <tag>aggregation</tag>
      <tag>domdoc</tag>
      <tag>appdoc</tag>
    </tags>
    <neighbors>
      <prev slug="getting-started" title="Getting Started"/>
      <next slug="xslt-themes" title="XSLT 3.0 Themes vs CSS Skins"/>
    </neighbors>
    <body>
      <document xmlns="http://commonmark.org/xml/1.0">
        <heading level="1">
          <text xml:space="preserve">Architecture &amp; XML Aggregation</text>
        </heading>
        <paragraph>
          <text xml:space="preserve">Xao is built around a single unifying architectural thesis: </text>
          <strong>
            <text xml:space="preserve">every request constructs one well-formed XML conglomeration document by aggregating heterogeneous data sources into a single DOM tree, then transforms that tree into the final representation via XSLT 3.0.</text>
          </strong>
        </paragraph>
        <code_block info="text" xml:space="preserve">  Relational DB (PDO / DbToXml) ──┐
  Static / File XML Fragments  ───┼──▶  DomDoc / AppDoc  ──▶  XsltDriverInterface (XSLT 3.0)  ──▶  HTML / XML / RSS / JSON
  External Feeds &amp; HTTP APIs   ───┤    (Conglomeration)         • PhcNativeXsltDriver (default, built-in xee-xslt)
  Domain DomDoc Objects        ───┤                             • SaxonHttpDriver (HTTP / distributed)
  Markdown to XML (CommonMark) ───┘                             • ClientSideXslDriver (fallback)
</code_block>
        <heading level="2">
          <text xml:space="preserve">Why XML Conglomeration Works</text>
        </heading>
        <list type="ordered" start="1" delim="period" tight="true">
          <item>
            <paragraph>
              <strong>
                <text xml:space="preserve">One data boundary, many outputs:</text>
              </strong>
              <text xml:space="preserve"> Because PHP produces a clean XML tree rather than concatenating HTML strings, the exact same </text>
              <code xml:space="preserve">DomDoc</code>
              <text xml:space="preserve"> can render HTML5, Atom/RSS, SVG, print-ready specs, or raw XML without changing PHP controllers.</text>
            </paragraph>
          </item>
          <item>
            <paragraph>
              <strong>
                <text xml:space="preserve">True separation of concerns:</text>
              </strong>
              <text xml:space="preserve"> PHP handles authentication, database queries, slug validation, Markdown parsing, and error normalization. XSLT 3.0 handles layout, grouping, navigation highlights, and accessibility landmarks.</text>
            </paragraph>
          </item>
          <item>
            <paragraph>
              <strong>
                <text xml:space="preserve">Inspectable page state:</text>
              </strong>
              <text xml:space="preserve"> During development or via dedicated endpoints like </text>
              <code xml:space="preserve">/xml/{slug}</code>
              <text xml:space="preserve"> in XaoDocs, the entire request model is inspectable as a single XML artifact.</text>
            </paragraph>
          </item>
          <item>
            <paragraph>
              <strong>
                <text xml:space="preserve">Stateless worker safety:</text>
              </strong>
              <text xml:space="preserve"> </text>
              <code xml:space="preserve">AppDoc</code>
              <text xml:space="preserve"> and </text>
              <code xml:space="preserve">DocsApp</code>
              <text xml:space="preserve"> hold zero mutable per-request static state, allowing </text>
              <code xml:space="preserve">phc serve</code>
              <text xml:space="preserve"> </text>
              <code xml:space="preserve">mode = "worker"</code>
              <text xml:space="preserve"> to reuse booted PHP workers across thousands of requests with zero state leakage.</text>
            </paragraph>
          </item>
        </list>
        <heading level="2">
          <text xml:space="preserve">Core Building Blocks</text>
        </heading>
        <table>
          <table_header>
            <table_cell>
              <text xml:space="preserve">Component</text>
            </table_cell>
            <table_cell>
              <text xml:space="preserve">Responsibility</text>
            </table_cell>
          </table_header>
          <table_row>
            <table_cell>
              <code xml:space="preserve">Xao\XaoRoot</code>
            </table_cell>
            <table_cell>
              <text xml:space="preserve">Structured, inspectable error tracking (</text>
              <code xml:space="preserve">addError</code>
              <text xml:space="preserve">, </text>
              <code xml:space="preserve">addException</code>
              <text xml:space="preserve">, </text>
              <code xml:space="preserve">hasErrors</code>
              <text xml:space="preserve">) without silent failures</text>
            </table_cell>
          </table_row>
          <table_row>
            <table_cell>
              <code xml:space="preserve">Xao\DomDoc</code>
            </table_cell>
            <table_cell>
              <text xml:space="preserve">Strict PHP 8 </text>
              <code xml:space="preserve">DOMDocument</code>
              <text xml:space="preserve"> / </text>
              <code xml:space="preserve">DOMXPath</code>
              <text xml:space="preserve"> wrapper for tree construction, XML/file consumption, namespace-aware nodes, and </text>
              <code xml:space="preserve">&lt;error&gt;</code>
              <text xml:space="preserve"> generation</text>
            </table_cell>
          </table_row>
          <table_row>
            <table_cell>
              <code xml:space="preserve">Xao\DomFactory</code>
            </table_cell>
            <table_cell>
              <text xml:space="preserve">Safe entrypoints (</text>
              <code xml:space="preserve">fromXml</code>
              <text xml:space="preserve">, </text>
              <code xml:space="preserve">fromFile</code>
              <text xml:space="preserve">, </text>
              <code xml:space="preserve">fromRoot</code>
              <text xml:space="preserve">) enforcing XXE/DOCTYPE rejection and </text>
              <code xml:space="preserve">realpath()</code>
              <text xml:space="preserve"> containment</text>
            </table_cell>
          </table_row>
          <table_row>
            <table_cell>
              <code xml:space="preserve">Xao\DbToXml</code>
            </table_cell>
            <table_cell>
              <text xml:space="preserve">Serializes </text>
              <code xml:space="preserve">PDO</code>
              <text xml:space="preserve"> queries, </text>
              <code xml:space="preserve">PDOStatement</code>
              <text xml:space="preserve">, and iterables into clean </text>
              <code xml:space="preserve">&lt;result&gt;&lt;row&gt;</code>
              <text xml:space="preserve"> XML trees</text>
            </table_cell>
          </table_row>
          <table_row>
            <table_cell>
              <code xml:space="preserve">Xao\AppDoc</code>
            </table_cell>
            <table_cell>
              <text xml:space="preserve">Stateless front controller pairing routes, gated debug output (</text>
              <code xml:space="preserve">?xao:XML=1</code>
              <text xml:space="preserve">), and XSLT 3.0 drivers</text>
            </table_cell>
          </table_row>
          <table_row>
            <table_cell>
              <code xml:space="preserve">Xao\Xslt\Transformer</code>
            </table_cell>
            <table_cell>
              <text xml:space="preserve">Enforces stylesheet-root </text>
              <code xml:space="preserve">realpath()</code>
              <text xml:space="preserve"> containment and delegates rendering to </text>
              <code xml:space="preserve">XsltDriverInterface</code>
            </table_cell>
          </table_row>
        </table>
        <heading level="2">
          <text xml:space="preserve">Explicit Non-Goals</text>
        </heading>
        <paragraph>
          <text xml:space="preserve">Xao intentionally avoids competing with full-stack ecosystems like Laravel or Symfony:</text>
        </paragraph>
        <list type="bullet" tight="true">
          <item>
            <paragraph>
              <text xml:space="preserve">No backwards compatibility with PHP 4 </text>
              <code xml:space="preserve">domxml</code>
              <text xml:space="preserve">, Sablotron </text>
              <code xml:space="preserve">xslt_*</code>
              <text xml:space="preserve">, or PEAR </text>
              <code xml:space="preserve">DB</code>
              <text xml:space="preserve">.</text>
            </paragraph>
          </item>
          <item>
            <paragraph>
              <text xml:space="preserve">No Composer runtime dependency tree in core </text>
              <code xml:space="preserve">src/</code>
              <text xml:space="preserve">.</text>
            </paragraph>
          </item>
          <item>
            <paragraph>
              <text xml:space="preserve">No unsafe C </text>
              <code xml:space="preserve">libxslt</code>
              <text xml:space="preserve"> FFI bindings inside PHC (</text>
              <code xml:space="preserve">#![forbid(unsafe_code)]</code>
              <text xml:space="preserve">).</text>
            </paragraph>
          </item>
        </list>
      </document>
    </body>
  </page>
</xao-docs>
