Built by the creator of tx|Primitives for memory, tasks & orchestrationVisit tx docs
tx-agent-kit
Apps

API Server

Effect HttpApi server powering auth, workspaces, tasks, and invitations with OpenAPI spec generation.

API Server (apps/api)

The API server is the backbone of tx-agent-kit. It is built on Effect HttpApi and exposes a fully typed, schema-validated REST API. The server runs on port 4000 by default.

Architecture

The API server follows a layered architecture where routes delegate to domain services, which in turn interact with repositories through Effect's dependency injection system.

Request -> Route Handler -> Domain Service -> Repository Port -> DB Repository

Each route handler extracts the authenticated principal from the Authorization header, invokes the appropriate domain service, and maps the result to an API response shape.

Route Groups

The API exposes the following route groups:

Auth (/v1/auth)

Auth routes use the custom kind marker since they expose domain-specific operations rather than standard CRUD.

EndpointMethodDescription
/v1/auth/sign-upPOSTRegister a new user and return a session
/v1/auth/sign-inPOSTAuthenticate and return a session
/v1/auth/meGETReturn the authenticated principal
/v1/auth/meDELETEDelete the authenticated user

Workspaces (/v1/workspaces)

Workspace routes use the crud kind marker and expose the full CRUD surface.

EndpointMethodDescription
/v1/workspacesGETList workspaces for the current user (paginated)
/v1/workspaces/:idGETGet a single workspace by ID
/v1/workspaces/manyPOSTGet multiple workspaces by IDs
/v1/workspacesPOSTCreate a workspace
/v1/workspaces/:idPATCHUpdate a workspace
/v1/workspaces/:idDELETERemove a workspace

Tasks (/v1/tasks)

Task routes also use the crud kind marker.

EndpointMethodDescription
/v1/tasksGETList tasks for a workspace (paginated)
/v1/tasks/:idGETGet a single task
/v1/tasks/manyPOSTGet multiple tasks by IDs
/v1/tasksPOSTCreate a task
/v1/tasks/:idPATCHUpdate a task
/v1/tasks/:idDELETERemove a task

Invitations (/v1/invitations)

Invitation endpoints are nested under the workspaces group and include idempotent acceptance.

EndpointMethodDescription
/v1/invitationsGETList invitations for the current user
/v1/invitations/:idGETGet a single invitation
/v1/invitationsPOSTCreate an invitation
/v1/invitations/:idPATCHUpdate an invitation
/v1/invitations/:idDELETERemove an invitation
/v1/invitations/accept/:tokenPOSTAccept an invitation (idempotent)

Kind Markers

Every route file declares an explicit kind marker that must match the corresponding repository port kind:

// apps/api/src/routes/workspaces.ts
export const WorkspacesRouteKind = 'crud' as const

// apps/api/src/routes/auth.ts
export const AuthRouteKind = 'custom' as const

The enforcement layer validates that crud routes expose the full list/get/create/update/remove surface, and that custom routes do not accidentally implement the full CRUD pattern.

OpenAPI Generation

The API spec is generated from the Effect HttpApi definitions:

pnpm openapi:generate

This produces apps/api/openapi.json, which is then consumed by Orval to generate typed client hooks for the web and mobile apps.

Config and Environment

Runtime environment variables are read exclusively through apps/api/src/config/env.ts. Direct process.env access is forbidden in route and service modules.

Integration Testing

The API integration suite lives at apps/api/src/api.integration.test.ts and uses the standardized harness:

import { createDbAuthContext } from '@tx-agent-kit/testkit'

const ctx = createDbAuthContext({
  apiCwd: resolve(dirname(fileURLToPath(import.meta.url)), '..')
})

The harness provides authenticated HTTP helpers and handles DB reset between test cases. Manual process spawning and direct createSqlTestContext wiring are forbidden in the API integration suite.

On this page