# Architecture

> How Sypnia Run is built: its parts, where Rust and TypeScript run, and how they connect.

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

For agents: Run architecture: control plane (Run API in Rust on Lambda, Postgres state, SQS work queue, builder on CodeBuild, deployer in Rust on Lambda) vs data plane (CloudFront + edge router CloudFront Function with KeyValueStore → S3 files / Lambda / Fargate); control-plane outage stops deploys but never takes apps offline; adapters in TypeScript inside builds; console private.

Run has two planes. The **control plane** decides: it keeps apps, deploys and environments, runs builds and tells AWS what to create. The **data plane** serves: CloudFront, S3, Lambda and Fargate answer your visitors without passing through the control plane, so a control-plane outage stops new deploys but never takes your app offline.

**Figure**: Sypnia Run: who calls it, its parts, and the AWS services your app runs on.

1. The CLI, CI or an agent calls the Run API.
2. The API records the deploy and queues a build.
3. The builder runs your build in an isolated CodeBuild machine and writes artifacts.
4. The deployer turns artifacts into AWS resources and switches the environment at the edge.
5. Visitors reach CloudFront, which serves S3 files or calls the deploy's Lambda or Fargate service directly.

The CLI, CI or an agent call the Run API, which stores apps, deploys and environments in Postgres and queues work in SQS. The builder runs builds in AWS CodeBuild and writes artifacts to S3. The deployer creates Lambda versions, Fargate services, EventBridge schedules and SQS queues, and updates the edge router's key-value store. Visitors reach CloudFront, whose edge function reads that store and sends each request to the right deploy's files in S3 or to its Lambda or Fargate service.

| Part               | Language                                                     | Runs on                   | Open source |
| ------------------ | ------------------------------------------------------------ | ------------------------- | ----------- |
| Run API            | Rust (axum)                                                  | AWS Lambda                | yes         |
| Builder            | Rust orchestrator + build images                             | AWS CodeBuild             | yes         |
| Deployer           | Rust                                                         | AWS Lambda, driven by SQS | yes         |
| Framework adapters | TypeScript (`@sypnia/run`)                                   | inside the build          | yes         |
| Edge router        | JavaScript (CloudFront Functions) + CloudFront KeyValueStore | CloudFront                | yes         |
| Console            | TypeScript (React)                                           | Sypnia Cloud              | no          |

## Functions or containers

Run has two ways to run the server part of an app, and they are for different things.

- **Functions, by default.** Every app runs on functions (AWS Lambda) unless it asks otherwise. A function runs only while it answers a request: you pay per request and for the time it takes, and when nobody visits, it scales to zero and costs nothing.
- **A container, only when the app asks for it.** An always-on container (AWS Fargate) is for what a function cannot do: work that takes longer than 15 minutes, WebSockets or other connections that stay open, workers that must always be running, or a container image of your own that needs a long-lived process.

A container is billed for every hour it is on, whether or not anyone visits, so it is a choice each app makes, never the default. An app opts in with `kind = "container"` and `runtime = "fargate"` in its table of `sypnia.toml` ([The configuration file](https://run.docs.sypnia.com/config/run-file#a-container-on-fargate)); without `runtime = "fargate"`, even a container image runs as a function that scales to zero ([Containers](https://run.docs.sypnia.com/apps/containers)).

The containers of a cell share **one load balancer**, the one that takes their traffic from CloudFront. No app pays for a load balancer of its own.

- [Request paths](/architecture/request-paths/): What happens, call by call, for a deploy, a release and a visitor's request.
- [Data model](/architecture/data-model/): The control plane's tables: projects, apps, environments, deploys, builds, releases, variables and domains.
- [Reference implementation on AWS](/architecture/reference-implementation-aws/): Every AWS service Run uses, what for, and how it is set up.
- [Isolation](/architecture/isolation/): How builds and apps of different customers are kept apart in Sypnia Cloud.
- [Failures and scaling](/architecture/failures-and-scaling/): What happens when each part fails, and how Run grows with traffic.
- [Codebase](/architecture/codebase/): How the open-source repository is organized.
