The Aegil mental model
Aegil is a deterministic domain compiler and verification harness designed to eliminate full-stack drift. It translates declarative specifications into a synchronized Serverpod backend, reactive Flutter BLoCs, and native platform shells—guaranteeing that code, security policies, and schemas remain permanently aligned.
Aegil has zero runtime dependencies. At runtime, your application is a 100% standard Serverpod backend communicating with a standard Flutter app over WebSockets and HTTP. Aegil exists entirely at design, build, and verification time.
The problem: Full-stack glue is brittle
Section titled “The problem: Full-stack glue is brittle”Building a modern full-stack Flutter application backed by Serverpod normally requires synchronizing dozens of moving parts by hand every time a single field or business rule changes:
- Database layer: Serverpod
.spy.yamlmodels, PostgreSQL migrations, foreign-key relations, and table indexes. - Backend logic: Session authentication checks, transaction boundaries, row-level SQL filters, and endpoint signatures.
- Domain invariants: Validation rules (e.g. min/max string lengths, numeric bounds) and state-machine transitions written once on the server and duplicated on the client.
- Client layer: Serialization protocols, state management (
flutter_blocevents and states), WebSocket stream listeners, and optimistic UI updates. - Native platform targets: iOS
Info.plist, AndroidAndroidManifest.xml, macOS.entitlements, and Webmanifest.json.
When developers or AI coding agents edit these files independently, small mistakes slip through: an authorization check is missed on a new mutation, a customer query leaks rows belonging to another organization, or an iOS camera permission string is forgotten in Info.plist.
System architecture: Runtime topology
Section titled “System architecture: Runtime topology”What does an Aegil application look like when running in development or production?

- Client Layer: Hand-written Flutter widgets live in
client/lib/and interact with the backend strictly through a single entrypoint:package:<app>_flutter/api.dart. The client uses generated BLoCs wired to Serverpod’sClientand coordinates local cache updates viaAegilCacheBus. - Backend Layer: A production Serverpod server (
.aegil/server/) handles authenticated requests, enforces Row-Level Security (RLS) policies directly in PostgreSQL SQL queries, executes transactions, and dispatches custom business logic to isolated handler hooks (hooks/*_hook.dart). - Database Layer: Standard PostgreSQL with append-only SQL migrations (
migrations/) generated from spec diffs viaaegil migrate.
Build architecture: Compilation & code ownership
Section titled “Build architecture: Compilation & code ownership”Aegil replaces hand-written glue code with a deterministic compiler pipeline:

To make full-stack development safe for both human teams and AI coding agents, Aegil strictly partitions every project into three ownership zones:
Zone 1: Declarative Specifications (specs/)
Section titled “Zone 1: Declarative Specifications (specs/)”- Owner: Developer and AI agent.
- Rules: The only place where entities, relations, validations, CEL policies, state machines, platforms, and permissions are declared.
- Feature Folders: All business domain models live in feature subfolders (e.g.
specs/notes/notes.tsp). Onlyapp.tspandplatforms.tsplive directly inspecs/. Putting domain specs at the root triggersERR_SPEC_MISPLACED.
Zone 2: Hand-Written Code (client/lib/, hooks/, migrations/)
Section titled “Zone 2: Hand-Written Code (client/lib/, hooks/, migrations/)”- Owner: Developer and AI agent.
- Rules: Where custom UI widgets, custom mutation hooks, and committed database migrations live. Aegil scaffolds initial stubs once, but never overwrites your custom files on subsequent builds.
- Client Boundary: Code in
client/lib/must consume backend APIs strictly throughpackage:<app>_flutter/api.dart. Accessing internal.aegil/client/lib/src/files directly triggersERR_UI_BOUNDARY_VIOLATION.
Zone 3: Generated Implementation (.aegil/)
Section titled “Zone 3: Generated Implementation (.aegil/)”- Owner: Aegil compiler exclusively.
- Rules: Contains the Serverpod server, PostgreSQL migrations, client SDK, BLoCs, and native platform shells (
android,ios,macos,web). - Cryptographic Hash Locking: Every file in Zone 3 is catalogued in
.aegil/manifest.jsonwith an FNV-1a 64-bit checksum. Editing any file in Zone 3 by hand triggers an immediate verification failure (ERR_TAMPERED_GENERATED_FILE).
The 3-Step agent execution loop
Section titled “The 3-Step agent execution loop”Aegil is designed from the ground up to allow autonomous AI coding agents to collaborate safely with human engineers without architectural drift:

- Step 1: Edit Specifications (
specs/<feature>/*.tsp) The developer or agent declares entities, relations, CEL access policies, validations, or custom@mutationoperations. - Step 2: Run Compiler (
aegil build --agent) Aegil compiles the specifications, signs all generated files with cryptographic checksums, and outputs an Action Manifest with tasks markedPENDING_IMPLEMENTATION. Each task specifies:targetFile: The hook file to implement (e.g.hooks/escalate_ticket_hook.dart).preconditionsGuaranteedByCompiler: Pre-verified caller identity, active transaction, pre-fetched entity, CEL policy verification, and state transition check.postconditionsRequiredFromAgent: The state changes and return value required.
- Step 3: Implement Hooks and Verify (
aegil verify --agent) The developer or agent implements the hook method. Aegil mirrors the hook into the server, executes Dart static analysis, runs dynamic invariant tests, and runs integration tests against real PostgreSQL in Docker.
Verification statuses: What “Done” means
Section titled “Verification statuses: What “Done” means”A task is never complete until aegil verify --agent returns "status": "VERIFIED".
| Verification Status | Meaning | Acceptable for Delivery? |
|---|---|---|
VERIFIED |
All 5 checks passed (Hash lock, Hooks, Static analysis, Dynamic invariants, PostgreSQL integration). | Yes. Ready to ship or commit. |
VERIFIED_PARTIAL |
Stages 1–4 passed, but Stage 5 was skipped via --skip-integration. |
No. Integration tests must run against real PostgreSQL. |
UNAVAILABLE |
Docker is not running or failed to launch the test container. | No. Start Docker and re-verify. |
Next steps
Section titled “Next steps”- Read Do’s and Don’ts for best practices and security rules.
- Read TypeSpec for Dart Developers to master the modeling language.
- Read Full-Stack Framework Architecture to explore Serverpod, Flutter, and server hooks.
- Read The 3-Step Agent Protocol to instruct AI assistants.