# sugan-developerinnooryze-stack/leadryze_backend architecture

> Architecture diagram of the GitHub repository sugan-developerinnooryze-stack/leadryze_backend, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-06). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/sugan-developerinnooryze-stack/leadryze_backend
- Repository: https://github.com/sugan-developerinnooryze-stack/leadryze_backend

## Overview

LeadRyze Backend is a multi-tenant CRM platform with marketing, messaging, analytics, and a substantial native CRM/field-service domain. The main user workflow enters through the API, authenticates and authorizes a tenant-scoped request, then uses a product module to manage records or operations. The tree also shows public-widget, automation, document, and integration capabilities. Relationships are limited to those visible in excerpts or the source index; unsampled modules are represented as subsystems without guessed call paths.

Main entry points: [`src/app.ts`](https://github.com/sugan-developerinnooryze-stack/leadryze_backend/blob/main/src/app.ts) (HTTP API), [`src/modules/native-crm/native-crm.router.ts`](https://github.com/sugan-developerinnooryze-stack/leadryze_backend/blob/main/src/modules/native-crm/native-crm.router.ts) (Native CRM API), [`src/config/database.ts`](https://github.com/sugan-developerinnooryze-stack/leadryze_backend/blob/main/src/config/database.ts) (MongoDB), [`src/modules/native-crm/pipeline-config/pipeline-config.controller.ts`](https://github.com/sugan-developerinnooryze-stack/leadryze_backend/blob/main/src/modules/native-crm/pipeline-config/pipeline-config.controller.ts) (Pipeline configuration)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API and identity"]
  node_app["HTTP API<br/>[app.ts]"]
  node_auth["Authentication<br/>[auth.service.ts]"]
  node_authorization["Access control<br/>[auth.middleware.ts]"]
  node_tenants["Tenant management<br/>[tenant.service.ts]"]
end

subgraph group_crm["Native CRM"]
  node_nativecrm["Native CRM API"]
  node_sales["Sales records<br/>[lead.service.ts]"]
  node_fieldservice["Field service"]
  node_automation["CRM automation"]
  node_datasets["Knowledge datasets"]
  node_pipeline["Pipeline configuration"]
end

subgraph group_engagement["Customer engagement"]
  node_customers["Customer records"]
  node_campaigns["Campaigns"]
  node_messaging["Messaging<br/>[message.service.ts]"]
  node_widget["Public widget"]
end

subgraph group_platform["Platform services"]
  node_database[("MongoDB<br/>[database.ts]")]
  node_search["CRM search index"]
  node_storage["S3 storage<br/>[s3.service.ts]"]
  node_webhooks["Webhook integrations"]
  node_analytics["Analytics"]
end

node_user(("CRM user"))
node_ai["AI service"]

node_user -->|"uses"| node_app
node_app -->|"routes"| node_auth
node_app -->|"routes"| node_tenants
node_app -->|"routes"| node_customers
node_app -->|"routes"| node_campaigns
node_app -->|"routes"| node_messaging
node_auth -->|"checks permissions"| node_authorization
node_authorization -.->|"checks roles"| node_database
node_app -.->|"routes"| node_nativecrm
node_nativecrm -.->|"dispatches"| node_sales
node_nativecrm -.->|"dispatches"| node_fieldservice
node_nativecrm -.->|"dispatches"| node_automation
node_nativecrm -.->|"dispatches"| node_pipeline
node_pipeline -.->|"reads and updates"| node_database
node_pipeline -->|"validates custom modules"| node_tenants
node_datasets -->|"searches semantically"| node_ai
node_datasets -->|"queries records"| node_database
node_widget -->|"uses sessions"| node_database
node_widget -->|"loads tenant"| node_tenants
node_search -.->|"indexes CRM records"| node_database
node_app -->|"serves file proxy"| node_storage

click node_app "https://github.com/sugan-developerinnooryze-stack/leadryze_backend/blob/main/src/app.ts"
click node_auth "https://github.com/sugan-developerinnooryze-stack/leadryze_backend/blob/main/src/modules/auth/auth.service.ts"
click node_authorization "https://github.com/sugan-developerinnooryze-stack/leadryze_backend/blob/main/src/middlewares/auth.middleware.ts"
click node_tenants "https://github.com/sugan-developerinnooryze-stack/leadryze_backend/blob/main/src/modules/tenants/tenant.service.ts"
click node_customers "https://github.com/sugan-developerinnooryze-stack/leadryze_backend/blob/main/src/modules/customers/customer.service.ts"
click node_campaigns "https://github.com/sugan-developerinnooryze-stack/leadryze_backend/blob/main/src/modules/campaigns/campaign.service.ts"
click node_messaging "https://github.com/sugan-developerinnooryze-stack/leadryze_backend/blob/main/src/modules/messages/message.service.ts"
click node_widget "https://github.com/sugan-developerinnooryze-stack/leadryze_backend/blob/main/src/modules/public-widget/public-widget.controller.ts"
click node_nativecrm "https://github.com/sugan-developerinnooryze-stack/leadryze_backend/blob/main/src/modules/native-crm/native-crm.router.ts"
click node_sales "https://github.com/sugan-developerinnooryze-stack/leadryze_backend/blob/main/src/modules/native-crm/leads/lead.service.ts"
click node_fieldservice "https://github.com/sugan-developerinnooryze-stack/leadryze_backend/blob/main/src/modules/native-crm/workorders/workorder.service.ts"
click node_automation "https://github.com/sugan-developerinnooryze-stack/leadryze_backend/blob/main/src/modules/native-crm/automation-flows/automation-flow.service.ts"
click node_datasets "https://github.com/sugan-developerinnooryze-stack/leadryze_backend/blob/main/src/modules/native-crm/datasets/dataset-query.service.ts"
click node_pipeline "https://github.com/sugan-developerinnooryze-stack/leadryze_backend/blob/main/src/modules/native-crm/pipeline-config/pipeline-config.controller.ts"
click node_database "https://github.com/sugan-developerinnooryze-stack/leadryze_backend/blob/main/src/config/database.ts"
click node_search "https://github.com/sugan-developerinnooryze-stack/leadryze_backend/blob/main/src/services/meilisearch.service.ts"
click node_storage "https://github.com/sugan-developerinnooryze-stack/leadryze_backend/blob/main/src/services/s3.service.ts"
click node_webhooks "https://github.com/sugan-developerinnooryze-stack/leadryze_backend/blob/main/src/modules/webhooks/webhook.controller.ts"
click node_analytics "https://github.com/sugan-developerinnooryze-stack/leadryze_backend/blob/main/src/modules/analytics/analytics.service.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_app,node_auth,node_authorization,node_tenants,node_user toneBlue
class node_nativecrm,node_sales,node_fieldservice,node_automation,node_datasets,node_pipeline toneAmber
class node_customers,node_campaigns,node_messaging,node_widget toneMint
class node_database,node_search,node_storage,node_webhooks,node_analytics toneRose
class node_ai toneIndigo
```

## Components

### API and identity

- [HTTP API](https://github.com/sugan-developerinnooryze-stack/leadryze_backend/blob/main/src/app.ts): `src/app.ts`
- [Authentication](https://github.com/sugan-developerinnooryze-stack/leadryze_backend/blob/main/src/modules/auth/auth.service.ts): `src/modules/auth/auth.service.ts`
- [Access control](https://github.com/sugan-developerinnooryze-stack/leadryze_backend/blob/main/src/middlewares/auth.middleware.ts): `src/middlewares/auth.middleware.ts`
- [Tenant management](https://github.com/sugan-developerinnooryze-stack/leadryze_backend/blob/main/src/modules/tenants/tenant.service.ts): `src/modules/tenants/tenant.service.ts`

### Native CRM

- [Native CRM API](https://github.com/sugan-developerinnooryze-stack/leadryze_backend/blob/main/src/modules/native-crm/native-crm.router.ts): `src/modules/native-crm/native-crm.router.ts`
- [Sales records](https://github.com/sugan-developerinnooryze-stack/leadryze_backend/blob/main/src/modules/native-crm/leads/lead.service.ts): `src/modules/native-crm/leads/lead.service.ts`
- [Field service](https://github.com/sugan-developerinnooryze-stack/leadryze_backend/blob/main/src/modules/native-crm/workorders/workorder.service.ts): `src/modules/native-crm/workorders/workorder.service.ts`
- [CRM automation](https://github.com/sugan-developerinnooryze-stack/leadryze_backend/blob/main/src/modules/native-crm/automation-flows/automation-flow.service.ts): `src/modules/native-crm/automation-flows/automation-flow.service.ts`
- [Knowledge datasets](https://github.com/sugan-developerinnooryze-stack/leadryze_backend/blob/main/src/modules/native-crm/datasets/dataset-query.service.ts): `src/modules/native-crm/datasets/dataset-query.service.ts`
- [Pipeline configuration](https://github.com/sugan-developerinnooryze-stack/leadryze_backend/blob/main/src/modules/native-crm/pipeline-config/pipeline-config.controller.ts): `src/modules/native-crm/pipeline-config/pipeline-config.controller.ts`

### Customer engagement

- [Customer records](https://github.com/sugan-developerinnooryze-stack/leadryze_backend/blob/main/src/modules/customers/customer.service.ts): `src/modules/customers/customer.service.ts`
- [Campaigns](https://github.com/sugan-developerinnooryze-stack/leadryze_backend/blob/main/src/modules/campaigns/campaign.service.ts): `src/modules/campaigns/campaign.service.ts`
- [Messaging](https://github.com/sugan-developerinnooryze-stack/leadryze_backend/blob/main/src/modules/messages/message.service.ts): `src/modules/messages/message.service.ts`
- [Public widget](https://github.com/sugan-developerinnooryze-stack/leadryze_backend/blob/main/src/modules/public-widget/public-widget.controller.ts): `src/modules/public-widget/public-widget.controller.ts`

### Platform services

- [MongoDB](https://github.com/sugan-developerinnooryze-stack/leadryze_backend/blob/main/src/config/database.ts): `src/config/database.ts`
- [CRM search index](https://github.com/sugan-developerinnooryze-stack/leadryze_backend/blob/main/src/services/meilisearch.service.ts): `src/services/meilisearch.service.ts`
- [S3 storage](https://github.com/sugan-developerinnooryze-stack/leadryze_backend/blob/main/src/services/s3.service.ts): `src/services/s3.service.ts`
- [Webhook integrations](https://github.com/sugan-developerinnooryze-stack/leadryze_backend/blob/main/src/modules/webhooks/webhook.controller.ts): `src/modules/webhooks/webhook.controller.ts`
- [Analytics](https://github.com/sugan-developerinnooryze-stack/leadryze_backend/blob/main/src/modules/analytics/analytics.service.ts): `src/modules/analytics/analytics.service.ts`

### Other components

- **CRM user**
- **AI service**

## Connections

- CRM user → HTTP API: uses (evidence: `src/app.ts`)
- HTTP API → Authentication: routes (evidence: `src/app.ts`)
- HTTP API → Tenant management: routes (evidence: `src/app.ts`)
- HTTP API → Customer records: routes (evidence: `src/app.ts`)
- HTTP API → Campaigns: routes (evidence: `src/app.ts`)
- HTTP API → Messaging: routes (evidence: `src/app.ts`)
- Authentication → Access control: checks permissions (evidence: `src/modules/auth/auth.service.ts`)
- Access control → MongoDB: checks roles
- HTTP API → Native CRM API: routes (evidence: `src/app.ts`)
- Native CRM API → Sales records: dispatches
- Native CRM API → Field service: dispatches
- Native CRM API → CRM automation: dispatches
- Native CRM API → Pipeline configuration: dispatches
- Pipeline configuration → MongoDB: reads and updates
- Pipeline configuration → Tenant management: validates custom modules (evidence: `src/modules/native-crm/pipeline-config/pipeline-config.controller.ts`)
- Knowledge datasets → AI service: searches semantically (evidence: `src/modules/native-crm/datasets/dataset-query.service.ts`)
- Knowledge datasets → MongoDB: queries records (evidence: `src/modules/native-crm/datasets/dataset-query.service.ts`)
- Public widget → MongoDB: uses sessions (evidence: `src/modules/public-widget/public-widget.controller.ts`)
- Public widget → Tenant management: loads tenant (evidence: `src/modules/public-widget/public-widget.controller.ts`)
- CRM search index → MongoDB: indexes CRM records
- HTTP API → S3 storage: serves file proxy
