Overview & Philosophy
Aegil is an agent-driven, full-stack application framework that unifies Serverpod on the backend (PostgreSQL) and Flutter on the frontend through declarative TypeSpec specifications. By establishing a single source of truth and deterministic boundaries, Aegil eliminates architectural drift and enables autonomous AI coding assistants to construct, modify, and verify production software safely.
The Two Crises of Modern App Development
Section titled “The Two Crises of Modern App Development”Aegil was born out of two painful realities in modern software engineering:
1. The Full-Stack Drift Problem
Section titled “1. The Full-Stack Drift Problem”Building full-stack Flutter applications requires maintaining multiple disjointed worlds: SQL migrations, backend ORMs, server routing, serialization DTOs, HTTP clients, and Flutter BLoCs. A single column change in the database triggers a cascade of manual updates across 6+ files, frequently causing silent runtime crashes.
2. The AI Agent Chaos Problem
Section titled “2. The AI Agent Chaos Problem”Autonomous AI coding agents (Claude Code, Cursor, Windsurf, Antigravity) are immensely capable, but when dropped into an unstructured codebase, they rapidly introduce critical defects:
- They edit generated ORM models or database migration files directly.
- They bypass server-side authorization by accepting client-sent parameters (
actingUserId,callerRole). - They hallucinate API endpoints and produce inconsistent, unmaintainable state management glue.
- They lack a deterministic verification loop to know if their changes actually work end-to-end.
How Aegil Solves Both
Section titled “How Aegil Solves Both”Aegil introduces an Agent-Driven, Zero-Drift Architecture:
- Declarative Truth in TypeSpec (
specs/): You or your AI agent describe data models, field constraints, row-level security (CEL), and API operations in concise.tspspecifications. - Deterministic Code Ownership (3 Zones): The compiler hash-locks all generated code in
.aegil/(Zone 3). Agents physically cannot tamper with or drift generated backend or frontend code. - Machine Action Manifest (
.aegil/manifest.json): When custom logic is needed, the compiler hands the agent an exact task contract: compiler-guaranteed preconditions (auth and transactions are already handled!) and required postconditions. - Automated Verification Self-Correction Loop:
aegil verify --agentruns real PostgreSQL integration tests in throwaway Docker containers and returns structured JSON error codes (ERR_*), allowing agents to self-correct autonomously.
The Aegil Architecture at a glance
Section titled “The Aegil Architecture at a glance”
Core Pillars of Aegil
Section titled “Core Pillars of Aegil”1. Single Source of Truth in TypeSpec (specs/)
Section titled “1. Single Source of Truth in TypeSpec (specs/)”You declare your domain models, relations, field validations, row-level access control, and state machine transitions in declarative TypeSpec files (specs/<feature>/*.tsp). Aegil compiles this model into both Serverpod backend and Flutter frontend artifacts.
2. Three Strict Code Ownership Zones
Section titled “2. Three Strict Code Ownership Zones”Aegil organizes every repository into three strict ownership zones:
- Zone 1 (Specifications):
specs/<feature>/*.tsp,specs/app.tsp,specs/platforms.tsp. (Human & agent writable). - Zone 2 (Handwritten Logic):
client/lib/**,hooks/*_hook.dart, andmigrations/**. (Human & agent writable; never overwritten on subsequent builds). - Zone 3 (Generated Code): Everything under
.aegil/. (Strictly compiler-owned; protected by cryptographic hash locks).
3. Zero-Trust Security by Default
Section titled “3. Zero-Trust Security by Default”- Generated endpoints never accept caller ID or role parameters from the client.
- Caller identity (
auth.idandauth.role) is derived strictly from verified server sessions. - Row-level access policies (
@policy) are written in Common Expression Language (CEL) and compiled directly into PostgreSQLWHEREclauses executed inside the database engine.
4. Mathematical Verification Harness (aegil verify)
Section titled “4. Mathematical Verification Harness (aegil verify)”Before shipping or merging code, aegil verify runs a 5-stage automated check:
- Hash Lock Check: Verifies no generated files were tampered with or edited out of sync.
- Hook Completeness: Confirms all custom operations have registered handlers.
- Dart Static Analysis: Confirms zero analyzer warnings across the entire monorepo.
- Dynamic Invariants: Verifies boundary limits and state machine transitions.
- PostgreSQL Integration Suite: Boots a throwaway Docker Postgres container to verify real endpoint execution against anonymous, customer, and admin caller personas.
Where to go next
Section titled “Where to go next”- Aegil vs. Traditional Flutter: Detailed architectural comparison of standard Flutter development vs. Aegil.
- Quickstart Guide: Build, run, and verify a complete full-stack Notes app in under 5 minutes.
- Mental Model & Architecture: Deep dive into build vs. runtime topology and the 3-zone code ownership model.
- Do’s and Don’ts: Master essential rules and avoid common pitfalls.
- The 3-Step Agent Protocol: Learn how autonomous AI coding agents interact with Aegil.