# Architecture

> How the engine is built, where Rust runs and where the logic lives, how requests flow, what is stored, how it runs on AWS, what happens when something fails, and how it scales.

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

For agents: Section index for Sypnia Data's architecture: one Rust binary (axum, sqlx, tokio) with modules core, auth, mail, rest, sql, install, server; stateless; all state in the project's Postgres; runs as a Lambda (arm64) behind CloudFront in Sypnia Cloud or as a container/binary self-hosted. Pages: components, request paths, data model, reference implementation on AWS, failures, scaling and pooling, codebase.

Sypnia Data is small on purpose: **one program and your database**. The program, the engine, is written in Rust and keeps nothing between requests: every user, session, key and setting lives in the project's Postgres. Run one copy or fifty; they agree because the database is the only memory.

**Figure**: Sypnia Data's parts. Everything the engine knows comes from, and goes to, your Postgres.

1. Your app calls the project's address with a publishable key and the user's token.
2. Agents and services sign in with OAuth and call the same address.
3. Auth: sign-up, sign-in, sessions, tokens, e-mails.
4. The Data API: a URL becomes one SQL statement, run as the caller's role.
5. Postgres: your tables, `sypnia_auth`, and the policies that decide who sees what.

- [Components](/architecture/components/): The engine's modules, what each one owns, and the services and libraries around them.
- [Request paths](/architecture/request-paths/): What happens, step by step, in a sign-in, a token refresh, a machine token request and a Data API query.
- [The data model](/architecture/data-model/): What the engine stores in your database, table by table, the roles it creates, and how row-level security ties them together.
- [A reference implementation on AWS, service by service](/architecture/reference-implementation-aws/): Every AWS service Sypnia Data uses, what it does, where the Rust runs, its limits, and what it costs at small scale.
- [When something fails](/architecture/failures/): What happens, and what you see, when the database, the e-mail provider, a key, a provider or the engine itself fails.
- [Scaling and connection pooling](/architecture/scaling-and-pooling/): How many database connections the engine uses, how to size it, and when to add a pooler.
- [The codebase](/architecture/codebase/): How the repository is organised, how to build and test it, and where to start reading.

## Where Rust runs and where the logic lives

| What                                                                               | Where                                 | Language                |
| ---------------------------------------------------------------------------------- | ------------------------------------- | ----------------------- |
| Checking credentials, issuing and verifying tokens, sessions, e-mails, OAuth, DPoP | the engine                            | Rust                    |
| Turning a URL into SQL, running SQL and migrations                                 | the engine                            | Rust                    |
| **Which rows a caller may see or change**                                          | **your database**, row-level security | SQL policies you write  |
| What your app does for a person                                                    | your code, with any ORM or none       | TypeScript, or anything |
| Sending e-mail, signing with KMS, the address                                      | managed services or your providers    | —                       |

The engine never filters rows itself. That single rule is why the Data API, your server's ORM and an agent with SQL access all obey the same permissions.
