# aldinokemal/go-whatsapp-web-multidevice architecture

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

- Interactive diagram: https://gitdiagram.com/aldinokemal/go-whatsapp-web-multidevice
- Repository: https://github.com/aldinokemal/go-whatsapp-web-multidevice

## Overview

Based on our analysis of the file tree and the README, this project is a Golang-based backend for a WhatsApp Multi Device API with both REST and WebSocket interfaces. It is designed as an API server that provides endpoints to manage WhatsApp sessions, send various types of messages, handle groups, users, newsletters, and more. Additionally, it contains front-end components (views and static assets) for user interactions as well as Docker and CI/CD configurations for building and deploying releases.

##### Main Components
- API Server – This is the centralized core of the system, handling incoming HTTP requests and WebSocket connections.
- REST API Layer – Located under src/internal/rest, this layer exposes endpoints (e.g., /app/*, /user/*, /send/*, /group/*, /message/*) which interact with the business logic.
- WebSocket Handler – Under src/internal/websocket, this component manages persistent connections for real-time messaging.
- Domain/Business Logic – Under src/domains and src/services, you have the business rules for each functional area (app, user, message, group, newsletter, send). This separation indicates a domain-driven design, where the “domains” package holds core models and the “services” package orchestrates use cases.
- Utility and Library Layer – The src/pkg folder encompasses common utility functions, error handling (error types for app, validation, WhatsApp-specific errors), and WhatsApp client initialization/wrappers.
- Configuration – The src/config and environment files (.env.example) support multi-layered configuration through command-line flags, environment variables, and .env files.
- Frontend/UI – The src/views directory contains HTML and JavaScript (React-like components) for rendering the user interface (login, send messages, group management, etc.).
- Documentation & API Specification – The docs folder, especially docs/openapi.yaml, details the API schema for client generation and integration.
- Deployment – Docker-related files (docker-compose.yml, docker files, GitHub workflows) indicate that the system is containerized and built via CI/CD pipelines.

##### Relationships and Interactions
- External Clients (Web browsers, mobile apps, API consumers) interact with the API server via REST endpoints and WebSockets.
- REST Controllers (located in src/internal/rest) call the corresponding Service functions (src/services) which in turn leverage Domain Models (src/domains) and Utility packages (src/pkg).
- The authentication process, basic auth middleware and environment configuration ensure secure, configurable endpoints.
- The UI (src/views) serves static assets for a web-based interface to interact with the API.
- CI/CD and containerization components (GitHub workflows and Docker files) facilitate automated building, testing, and deployment.

##### Architectural Patterns & Design Principles
- Layered Architecture: The project shows a clear separation of concerns (API layer → Service layer → Domain models & utilities). This improves maintainability and scalability.
- Domain-Driven Design: The “domains” folder indicates the encapsulation of business logic in discrete, functionally organized modules.
- Configuration Priority: There’s a defined priority for configuration using command-line flags, environment variables, and .env files.
- Containerization: Use of Docker and docker-compose along with CI/CD workflows shows an emphasis on reproducible builds and deployments.
- RESTful & Event-driven Communication: With defined REST endpoints and a WebSocket component, the system uses both synchronous and real-time communication.

##### Relevant Technologies, Frameworks, and Libraries
- Golang as the core language.
- Docker for containerization.
- GitHub Actions for CI/CD.
- ffmpeg (as an external dependency on supported OS) for media processing.
- Swagger/OpenAPI (docs/openapi.yaml) for API specification.
- Web technologies (HTML, JavaScript, and CSS) for the front-end.

- The top level represents the Client/UI layer.
- The middle level represents the API gateway – the REST endpoints and WebSocket handler.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Interaction
    EC["External Clients"]:::external

    %% API Gateway Layer
    subgraph "API Gateway"
        APIS["API Server"]:::api
        REST["REST API"]:::api
        WS["WebSocket Server"]:::api
    end

    %% Business & Domain Layer
    subgraph "Business & Domain Layer"
        BS["Business Services"]:::business
        DM["Domain Models"]:::business
        UL["Utility Libraries"]:::utility
        CONF["Configuration Module"]:::config
    end

    %% Frontend/UI Layer
    subgraph "User Interface"
        UI["Frontend UI"]:::frontend
    end

    %% Documentation
    subgraph "Documentation"
        DOC["OpenAPI Spec"]:::doc
    end

    %% Deployment & CI/CD
    subgraph "Deployment & CI/CD Pipeline"
        DEP["Deployment & CI/CD Pipeline"]:::deployment
    end

    %% Relationships
    EC -->|"calls"| APIS
    APIS -->|"routes_to"| REST
    APIS -->|"upgrades_to"| WS
    REST -->|"invokes"| BS
    BS -->|"manages"| DM
    BS -->|"utilizes"| UL
    CONF -->|"configures"| APIS
    CONF -->|"configures"| BS
    UI -->|"consumes_API"| APIS
    DOC -->|"documents"| APIS
    DEP -->|"deploys"| APIS
    DEP -->|"deploys"| UI
    DEP -->|"runs"| DOC

    %% Click Events
    click APIS "https://github.com/aldinokemal/go-whatsapp-web-multidevice/blob/main/src/main.go"
    click REST "https://github.com/aldinokemal/go-whatsapp-web-multidevice/tree/main/src/internal/rest"
    click WS "https://github.com/aldinokemal/go-whatsapp-web-multidevice/blob/main/src/internal/websocket/websocket.go"
    click DM "https://github.com/aldinokemal/go-whatsapp-web-multidevice/tree/main/src/domains"
    click BS "https://github.com/aldinokemal/go-whatsapp-web-multidevice/tree/main/src/services"
    click UL "https://github.com/aldinokemal/go-whatsapp-web-multidevice/tree/main/src/pkg"
    click CONF "https://github.com/aldinokemal/go-whatsapp-web-multidevice/tree/main/src/config"
    click UI "https://github.com/aldinokemal/go-whatsapp-web-multidevice/tree/main/src/views"
    click DOC "https://github.com/aldinokemal/go-whatsapp-web-multidevice/blob/main/docs/openapi.yaml"
    click DEP "https://github.com/aldinokemal/go-whatsapp-web-multidevice/blob/main/docker-compose.yml"

    %% Styles
    classDef api fill:#ffcccc,stroke:#990000,stroke-width:2px;
    classDef business fill:#ccffcc,stroke:#006600,stroke-width:2px;
    classDef utility fill:#cce5ff,stroke:#004085,stroke-width:2px;
    classDef config fill:#fff0b3,stroke:#cc7a00,stroke-width:2px;
    classDef frontend fill:#e6ccff,stroke:#663399,stroke-width:2px;
    classDef doc fill:#ffebcc,stroke:#cc6600,stroke-width:2px;
    classDef deployment fill:#d9edf7,stroke:#31708f,stroke-width:2px;
    classDef external fill:#f2dede,stroke:#a94442,stroke-width:2px;
```
