# Request paths

> What happens, call by call, for a deploy, a release and a visitor's request.

Applies to: the Sypnia engine (open source, self-hosted) and Sypnia Cloud (paid service).  
Source: https://run.docs.sypnia.com/architecture/request-paths/

For agents: Run request paths: deploy (API checks scopes and credits, writes deploys/builds rows, queues build; builder starts CodeBuild with per-project role and signed URLs; deployer uploads to s3 deploys/<deploy>/, publishes Lambda version or Fargate task definition, schedules, queues; health check; ready; auto release); release (deployer writes host→deploy to CloudFront KeyValueStore, shifts Fargate target group; previous deploy intact); visitor (CloudFront TLS, edge CloudFront Function reads KVS and rewrites to deploy origin path; S3 cached, Lambda function URL with OAC, or Fargate via load balancer; real-time logs).

## A deploy

1. `POST /v1/apps/laespiga/deploys` reaches the Run API with a token. The API checks the token's scopes and the organization's credits, writes a `deploys` row (`queued`) and a `builds` row, and sends a message to the build queue.
2. The builder takes the message, starts a CodeBuild build with the build role of that project, and passes a signed URL to fetch the source and a signed prefix to write artifacts.
3. CodeBuild streams logs; the builder copies them to the build's log and marks the build `succeeded` or `failed`.
4. On success the deployer creates the deploy's resources: uploads files under `s3://…/deploys/<deploy>/`, publishes a Lambda version or registers a Fargate task definition, creates schedules and queues the first time. Resources are tagged with project, app and deploy.
5. The deployer calls the health check at the deploy's own address and marks the deploy `ready`.
6. If the environment follows this deploy automatically, the release step runs.

## A release

1. `POST …/environments/production/release` (or step 6 above) checks the deploy is `ready`.
2. The deployer writes `laespiga.sypnia.app → dpl_7h3k` (and every custom domain of the environment) to the CloudFront KeyValueStore, and for Fargate shifts the load balancer's target group.
3. The release row is written; the previous deploy stays intact for rollbacks.

## A visitor's request

1. The browser asks `https://laespiga.sypnia.app/pedidos`.
2. CloudFront terminates TLS and runs the edge router (a CloudFront Function): it reads the host's deploy from the KeyValueStore and rewrites the request to that deploy's origin path.
3. Static paths are served from S3 (cached). Dynamic paths go to the deploy's Lambda function URL (signed by CloudFront with origin access control) or to the Fargate service behind the load balancer.
4. The response returns through CloudFront. The request log line is written by CloudFront's real-time logs to the log pipeline.
