Architecture
What runs on the host, how a request and an inbound message move through the backend, and which outside services it calls.
eDGR is two applications on top of three infrastructure services, all on one host under Docker Compose. The web app is a React single-page app and talks to nothing but the backend. The backend is one NestJS process that does all the work: it serves the API, runs the AI reply agent, delivers events between its own areas, runs timed jobs, and executes campaign steps when Restate calls it. Postgres holds every piece of application data. Restate holds the state of the campaigns in progress. On the server, a Caddy reverse proxy in front of the host terminates TLS and splits API traffic from the web app.
Hover or focus any box to see what it does and what it talks to.
The parts
| Part | What it does | Talks to |
|---|---|---|
| Web app | Every screen. Keeps the sign-in tokens, refreshes them, and holds an open stream for inbox updates. | The backend only |
| Reverse proxy | TLS on the server. Sends API paths to the backend with the /api prefix removed and everything else to the web app. Webhooks and tracking links enter here too. | Backend, web app |
| Backend | The API, the reply agent, the event bus, the timed jobs and the campaign step handler, in one process | Postgres, Restate, every outside service |
| Postgres with pgvector | Business data, plus the event bus queue, the job locks, and the vector embeddings for knowledge and lead memory | Read and written by the backend |
| Restate | Durable campaign execution: one workflow per person in a run, so waits and retries survive a restart | Calls the backend’s campaign handler |
| Redis | Started, and required at boot, but nothing in the backend connects to it | Nothing |
One process means one image to build, one log to read and one set of settings. It also means the API, the agent and the background jobs share the same CPU and restart together.
A request from the browser
Every call carries the short-lived access token. When several calls fail at once because it expired, the web app refreshes it once and retries them all.
Sign-in returns two tokens. With the example settings, the access token lasts 15 minutes and the refresh token 7 days. The web app keeps both in the browser and sends the access token on every call. The inbox stream is a server-sent event stream that the web app opens with the same token, so new messages appear without a reload.
The /api prefix is handled in three ways:
| Where | Who removes /api |
|---|---|
| Server | Caddy, which also routes everything else to the web app |
| Dev stack, or the web app run on its own | The Vite dev server’s proxy |
| Prod images on a laptop | Nobody. The web app is built with the backend’s own address and calls it directly. |
The API address is written into the web app when it is built, so a different address needs a new web app image.
An inbound message
A message that arrives on any channel takes the same path, whether it came by webhook or by polling a mailbox.
Telegram, LinkedIn (through Unipile), Zalo and SES call a webhook. Email accounts are polled over IMAP every 60 seconds.
The agent’s side of this is on AI reply agent.
Background work
All background work runs inside the backend process, beside the API.
- 1 Publish An area announces what happened
- 2 Store One delivery row per subscriber, in Postgres
- 3 Poll Every 250 ms, in the same process
- 4 Deliver The subscriber runs its work
- 5 Retry A thrown error is retried later with the stored payload
The bus is how one area makes another react without calling it. Deliveries are rows in Postgres, so an event published just before a crash is still delivered after the restart. An event that no area subscribes to is dropped with a warning. An event type can be debounced, which collapses repeats for the same record into one delivery.
A delivery is retried only when its subscriber throws. The wait doubles after each failure, from one second up to 256 seconds, and there is no limit on attempts. The subscriber for inbound messages catches and logs its own errors, so a message that fails there is not retried.
| Mechanism | What it does |
|---|---|
| Restate workflows | Each person in a campaign run is one durable workflow. On boot the backend registers its campaign handler with Restate and exits if Restate refuses, which is why Compose starts the backend only after Restate is healthy. |
| Timed jobs | Mailbox polling every 60 seconds, the campaign scheduler, lead research, CRM sync, the sweep of idle agent sessions, and a daily analytics rollup at 01:00 |
| Locks | Lease rows in Postgres, so a mailbox or a job is worked by one process at a time. A lease expires on its own if the process holding it dies. |
Data and files
The database is split into five schemas by area: accounts, analytics, automation, content and CRM. There is no migration history. The schema is pushed to match the code, and a change that would lose data ships as a hand-written SQL file that runs first; see Schema changes.
Knowledge chunks and lead memories store their embeddings with the model name and the vector size next to each row. Search compares only rows made by the workspace’s current embedding model, so a workspace that changes models never mixes vectors from two models.
Uploaded files go to a folder on the host or to S3, chosen in the backend’s settings.
Saved credentials, such as SMTP passwords, bot tokens and AI keys, are encrypted in the database with AES-256-GCM. The key is a dedicated encryption key when one is set. Without one it is derived from the token signing secret, and changing that secret makes every saved credential unreadable.
Outside services
| Service | Used for | How it reaches eDGR |
|---|---|---|
| SMTP servers | Sending email from each email channel | It does not; the backend sends |
| IMAP | Reading replies and bounce reports | Polled every 60 seconds |
| Amazon SES, through SNS | Inbound email, and delivery, bounce and complaint events | Webhook |
| Unipile | LinkedIn messages and the hosted LinkedIn login | Webhook |
| Telegram Bot API | One bot per Telegram channel | Webhook |
| Zalo | Official Account messages | Webhook |
| Amazon Bedrock, OpenAI, Anthropic | Chat, structured output and embeddings, with each workspace’s own key | It does not; the backend calls |
| HubSpot, Salesforce, Slack | Optional CRM sync and notifications | It does not; the backend calls |
| Calendly, Cal.com | Booking events | Webhook |
| Company websites | Lead research reads a company’s public site | It does not; the backend fetches |
Webhooks and tracking links come in through the same proxy route as API calls, at the backend’s public address. Zalo and the booking services sign the exact bytes of a request, so the backend keeps the raw body on their routes. The channel webhooks are registered by each channel’s client rather than beside the other API routes, so they are missing from a list of the API’s routes.
Known weak spots
| Spot | Effect |
|---|---|
| Redis runs but is unused | The backend refuses to boot without its address, yet never connects. The bus and the locks are in Postgres. |
| The cache is in memory | Each backend process has its own small cache, so two processes would not share it. |
| The inbox stream is in memory | A new message reaches only the inbox streams held by the process that logged it, so a second backend process would leave some inboxes without live updates. |
| The Telegram webhook is unauthenticated | It checks no secret, so anyone who knows a bot’s id can post a fake inbound message into that workspace. |
| No health route | A Compose health check only tests that the API port accepts connections; see Health checking. |
| Boot depends on Restate | If Restate cannot reach the backend’s campaign handler, the backend exits and restarts in a loop. |