Architecture and components
Overview​
All the components share one database and one file bucket. Breign API and Breign Document API don't call each other: Breign API writes parsing jobs into the database, Document API picks them up, writes the result to the bucket and marks the job done.
Containers​
Breign APP​
The web interface (Next.js, port 3000). It also runs sign-in (one-time codes by e-mail, passkeys, SSO with OpenID Connect or SAML), so it reads and writes the users, sessions and organizations in the database directly.
For everything else it calls Breign API with the platform API key (BRAIN_) on behalf of the signed-in user. This key gives full access to the API: keep it server-side and never set it in a NEXT_PUBLIC_* variable.
- Stateless: you can run several replicas behind a load balancer.
- The image is built once and configured at start: its entrypoint writes the public URLs (
NEXT_PUBLIC_*) into the built files. The container filesystem must therefore be writable (no read-only root filesystem). - The server side calls the public API URL (
NEXT_), not an internal one: the container must be able to reach it.PUBLIC_ BRAIN_ API_ ENDPOINT
Breign API​
The core of the platform (Node.js, port 8080 by default, set PORT to change it). One container does everything:
- the REST API used by the app, the CLI, Breign Mate and your integrations;
- the WebSockets (execution nodes, avatar apps);
- the MCP servers exposed by Breign and the OpenAI-compatible AI Gateway;
- the background jobs, which run inside the same process: scheduled tasks, automations and webhooks, ticket work, knowledge indexing, purges.
It connects to the database, the bucket, the vector database, the AI providers configured in each organization, and the tools (MCP servers, APIs) your agents use.
Running several replicas. Background jobs claim their work with atomic database operations (leases), so several replicas don't run the same job twice, and conversation turns are stored in the database as they progress, so any replica can answer. Two limits:
- a conversation turn runs in the replica that received it; if that replica stops, the turn stops too (the API waits a few seconds for running work when it receives
SIGTERM); - avatar apps (
/apps/.../sockets,/agents/.../sockets) keep their WebSocket connections in memory: if you use avatar apps, run a single replica.
Breign Document API​
Converts the files added to knowledge bases and conversations (PDF, Word, Excel, PowerPoint, images…) into Markdown and images (Python, port 8000). It can also run OCR on a document, by sending its pages to a vision model or to Mistral OCR, as configured in each organization.
- It polls the job queue in the database: it must use the same database and the same bucket as Breign API.
- It decrypts the OCR provider keys stored by Breign API: its
ENCRYPTION__must be identical.SECRET - Safe to scale: replicas share the queue with leases. Each replica runs several parsing workers in parallel, limited by its CPUs and memory (about 1.6 GB per parse). See Prerequisites and sizing.
- Parsing runs on CPU. OCR is delegated to the configured provider: no GPU is needed.
Breign Scrapping API (optional)​
Crawls the websites added as knowledge sources and stores their pages (Python, port 8000). Breign API starts the crawls and follows them; the Scrapping API writes the pages into the database and the bucket and calls Breign API back.
- Only needed if you use website knowledge sources.
- It fetches HTML pages as they are served: pages built in the browser by JavaScript are not supported. It follows
robots.txtand crawls politely (one request per site at a time). - Run a single replica: crawl status is kept in memory.
- It doesn't check the API key of incoming calls: keep it on a private network, reachable by Breign API only.
Guards API (optional)​
Runs the guardians an organization can attach to its agents: anonymization (and de-anonymization) of personal data, toxicity, prompt injection, banned topics. Its URL is entered on each guardian engine, in the app, not in the API configuration.
- Only needed if you use guardians based on this service.
- The models are loaded in memory: plan several GB of RAM. The image is several GB as well.
- Run a single replica: anonymized values are kept in memory to be restored in the answer.
- Toxicity, prompt injection and banned topics translate non-English text with Google Translate before analysis: that text leaves your infrastructure.
- The image starts Python's built-in web server. Set its
API_(all calls must send it) and keep it on a private network.KEY
Execution nodes (optional)​
An execution node runs agent turns on a coding CLI (fx, Claude Code or OpenCode) instead of on the Breign server — on a developer's machine with Breign Mate or the CLI, or as containers in your cluster. A node only makes outbound connections to Breign API (WebSocket and HTTPS): it can sit inside your network, next to your code and internal systems, without opening anything inbound. See Run a cluster of nodes.
Services​
| Service | Supported | Used by |
|---|---|---|
| Database | PostgreSQL 13 or later, or MongoDB (including compatible managed services such as Azure Cosmos DB for MongoDB vCore) | APP, API, Document API, Scrapping API |
| Object storage | Any S3-compatible storage (MinIO, OVH, Scaleway, AWS S3…), Azure Blob Storage, Google Cloud Storage | API, Document API, Scrapping API, users' browsers |
| Vector database | Weaviate or Qdrant (chosen per knowledge base) | API |
| Resend | APP (sign-in codes, invitations), API | |
| AI models | OpenAI, Mistral, Anthropic, Google Gemini, Ollama, vLLM and any OpenAI-compatible endpoint (Azure OpenAI, LiteLLM, a self-hosted gateway…) | API, Document API (OCR) |
| Identity provider (optional) | Any OpenID Connect or SAML provider (Microsoft Entra ID, Keycloak, Google…) | APP, API |
| Redis (optional) | Only to run scheduled tasks in a separate worker; not needed otherwise | API |
The choice of database is global: every component must be configured with the same type (pg or mongodb) and the same database.
Shared secrets​
Some values must be identical across components:
| Value | Where |
|---|---|
| Database connection | APP (PG_ / MONGODB_), API (SERVICES__ / SERVICES__), Document API, Scrapping API |
| Encryption secret | API and Document API: ENCRYPTION__ |
| Document API key | Document API API_ = API SERVICES__ |
| Platform API key | API AUTHENTICATION__ = APP BRAIN_ = Scrapping API BRAIN_ |
| Scrapping API key | API SERVICES__ |
| Bucket | API, Document API, Scrapping API: same bucket and credentials |
Environment variables lists every variable of each component.