@@ -11,37 +11,95 @@ This document captures the implemented architecture after the recent modularizat
1111
1212## Layering Model
1313
14- 1 . Kernel type layer
14+ ```
15+ ┌─────────────────────────────────────────────────┐
16+ │ 4. Composition root │
17+ │ index.ts (ComputeEngine) │
18+ │ Composes services, exposes public API │
19+ ├─────────────────────────────────────────────────┤
20+ │ 3. Runtime services │
21+ │ engine-*.ts │
22+ │ One bounded concern per file │
23+ ├─────────────────────────────────────────────────┤
24+ │ 2. Specialized type wrappers │
25+ │ types-*.ts, global-types.ts │
26+ │ Bind kernel generics to concrete types │
27+ ├─────────────────────────────────────────────────┤
28+ │ 1. Kernel type layer │
29+ │ types-kernel-*.ts │
30+ │ Generic type contracts (no engine imports) │
31+ └─────────────────────────────────────────────────┘
32+ ```
33+
34+ ### 1. Kernel type layer
1535- Files: ` types-kernel-*.ts `
1636- Responsibility: generic type contracts for evaluation/serialization behavior without engine-specific concrete types.
1737- Rule: no dependency on ` ComputeEngine ` implementation modules.
1838
19- 2 . Specialized type wrappers
39+ ### 2. Specialized type wrappers
2040- Files: ` types-*.ts ` , ` global-types.ts `
2141- Responsibility: bind kernel generics to concrete compute-engine types (` BoxedExpression ` , ` IComputeEngine ` , etc.).
2242- Rule: avoid importing runtime implementation modules.
2343
24- 3 . Runtime services
44+ ### 3. Runtime services
2545- Files: ` engine-*.ts `
2646- Responsibility: focused implementation concerns (parse entrypoints, startup/bootstrap, configuration lifecycle, numeric config, scope/assumptions/sequences, workflow helpers, validation helpers, extension contracts).
2747- Rule: services should not become secondary monoliths; each service owns one bounded concern.
2848
29- 4 . Composition root
49+ ### 4. Composition root
3050- File: ` index.ts ` (` ComputeEngine ` )
3151- Responsibility: compose services, expose public API methods, and own lifecycle orchestration.
3252- Rule: business logic should prefer service modules; ` ComputeEngine ` should remain an API shell and integration point.
3353
34- ## Service Boundaries (Implemented)
35-
36- - Startup/bootstrap: ` engine-startup-coordinator.ts ` , ` engine-library-bootstrap.ts `
37- - Parse defaults/policy: ` engine-parse-entrypoint.ts `
38- - Workflow API helpers: ` engine-workflow-entrypoints.ts `
39- - Validation/error expression entrypoints: ` engine-validation-entrypoints.ts `
40- - Numeric policy/state: ` engine-numeric-configuration.ts `
41- - Runtime limits/verification state: ` engine-runtime-state.ts `
42- - Configuration lifecycle/reset fan-out: ` engine-configuration-lifecycle.ts `
43- - Compilation target registry: ` engine-compilation-targets.ts `
44- - Extension contracts: ` engine-extension-contracts.ts `
54+ ## Service Inventory
55+
56+ ### Startup & Initialization
57+ | File | Responsibility |
58+ | ------| ---------------|
59+ | ` engine-startup-coordinator.ts ` | Orchestrates initialization sequence: common numbers, library bootstrap, common symbols |
60+ | ` engine-library-bootstrap.ts ` | Resolves library entries, topological sort, loads definitions, collects LaTeX dictionaries |
61+ | ` engine-common-symbols.ts ` | Initializes well-known symbol bindings (True, False, Pi, E, Nothing) |
62+
63+ ### Parsing & Workflows
64+ | File | Responsibility |
65+ | ------| ---------------|
66+ | ` engine-parse-entrypoint.ts ` | Engine-specific parse defaults, symbol type resolution, boxing of parse results |
67+ | ` engine-workflow-entrypoints.ts ` | High-level ` parseSimplify/parseEvaluate/parseNumeric ` combining parse + operation |
68+
69+ ### Validation & Errors
70+ | File | Responsibility |
71+ | ------| ---------------|
72+ | ` engine-validation-entrypoints.ts ` | Factory functions for error and type-mismatch expressions |
73+ | ` engine-extension-contracts.ts ` | Runtime contract validation for compilation targets, libraries, and compile options |
74+
75+ ### Engine State
76+ | File | Responsibility |
77+ | ------| ---------------|
78+ | ` engine-numeric-configuration.ts ` | Precision, tolerance, angular unit, and Decimal.js configuration |
79+ | ` engine-runtime-state.ts ` | Execution limits (time, iteration, recursion) and verification state |
80+ | ` engine-configuration-lifecycle.ts ` | Configuration change propagation and reset fan-out |
81+ | ` engine-cache.ts ` | Expression and rule-set caching with generation-based invalidation |
82+ | ` engine-latex-dictionary-state.ts ` | LaTeX dictionary indexing and rebuild |
83+
84+ ### Scoping & Declarations
85+ | File | Responsibility |
86+ | ------| ---------------|
87+ | ` engine-scope.ts ` | Lexical scope push/pop, eval context management, symbol lookup |
88+ | ` engine-declarations.ts ` | Symbol and operator declaration, type declaration, assignment |
89+ | ` engine-assumptions.ts ` | Assumption management, ` ask() ` , ` verify() ` , ` forget() ` |
90+ | ` engine-sequences.ts ` | Sequence declaration, OEIS lookup, recurrence evaluation |
91+
92+ ### Expression Construction
93+ | File | Responsibility |
94+ | ------| ---------------|
95+ | ` engine-expression-entrypoints.ts ` | Symbol and number expression creation with definition binding |
96+ | ` engine-simplification-rules.ts ` | Built-in simplification rule initialization |
97+
98+ ### Compilation
99+ | File | Responsibility |
100+ | ------| ---------------|
101+ | ` engine-compilation-targets.ts ` | Registry for named compilation targets (JavaScript, GLSL, etc.) |
102+ | ` engine-type-resolver.ts ` | Type resolution callback for parser integration |
45103
46104## Public Workflow API Policy
47105
@@ -55,10 +113,13 @@ This document captures the implemented architecture after the recent modularizat
55113 - Parse presets: ` parseMode = strict | permissive `
56114
57115Precedence rule across workflow helpers:
58- - Explicit low-level options win over presets.
116+ - Explicit low-level options always win over presets.
59117 - ` parse.strict ` overrides ` parseMode `
60118 - ` evaluate.numericApproximation ` overrides ` evaluateMode `
61119 - ` simplify.strategy ` overrides ` simplifyMode `
120+ - This is implemented via object spread: the preset sets a default, then ` ...options.parse ` overwrites it.
121+
122+ Note: ` simplifyMode: 'trigonometric' ` maps to the internal ` strategy: 'fu' ` (the Fu algorithm for trigonometric simplification, named after Fu, Zhong, and Zeng).
62123
63124## Extension Contracts (Runtime Guards)
64125
@@ -92,12 +153,14 @@ Rules:
92153
93154## Guardrails
94155
95- - Circular dependency budget: ` 0 ` (checked in ` typecheck ` + ` check:deps ` workflows).
156+ - ** Circular dependency budget: ` 0 ` ** — no cycles of any kind (runtime or type-only). Checked via ` npx madge --circular --extensions ts src/compute-engine ` .
157+ - ESLint ` import/no-restricted-paths ` enforces layered dependencies (35 zone rules in ` .eslintrc.cjs ` ). Run with ` npm run check:deps ` .
96158- Public type surfaces must not include explicit ` any ` .
97159- Contract tests exist for extension seams (` test/compute-engine/extension-contracts.test.ts ` ).
98160
99161## Immediate Next Work
100162
101- 1 . Keep shrinking ` ComputeEngine ` orchestration by extracting remaining utility glue .
163+ 1 . Add tests for library circular dependency detection and compilation target unregistration/re-registration .
1021642 . Expand extension contract tests to additional compile-target families and compile-edge payloads.
103- 3 . Keep documentation synchronized between kernel contracts and specialized wrappers.
165+ 3 . Consider skipping contract validation for built-in compilation targets to reduce startup cost.
166+ 4 . Keep documentation synchronized between kernel contracts and specialized wrappers.
0 commit comments