Skip to content
Docs
On this page The parts 1/7
Internal — not published

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.

eDGR on one host Hover a box for details
One host · Docker Compose Outside services
People's browsers
/api everything else

Hover or focus any box to see what it does and what it talks to.

Request path Backend call Started, unused Leaves the host

The parts

PartWhat it doesTalks to
Web appEvery screen. Keeps the sign-in tokens, refreshes them, and holds an open stream for inbox updates.The backend only
Reverse proxyTLS 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
BackendThe API, the reply agent, the event bus, the timed jobs and the campaign step handler, in one processPostgres, Restate, every outside service
Postgres with pgvectorBusiness data, plus the event bus queue, the job locks, and the vector embeddings for knowledge and lead memoryRead and written by the backend
RestateDurable campaign execution: one workflow per person in a run, so waits and retries survive a restartCalls the backend’s campaign handler
RedisStarted, and required at boot, but nothing in the backend connects to itNothing

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

One API call Step 1 of 6

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:

WhereWho removes /api
ServerCaddy, which also routes everything else to the web app
Dev stack, or the web app run on its ownThe Vite dev server’s proxy
Prod images on a laptopNobody. 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.

From inbound message to the reply agent Step 1 of 6

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.

The event bus
  1. 1 Publish An area announces what happened
  2. 2 Store One delivery row per subscriber, in Postgres
  3. 3 Poll Every 250 ms, in the same process
  4. 4 Deliver The subscriber runs its work
  5. 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.

MechanismWhat it does
Restate workflowsEach 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 jobsMailbox 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
LocksLease 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

ServiceUsed forHow it reaches eDGR
SMTP serversSending email from each email channelIt does not; the backend sends
IMAPReading replies and bounce reportsPolled every 60 seconds
Amazon SES, through SNSInbound email, and delivery, bounce and complaint eventsWebhook
UnipileLinkedIn messages and the hosted LinkedIn loginWebhook
Telegram Bot APIOne bot per Telegram channelWebhook
ZaloOfficial Account messagesWebhook
Amazon Bedrock, OpenAI, AnthropicChat, structured output and embeddings, with each workspace’s own keyIt does not; the backend calls
HubSpot, Salesforce, SlackOptional CRM sync and notificationsIt does not; the backend calls
Calendly, Cal.comBooking eventsWebhook
Company websitesLead research reads a company’s public siteIt 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

SpotEffect
Redis runs but is unusedThe backend refuses to boot without its address, yet never connects. The bus and the locks are in Postgres.
The cache is in memoryEach backend process has its own small cache, so two processes would not share it.
The inbox stream is in memoryA 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 unauthenticatedIt checks no secret, so anyone who knows a bot’s id can post a fake inbound message into that workspace.
No health routeA Compose health check only tests that the API port accepts connections; see Health checking.
Boot depends on RestateIf Restate cannot reach the backend’s campaign handler, the backend exits and restarts in a loop.
Docs
EN VI