Architecture Internals
Compiler architecture and path ownership
This section documents the internal engineering design of the Aegil compiler itself (bin/, lib/compiler/, lib/templates/, and tool/). Emitters operate as pure in-memory planning functions, OwnershipPolicy validates every path before ProjectWriter commits bytes to disk, and .aegil/manifest.json locks generated artifacts with deterministic 64-bit FNV-1a checksums.
Compiler layers (lib/compiler/)
Section titled “Compiler layers (lib/compiler/)”| Layer | Path | Responsibility |
|---|---|---|
| Config | lib/compiler/config/project_config.dart |
Parses aegil.yaml without third-party dependencies, validating name, namespace, layout, exact toolchain pins, and paths. |
| Frontend | lib/compiler/frontend/ |
SpecLoader merges specs/**/*.tsp in sorted order; SpecPodParser, AppParser, and PlatformParser compile entities, CEL policies, state machines, @app, and @platform into SpecPodIr. |
| Layout | lib/compiler/layout/project_layout.dart |
Single source of truth for directory paths (server/, generated/, client/, hooks/) versus Dart package names (<name>_server, <name>_client, <name>_flutter, <name>_hooks). |
| Platforms | lib/compiler/platforms/permission_registry.dart |
Maps abstract @permission declarations to Android manifest entries, iOS and macOS Info.plist usage keys, and macOS entitlements across the four @platform targets. |
| Emitters | lib/compiler/emitters/ |
Pure generators (ServerpodShellEmitter, ServerpodMonorepoEmitter, FlutterShellEmitter, PlatformShellEmitter, IntegrationTestEmitter, GitignoreEmitter, SecretsEmitter) that take ProjectConfig + SpecPodIr and return PlannedFile lists. |
| Harness | lib/compiler/harness/ |
OutputPlan, OwnershipPolicy, ProjectWriter, AegilManifestManager, ToolchainResolver, IntegrationRunner, ProjectInitializer. |
Determinism and per-file-type escaping
Section titled “Determinism and per-file-type escaping”Generated files must be byte-identical across machines and years:
- Emitters never emit timestamps, current years, random values, or absolute paths into
FileOwner.generatedorFileOwner.toolManagedfiles. - User-supplied strings (
displayName, permissionreason) are escaped for the file format they enter:.tspdecorator strings:ProjectInitializer.escapeSpecString(\and")- YAML double-quoted strings:
_yamlQuote(\and") - Dart single-quoted literals:
_dartString(\,', and$) - XML /
Info.plist/AndroidManifest.xml/ HTML:_xml(&,<,>,",') .xcconfig:replaceAll('//', '/ /')so//cannot start a comment- JSON:
jsonEncode