% Deutsch: Architekturübersicht; benötigt die unten genannten TikZ-Bibliotheken.
% English: Architecture overview; requires the TikZ libraries named below.
% \usetikzlibrary{arrows.meta,backgrounds,fit,positioning}
\begin{tikzpicture}[
  font=\sffamily\footnotesize,
  >={Stealth[length=2mm]},
  flow/.style={->, semithick, draw=black!70},
  late/.style={->, semithick, dashed, draw=blue!65!black},
  box/.style={
    draw=black!65,
    rounded corners=1.5pt,
    align=center,
    text width=26mm,
    inner sep=2mm,
    fill=white
  },
  source/.style={box, fill=orange!12},
  semantic/.style={box, fill=green!11},
  execution/.style={box, fill=blue!9},
  owner/.style={box, fill=violet!10},
  phase/.style={box, minimum height=15mm, fill=blue!7},
  boundary/.style={
    draw=black!35,
    rounded corners=3pt,
    dashed,
    inner sep=3mm
  },
  zonelabel/.style={font=\sffamily\scriptsize\bfseries, text=black!65, label distance=0.5mm}
]

% Deutsch: Oben liegt die semantische Pipeline. PDF-Objektidentitäten enden am
% Inspector; danach kommunizieren alle Komponenten über die kanonische IR.
% English: The top row is the semantic pipeline. PDF object identities end at
% the inspector; later components communicate through canonical IR.
\node[source] (pdf) {Tagged source PDF\\[1pt]
  \scriptsize pages, structure, links, destinations};
\node[semantic, right=9mm of pdf] (inspect) {Inspector\\[1pt]
  \texttt{tagpax.lua}};
\node[semantic, right=5mm of inspect] (ir) {Canonical IR\\[1pt]
  \scriptsize\texttt{.tagpax} / Lua tables};
\node[semantic, right=5mm of ir] (validate) {Validation and planning\\[1pt]
  \texttt{validate.lua}\\ \texttt{import.lua}};

\draw[flow] (pdf) -- (inspect);
\draw[flow] (inspect) -- (ir);
\draw[flow] (ir) -- (validate);

% Deutsch: Form- und Annotationsreferenzen entstehen spät; die drei Boxen zeigen
% diese zeitliche Abhängigkeit, nicht drei verschiedene IRs.
% English: Form and annotation references are allocated late; the three boxes
% show this timing constraint, not three distinct IRs.
\node[phase, below=17mm of inspect] (reserve) {
  \textbf{1. Reserve}\\[2pt]
  StructElems and\\ordered MCR/OBJR slots};
\node[phase, right=6mm of reserve] (write) {
  \textbf{2. Write and bind}\\[2pt]
  page Forms, geometry,\\destinations, annotations};
\node[phase, right=6mm of write] (finalize) {
  \textbf{3. Finalize}\\[2pt]
  MCID bindings and\\ParentTree arrays};

% Deutsch: Zeilenübergreifende Kanten knicken im freien Zwischenraum und
% berühren dadurch keine Nachbarbox.
% English: Cross-row connectors bend in the open gap and do not touch adjacent
% boxes.
\draw[flow] (ir.south) -- ++(0,-7mm) -| (reserve.north);
\draw[flow] (reserve) -- (write);
\draw[flow] (write) -- (finalize);

% Deutsch: Der Seitenschreiber öffnet die Quelle nur für Inhalt und Geometrie;
% semantische Objekte stammen ausschließlich aus der IR.
% English: The page writer opens the source only for content and geometry;
% semantic objects come exclusively from the IR.
\draw[late] (pdf.south) -- ++(0,-11mm) -| (write.north)
  node[pos=0.25, above, font=\scriptsize, text=blue!65!black] {raw page content only};

\node[owner, below=17mm of write] (bridge) {Isolated \texttt{tagpdf} bridge\\[1pt]
  \scriptsize explicit parents, deferred references};
\node[owner, right=10mm of bridge] (master) {Tagged master PDF\\[1pt]
  \scriptsize one StructTreeRoot and ParentTree};

\draw[flow] (finalize.south) -- ++(0,-11mm) -| (bridge.north);
\draw[flow] (bridge) -- (master);

% Deutsch: Gestrichelte Rahmen markieren Zuständigkeiten, keine zusätzlichen
% Laufzeitkomponenten; tagpdf bleibt Eigentümer der globalen Bäume.
% English: Dashed frames mark ownership, not additional runtime components;
% tagpdf remains the owner of global trees.
\begin{scope}[on background layer]
  \node[boundary, fit=(inspect)(ir)(validate),
    label={[zonelabel]above:semantic layer}] {};
  \node[boundary, fit=(reserve)(write)(finalize),
    label={[zonelabel]below:TeX-facing execution}] {};
  \node[boundary, fit=(bridge)(master),
    label={[zonelabel]below:LaTeX PDF management / \texttt{tagpdf} ownership}] {};
\end{scope}

\end{tikzpicture}
