Skip to content
VerificationWould you notice if your agent drifted in production?Explore the 5-stage harness›
Overview

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.


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:

  1. Database layer: Serverpod .spy.yaml models, PostgreSQL migrations, foreign-key relations, and table indexes.
  2. Backend logic: Session authentication checks, transaction boundaries, row-level SQL filters, and endpoint signatures.
  3. 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.
  4. Client layer: Serialization protocols, state management (flutter_bloc events and states), WebSocket stream listeners, and optimistic UI updates.
  5. Native platform targets: iOS Info.plist, Android AndroidManifest.xml, macOS .entitlements, and Web manifest.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.


What does an Aegil application look like when running in development or production?

Aegil Full-Stack Runtime Topology

  • 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’s Client and coordinates local cache updates via AegilCacheBus.
  • 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 via aegil migrate.

Build architecture: Compilation & code ownership

Section titled “Build architecture: Compilation & code ownership”

Aegil replaces hand-written glue code with a deterministic compiler pipeline:

Aegil Build Architecture and 3-Zone Ownership

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). Only app.tsp and platforms.tsp live directly in specs/. Putting domain specs at the root triggers ERR_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 through package:<app>_flutter/api.dart. Accessing internal .aegil/client/lib/src/ files directly triggers ERR_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.json with an FNV-1a 64-bit checksum. Editing any file in Zone 3 by hand triggers an immediate verification failure (ERR_TAMPERED_GENERATED_FILE).

Aegil is designed from the ground up to allow autonomous AI coding agents to collaborate safely with human engineers without architectural drift:

The 3-Step Agent Execution Loop

  1. Step 1: Edit Specifications (specs/<feature>/*.tsp) The developer or agent declares entities, relations, CEL access policies, validations, or custom @mutation operations.
  2. 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 marked PENDING_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.
  3. 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.