eAkto Docs
/

FastAPI backend

The backend is a FastAPI modular monolith. backend/app/main.py constructs the database, provider clients, controlled orchestrators, workflow seeds, application services, middleware, and mounted routers.

Startup lifecycle

create_app() performs these steps:

  1. Load validated settings.
  2. Construct provider clients.
  3. Build the SQLAlchemy engine and session factory.
  4. Create compatible local tables and migrations.
  5. Seed active workflow templates.
  6. Construct the eGovAI capability registry and orchestrator during lifespan.
  7. Mount API routers under /api/v1.
  8. Register consistent error handlers.
  9. Close provider clients and dispose the database engine during shutdown.

Backend packages

Package Responsibility
api/ FastAPI routers and dependencies
schemas/ Pydantic request, response, rule, and provider models
models/ SQLAlchemy persistence models
repositories/ Queries, ownership, and transaction boundaries
services/ Authentication, intent compilation, identity, vault, and access services
domain/ Deterministic journey, roadmap, dependency, and rule engines
integrations/ External provider clients, adapters, registry, and orchestration
agents/ Bounded journey-assistance tools and run metadata
seeds/ Versioned workflow definitions

Dependency injection

FastAPI dependencies open and close a SQLAlchemy session per request. Authentication dependencies resolve the bearer token into an AuthenticatedCitizen.

def get_db(request: Request):
    session = request.app.state.session_factory()
    try:
        yield session
    finally:
        session.close()

require_high_assurance builds on authentication and requires a current DOCUMENT_VAULT_ACCESS assurance record.

Controlled external capabilities

The ControlledApiOrchestrator accepts a capability code, not a caller-supplied URL. For each call it validates:

  • whether the capability exists and is enabled;
  • required permissions;
  • internal-only restrictions;
  • consent references;
  • current journey/action context;
  • idempotency keys;
  • Pydantic argument shape;
  • a per-capability in-memory rate limit; and
  • a timeout.

This prevents an AI response or API caller from turning the backend into an arbitrary HTTP proxy.

Persistence behavior

SQLite is the local default. SQLAlchemy 2 models and repositories also support a configured relational database URL. Workflow templates are versioned and seeded idempotently; existing personal journeys retain the workflow version used at creation.

Error handling

Expected failures raise EaktoError and return a safe error envelope. Unexpected exceptions are converted to a generic INTERNAL_SERVER_ERROR; exception details are not returned to the client.

See Error format.

View source

Built for the eGovPH Hackathon 2026. Prototype guidance is not official agency policy.