# maxima24/conduit architecture

> Architecture diagram of the GitHub repository maxima24/conduit, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-19). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/maxima24/conduit
- Repository: https://github.com/maxima24/conduit

## Overview

#### Purpose and Workspace
Conduit is a webhook-delivery system: ingest external webhooks, persist events idempotently, queue delivery, track attempts/retries/DLQ, reconcile delivery gaps, and expose operational visibility. It is a pnpm/Turborepo monorepo with a NestJS API, Next.js dashboard, and a shared contract package. Root orchestration is in `package.json`, `turbo.json`, and `docker-compose.yml`.

#### Entrypoints and Runtime Composition
The API starts through Nest bootstrap in `apps/api/src/main.ts`, assembling feature modules in `apps/api/src/app.module.ts`. The dashboard uses the Next App Router rooted at `apps/web/src/app/layout.tsx`, with principal pages for events, DLQ, and reconciliation. Local/runtime infrastructure is PostgreSQL and Redis, configured for deployment alongside the API by `docker-compose.yml` and `render.yaml`; the API worker runs in-process on Render.

#### Shared API Boundary
`packages/contracts` is the source of truth for HTTP routes, request/response DTOs, enums, errors, pagination, and stream messages. Both applications should cross the API boundary through these definitions, notably `packages/contracts/src/routes.ts`, `packages/contracts/src/index.ts`, and `packages/contracts/src/stream.ts`. API responses use a common error envelope and cursor-paginated lists, while timestamps are ISO-8601 UTC strings and optional values are `null`.

#### Persistence and Data Access
Prisma models and migrations define the durable event, send, attempt, and reconciliation state in PostgreSQL: `apps/api/prisma/schema.prisma` and `apps/api/prisma/migrations/20260719065629_init/migration.sql`. Prisma access is deliberately isolated behind repositories, with shared client lifecycle in `apps/api/src/common/prisma/prisma.service.ts`. Feature repositories form the database boundary, including `apps/api/src/modules/events/events.repository.ts`, `apps/api/src/modules/delivery/sends.repository.ts`, and `apps/api/src/modules/reconciliation/reconciliation.repository.ts`.

#### Ingest-to-Delivery Pipeline
Webhook requests enter the webhooks module, which validates/verifies source input, persists idempotently, and enqueues work: `apps/api/src/modules/webhooks/webhooks.controller.ts`, `apps/api/src/modules/webhooks/webhooks.service.ts`, and `apps/api/src/modules/webhooks/webhooks.repository.ts`. Delivery jobs are defined and connected through `apps/api/src/queue/queue.module.ts` and `apps/api/src/queue/job.types.ts`, then consumed by `apps/api/src/modules/delivery/delivery.processor.ts`. Redis/BullMQ provides asynchronous delivery control; Resend is the intended outbound email provider at `apps/api/src/modules/delivery/email/resend.provider.ts`. Actual send/attempt/backoff/DLQ behavior remains marked scaffold TODO work.

#### Operational Read and Repair Surfaces
Events and delivery modules provide persisted operational history, with mapping from database state to contracts in `apps/api/src/modules/events/events.service.ts` and `apps/api/src/modules/delivery/sends.service.ts`. Reconciliation identifies or reports missing/inconsistent delivery state via `apps/api/src/modules/reconciliation/reconciliation.service.ts`; automated gap detection is still a TODO. Aggregate reporting is isolated in `apps/api/src/modules/stats/stats.service.ts`. Live updates are exposed through `apps/api/src/modules/stream/stream.controller.ts` and `apps/api/src/modules/stream/stream.service.ts`.

#### Dashboard Data Flow
The Next dashboard renders server-state views for events, event detail/timelines, DLQ replay, reconciliation, and statistics from `apps/web/src/app/events/page.tsx`, `apps/web/src/app/dlq/page.tsx`, and `apps/web/src/app/reconciliation/page.tsx`. Feature API clients call the backend through `apps/web/src/lib/api-client.ts`; TanStack Query owns server data via `apps/web/src/lib/query-client.ts`. Zustand is restricted to UI intent and live-stream state, such as `apps/web/src/stores/filters.store.ts` and `apps/web/src/stores/stream.store.ts`. The dashboard can run against fixtures through `apps/web/src/mocks/index.ts` before the API is available.

