Files
vpn-dns-gateway/demo/tikzrefinery/documents/latex/tkrSoftwareArchitecture.tex
vsun1 27b82c169e
vpn-dns-gateway/pipeline/head This commit looks good
vpn-dns-gateway/pipeline/pr-main This commit looks good
Add frozen TikZRefinery demo baseline and build pipeline
2026-11-25 22:46:33 -05:00

364 lines
20 KiB
TeX

\chapter{Software Architecture}\ChapterLabel{SoftwareArchitecture}
\index{software architecture}
\section{Scope and Evidence}
The \hyperref[FrontMatter:DiagramIndex]{List of Figures} links all active figures.
The repository's generated \path{documents/DIAGRAM_INDEX.md} and machine-readable
\path{documents/diagram-index.json} additionally locate editable sources,
current/planned status and physical pages in both editions. They support targeted
diagram review; material design changes still require whole-document impact
and layout review.
This chapter records C++/Qt MVC roles, ownership, class contracts and the
Windows Alpha deployment (Section~\ref{Section:AlphaDeployment}), adapting the
course architecture and component patterns. Broader logical, process and
development views remain deferred. Supporting activities appear in
\AppendixRef{DesignDocuments}; the implementation rationale is in
Section~\ref{Section:SelectedImplementationDesign}.
The current diagrams follow source. Section~\ref{Section:CurrentSidebarShell}
records the implemented 0.1.3-alpha sidebar shell; broader catalogue/creation
and shared-service ownership views remain separately planned. The loaded
rectangle module and development deployment are in
Section~\ref{Section:CurrentPlugin}. Historical packages and reports remain frozen; active diagrams describe 0.1.4-alpha. On October
20, 2026, the scaffold built successfully and its foundation test passed;
Vincent then confirmed that opening the box sample displayed its source.
Section~\ref{Section:NativeScaffoldCheck} records this limited evidence.
Rectangle, line and arrow display now have limited evidence in
Section~\ref{Section:SegmentDisplayCheck}. Whole-element dragging, cancellation,
save/reopen and saved-output comparisons follow in
Section~\ref{Section:WholeElementDragCheck}; endpoint editing, broader parsing
and LaTeX/PDF integration remain unfinished.
Neither the build nor these diagrams establish product acceptance.
\RequirementRef{REQ-DEV-006} aligns the Alpha application's version with the
architecture metadata. The existing CMake path reads the numeric baseline from \texttt{DocumentVersion}; a build-time step
generates the version, Git checkpoint and source state for the title/About UI
and package metadata. An unavailable Git context is explicitly labelled.
The source archive therefore remains buildable without inventing a checkpoint.
The feature-based title/About policy is implemented for the separate
0.1.3-alpha sidebar-shell package; the frozen executable is unchanged.
The reviewed transaction/history design in Section~\ref{Section:TransactionDesign}
now has a bounded coordinate-edit implementation in the matching
\texttt{0.1.4-alpha} package. Generic transactions and file-store extraction
remain planned. Demo 3 now presents \texttt{0.1.4-alpha}; the older package and
slides remain preserved at \texttt{0.1.3-alpha}. See
Section~\ref{Section:SessionHistoryCheck}.
The MVC and class views support architectural rules
\RequirementRef{REQ-A-004} through \RequirementRef{REQ-A-007}, together with
developer rules \RequirementRef{REQ-DEV-001} through \RequirementRef{REQ-DEV-004}.
Figures~\ref{Figure:CurrentClasses} and~\ref{Figure:MVCAllocation} link to the
class details;
each detail provides links back to the overview and MVC diagram.
\noindent\textbf{Notation.} The class overview uses associations, dashed dependencies, composition
diamonds at owners and hollow generalization triangles toward Qt bases.
MVC packages group roles; their arrows show dependencies rather than execution
order. Ownership is also recorded in Table~\ref{Table:DesignOwnership}.
All routes are orthogonal; UML messages and aligned links remain straight.
Class details use \texttt{+}, \texttt{-}, and \texttt{\#} for public,
private, and protected visibility. Signatures use UML-style
\texttt{name: type} parameters and return types; C++ \texttt{const}, reference,
and pointer markers are retained. Inherited members, compiler-generated
operations, and macro expansions are omitted. Signals and slots have their
own headings. Endpoint editing and compiler/PDF integration remain future work.
\subsection{Feature Baselines and Package Identity}\label{Section:VersionPolicy}
Numbering is controlled by \hyperref[Table:DocumentHistory]{Document History}
and \RequirementRef{REQ-DEV-006}--\RequirementRef{REQ-DEV-008}. A report revision
may advance without a new application package. The active deployment below
describes the current 0.1.4-alpha package; archived 0.10.3 evidence retains its original identity. The separate 0.1.2-alpha package implements
rectangle extraction and About identity. The retained 0.1.3-alpha package adds
the sidebar shell; 0.1.4-alpha adds bounded session undo/redo. Shape discovery/creation define the later 0.2.0-alpha milestone.\par
\input{../assets/design-diagrams/styles.tex}
\clearpage
\section{Current Alpha Deployment}\label{Section:AlphaDeployment}
\index{deployment diagram}\index{Windows package}
Figure~\ref{Figure:AlphaDeployment} shows the current Windows
\texttt{0.1.4-alpha} package on the author's computer. Perspective UML device
and execution-environment nodes contain the deployed artifacts: executable,
rectangle module, bundled runtime and build records. Figure~\ref{Figure:CurrentPluginDeployment}
details the native module boundary. Local file I/O follows
\RequirementRef{REQ-C-001}; identity follows \RequirementRef{REQ-DEV-006}.
TinyTeX and PDF viewing remain separately operated tools. Dashed arrows are
usage dependencies; solid arrows annotate file I/O and the author's manual
workflow, rather than structural ownership. Frozen 0.10.3 packages, reports
and the prior editable figure are retained as historical evidence.
\begin{figure}[ht]
\centering
\resizebox{\linewidth}{!}{\input{../assets/design-diagrams/deployment.tex}}
\caption[Current Alpha physical deployment]{Current Alpha deployment and external compilation boundary.
Compilation and PDF viewing are manual; in-app compiler/PDF integration remains
unimplemented.\label{Figure:AlphaDeployment}}
\end{figure}
\clearpage
\input{tkrUserInterfaceDesign.tex}
\clearpage
\section{Model-View-Controller Allocation}\label{Section:MVCAllocation}
\index{Model-View-Controller}\index{ownership}
Vincent reported that the instructor revisited MVC and preferred class
responsibilities in the diagrams. This section records that discussion through
Vincent's account. MVC separates document state, presentation, and response to
user input~\cite{FowlerMVC}. Figure~\ref{Figure:MVCAllocation} applies those roles
to the current editor; it is a project-specific allocation, not a claim of
strict conformance to every MVC variant.
Document state belongs to \texttt{tkrTikzDocument}; the window, view and scene supply
presentation, including the sidebar and its Shapes/Files pages. \texttt{tkrEditorController} coordinates actions. Parsing and
coordinate conversion and edit preparation are GUI-independent support services
owned by the controller. They interpret or transform data; they are not additional
controllers or persistent document state.
The window also assembles components, reads document state for display, and
handles dialogs and the close guard. The document is an ordinary C++ class
with no Qt signals: the controller emits \texttt{documentChanged()}, and the
window then reads source, path, and dirty state. The scene does not mutate
source. This application-level allocation is distinct from Qt's item
model/view framework, which combines view/controller responsibilities and
uses item models and delegates~\cite{QtModelView}. The scaffold does not use
\texttt{QAbstractItemModel}.
\begin{tabularx}{\linewidth}{@{}L{4.3cm}L{3.2cm}Y@{}}
\caption{Ownership Is Separate from MVC Role\label{Table:DesignOwnership}}\\
\toprule\textbf{Owner} & \textbf{Owned object} & \textbf{Mechanism and lifetime}\\
\midrule\endfirsthead
\toprule\textbf{Owner} & \textbf{Owned object} & \textbf{Mechanism and lifetime}\\
\midrule\endhead\bottomrule\endfoot
\path{main.cpp} & \texttt{tkrMainWindow} & Stack object; destroyed after the final
window close ends the event loop.\\
\texttt{tkrMainWindow} & Document; controller & Document by value; controller by
\texttt{unique\_ptr}, destroyed before the document.\\
\texttt{tkrMainWindow} & Scene and UI objects & QObject parent ownership,
including the canvas view and sidebar through central splitters. The sidebar
owns its stacked page widgets; \texttt{QGraphicsScene} owns its graphics items.\\
\texttt{tkrTikzDocument} & Edit history & Value member; exact session snapshots,
no automatic eviction. The document alone publishes/traverses history.\\
\texttt{tkrDiagramScene} & Shape module store; mapper calibration & Value members; store owns loader and borrows its pinned provider root.\\
\texttt{tkrEditorController} & Parser; mapper; edit service & Value members. Document and scene
references are non-owning; both must outlive the controller.\\
\end{tabularx}
Ownership and MVC roles are distinct. The window owns the model without becoming
the model. File-store extraction remains a separate planned refactor.
\clearpage
\subsection{MVC Diagram}\label{Section:MVCDiagram}
\index{Model-View-Controller}
Select a class name to open its detailed diagram. UML packages group current role allocations. Package grouping does not imply
C++ inheritance or object ownership.
\begin{figure}[ht]
\centering
\resizebox{\linewidth}{!}{\input{../assets/design-diagrams/mvc.tex}}
\caption[Current MVC allocation]{Current MVC roles and communication. Whole-element gestures are implemented.
Ownership is given in Table~\ref{Table:DesignOwnership};
class relationships appear in Figure~\ref{Figure:CurrentClasses}.
\label{Figure:MVCAllocation}}
\end{figure}
\clearpage
\begin{landscape}
\section{Current Class Diagram}\label{Section:CurrentClassDiagram}
\index{class diagram}\index{class responsibilities}
There are thirteen concrete host classes, all \texttt{final}: ten core classes
in this overview and three sidebar UI classes in Figure~\ref{Figure:CurrentSidebarClasses}.
The provider interface and module realization are in Figure~\ref{Figure:CurrentProviderClasses}.
Qt's existing ancestry is outside
the three-level project inheritance-depth limit (main/base, child, grandchild).
The host has no project-defined inheritance chain; the module realizes its provider interface.
This overview emphasizes responsibilities
and structural dependencies/ownership. Select a class name to open its attributes,
operations, and contracts. See Figure~\ref{Figure:MVCAllocation} for MVC roles.
\begin{figure}[ht]
\centering
\resizebox{0.93\linewidth}{!}{\input{../assets/design-diagrams/classes.tex}}
\caption[Current core host classes]{Current UML class responsibilities, ownership, borrowed dependencies and direct
Qt bases. Sequence diagrams describe temporal communication separately.
\label{Figure:CurrentClasses}}
\end{figure}
\end{landscape}
\clearpage
\section{Individual Class Diagrams}\label{Section:IndividualClassDiagrams}
\subsection{tkrEditHistory}\label{Section:ClassEditHistory}
Source: \path{code/src/editing/tkrEditHistory.h} and its implementation.
Only the owning document can record or traverse entries. Candidate storage is
prepared before publication; allocation failure preserves the redo branch.
\begin{figure}[htbp]
\centering
\resizebox{0.90\linewidth}{!}{\input{../assets/design-diagrams/class-history.tex}}
\caption[Current session history]{Implemented session snapshot storage; no automatic eviction.
\label{Figure:ClassEditHistory}}
\end{figure}
\clearpage
\subsection{tkrTikzDocument}\label{Section:ClassTikzDocument}
\index{class diagram!tkrTikzDocument}
Source: \path{code/src/model/tkrTikzDocument.h} and its implementation.
The saved byte copy determines dirty state. Loading increments the revision;
accepted source changes increment it and invalidate parsed records. Edit batches
check revision, bounds, overlaps, and expected bytes before mutation.
\begin{figure}[ht]
\centering
\resizebox{0.84\linewidth}{!}{\input{../assets/design-diagrams/class-document.tex}}
\caption[Current document]{Model state and guarded edits. Return to the
\hyperref[Figure:CurrentClasses]{class overview} or
\hyperref[Figure:MVCAllocation]{MVC diagram}.\label{Figure:ClassTikzDocument}}
\end{figure}
\clearpage
\subsection{tkrMainWindow}\label{Section:ClassMainWindow}
\index{class diagram!tkrMainWindow}
Source: \path{code/src/ui/tkrMainWindow.h} and its implementation.
An optional startup-file argument loads a source through the controller.
The source widget decodes bytes only for viewing. Open and close ask whether
to save, discard, or cancel when dirty. Save errors keep the window open.
Widget/action parent chains ultimately belong to the window.
The window labels the Canvas and TikZ source panes. Its child
\texttt{tkrDiagramView} extends \texttt{QGraphicsView}; it fits the scene to
the pane uniformly and draws white paper only within an explicit fixed editing
extent, with a grey surround. Without a fixed extent it keeps a white viewport.
This view transform leaves scene coordinates and source unchanged.
See Section~\ref{Section:ClassDiagramView} for the view's responsibilities.
\begin{figure}[ht]
\centering
\resizebox{\linewidth}{!}{\input{../assets/design-diagrams/class-window.tex}}
\caption[Current main window]{View controls, assembly, and close protection. Return to the
\hyperref[Figure:CurrentClasses]{class overview} or
\hyperref[Figure:MVCAllocation]{MVC diagram}.\label{Figure:ClassMainWindow}}
\end{figure}
\clearpage
\subsection{tkrDiagramView}\label{Section:ClassDiagramView}
\index{class diagram!tkrDiagramView}
The window supplies scene bounds and whether they are fixed. The scene owns
the diagram items and keeps the preview within a fixed extent. The view owns
the viewport transform and background: its uniform fit preserves the aspect
ratio, and white paper ends at a declared editing boundary. During partial
repaints, background fills temporarily disable antialiasing. The view paints
the whole paper against the viewport's existing repaint clip so the paper
edge stays fixed. Painter state is restored before drawing
items, which keep smooth outlines. The view makes no source edits.
This supports \RequirementRef{REQ-I-011}--\RequirementRef{REQ-I-014}.
\begin{figure}[ht]
\centering
\resizebox{\linewidth}{!}{\input{../assets/design-diagrams/class-view.tex}}
\caption[Current diagram view]{Fitted canvas view, owned through the window's widget hierarchy.
Return to the \hyperref[Figure:CurrentClasses]{class overview} or
\hyperref[Figure:MVCAllocation]{MVC diagram}.\label{Figure:ClassDiagramView}}
\end{figure}
\clearpage
\subsection{tkrDiagramScene}\label{Section:ClassDiagramScene}
\index{class diagram!tkrDiagramScene}
Source: \path{code/src/ui/tkrDiagramScene.h} and its implementation.
\texttt{resetDiagram()} clears owned items and resets the scene extent.
\texttt{displayElements()} validates and draws rectangles and straight segments
with TeX-point widths. Default curved arrow tips use the installed PGF geometry,
round tip strokes and shortened butt-cap shafts. Each segment is one filled
outline item, including its tips. A separate comparison extent sets scene bounds
without creating an item and limits the drag preview. Release still validates
the constrained edit. Selectable items use scene-controlled movement. Selected
rectangles show screen-sized corner handles drawn in the foreground, without
adding diagram elements. Mouse events emit move or corner-resize gestures with revision,
element ID and scene positions; no item pointer survives a rebuild. Escape or
focus loss cancels the preview. Endpoint gestures remain unsupported.
\begin{figure}[ht]
\centering
\resizebox{\linewidth}{!}{\input{../assets/design-diagrams/class-scene.tex}}
\caption[Current diagram scene]{Scene presentation and gesture interface. Return to the
\hyperref[Figure:CurrentClasses]{class overview} or
\hyperref[Figure:MVCAllocation]{MVC diagram}.\label{Figure:ClassDiagramScene}}
\end{figure}
\clearpage
\subsection{tkrEditorController}\label{Section:ClassEditorController}
\index{class diagram!tkrEditorController}
Source: \path{code/src/controller/tkrEditorController.h} and its implementation.
Open success means bytes were read, even if parsing is unavailable. Saving
compares the disk file with its baseline, then uses \texttt{QSaveFile}; it
marks saved only after a successful commit. This comparison does not eliminate
a concurrent-write race. Refresh clears obsolete records/items on failure;
success stores supported elements. Preview validates the gesture and moves the
scene geometry without source mutation. The owned edit service prepares
constraints and coordinate replacements; release validates a candidate
parse/display before applying one guarded batch.
Unchanged axes retain their spelling. Cancellation rebuilds from source;
invalid requests preserve the document. Ordinary boundary gestures apply the
furthest valid result.
\begin{figure}[ht]
\centering
\resizebox{0.78\linewidth}{!}{\input{../assets/design-diagrams/class-controller.tex}}
\caption[Current controller]{Controller coordination, borrowed references, and owned services.
Return to the \hyperref[Figure:CurrentClasses]{class overview} or
\hyperref[Figure:MVCAllocation]{MVC diagram}.\label{Figure:ClassEditorController}}
\end{figure}
\clearpage
\subsection{tkrTikzParserExplicit}\label{Section:ClassExplicitTikzParser}
\index{class diagram!tkrTikzParserExplicit}
\noindent Source: \path{code/src/parsing/tkrTikzParserExplicit.h}.\par
The implementation uses the matching \texttt{.cpp} file.
The parser accepts explicit centimetre rectangles and straight segments with
optional forward, backward or double arrowheads. It masks comments
without changing byte offsets, and returns revision-tagged numeric ranges.
It recognizes only bare command fragments, one unconfigured picture, or the
corpus wrapper. Unknown syntax rejects the entire interpretation. A bounding
path is calibration data, separate from element records. Broader syntax remains
unsupported. Shared records, including \texttt{ComparisonExtent}, are declared in
\path{code/src/model/EditorTypes.h}.
\begin{figure}[ht]
\centering
\resizebox{\linewidth}{!}{\input{../assets/design-diagrams/class-parser.tex}}
\caption[Current explicit parser]{Stateless subset parser and conservative source contract. Return to
the \hyperref[Figure:CurrentClasses]{class overview} or
\hyperref[Figure:MVCAllocation]{MVC diagram}.\label{Figure:ClassExplicitTikzParser}}
\end{figure}
\clearpage
\subsection{tkrCoordinateMapper}\label{Section:ClassCoordinateMapper}
\index{class diagram!tkrCoordinateMapper}
Source: \path{code/src/geometry/tkrCoordinateMapper.h} and its implementation.
The mapper stores scene origin and scene units per centimetre. Configuration
rejects nonfinite values and nonpositive scale before mutation. Mapping
methods assume finite input points; they do not validate them. The defaults
are scaffold values, not stakeholder performance or accuracy targets.
\begin{figure}[ht]
\centering
\resizebox{\linewidth}{!}{\input{../assets/design-diagrams/class-mapper.tex}}
\caption[Current coordinate mapper]{Coordinate conversion state, operations, and inverse equations.
Return to the \hyperref[Figure:CurrentClasses]{class overview} or
\hyperref[Figure:MVCAllocation]{MVC diagram}.\label{Figure:ClassCoordinateMapper}}
\end{figure}
\clearpage
\subsection{tkrEditService}\label{Section:ClassEditService}
\index{class diagram!tkrEditService}
\noindent Source: \path{code/src/editing/tkrEditService.h}.\par
The implementation uses the matching \texttt{.cpp} file.
This GUI-independent value member prepares move/resize geometry and coordinate
replacements. It shares the stroke envelope with the parser through
\texttt{ShapeGeometryLimits}. Offsets use $0.000001$ cm precision, rounded inward
at boundaries; decimal addition retains original high-precision coordinates.
No source bytes or history are mutated here. The current document validates
revision, ranges, expected bytes and overlaps before applying a batch.
The general transaction API remains proposed; this service is its
bounded edit-preparation step. Rectangle calculations now use the borrowed
provider interface; host validation and exact source rewriting remain here
(\hyperref[Section:CurrentPlugin]{current extraction}).
\begin{figure}[ht]
\centering
\resizebox{\linewidth}{!}{\input{../assets/design-diagrams/class-edit-service.tex}}
\caption[Current edit service]{Implemented edit preparation service. Return to the
\hyperref[Figure:CurrentClasses]{class overview} or
\hyperref[Figure:MVCAllocation]{MVC diagram}.\label{Figure:ClassEditService}}
\end{figure}
\input{tkrCurrentPlugin.tex}
\input{tkrTransactionDesign.tex}
\input{tkrPluginDesign.tex}
\input{tkrSidebarDesign.tex}