# jacobo0312/whatsappclient architecture

> Architecture diagram of the GitHub repository jacobo0312/whatsappclient, 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/jacobo0312/whatsappclient
- Repository: https://github.com/jacobo0312/whatsappclient

## Overview

##### Main Components
- Entry Point (app.ts): This component sets up the Express server and defines the port and middleware. It acts as the entry point for all incoming HTTP requests.
- Controller (controller.ts): This module is responsible for defining the API endpoints (GET /sendMessage, GET /isAuthenticated, GET /getQr) and delegating the appropriate business logic.
- WhatsApp Client (WhatsAppClient.ts): This is the core logic that handles the interaction with the WhatsApp Web API, using a singleton pattern to ensure only one instance exists.
- External WhatsApp Web API: Represent this as an external system that the WhatsAppClient interacts with to perform actions like sending messages and retrieving the QR code.

##### Relationships and Data Flow
- The Controller processes the requests and delegates them to the WhatsApp Client for the actual interaction with the WhatsApp Web API.
- The WhatsApp Client then makes calls to the external WhatsApp Web API (authentication, sending messages, retrieving data) and returns responses back up the chain.
- Finally, responses are delivered back to the client that made the HTTP request.

##### Important Design Patterns and Technologies
- Express.js for HTTP Server: Highlight that the Express framework manages incoming API requests.
- TypeScript: Mark the project as TypeScript-based, emphasizing type safety and maintainability.
- REST API: Indicate the architectural style used for exposing operations (e.g., GET endpoints).

- Optionally, include notes on important configurations (like the use of TypeScript, ESLint, and Prettier for code quality, even though they are helper tools rather than major architectural elements).

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Client Interaction"
        HTTPReq("HTTP Client Request"):::internal
    end

    subgraph "Backend Service"
        Express("Express Server (app.ts)"):::internal
        Controller("API Controller (controller.ts)"):::internal
        WhatsApp("WhatsApp Client (Singleton) (WhatsAppClient.ts)"):::internal
    end

    subgraph "External Systems"
        ExtAPI("WhatsApp Web API (External Service)"):::external
    end

    HTTPReq -->|"HTTP_Request"| Express
    Express -->|"Routes_request"| Controller
    Controller -->|"Delegates_to"| WhatsApp
    WhatsApp -->|"Calls_API"| ExtAPI
    ExtAPI -->|"Returns_response"| WhatsApp
    WhatsApp -->|"Sends_response"| Controller
    Controller -->|"Forwards_response"| Express
    Express -->|"HTTP_Response"| HTTPReq

    click Express "https://github.com/jacobo0312/whatsappclient/blob/main/src/app.ts"
    click Controller "https://github.com/jacobo0312/whatsappclient/blob/main/src/controller.ts"
    click WhatsApp "https://github.com/jacobo0312/whatsappclient/blob/main/src/WhatsAppClient.ts"

    classDef internal fill:#BBDEFB,stroke:#0D47A1,stroke-width:2px;
    classDef external fill:#FFCDD2,stroke:#B71C1C,stroke-width:2px;
```
