# solutionproviderdev/easeit-backend architecture

> Architecture diagram of the GitHub repository solutionproviderdev/easeit-backend, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-21). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/solutionproviderdev/easeit-backend
- Repository: https://github.com/solutionproviderdev/easeit-backend

## Overview

##### Main System Components

a) Core Services Layer:
- Authentication & Authorization Service
- Lead Management Service
- Communication Services (Facebook, WhatsApp)
- Meeting Management Service
- Dashboard Service
- Settings Management
- File Upload Service

b) Data Layer:
- MongoDB Collections (based on schemas)
- File Storage (public/files, public/profile_pictures)

c) Integration Layer:
- Facebook Integration
- WhatsApp Integration
- Daraz Integration
- Solution Bot (Gemini AI Integration)

##### Architectural Patterns to Highlight

The system follows a clear MVC (Model-View-Controller) pattern with some additional layers:
- Models (src/schemas)
- Controllers (src/controller)
- Routes (src/routes)
- Middlewares (src/middlewares)
- Helpers (src/helpers)
- Ongoing Tasks (src/ongoing)
- Cron Jobs (src/cron)

**[External Services Layer]**

- ▼
**[API Gateway / Routes Layer]**

- ▼
**[Middleware Layer]**

- ▼
**[Controller Layer]**

- ▼
**[Service Layer]**

- ▼
**[Data Access Layer]**

##### Important Connections

- Authentication flow
- Lead management workflow
- Message handling between external services
- Data flow between services
- Background task interactions

##### Component Details

For each major component, include:
- Input/Output specifications
- Key dependencies
- Primary responsibilities
- Integration points

##### Security Boundaries

Clearly mark:
- Authentication checkpoints
- Permission boundaries
- External API security
- File upload restrictions

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph External
        FB[Facebook]
        WA[WhatsApp]
        DZ[Daraz]
    end

    subgraph "API Gateway"
        API["API Routes"]:::gateway
    end

    subgraph "Core Services"
        Auth["Authentication Service"]:::core
        Lead["Lead Management"]:::core
        Comm["Communication Services"]:::core
        Meet["Meeting Management"]:::core
        Dash["Dashboard Service"]:::core
        Set["Settings Management"]:::core
        Upload["File Upload Service"]:::core
    end

    subgraph "Integration Services"
        FBInt["Facebook Integration"]:::integration
        WAInt["WhatsApp Integration"]:::integration
        DZInt["Daraz Integration"]:::integration
    end

    subgraph "Background Services"
        Cron["Cron Jobs"]:::background
        Ongoing["Ongoing Tasks"]:::background
    end

    subgraph "Special Services"
        SBot["Solution Bot"]:::special
        CID["Customer ID Generator"]:::special
        SKU["SKU Generator"]:::special
        PCRE["Performance CRE"]:::special
    end

    subgraph "Middleware"
        AuthMid["Authentication"]:::middleware
        ErrHandler["Error Handler"]:::middleware
    end

    subgraph "Data Layer"
        DB[(MongoDB)]:::database
        Files[("File Storage")]:::storage
        ProfilePics[("Profile Pictures")]:::storage
        Schemas["MongoDB Schemas"]:::database
    end

    FB --> FBInt
    WA --> WAInt
    DZ --> DZInt

    API --> AuthMid
    AuthMid --> Auth
    AuthMid --> ErrHandler

    Auth --> Lead
    Auth --> Comm
    Auth --> Meet
    Auth --> Dash
    Auth --> Set
    Auth --> Upload

    Lead --> DB
    Comm --> DB
    Meet --> DB
    Dash --> DB
    Set --> DB
    Upload --> Files
    Upload --> ProfilePics

    FBInt --> Comm
    WAInt --> Comm
    DZInt --> Lead

    Cron --> DB
    Ongoing --> DB

    SBot --> Lead
    CID --> Lead
    SKU --> Lead
    PCRE --> Lead

    classDef core fill:#3498db
    classDef integration fill:#2ecc71
    classDef database fill:#f1c40f
    classDef background fill:#e74c3c
    classDef middleware fill:#9b59b6
    classDef special fill:#e67e22
    classDef storage fill:#95a5a6
    classDef gateway fill:#1abc9c

    click Auth "https://github.com/solutionproviderdev/easeit-backend/tree/main/src/controller/auth"
    click Lead "https://github.com/solutionproviderdev/easeit-backend/tree/main/src/controller/lead"
    click Comm "https://github.com/solutionproviderdev/easeit-backend/blob/main/src/controller/FbMessageController.js"
    click Meet "https://github.com/solutionproviderdev/easeit-backend/tree/main/src/controller/meetings"
    click Dash "https://github.com/solutionproviderdev/easeit-backend/tree/main/src/controller/dashboard"
    click Set "https://github.com/solutionproviderdev/easeit-backend/tree/main/src/controller/settings"
    click Upload "https://github.com/solutionproviderdev/easeit-backend/blob/main/src/controller/uploadController.js"
    click Files "https://github.com/solutionproviderdev/easeit-backend/tree/main/public/files"
    click ProfilePics "https://github.com/solutionproviderdev/easeit-backend/tree/main/public/profile_pictures"
    click Schemas "https://github.com/solutionproviderdev/easeit-backend/tree/main/src/schemas"
    click FBInt "https://github.com/solutionproviderdev/easeit-backend/blob/main/src/routes/settings/endpoints/facebook.js"
    click WAInt "https://github.com/solutionproviderdev/easeit-backend/blob/main/src/routes/WhatsAppMessage.js"
    click DZInt "https://github.com/solutionproviderdev/easeit-backend/blob/main/src/ongoing/fetchAndStoreDarazData.js"
    click Cron "https://github.com/solutionproviderdev/easeit-backend/tree/main/src/cron"
    click Ongoing "https://github.com/solutionproviderdev/easeit-backend/tree/main/src/ongoing"
    click SBot "https://github.com/solutionproviderdev/easeit-backend/tree/main/src/SolutionBot"
    click CID "https://github.com/solutionproviderdev/easeit-backend/blob/main/src/helpers/CustomerIdGenerator.js"
    click SKU "https://github.com/solutionproviderdev/easeit-backend/blob/main/src/helpers/SKUGenerator.js"
    click PCRE "https://github.com/solutionproviderdev/easeit-backend/blob/main/src/helpers/getPerformanceBasedCRE.js"
    click AuthMid "https://github.com/solutionproviderdev/easeit-backend/tree/main/src/middlewares/auth"
    click ErrHandler "https://github.com/solutionproviderdev/easeit-backend/blob/main/src/middlewares/common/errorHandler.js"
    click API "https://github.com/solutionproviderdev/easeit-backend/tree/main/src/routes"
```
