# canove/whaticket-community architecture

> Architecture diagram of the GitHub repository canove/whaticket-community, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-02-04). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/canove/whaticket-community
- Repository: https://github.com/canove/whaticket-community

## Overview

##### High-Level Architecture Components

a. Frontend Layer:
- React Application (Port 3000)
- Key components:
- User Interface (Material UI)
- WebSocket Client
- REST API Client
- Authentication Module

b. Backend Layer:
- Node.js Application (Port 8080)
- Key components:
- Express Server
- WebSocket Server
- Authentication Service
- WhatsApp Integration Service
- Business Logic Services
- Database Access Layer

c. Database Layer:
- MySQL/MariaDB Database (Port 3306)
- Key entities:
- Users
- Tickets
- Messages
- Contacts
- WhatsApp Sessions
- Queues
- Settings

d. External Services:
- WhatsApp Web Client (via whatsapp-web.js)
- Nginx Reverse Proxy
- SSL/TLS Termination

##### Component Relationships

**Client Browser → Nginx Reverse Proxy**
**Nginx Reverse Proxy → Frontend Server**
**Frontend Server → Backend API**
**Backend API → Database**
**Backend API → WhatsApp Web Client**
**WhatsApp Web Client → WhatsApp Servers**

##### Data Flow Visualization

Following flows:
- User Authentication Flow
- Message Processing Flow
- Ticket Creation/Management Flow
- Real-time Updates Flow (WebSocket)

##### Key Technical Elements to Highlight

a. Security Layer:
- JWT Authentication
- SSL/TLS Encryption
- API Authorization

b. Real-time Communication:
- WebSocket Connections
- Event Broadcasting

c. Service Architecture:
- Controller Layer
- Service Layer
- Model Layer
- Queue Management

##### Deployment Architecture

Containerization structure:
- Docker Containers
- Network Configuration
- Volume Mounts
- Port Mappings

##### Additional Elements

Include:
- Load Balancer (if applicable)
- Cache Layer (if implemented)
- Message Queue System
- File Storage System

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        Browser["Web Browser"]
    end

    subgraph "Frontend Server"
        UI["User Interface"]:::frontend
        WSClient["WebSocket Client"]:::frontend
        APIClient["REST API Client"]:::frontend
        AuthModule["Auth Module"]:::frontend
        Router["Frontend Router"]:::frontend
        TicketComp["Ticket Components"]:::frontend
    end

    subgraph "Backend Server"
        Express["Express Server"]:::backend
        WSServer["WebSocket Server"]:::backend
        AuthService["Authentication Service"]:::backend
        WhatService["WhatsApp Integration"]:::backend
        Controllers["Controllers"]:::backend
        Services["Service Layer"]:::backend
        Models["Model Layer"]:::backend
        QueueMgmt["Queue Management"]:::backend
        MessageService["Message Service"]:::backend
        TicketService["Ticket Service"]:::backend
        Router2["Backend Router"]:::backend
    end

    subgraph "Database Layer"
        DB[(MySQL/MariaDB)]:::database
        Users[("Users")]:::database
        Tickets[("Tickets")]:::database
        Messages[("Messages")]:::database
        Contacts[("Contacts")]:::database
        WhatsAppSessions[("WhatsApp Sessions")]:::database
        Queues[("Queues")]:::database
        Settings[("Settings")]:::database
    end

    subgraph "External Services"
        WhatsAppWeb["WhatsApp Web Client"]:::external
        WhatsAppServers["WhatsApp Servers"]:::external
        Nginx["Nginx Reverse Proxy"]:::external
    end

    Browser --> Nginx
    Nginx --> UI
    UI --> WSClient
    UI --> APIClient
    UI --> AuthModule
    UI --> Router
    UI --> TicketComp

    WSClient --> WSServer
    APIClient --> Express
    AuthModule --> AuthService
    Express --> Controllers
    Controllers --> Services
    Services --> Models
    Models --> DB
    WhatService --> WhatsAppWeb
    WhatsAppWeb --> WhatsAppServers
    QueueMgmt --> Services
    MessageService --> Services
    TicketService --> Services
    Router2 --> Controllers
    WSServer --> Services

    DB --> Users
    DB --> Tickets
    DB --> Messages
    DB --> Contacts
    DB --> WhatsAppSessions
    DB --> Queues
    DB --> Settings

    %% Click events for component mapping
    click UI "https://github.com/canove/whaticket-community/tree/master/frontend/src/components/"
    click WSClient "https://github.com/canove/whaticket-community/blob/master/frontend/src/services/socket-io.js"
    click AuthModule "https://github.com/canove/whaticket-community/tree/master/frontend/src/context/Auth/"
    click Router "https://github.com/canove/whaticket-community/tree/master/frontend/src/routes/"
    click TicketComp "https://github.com/canove/whaticket-community/tree/master/frontend/src/components/Ticket/"
    click Express "https://github.com/canove/whaticket-community/tree/master/backend/src/"
    click WSServer "https://github.com/canove/whaticket-community/blob/master/backend/src/libs/socket.ts"
    click AuthService "https://github.com/canove/whaticket-community/tree/master/backend/src/services/AuthServices/"
    click WhatService "https://github.com/canove/whaticket-community/tree/master/backend/src/services/WbotServices/"
    click Controllers "https://github.com/canove/whaticket-community/tree/master/backend/src/controllers/"
    click Services "https://github.com/canove/whaticket-community/tree/master/backend/src/services/"
    click Models "https://github.com/canove/whaticket-community/tree/master/backend/src/models/"
    click QueueMgmt "https://github.com/canove/whaticket-community/tree/master/backend/src/services/QueueService/"
    click MessageService "https://github.com/canove/whaticket-community/tree/master/backend/src/services/MessageServices/"
    click TicketService "https://github.com/canove/whaticket-community/tree/master/backend/src/services/TicketServices/"
    click Router2 "https://github.com/canove/whaticket-community/tree/master/backend/src/routes/"
    click DB "https://github.com/canove/whaticket-community/tree/master/backend/src/database/"

    classDef frontend fill:#2196F3,stroke:#1565C0,color:white
    classDef backend fill:#4CAF50,stroke:#2E7D32,color:white
    classDef database fill:#FF9800,stroke:#EF6C00,color:white
    classDef external fill:#9E9E9E,stroke:#616161,color:white

    %% Legend
    subgraph Legend
        Frontend["Frontend Component"]:::frontend
        Backend["Backend Component"]:::backend
        Database["Database Component"]:::database
        External["External Service"]:::external
    end
```
