Quickstart
Welcome to Aegil. In this tutorial, you will build, run, and verify a complete full-stack Notes application with a Serverpod PostgreSQL backend and a reactive Flutter UI.
By following this guide, you will learn the fundamental workflow of Aegil: declaring your data and APIs in TypeSpec, running the full stack with a single command, connecting a reactive Flutter UI, and mathematically verifying application invariants.
[!TIP] Looking for a pre-built starter? Run
aegil create my_counter --template counter && cd my_counter && aegil runto scaffold and run an interactive full-stack counter in seconds. Follow the steps below to build an application from scratch.
What you will build
Section titled “What you will build”You will build a full-stack Notes app from scratch:
- A PostgreSQL database table and Serverpod server with declarative CRUD queries and mutations.
- A declarative TypeSpec feature specification (
specs/notes/notes.tsp). - A reactive Flutter client consuming the generated
NoteBlocthrough a single import (package:notes_flutter/api.dart). - End-to-end verification proving type safety, validation boundaries, and database integrity.

Prerequisites
Section titled “Prerequisites”Before starting, make sure you have:
- Flutter SDK (
3.35.xor later, which includes Dart). - Serverpod CLI (
dart pub global activate serverpod_cli). - Docker Desktop (or Docker Engine, running locally for the database).
- Aegil CLI installed and on your
PATH:
# Option 1: Homebrew (macOS & Linux)brew tap steach-IDE/aegil https://github.com/steach-IDE/aegilbrew install aegil
# Option 2: Dart pub globaldart pub global activate --source git https://github.com/steach-IDE/aegil.git --git-ref v0.1.0Verify your installation:
aegil versionStep 1: Create your project with aegil create
Section titled “Step 1: Create your project with aegil create”Just like flutter create my_app scaffolds a clean Flutter project, aegil create scaffolds a full-stack workspace with sensible defaults and builds the initial toolchain:
aegil create notescd notesNotice how lightweight and uncluttered the project directory is:
notes/ aegil.yaml # Project metadata and pinned toolchain versions specs/ # Zone 1: Your declarative domain specifications app.tsp # App identity and metadata platforms.tsp # Supported native platforms and permissions hooks/ # Zone 2: Hand-written server business logic (empty for now) client/ # Zone 2: Hand-written Flutter UI code lib/ main.dart # Flutter entry point pubspec.yaml # Client dependenciesAll heavy generated files (Serverpod ORM models, migration SQL, endpoints, client protocol, and native platform folders) are maintained automatically under .aegil/. Your workspace stays light and clean.
Step 2: Define your domain in TypeSpec (specs/notes/notes.tsp)
Section titled “Step 2: Define your domain in TypeSpec (specs/notes/notes.tsp)”In Aegil, you never write repetitive database migration scripts, boilerplate ORM classes, or REST endpoints by hand. You declare your data model and API in a TypeSpec file inside its feature folder.
Feature folder rule: Aegil organizes domain models into feature subfolders under
specs/(e.g.specs/notes/notes.tsp). Only root configuration files (app.tspandplatforms.tsp) live directly inspecs/. Placing domain specs at the root triggersERR_SPEC_MISPLACED.
Create the feature directory and spec file:
mkdir -p specs/notesAdd specs/notes/notes.tsp:
namespace Notes;
@entity({ table: "notes" })model Note { @pk id: uuid;
@validate({ minLength: 1, maxLength: 200 }) title: string;
content: string;
createdAt: utcDateTime;}
@public@autoQuery({ entity: "Note", paginate: "cursor", filterBy: [], sortBy: ["createdAt"] })op listNotes(limit?: int): Page<Note>;
@public@autoMutation({ entity: "Note", action: "create", touches: ["Note"] })op addNote(title: string, content: string): Note;Understanding the TypeSpec code (A Dart developer’s view)
Section titled “Understanding the TypeSpec code (A Dart developer’s view)”If you know Dart, TypeSpec is immediately familiar:
namespace Notes;groups declarations under the project namespace defined inaegil.yaml.model Note { ... }defines a data model—just like a Dart class—and tells Aegil to create a PostgreSQL table namednotes.string,uuid, andutcDateTimemap directly to Dart’sString,UuidValue, andDateTime.@validate({ minLength: 1, maxLength: 200 })is a decorator (analogous to a Dart annotation like@overrideor@JsonSerializable). Aegil compiles it into input checks that run on both client and server.@publicdeclares that these endpoints do not require a signed-in user session for this starter app.@autoQuerygenerates the Serverpod endpoint, cursor-based pagination query, and Flutter BLoC events automatically.@autoMutationgenerates the Serverpod endpoint, database insertion logic, cache invalidation (touches: ["Note"]), and client mutation event.
Step 3: Run the full stack with aegil run
Section titled “Step 3: Run the full stack with aegil run”Just like flutter run starts your mobile app, aegil run manages and launches your entire full-stack environment in a single command:
aegil runWhat aegil run does behind the scenes:
- Compiles
specs/**/*.tspinto Serverpod backend code and Flutter client code. - Checks Docker and starts a local PostgreSQL database container on port
8090. - Runs database migrations to create the
notestable with primary keys and constraints. - Boots the Serverpod backend server on
http://localhost:8080. - Launches your Flutter client application with hot reload enabled.
When the server starts, you will see:
Aegil Postgres container ready on port 8090.Serverpod server listening on http://localhost:8080Launching Flutter client on macOS/Chrome...Step 4: Build the Flutter UI (client/lib/main.dart)
Section titled “Step 4: Build the Flutter UI (client/lib/main.dart)”Open client/lib/main.dart. Replace its contents with a simple reactive UI that displays notes and allows adding new ones:
import 'package:flutter/material.dart';import 'package:flutter_bloc/flutter_bloc.dart';import 'package:notes_flutter/api.dart';
late final Client client;
Future<void> main() async { WidgetsFlutterBinding.ensureInitialized(); client = await createAppClient(); runApp(const NotesApp());}
class NotesApp extends StatelessWidget { const NotesApp({super.key});
@override Widget build(BuildContext context) { return MaterialApp( title: 'Notes', theme: ThemeData( colorScheme: ColorScheme.fromSeed(seedColor: Colors.amber), useMaterial3: true, ), home: BlocProvider( create: (_) => NoteBloc(client: client) ..add(const ListNotesRequested(limit: 100)), child: const NotesScreen(), ), ); }}
class NotesScreen extends StatelessWidget { const NotesScreen({super.key});
void _showAddNoteDialog(BuildContext context) { final titleController = TextEditingController(); final contentController = TextEditingController();
showDialog<void>( context: context, builder: (dialogContext) { return AlertDialog( title: const Text('New Note'), content: Column( mainAxisSize: MainAxisSize.min, children: [ TextField( controller: titleController, autofocus: true, decoration: const InputDecoration(labelText: 'Title'), ), const SizedBox(height: 12), TextField( controller: contentController, maxLines: 3, decoration: const InputDecoration(labelText: 'Content'), ), ], ), actions: [ TextButton( onPressed: () => Navigator.of(dialogContext).pop(), child: const Text('Cancel'), ), FilledButton( onPressed: () { final title = titleController.text.trim(); final content = contentController.text.trim(); if (title.isNotEmpty) { context.read<NoteBloc>().add( AddNoteRequested(title: title, content: content), ); Navigator.of(dialogContext).pop(); } }, child: const Text('Save'), ), ], ); }, ); }
@override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: const Text('Notes'), actions: [ IconButton( icon: const Icon(Icons.refresh), tooltip: 'Refresh', onPressed: () => context.read<NoteBloc>().add( const ListNotesRequested(limit: 100), ), ), ], ), body: BlocBuilder<NoteBloc, NoteState>( builder: (context, state) { if (state.status == NoteLoadStatus.loading && state.items.isEmpty) { return const Center(child: CircularProgressIndicator()); } if (state.status == NoteLoadStatus.failure && state.items.isEmpty) { return Center( child: Column( mainAxisSize: MainAxisSize.min, children: [ const Icon(Icons.error_outline, size: 48, color: Colors.red), const SizedBox(height: 12), Text('Failed to load notes: ${state.error}'), const SizedBox(height: 16), FilledButton( onPressed: () => context.read<NoteBloc>().add( const ListNotesRequested(limit: 100), ), child: const Text('Try Again'), ), ], ), ); } if (state.items.isEmpty) { return const Center(child: Text('No notes yet. Add one below!')); } return ListView.builder( itemCount: state.items.length, itemBuilder: (context, index) { final note = state.items[index]; return ListTile( title: Text(note.title), subtitle: Text(note.content), ); }, ); }, ), floatingActionButton: FloatingActionButton( onPressed: () => _showAddNoteDialog(context), child: const Icon(Icons.add), ), ); }}Notice how clean this is:
- Single import surface: You only import
package:notes_flutter/api.dart. - Pre-configured client:
createAppClient()handles WebSocket reconnects and server connectivity. - Generated BLoC:
NoteBlochandles fetching data, caching items instate.items, and executing theAddNoteRequestedmutation.
Step 5: Verify your application with aegil verify
Section titled “Step 5: Verify your application with aegil verify”In another terminal window, run the Aegil verification harness:
aegil verifyaegil verify runs a rigorous, 5-stage automated check:
================================================================= Aegil Verification Harness Report: VERIFIED Project: . (Notes)================================================================= [1/5] Generated File Hash Lock : PASSED [2/5] Hook Completeness : PASSED [3/5] Dart Static Analyzer : PASSED [4/5] Invariant Harness Suite : PASSED [5/5] Server Integration Suite : PASSED=================================================================What aegil verify guarantees:
- Hash Lock: Proves no generated files were tampered with or edited out of sync.
- Hook Completeness: Confirms all custom operations have registered handlers.
- Dart Static Analysis: Proves zero analyzer errors or warnings.
- Invariant Testing: Verifies client validation bounds (e.g. titles longer than 200 characters are rejected).
- Server Integration: Spins up a throwaway Postgres container to test real SQL queries and endpoint calls.
What could go wrong?
Section titled “What could go wrong?”| What you see | Why | What to do |
|---|---|---|
ERR_SPEC_MISPLACED |
A domain spec file was placed directly in specs/ rather than a feature folder. |
Move domain specs into specs/<feature>/<feature>.tsp. Only app.tsp and platforms.tsp belong at the root. |
Cannot connect to Docker |
Docker Desktop or daemon is not running. | Start Docker Desktop and re-run aegil run or aegil verify. |
ERR_TAMPERED_GENERATED_FILE |
A file inside .aegil/ was modified directly. |
Discard changes to .aegil/. Modify specs/<feature>/*.tsp and run aegil build. |
Port 8080 already in use |
Another local web server or Serverpod instance is active. | Stop the other process or pass a custom port to Serverpod. |
Next steps
Section titled “Next steps”Now that you have built and verified your first full-stack Aegil app:
- Explore The Mental Model & Architecture to understand how Aegil unifies Flutter and Serverpod.
- Read Do’s and Don’ts for critical guidelines and best practices.
- Master schema modeling in TypeSpec for Dart Developers.
- Learn Full-Stack Framework Architecture to build production applications.