Skip to content

Latest commit

 

History

History
56 lines (35 loc) · 9.16 KB

backend-integration.md

File metadata and controls

56 lines (35 loc) · 9.16 KB

Backend integration contract — implemented local platform

The typed boundary remains UI → src/data/hooks.ts → PlatformApi → src/data/http.ts → /api/v1 → Go control plane. src/domain/types.ts defines the UI vocabulary. scripts/generate-go-models.cjs generates typed Go DTOs (see the script's header for usage); domain behavior lives in dedicated Go packages. Components do not issue ad hoc fetches. The fixture adapter is enabled only by explicit NEXT_PUBLIC_GANTRY_MODE=demo.

Transport and error contract

Next rewrites same-origin /api/v1/* to loopback Go port 8080. JSON requests have a 64 KiB maximum, unknown fields are rejected, and names/environments/runtime/ownership/plans are validated. Errors return a stable code, human message, optional safe detail and request correlation ID. Ordinary responses never expose stack traces. HTTP 400 validation, 401 unauthenticated, 403 forbidden/CSRF, 404 missing entity, 409 conflict/idempotency mismatch and 503 unavailable are distinct.

Pagination accepts page and pageSize (1–100); page responses include items, total, hasMore. The central adapter caps its internal broad requests to this server maximum. Stable service IDs are svc-<slug>; jobs, resources and deployments have generated stable IDs. Slugs are DNS-safe and unique. Invalid enum/filter/page inputs fail explicitly where constrained; query results are bounded for this six-service local proof.

Mutating workflow requests send Idempotency-Key. Actor, operation and key form a unique database key; a request hash detects changed content. Repeated identical requests return the same durable entity. Catalog slug uniqueness and service/environment/resource-kind uniqueness additionally prevent duplicates across different keys. Resource/creation retry preserves identity. Deployment retry is a new deliberate deployment, with its own idempotency key. SSE cursor IDs are durable database sequences.

Identity

POST /auth/login accepts {handle,password}. GET /me returns the current role/team profile. POST /auth/logout invalidates the session. Passwords are bcrypt cost 12; random eight-hour sessions and CSRF tokens persist only as hashes. Cookie settings are HttpOnly for the session, SameSite=Strict, bounded Max-Age and Secure when HTTPS is configured. Local proof uses loopback HTTP. Login is bounded per account and client address.

Every mutation requires an allowed Origin and matching X-CSRF-Token from the CSRF cookie. Developer operates its own team outside production; lead additionally operates its own production services; platform operates all local teams and ownership administration; read-only cannot mutate. The worker rechecks the actor's current authorization. Hiding a frontend action is never the security boundary.

REST surface

All routes below are relative to /api/v1 and authenticated unless stated otherwise. /healthz, /readyz, /version and /metrics live at the control-plane root; health/version are public local diagnostics and readiness checks real PostgreSQL connectivity.

Area Endpoints and behavior
Reference / identity GET /me, /users, /users/{id}, /teams, /teams/{slug}, /systems, /golden-paths, /golden-paths/{id-or-slug}, /policies, /policies/{id}, /standards, /resource-plans
Catalog GET /services and /services/{slug}; search q, owner/team, type, language, lifecycle, health, Golden Path, sorting and pagination
Create POST /services → durable CreationJob; GET /creations/{id}; POST /creations/{id}/retry
Metadata PUT /services/{slug}/owner, PUT /services/{slug}/runbook ({slug}), PUT /services/{slug}/dependencies ({targetSlugs}), POST /services/{slug}/visits
Environments GET /services/{slug}/environments and /{env}; POST /{env}/sync; GET /{env}/probe executes an instrumented bounded consumer request
Deployments GET /deployments, /deployments/{id}; POST /deployments; POST /deployments/{id}/retry; POST /deployments/{id}/rollback with reason
Resources GET /resources, /resources/{id}; POST /resources; POST /resources/{id}/retry
Evidence GET /services/{slug}/dependencies, /scorecard, /slos, /metrics?environment=…&period=…; GET /slos/at-risk
Logs / traces GET /logs?serviceId=…&environment=…; /traces?serviceId=…&environment=…; /traces/{actual-trace-id}
Incidents GET /incidents?serviceId=…&state=…, /incidents/{id}; durable observed availability incidents, automatic observed resolution
Experience GET /home, /teams/{slug}/summary, /action-items, /activity, /docs, /docs/{slug}, /services/{slug}/docs, /platform/capabilities
Live GET /events, optional Last-Event-ID header or lastEventId query for replay

Deployment input is {serviceSlug,environment,version,reason?,configuration?,fixDeploymentId?}. The normal path uses Golden Path defaults. The deliberate advanced configuration supports memory limit, CPU request, privilege and exposure proposals; exact Kubernetes admission evaluates unsafe workload proposals. Literal env configuration is rejected before persistence. A recommended fix references the actual failed deployment and disallows competing overrides. Rollback restores an earlier healthy source-addressed image through the normal admission/GitOps/readiness path.

Resource input is {serviceSlug,kind,planId,environment,name?,reason?}. Only postgresql-local and redis-local are implemented. States are requested → validating → policy-check → provisioning → ready, with policy-blocked, provisioning-failed and degraded evidence/remediation. READY requires resource reachability and successful use from the consumer, not merely a Kubernetes object existing.

Creation and live behavior

The nine-step wizard keeps its accepted interaction contract. Real mode offers the four verified runtime paths, internal exposure, configured development/staging/production environments, mandatory telemetry, fixed local scaling and bounded resource plans. Unsupported mock-only options are disabled with local-scope explanations.

Creation steps report actual validation, source/build/test, admission, registration, GitOps/environment and observability configuration evidence. Ready is returned only after observed Argo revision, Kubernetes replicas and HTTP readiness. Metadata identifies platform origin; catalog registration is part of the workflow, not a manual seed of consumer records.

The SSE connection emits a connected frame immediately, durable entity invalidations and ten-second heartbeats; its DB scan interval is two seconds. Cache-Control: no-store, no-transform is essential: it prevents Next's compression proxy from buffering small events. Reconnection is bounded (six attempts, exponential delay capped at 30 seconds) and exposes LIVE/UPDATING/STALE/RECONNECTING/CONNECTION LOST. Session revocation closes an open stream. UI hooks refetch affected typed data after invalidation; no aggressive per-component polling is introduced.

Truthful data presentation

Environment status is observed from Argo and Kubernetes, with explicit stale metadata on observation failure. Desired/observed revisions and readiness are not inferred from a submitted request. Admission failures preserve the exact policy output behind progressive technical detail and lead with what/where/why/next. Audit captures actual actors and safe outcomes.

Metrics and traces query Prometheus/Jaeger; logs use bounded Kubernetes retrieval. Missing samples stay unknown/unavailable. CPU/memory are actual current Kubernetes samples, not invented chart history. SLO calculations use the local five-minute window documented in architecture. Scorecard checks include source/evidence/remediation and persist their evaluation. Dependency edges are explicit catalog relationships and resource attachments, without asserting unsupported causality.

Fixture-mode behavior and the protected frontend suite are documented in testing.md. Protected fixture results are not current platform execution evidence.