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

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 run to scaffold and run an interactive full-stack counter in seconds. Follow the steps below to build an application from scratch.

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 NoteBloc through a single import (package:notes_flutter/api.dart).
  • End-to-end verification proving type safety, validation boundaries, and database integrity.

Aegil Quickstart Overview


Before starting, make sure you have:

  1. Flutter SDK (3.35.x or later, which includes Dart).
  2. Serverpod CLI (dart pub global activate serverpod_cli).
  3. Docker Desktop (or Docker Engine, running locally for the database).
  4. Aegil CLI installed and on your PATH:
Terminal window
# Option 1: Homebrew (macOS & Linux)
brew tap steach-IDE/aegil https://github.com/steach-IDE/aegil
brew install aegil
# Option 2: Dart pub global
dart pub global activate --source git https://github.com/steach-IDE/aegil.git --git-ref v0.1.0

Verify your installation:

Terminal window
aegil version

Step 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:

Terminal window
aegil create notes
cd notes

Notice 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 dependencies

All 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.tsp and platforms.tsp) live directly in specs/. Placing domain specs at the root triggers ERR_SPEC_MISPLACED.

Create the feature directory and spec file:

Terminal window
mkdir -p specs/notes

Add 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 in aegil.yaml.
  • model Note { ... } defines a data model—just like a Dart class—and tells Aegil to create a PostgreSQL table named notes.
  • string, uuid, and utcDateTime map directly to Dart’s String, UuidValue, and DateTime.
  • @validate({ minLength: 1, maxLength: 200 }) is a decorator (analogous to a Dart annotation like @override or @JsonSerializable). Aegil compiles it into input checks that run on both client and server.
  • @public declares that these endpoints do not require a signed-in user session for this starter app.
  • @autoQuery generates the Serverpod endpoint, cursor-based pagination query, and Flutter BLoC events automatically.
  • @autoMutation generates the Serverpod endpoint, database insertion logic, cache invalidation (touches: ["Note"]), and client mutation event.

Just like flutter run starts your mobile app, aegil run manages and launches your entire full-stack environment in a single command:

Terminal window
aegil run

What aegil run does behind the scenes:

  1. Compiles specs/**/*.tsp into Serverpod backend code and Flutter client code.
  2. Checks Docker and starts a local PostgreSQL database container on port 8090.
  3. Runs database migrations to create the notes table with primary keys and constraints.
  4. Boots the Serverpod backend server on http://localhost:8080.
  5. 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:8080
Launching 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: NoteBloc handles fetching data, caching items in state.items, and executing the AddNoteRequested mutation.

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:

Terminal window
aegil verify

aegil 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:

  1. Hash Lock: Proves no generated files were tampered with or edited out of sync.
  2. Hook Completeness: Confirms all custom operations have registered handlers.
  3. Dart Static Analysis: Proves zero analyzer errors or warnings.
  4. Invariant Testing: Verifies client validation bounds (e.g. titles longer than 200 characters are rejected).
  5. Server Integration: Spins up a throwaway Postgres container to test real SQL queries and endpoint calls.

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.

Now that you have built and verified your first full-stack Aegil app: