Skip to main content

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_API_KEY) 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_PUBLIC_BRAIN_API_ENDPOINT), not an internal one: the container must be able to reach it.

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__SECRET must be identical.
  • 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.txt and 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_KEY (all calls must send it) and keep it on a private network.

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​

ServiceSupportedUsed by
DatabasePostgreSQL 13 or later, or MongoDB (including compatible managed services such as Azure Cosmos DB for MongoDB vCore)APP, API, Document API, Scrapping API
Object storageAny S3-compatible storage (MinIO, OVH, Scaleway, AWS S3…), Azure Blob Storage, Google Cloud StorageAPI, Document API, Scrapping API, users' browsers
Vector databaseWeaviate or Qdrant (chosen per knowledge base)API
E-mailResendAPP (sign-in codes, invitations), API
AI modelsOpenAI, 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 otherwiseAPI

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:

ValueWhere
Database connectionAPP (PG_URI / MONGODB_URI), API (SERVICES__PG__URI / SERVICES__MONGODB__URI), Document API, Scrapping API
Encryption secretAPI and Document API: ENCRYPTION__SECRET
Document API keyDocument API API_KEY = API SERVICES__DOCUMENTS_SERVICE__API_KEY
Platform API keyAPI AUTHENTICATION__API_KEY = APP BRAIN_API_KEY = Scrapping API BRAIN_API_KEY
Scrapping API keyAPI SERVICES__SCRAPPING__API_KEY
BucketAPI, Document API, Scrapping API: same bucket and credentials

Environment variables lists every variable of each component.