Main entry points: [`apps/api/src/app.module.ts`](https://github.com/maxima24/conduit/blob/master/apps/api/src/app.module.ts) (Feature modules), [`apps/api/src/common/prisma/prisma.service.ts`](https://github.com/maxima24/conduit/blob/master/apps/api/src/common/prisma/prisma.service.ts) (Prisma data access), [`apps/api/src/modules/webhooks/webhooks.service.ts`](https://github.com/maxima24/conduit/blob/master/apps/api/src/modules/webhooks/webhooks.service.ts) (Webhook ingest), [`apps/api/src/queue/queue.module.ts`](https://github.com/maxima24/conduit/blob/master/apps/api/src/queue/queue.module.ts) (Delivery queue)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["NestJS API"]
  node_api_bootstrap["API bootstrap<br/>NestJS entrypoint<br/>[main.ts]"]
  node_api_modules["Feature modules<br/>NestJS composition<br/>[app.module.ts]"]
  node_webhook_ingest["Webhook ingest<br/>controller and service"]
  node_webhook_store["Webhook repository"]
  node_queue["Delivery queue<br/>BullMQ integration<br/>[queue.module.ts]"]
  node_delivery_worker["Delivery processor<br/>in-process worker"]
  node_email_provider["Resend provider<br/>outbound email<br/>[resend.provider.ts]"]
  node_operations_api["Operational services<br/>events and sends services<br/>[events.service.ts]"]
  node_reconciliation["Reconciliation<br/>repair service"]
  node_stats["Aggregate stats<br/>reporting service<br/>[stats.service.ts]"]
  node_stream["Live stream<br/>stream controller and service<br/>[stream.service.ts]"]
end

subgraph group_data["Data and Queue"]
  node_prisma["Prisma data access<br/>client lifecycle<br/>[prisma.service.ts]"]
  node_postgres[("PostgreSQL<br/>durable event state<br/>[schema.prisma]")]
  node_redis[("Redis<br/>BullMQ backend<br/>[docker-compose.yml]")]
end

subgraph group_web["Next.js Dashboard"]
  node_dashboard["Dashboard shell<br/>Next App Router<br/>[layout.tsx]"]
  node_dashboard_views["Operations views<br/>events, DLQ, reconciliation<br/>[page.tsx]"]
  node_api_client["API client<br/>[api-client.ts]"]
  node_query_state["Server data cache<br/>TanStack Query<br/>[query-client.ts]"]
  node_ui_stream_state["UI and stream state<br/>Zustand stores<br/>[stream.store.ts]"]
  node_fixtures["Dashboard fixtures<br/>mock runtime<br/>[index.ts]"]
end

subgraph group_shared["Shared Contracts"]
  node_contracts["HTTP and stream contracts<br/>shared package<br/>[index.ts]"]
end

node_api_bootstrap -->|"starts"| node_api_modules
node_api_modules -->|"routes webhooks"| node_webhook_ingest
node_api_modules -->|"serves history"| node_operations_api
node_api_modules -->|"serves repair"| node_reconciliation
node_api_modules -->|"serves reporting"| node_stats
node_api_modules -->|"exposes updates"| node_stream
node_webhook_ingest -->|"persists idempotently"| node_webhook_store
node_webhook_store -->|"uses"| node_prisma
node_webhook_ingest -->|"enqueues delivery"| node_queue
node_queue -->|"stores jobs"| node_redis
node_queue -->|"dispatches jobs"| node_delivery_worker
node_delivery_worker -->|"sends email"| node_email_provider
node_delivery_worker -.->|"records attempts"| node_prisma
node_operations_api -->|"reads history"| node_prisma
node_reconciliation -->|"checks state"| node_prisma
node_stats -->|"aggregates"| node_prisma
node_prisma -->|"reads and writes"| node_postgres
node_dashboard -->|"renders"| node_dashboard_views
node_dashboard_views -->|"uses server state"| node_query_state
node_query_state -->|"fetches through"| node_api_client
node_dashboard_views -->|"uses live UI state"| node_ui_stream_state
node_api_client -->|"uses API definitions"| node_contracts
node_api_modules -->|"implements"| node_contracts
node_stream -->|"publishes live updates"| node_ui_stream_state
node_fixtures -.->|"can substitute backend"| node_api_client

click node_api_bootstrap "https://github.com/maxima24/conduit/blob/master/apps/api/src/main.ts"
click node_api_modules "https://github.com/maxima24/conduit/blob/master/apps/api/src/app.module.ts"
click node_webhook_ingest "https://github.com/maxima24/conduit/blob/master/apps/api/src/modules/webhooks/webhooks.service.ts"
click node_webhook_store "https://github.com/maxima24/conduit/blob/master/apps/api/src/modules/webhooks/webhooks.repository.ts"
click node_queue "https://github.com/maxima24/conduit/blob/master/apps/api/src/queue/queue.module.ts"
click node_delivery_worker "https://github.com/maxima24/conduit/blob/master/apps/api/src/modules/delivery/delivery.processor.ts"
click node_email_provider "https://github.com/maxima24/conduit/blob/master/apps/api/src/modules/delivery/email/resend.provider.ts"
click node_operations_api "https://github.com/maxima24/conduit/blob/master/apps/api/src/modules/events/events.service.ts"
click node_reconciliation "https://github.com/maxima24/conduit/blob/master/apps/api/src/modules/reconciliation/reconciliation.service.ts"
click node_stats "https://github.com/maxima24/conduit/blob/master/apps/api/src/modules/stats/stats.service.ts"
click node_stream "https://github.com/maxima24/conduit/blob/master/apps/api/src/modules/stream/stream.service.ts"
click node_prisma "https://github.com/maxima24/conduit/blob/master/apps/api/src/common/prisma/prisma.service.ts"
click node_postgres "https://github.com/maxima24/conduit/blob/master/apps/api/prisma/schema.prisma"
click node_redis "https://github.com/maxima24/conduit/blob/master/docker-compose.yml"
click node_contracts "https://github.com/maxima24/conduit/blob/master/packages/contracts/src/index.ts"
click node_dashboard "https://github.com/maxima24/conduit/blob/master/apps/web/src/app/layout.tsx"
click node_dashboard_views "https://github.com/maxima24/conduit/blob/master/apps/web/src/app/events/page.tsx"
click node_api_client "https://github.com/maxima24/conduit/blob/master/apps/web/src/lib/api-client.ts"
click node_query_state "https://github.com/maxima24/conduit/blob/master/apps/web/src/lib/query-client.ts"
click node_ui_stream_state "https://github.com/maxima24/conduit/blob/master/apps/web/src/stores/stream.store.ts"
click node_fixtures "https://github.com/maxima24/conduit/blob/master/apps/web/src/mocks/index.ts"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_api_bootstrap,node_api_modules,node_webhook_ingest,node_webhook_store,node_queue,node_delivery_worker,node_email_provider,node_operations_api,node_reconciliation,node_stats,node_stream toneBlue
class node_prisma,node_postgres,node_redis toneAmber
class node_dashboard,node_dashboard_views,node_api_client,node_query_state,node_ui_stream_state,node_fixtures toneMint
class node_contracts toneRose
```

## Components

### NestJS API

Webhook ingestion, delivery, and operational APIs.

- [API bootstrap](https://github.com/maxima24/conduit/blob/master/apps/api/src/main.ts): NestJS entrypoint · `apps/api/src/main.ts`
- [Feature modules](https://github.com/maxima24/conduit/blob/master/apps/api/src/app.module.ts): NestJS composition · Assembles the API feature boundaries. · `apps/api/src/app.module.ts`
- [Webhook ingest](https://github.com/maxima24/conduit/blob/master/apps/api/src/modules/webhooks/webhooks.service.ts): controller and service · Validates input, enforces idempotency, and creates delivery work. · `apps/api/src/modules/webhooks/webhooks.service.ts`
- [Webhook repository](https://github.com/maxima24/conduit/blob/master/apps/api/src/modules/webhooks/webhooks.repository.ts): repository · `apps/api/src/modules/webhooks/webhooks.repository.ts`
- [Delivery queue](https://github.com/maxima24/conduit/blob/master/apps/api/src/queue/queue.module.ts): BullMQ integration · `apps/api/src/queue/queue.module.ts`
- [Delivery processor](https://github.com/maxima24/conduit/blob/master/apps/api/src/modules/delivery/delivery.processor.ts): in-process worker · Send, retry, backoff, and DLQ behavior is scaffolded. · `apps/api/src/modules/delivery/delivery.processor.ts`
- [Resend provider](https://github.com/maxima24/conduit/blob/master/apps/api/src/modules/delivery/email/resend.provider.ts): outbound email · `apps/api/src/modules/delivery/email/resend.provider.ts`
- [Operational services](https://github.com/maxima24/conduit/blob/master/apps/api/src/modules/events/events.service.ts): events and sends services · Maps persisted history to contract responses. · `apps/api/src/modules/events/events.service.ts`
- [Reconciliation](https://github.com/maxima24/conduit/blob/master/apps/api/src/modules/reconciliation/reconciliation.service.ts): repair service · Reports missing or inconsistent delivery state; detection is scaffolded. · `apps/api/src/modules/reconciliation/reconciliation.service.ts`
- [Aggregate stats](https://github.com/maxima24/conduit/blob/master/apps/api/src/modules/stats/stats.service.ts): reporting service · `apps/api/src/modules/stats/stats.service.ts`
- [Live stream](https://github.com/maxima24/conduit/blob/master/apps/api/src/modules/stream/stream.service.ts): stream controller and service · `apps/api/src/modules/stream/stream.service.ts`

### Data and Queue

Durable state and asynchronous job control.

- [Prisma data access](https://github.com/maxima24/conduit/blob/master/apps/api/src/common/prisma/prisma.service.ts): client lifecycle · Shared database client behind feature repositories. · `apps/api/src/common/prisma/prisma.service.ts`
- [PostgreSQL](https://github.com/maxima24/conduit/blob/master/apps/api/prisma/schema.prisma): durable event state · Stores events, sends, attempts, and reconciliation state. · `apps/api/prisma/schema.prisma`
- [Redis](https://github.com/maxima24/conduit/blob/master/docker-compose.yml): BullMQ backend · `docker-compose.yml`

### Next.js Dashboard

Operational interface and client-side state.

- [Dashboard shell](https://github.com/maxima24/conduit/blob/master/apps/web/src/app/layout.tsx): Next App Router · `apps/web/src/app/layout.tsx`
- [Operations views](https://github.com/maxima24/conduit/blob/master/apps/web/src/app/events/page.tsx): events, DLQ, reconciliation · Renders operational history and repair surfaces. · `apps/web/src/app/events/page.tsx`
- [API client](https://github.com/maxima24/conduit/blob/master/apps/web/src/lib/api-client.ts): feature API client · `apps/web/src/lib/api-client.ts`
- [Server data cache](https://github.com/maxima24/conduit/blob/master/apps/web/src/lib/query-client.ts): TanStack Query · `apps/web/src/lib/query-client.ts`
- [UI and stream state](https://github.com/maxima24/conduit/blob/master/apps/web/src/stores/stream.store.ts): Zustand stores · Holds UI intent and live-stream state only. · `apps/web/src/stores/stream.store.ts`
- [Dashboard fixtures](https://github.com/maxima24/conduit/blob/master/apps/web/src/mocks/index.ts): mock runtime · Allows dashboard work before the API is available. · `apps/web/src/mocks/index.ts`

### Shared Contracts

Cross-application API definitions.

- [HTTP and stream contracts](https://github.com/maxima24/conduit/blob/master/packages/contracts/src/index.ts): shared package · Routes, DTOs, errors, pagination, enums, and stream messages. · `packages/contracts/src/index.ts`

## Connections

- API bootstrap → Feature modules: starts
- Feature modules → Webhook ingest: routes webhooks
- Feature modules → Operational services: serves history
- Feature modules → Reconciliation: serves repair
- Feature modules → Aggregate stats: serves reporting
- Feature modules → Live stream: exposes updates
- Webhook ingest → Webhook repository: persists idempotently
- Webhook repository → Prisma data access: uses
- Webhook ingest → Delivery queue: enqueues delivery
- Delivery queue → Redis: stores jobs
- Delivery queue → Delivery processor: dispatches jobs
- Delivery processor → Resend provider: sends email
- Delivery processor → Prisma data access: records attempts
- Operational services → Prisma data access: reads history
- Reconciliation → Prisma data access: checks state
- Aggregate stats → Prisma data access: aggregates
- Prisma data access → PostgreSQL: reads and writes
- Dashboard shell → Operations views: renders
- Operations views → Server data cache: uses server state
- Server data cache → API client: fetches through
- Operations views → UI and stream state: uses live UI state
- API client → HTTP and stream contracts: uses API definitions
- Feature modules → HTTP and stream contracts: implements
- Live stream → UI and stream state: publishes live updates
- Dashboard fixtures → API client: can substitute backend
