Draft: This documentation is currently a work in progress and subject to change.
Quick Navigation: - For complete endpoint implementations, see API
Specifications - For code examples and patterns, see
Data Ownership - For authentication and security, see
Auth
Table of Contents
- API Response Contract
- Field Design Rules
- Implementation Reference
- Naming Conventions
- Action Endpoints
- Bulk Operations
- Error Handling
- Audit Logging
- Multi-Tenancy Patterns
API Response Contract
All API responses use a consistent discriminated union envelope structure with asuccess boolean discriminator.
Type Definition
Base Meta Object
Themeta object is always present and contains request tracking information:
Design Decision:
requestId and timestamp are always included because
they provide negligible overhead while being critical for distributed
debugging and log correlation across services.Extension Meta Types
Success responses can extend meta with additional context:Error Response Structure
Response Examples
Meta Object Design Decisions
Implementation Reference
Technology Stack
Zod Schema Definitions
Define all request/response schemas using Zod for validation and type inference:Pattern: Workflows by Default. All operations that interact with
infrastructure (BMC, K8s) are executed as Trigger.dev workflows and return
immediately with a workflow run ID. Clients poll workflow status via the
Workflows API or receive webhooks.
Field Design Rules
Design fields for extension from day one. The cost of refactoring primitive fields into objects later is high and often requires breaking changes.Principle: Objects Over Primitives. Always wrap values that might grow
into structured objects. It’s better to have nested objects early than to
break APIs later when you need to add context.
Use Objects Over Primitives
Wrap values that might grow into objects immediately.Never Use Booleans for State
States often grow beyond two values.Use IDs with Optional Expansion
Don’t embed full objects. Use IDs and let clients request expansion.GET /v1/compute/servers/srv_123
GET /v1/compute/servers/srv_123?expand=cluster
API Versioning
All API endpoints include version in the URL path:/v1/...
Domain-based routing separates Atlas and Arc APIs:
Version Format
Version Policy
- Major versions (
v1,v2) for breaking changes - No minor versions in URL - use feature flags and deprecation warnings instead
- Deprecation timeline: 6 months notice before removing deprecated endpoints
- Version in URL, not response: The
apiVersionfield is omitted from responses because the URL path is the source of truth
When deprecating fields or endpoints, include warnings in the
meta.warnings
array with sunset dates and migration guides.Deprecation Example
Naming Conventions
Consistent naming across URLs, fields, and resources improves developer experience and reduces confusion.URL Paths
Hono uses colon-prefixed route parameters.NOTE: Lowercase, hyphenated is only for url paths and not the same for the database, response, request body, and other contexts.
Resource IDs
Resources (clusters, servers, organizations, etc.) get globally unique, opaque IDs that do NOT contain region information. This decouples resource identity from physical location. Format:{prefix}_{base62}
Special ID:
org_system is reserved for platform-level admin operations. TBD if this is needed still. Originally it was for something else.
Field Names
Pagination
Use cursor-based pagination for real-time data, offset/limit for stable datasets.Query Parameters
Response
Filtering and Sorting
Query String Format
Use consistent query parameter patterns for filtering and sorting:Implementation with Zod
Action Endpoints
For operations beyond CRUD, use a unified action endpoint with POST method. Actions represent commands that change resource state asynchronously.Design Principles
- Unified Endpoint: Single
/actionsendpoint handles all action types (power, provision, deprovision, inspect, maintenance) - Type-Safe Parameters: Each action type has its own request schema with action-specific options
- Async by Default: Actions return
202 Acceptedwith workflow/operation IDs for tracking - Audit Trail: Logs show “POST /actions with type=power action=off” for clear tracking
- Granular Permissions: Easy to scope permissions like
servers:lifecyclevsservers:update
Endpoint Pattern
Action Request Schema
Implementation Example
Bulk Operations
Bulk operations allow applying actions to multiple resources simultaneously. All bulk actions use partial success semantics - individual resource failures do not fail the entire bulk operation.Design Principles
- Partial Success: Individual failures don’t abort the entire bulk operation
- Explicit IDs: Use explicit ID lists for predictability and safety
- Per-Resource Results: Response includes success/failure status for each resource
- 207 Multi-Status: Always return 207 to indicate mixed results possible
- Dedicated Endpoints: Use
/bulkpattern for consistency
Endpoint Pattern
Request Schema
Response Structure
Implementation Example
Safety Features
Dry-Run Mode
Preview which resources would be affected without executing:Rate Limiting
Bulk operations are throttled to prevent resource overload. Default: 10 requests/min.Implementation Reference
Error Handling
Typed Error Classes
Define semantic error types for consistent error responses:lib/errors.ts
Global Error Handler
middleware/error-handler.ts
Usage in Routes
Audit Logging
SOC 2 compliant audit logging for all API requests. Every significant action must be traceable to a user and timestamp.What to Log
For multi-tenant security architecture and authorization patterns, see Auth
Architecture.
Sensitive Entities Requiring Audit Logs
These entities require audit logging on all operations, including reads:Audit Event Schema
Audit Event Naming Convention
Use past-tense, dot-namespaced actions:Multi-Tenancy Patterns
Row-Level Security (RLS)
Use PostgreSQL RLS for defense-in-depth isolation:Setting Context Per Request
middleware/rls-context.ts
Critical: RLS context is set per-transaction. For connection pooling,
always set context at the start of each request. Drizzle’s
transaction()
helper ensures this.Decision Log
Response Envelope Pattern
Resource ID Format
Action Endpoints
Bulk Operation Responses
Async Operation Default
Testing
Test Structure
All API endpoints should have integration tests covering:- Happy path: Successful requests with expected responses
- Validation: Invalid inputs return appropriate errors
- Authorization: Unauthorized users receive 403
- State transitions: Invalid state transitions are rejected
- Edge cases: Empty lists, missing resources, etc.
Test Helpers
tests/helpers/api.ts
Example Test
Related Documentation
- Specification - Complete API specification with detailed endpoint examples
- Auth Architecture - Authentication, authorization, and multi-tenant security patterns
- Data Ownership - Implementation patterns, workflow orchestration, and development guidance
- Data Model - Database schema and relationships