# ahmedrashed2811/crm_2 architecture

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

- Interactive diagram: https://gitdiagram.com/ahmedrashed2811/crm_2
- Repository: https://github.com/ahmedrashed2811/crm_2

## Overview

This Django CRM backend supports lead intake and management, assignment and routing, scoring, call and site-visit activity, workflow stages, bulk imports, webhooks, and analytics. The principal API flow is a user request through lead views and services into lead records and, where needed, workflow transitions; interaction services also record timeline and audit events. The graph includes documented or indexed capabilities even where implementation excerpts were unavailable. Some links are omitted where the supplied evidence does not show the caller.

Main entry points: [`leads/views.py`](https://github.com/ahmedrashed2811/crm_2/blob/main/leads/views.py) (API views), [`leads/services/leads_service.py`](https://github.com/ahmedrashed2811/crm_2/blob/main/leads/services/leads_service.py) (Lead management), [`leads/services/interaction_service.py`](https://github.com/ahmedrashed2811/crm_2/blob/main/leads/services/interaction_service.py) (Calls and visits), [`leads/models.py`](https://github.com/ahmedrashed2811/crm_2/blob/main/leads/models.py) (Lead records)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API and access"]
  node_api_views["API views<br/>[views.py]"]
  node_api_context["Request context<br/>[context.py]"]
  node_api_security["Lead permissions<br/>[security.py]"]
  node_api_errors["API errors<br/>[exceptions.py]"]
  node_api_responses["API responses<br/>[responses.py]"]
  node_api_query["Query parsing<br/>[query.py]"]
end

subgraph group_lead["Lead operations"]
  node_lead_models[("Lead records<br/>[models.py]")]
  node_lead_service["Lead management<br/>[leads_service.py]"]
  node_lead_routing["Lead routing<br/>[routing_service.py]"]
  node_lead_scoring["Lead scoring<br/>[scoring_service.py]"]
  node_lead_import["Bulk import<br/>[import_service.py]"]
  node_lead_interaction["Calls and visits"]
  node_lead_escalation["Escalation"]
  node_lead_sla["SLA tracking<br/>[sla_service.py]"]
  node_lead_webhook["Webhook handling<br/>[webhook_service.py]"]
end

subgraph group_workflow["Lifecycle workflow"]
  node_workflow_engine["Transition engine<br/>[engine.py]"]
  node_workflow_models[("Workflow records<br/>[models.py]")]
  node_workflow_read["Workflow reads<br/>[read.py]"]
end

subgraph group_observability["Audit and analytics"]
  node_audit_recorder["Audit recorder<br/>[recorder.py]"]
  node_audit_records[("Audit events<br/>[models.py]")]
  node_analytics_views["Analytics API<br/>[views.py]"]
  node_analytics_service["Analytics reports<br/>[services.py]"]
  node_analytics_auth["Analytics access<br/>[security.py]"]
end

node_user(("CRM user"))

node_user -->|"sends requests"| node_api_views
node_api_views -->|"builds context"| node_api_context
node_api_views -->|"invokes services"| node_lead_service
node_api_views -->|"logs activity"| node_lead_interaction
node_api_views -->|"imports leads"| node_lead_import
node_api_views -->|"handles webhooks"| node_lead_webhook
node_api_views -->|"reads workflow"| node_workflow_read
node_api_views -->|"parses queries"| node_api_query
node_api_views -->|"formats responses"| node_api_responses
node_api_views -->|"checks access"| node_api_security
node_lead_service -->|"reads and writes"| node_lead_models
node_lead_service -->|"changes stages"| node_workflow_engine
node_lead_service -->|"delegates routing"| node_lead_routing
node_lead_service -->|"delegates scoring"| node_lead_scoring
node_lead_service -->|"records changes"| node_audit_recorder
node_lead_routing -->|"reads lead rules"| node_lead_models
node_lead_scoring -->|"reads scoring data"| node_lead_models
node_lead_import -->|"creates leads"| node_lead_service
node_lead_interaction -->|"writes activity"| node_lead_models
node_lead_interaction -->|"updates timeline"| node_lead_service
node_lead_interaction -->|"records activity"| node_audit_recorder
node_lead_interaction -->|"checks access"| node_api_security
node_lead_webhook -->|"delegates lead work"| node_lead_service
node_workflow_engine -->|"reads and writes"| node_workflow_models
node_workflow_read -->|"reads instances"| node_workflow_models
node_audit_recorder -->|"creates events"| node_audit_records
node_analytics_views -->|"requests reports"| node_analytics_service
node_analytics_service -->|"checks access"| node_analytics_auth
node_analytics_service -->|"aggregates activity"| node_lead_models
node_analytics_views -->|"formats responses"| node_api_responses

click node_api_views "https://github.com/ahmedrashed2811/crm_2/blob/main/leads/views.py"
click node_api_context "https://github.com/ahmedrashed2811/crm_2/blob/main/core/utils/context.py"
click node_api_security "https://github.com/ahmedrashed2811/crm_2/blob/main/leads/utils/security.py"
click node_api_errors "https://github.com/ahmedrashed2811/crm_2/blob/main/core/api/exceptions.py"
click node_api_responses "https://github.com/ahmedrashed2811/crm_2/blob/main/core/api/responses.py"
click node_api_query "https://github.com/ahmedrashed2811/crm_2/blob/main/core/utils/query.py"
click node_lead_models "https://github.com/ahmedrashed2811/crm_2/blob/main/leads/models.py"
click node_lead_service "https://github.com/ahmedrashed2811/crm_2/blob/main/leads/services/leads_service.py"
click node_lead_routing "https://github.com/ahmedrashed2811/crm_2/blob/main/leads/services/routing_service.py"
click node_lead_scoring "https://github.com/ahmedrashed2811/crm_2/blob/main/leads/services/scoring_service.py"
click node_lead_import "https://github.com/ahmedrashed2811/crm_2/blob/main/leads/services/import_service.py"
click node_lead_interaction "https://github.com/ahmedrashed2811/crm_2/blob/main/leads/services/interaction_service.py"
click node_lead_escalation "https://github.com/ahmedrashed2811/crm_2/blob/main/leads/services/escalation_service.py"
click node_lead_sla "https://github.com/ahmedrashed2811/crm_2/blob/main/leads/services/sla_service.py"
click node_lead_webhook "https://github.com/ahmedrashed2811/crm_2/blob/main/leads/services/webhook_service.py"
click node_workflow_engine "https://github.com/ahmedrashed2811/crm_2/blob/main/workflow/services/engine.py"
click node_workflow_models "https://github.com/ahmedrashed2811/crm_2/blob/main/workflow/models.py"
click node_workflow_read "https://github.com/ahmedrashed2811/crm_2/blob/main/workflow/services/read.py"
click node_audit_recorder "https://github.com/ahmedrashed2811/crm_2/blob/main/audit/utils/recorder.py"
click node_audit_records "https://github.com/ahmedrashed2811/crm_2/blob/main/audit/models.py"
click node_analytics_views "https://github.com/ahmedrashed2811/crm_2/blob/main/analytics/views.py"
click node_analytics_service "https://github.com/ahmedrashed2811/crm_2/blob/main/analytics/services.py"
click node_analytics_auth "https://github.com/ahmedrashed2811/crm_2/blob/main/analytics/utils/security.py"

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_views,node_api_context,node_api_security,node_api_errors,node_api_responses,node_api_query,node_user toneBlue
class node_lead_models,node_lead_service,node_lead_routing,node_lead_scoring,node_lead_import,node_lead_interaction,node_lead_escalation,node_lead_sla,node_lead_webhook toneAmber
class node_workflow_engine,node_workflow_models,node_workflow_read toneMint
class node_audit_recorder,node_audit_records,node_analytics_views,node_analytics_service,node_analytics_auth toneRose
```

## Components

### API and access

- [API views](https://github.com/ahmedrashed2811/crm_2/blob/main/leads/views.py): `leads/views.py`
- [Request context](https://github.com/ahmedrashed2811/crm_2/blob/main/core/utils/context.py): `core/utils/context.py`
- [Lead permissions](https://github.com/ahmedrashed2811/crm_2/blob/main/leads/utils/security.py): `leads/utils/security.py`
- [API errors](https://github.com/ahmedrashed2811/crm_2/blob/main/core/api/exceptions.py): `core/api/exceptions.py`
- [API responses](https://github.com/ahmedrashed2811/crm_2/blob/main/core/api/responses.py): `core/api/responses.py`
- [Query parsing](https://github.com/ahmedrashed2811/crm_2/blob/main/core/utils/query.py): `core/utils/query.py`

### Lead operations

- [Lead records](https://github.com/ahmedrashed2811/crm_2/blob/main/leads/models.py): `leads/models.py`
- [Lead management](https://github.com/ahmedrashed2811/crm_2/blob/main/leads/services/leads_service.py): `leads/services/leads_service.py`
- [Lead routing](https://github.com/ahmedrashed2811/crm_2/blob/main/leads/services/routing_service.py): `leads/services/routing_service.py`
- [Lead scoring](https://github.com/ahmedrashed2811/crm_2/blob/main/leads/services/scoring_service.py): `leads/services/scoring_service.py`
- [Bulk import](https://github.com/ahmedrashed2811/crm_2/blob/main/leads/services/import_service.py): `leads/services/import_service.py`
- [Calls and visits](https://github.com/ahmedrashed2811/crm_2/blob/main/leads/services/interaction_service.py): `leads/services/interaction_service.py`
- [Escalation](https://github.com/ahmedrashed2811/crm_2/blob/main/leads/services/escalation_service.py): `leads/services/escalation_service.py`
- [SLA tracking](https://github.com/ahmedrashed2811/crm_2/blob/main/leads/services/sla_service.py): `leads/services/sla_service.py`
- [Webhook handling](https://github.com/ahmedrashed2811/crm_2/blob/main/leads/services/webhook_service.py): `leads/services/webhook_service.py`

### Lifecycle workflow

- [Transition engine](https://github.com/ahmedrashed2811/crm_2/blob/main/workflow/services/engine.py): `workflow/services/engine.py`
- [Workflow records](https://github.com/ahmedrashed2811/crm_2/blob/main/workflow/models.py): `workflow/models.py`
- [Workflow reads](https://github.com/ahmedrashed2811/crm_2/blob/main/workflow/services/read.py): `workflow/services/read.py`

### Audit and analytics

- [Audit recorder](https://github.com/ahmedrashed2811/crm_2/blob/main/audit/utils/recorder.py): `audit/utils/recorder.py`
- [Audit events](https://github.com/ahmedrashed2811/crm_2/blob/main/audit/models.py): `audit/models.py`
- [Analytics API](https://github.com/ahmedrashed2811/crm_2/blob/main/analytics/views.py): `analytics/views.py`
- [Analytics reports](https://github.com/ahmedrashed2811/crm_2/blob/main/analytics/services.py): `analytics/services.py`
- [Analytics access](https://github.com/ahmedrashed2811/crm_2/blob/main/analytics/utils/security.py): `analytics/utils/security.py`

### Other components

- **CRM user**

## Connections

- CRM user → API views: sends requests (evidence: `leads/views.py`)
- API views → Request context: builds context (evidence: `leads/views.py`)
- API views → Lead management: invokes services (evidence: `leads/views.py`)
- API views → Calls and visits: logs activity (evidence: `leads/views.py`)
- API views → Bulk import: imports leads (evidence: `leads/views.py`)
- API views → Webhook handling: handles webhooks (evidence: `leads/views.py`)
- API views → Workflow reads: reads workflow (evidence: `leads/views.py`)
- API views → Query parsing: parses queries (evidence: `leads/views.py`)
- API views → API responses: formats responses (evidence: `leads/views.py`)
- API views → Lead permissions: checks access (evidence: `leads/views.py`)
- Lead management → Lead records: reads and writes (evidence: `leads/services/leads_service.py`)
- Lead management → Transition engine: changes stages (evidence: `leads/services/leads_service.py`)
- Lead management → Lead routing: delegates routing (evidence: `leads/services/leads_service.py`)
- Lead management → Lead scoring: delegates scoring (evidence: `leads/services/leads_service.py`)
- Lead management → Audit recorder: records changes (evidence: `leads/services/leads_service.py`)
- Lead routing → Lead records: reads lead rules (evidence: `leads/services/routing_service.py`)
- Lead scoring → Lead records: reads scoring data (evidence: `leads/services/scoring_service.py`)
- Bulk import → Lead management: creates leads (evidence: `leads/services/import_service.py`)
- Calls and visits → Lead records: writes activity (evidence: `leads/services/interaction_service.py`)
- Calls and visits → Lead management: updates timeline (evidence: `leads/services/interaction_service.py`)
- Calls and visits → Audit recorder: records activity (evidence: `leads/services/interaction_service.py`)
- Calls and visits → Lead permissions: checks access (evidence: `leads/services/interaction_service.py`)
- Webhook handling → Lead management: delegates lead work (evidence: `leads/services/webhook_service.py`)
- Transition engine → Workflow records: reads and writes (evidence: `workflow/services/engine.py`)
- Workflow reads → Workflow records: reads instances (evidence: `workflow/services/read.py`)
- Audit recorder → Audit events: creates events (evidence: `audit/utils/recorder.py`)
- Analytics API → Analytics reports: requests reports (evidence: `analytics/views.py`)
- Analytics reports → Analytics access: checks access (evidence: `analytics/services.py`)
- Analytics reports → Lead records: aggregates activity (evidence: `analytics/services.py`)
- Analytics API → API responses: formats responses (evidence: `analytics/views.py`)
