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

Serverpod Backend & PostgreSQL

Aegil generates and manages a complete, production-grade Serverpod backend project under .aegil/server/ featuring type-safe ORM models, session-based authentication, and transactional endpoints derived directly from your TypeSpec specifications.

Server directory structure (.aegil/server/)

Section titled “Server directory structure (.aegil/server/)”

Aegil compiles your TypeSpec declarations into a standard Serverpod server application:

.aegil/server/
bin/
main.dart # Serverpod server entrypoint
config/
development.yaml # Database port (8090) and server port (8080)
passwords.yaml # Local database passwords and JWT secrets (mode 0600)
lib/
src/
endpoints/ # Generated session-authenticated endpoints
generated/ # Serverpod protocol models (*.spy.yaml -> protocol.dart)
handlers/ # Generated handler interfaces for custom hooks
hooks/ # Mirrored hook implementations from Zone 2
pubspec.yaml # Server dependencies (Serverpod, PostgreSQL driver)

Remember: .aegil/server/ belongs to Zone 3 (Compiler-Owned). You should never edit files in this directory directly. If you need to change a schema, edit specs/<feature>/*.tsp and run aegil build.


For every @entity declared in TypeSpec, Aegil generates a Serverpod .spy.yaml file:

# Generated by Aegil compiler from specs/helpdesk/tickets.tsp
class: Ticket
table: tickets
fields:
reporterId: UuidValue
title: String
status: TicketStatus
createdAt: DateTime

Serverpod compiles these YAML models into Dart ORM classes with type-safe database queries (Ticket.db.find, Ticket.db.insertRow, Ticket.db.updateRow).


Aegil generates authenticated Serverpod endpoints that enforce session security:

class TicketEndpoint extends Endpoint {
@override
bool get requireLogin => true; // Private by default
Future<Ticket> getTicket(Session session, UuidValue id) async {
// 1. Caller identity extracted securely from session (never client parameters)
final callerId = await session.auth.authenticatedUserId;
final callerRole = await session.auth.authenticatedUserRole;
// 2. Query executed with PostgreSQL RLS filter compiled from @policy
final ticket = await Ticket.db.findById(session, id, where: (t) => ...);
if (ticket == null) {
throw EndpointException('ERR_NOT_FOUND', 'Ticket not found or access denied');
}
return ticket;
}
}
  • No client identity parameters: Endpoints never accept actingUserId or callerRole. Caller ID is extracted strictly from the cryptographic session.
  • SQL filter pushdown: Row-level access policies compile directly into parameterized PostgreSQL queries, preventing cross-tenant leakage.

Aegil does not generate secret or undocumented HTTP routes. If your cloud deployment (e.g. Kubernetes, AWS ECS, Google Cloud Run) requires a health check, declare it explicitly in your spec:

@health({ path: "/health" })
op checkHealth(): string;

Aegil registers a lightweight HTTP GET handler at /health returning 200 OK. The BOOT check in aegil verify tests this endpoint automatically.


What you see Why What to do
Cannot connect to Docker PostgreSQL container is not running. Start Docker Desktop or daemon and re-run aegil run or aegil verify.
ERR_TAMPERED_GENERATED_FILE A file in .aegil/server/ was modified manually. Discard changes to .aegil/. Modify specs/<feature>/*.tsp and run aegil build.
Port 8080 already in use Another process is occupying the Serverpod port. Terminate the occupying process or run Serverpod on a custom port.