# dhvll/crm-system architecture

> Architecture diagram of the GitHub repository dhvll/crm-system, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/dhvll/crm-system
- Repository: https://github.com/dhvll/crm-system

## Overview

##### Main Components
- Web Client: Represents the browser (or client) where users interact with the UI. It loads pages (templates) and assets (CSS/JS).
- Web Server (Django Application): The central component that handles requests. It includes:
- The core project (djcrm) that contains project-wide settings, URL routing, and WSGI/ASGI configurations.
- Two major apps:
▪ Agents: Manages agent profiles, CRUD operations, and related business logic.
▪ Leads: Handles lead data, lead assignment, categorization, and follow-ups.
- Database: PostgreSQL is used to store customer, agent, lead, and related metadata.
- Static & Media Assets: Managed through Django’s static and media directories that supply CSS, JavaScript, and image resources.
- External Services: Optionally, if any third-party integrations exist (like sending emails, using Django REST Framework endpoints) indicate these as external connectors.

##### Out Relationships and Interactions
- Requests hit the web server (Django) where the URL router (configured in djcrm/urls.py) dispatches traffic into the proper app (agents or leads) based on routes.
- Within each app, controllers (views), forms, and models process the request, applying business logic.
- The models interact with PostgreSQL for data storage and retrieval.
- The templates (separated per app as well as common templates in src/templates) render the HTML returned to the client.
- Dependency on Django Rest Framework if any endpoints are exposed to external applications.

##### Architectural Patterns & Design Principles
- MVC / MVT (Model-View-Template) Pattern: Clearly represent how models, views, and templates interact within each app.
- Layered Architecture: Show separation between the presentation layer (templates, static assets), business logic layer (views, forms, mixins), and persistence layer (models connected to PostgreSQL).
- That apps are modular. Each app (agents and leads) is self-contained with its own URL configurations, migrations, and templates, which promotes separation of concerns.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer
    subgraph "Presentation Layer"
        Browser["Web Client (Browser)"]:::frontend
        Templates["Project Templates"]:::templates
        AgentsTemplates["Agents Templates"]:::templates
        LeadsTemplates["Leads Templates"]:::templates
        Static["Static Assets"]:::static
        Media["Media Files"]:::static
    end

    %% Business Logic Layer
    subgraph "Business Logic Layer"
        Core["Core Project (djcrm)"]:::backend
        Manage["Manage Script"]:::backend
        Agents["Agents App"]:::backend
        Leads["Leads App"]:::backend
        AgentsModels["Agents Models"]:::backend
        LeadsModels["Leads Models"]:::backend
    end

    %% Persistence Layer
    subgraph "Persistence Layer"
        DB(("Database (PostgreSQL)")):::database
    end

    %% Connections between layers
    Browser -->|"HTTP_Request"| Core
    Manage -->|"StartsServer"| Core
    Core -->|"Routes_to_agents"| Agents
    Core -->|"Routes_to_leads"| Leads
    Core -->|"ServesTemplates"| Templates
    Core -->|"DeliversStatic"| Static
    Core -->|"DeliversMedia"| Media

    Agents -->|"Renders"| AgentsTemplates
    Leads -->|"Renders"| LeadsTemplates

    Agents -->|"UsesModels"| AgentsModels
    Leads -->|"UsesModels"| LeadsModels

    AgentsModels -->|"CRUD"| DB
    LeadsModels -->|"CRUD"| DB

    %% Click Events for Presentation Layer
    click Templates "https://github.com/dhvll/crm-system/tree/main/src/templates"
    click AgentsTemplates "https://github.com/dhvll/crm-system/tree/main/src/agents/templates/agents"
    click LeadsTemplates "https://github.com/dhvll/crm-system/tree/main/src/leads/templates/leads"
    click Static "https://github.com/dhvll/crm-system/tree/main/src/static"
    click Media "https://github.com/dhvll/crm-system/tree/main/src/media_root"

    %% Click Events for Business Logic Layer
    click Core "https://github.com/dhvll/crm-system/tree/main/src/djcrm"
    click Manage "https://github.com/dhvll/crm-system/blob/main/src/manage.py"
    click Agents "https://github.com/dhvll/crm-system/tree/main/src/agents"
    click Leads "https://github.com/dhvll/crm-system/tree/main/src/leads"
    click AgentsModels "https://github.com/dhvll/crm-system/blob/main/src/agents/models.py"
    click LeadsModels "https://github.com/dhvll/crm-system/blob/main/src/leads/models.py"

    %% Styles
    classDef frontend fill:#fde2e4,stroke:#b30000,stroke-width:2px;
    classDef templates fill:#e0fbfc,stroke:#006494,stroke-width:2px;
    classDef static fill:#fefbd8,stroke:#b58900,stroke-width:2px;
    classDef backend fill:#e6e6fa,stroke:#5f4b8b,stroke-width:2px;
    classDef database fill:#c7f0db,stroke:#2f5233,stroke-width:2px;
```
