# leifermendez/api-whatsapp-ts architecture

> Architecture diagram of the GitHub repository leifermendez/api-whatsapp-ts, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-06-12). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/leifermendez/api-whatsapp-ts
- Repository: https://github.com/leifermendez/api-whatsapp-ts

## Overview

##### Project type and purpose
- This is a Node.js/TypeScript microservice that exposes a REST API for creating “leads” and dispatching them to WhatsApp via various providers (Baileys, Meta, Twilio, Venom, or a mock).
- The README shows simple install/build/dev instructions and a Docker entrypoint, confirming it’s a containerized backend service (no frontend).

##### File structure
- **Top-level files**: Dockerfile, .env.example, package.json, tsconfig.json, README.MD.
- **src/app.ts**: the entrypoint (bootstraps the server, loads IoC container, starts Express).
- **src/application**: application services (use-case layer), e.g. `lead.create.ts`.
- **src/domain**: domain model and repository interfaces (`lead.ts`, `lead.repository.ts`, `lead-external.repository.ts`).
- **src/infrastructure**:
- **controller**: Express controllers (e.g. `lead.ctrl.ts`)
- **router**: Express router definitions (`lead.route.ts`, combined in `index.ts`)
- **repositories**: concrete adapters implementing repository interfaces (Baileys, Meta, Twilio, Venom, WS external, mock)
- **ioc.ts**: wires interfaces to concrete implementations via dependency injection
- No database directory—persistence is represented by external-API adapters.

##### README for additional insights
- The service name (“apiwhatsappts”) and build commands confirm a server-only, DDD-style project.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% External Client
    Client["External Client (Postman, Frontend)"]:::external

    %% Entry Point
    subgraph "Server Entry"
        App["app.ts (Express Entrypoint)"]:::infra
    end

    %% Router Layer
    subgraph "Router Layer"
        RouterIndex["index.ts (Router Index)"]:::infra
        LeadRoutes["lead.route.ts"]:::infra
    end

    %% Controller Layer
    subgraph "Controller Layer"
        LeadController["lead.ctrl.ts"]:::infra
    end

    %% Application Layer
    subgraph "Application Layer"
        CreateLead["lead.create.ts (CreateLead UseCase)"]:::app
    end

    %% Domain Layer
    subgraph "Domain Layer"
        LeadEntity["lead.ts (Lead Entity)"]:::domain
        LeadRepoIface["lead.repository.ts"]:::domain
        LeadExtRepoIface["lead-external.repository.ts"]:::domain
    end

    %% Infrastructure / IoC
    subgraph "Infrastructure" 
        IoC["ioc.ts (IoC Container)"]:::infra
        subgraph "Adapters"
            Baileys["baileys.repository.ts"]:::infra
            Meta["meta.repository.ts"]:::infra
            Twilio["twilio.repository.ts"]:::infra
            Venom["venom.repository.ts"]:::infra
            WS["ws.external.ts"]:::infra
            Mock["mock.repository.ts"]:::infra
        end
    end

    %% External Services
    subgraph "External WhatsApp Providers"
        ExtBaileys["Baileys API"]:::external
        ExtMeta["Meta API"]:::external
        ExtTwilio["Twilio API"]:::external
        ExtVenom["Venom API"]:::external
        ExtWS["WebSocket Service"]:::external
    end

    %% Configuration & Deployment
    subgraph "Config & Deployment" 
        Env[".env.example"]:::config
        Docker["Dockerfile"]:::config
        Package["package.json"]:::config
        TSConfig["tsconfig.json"]:::config
        Readme["README.MD"]:::config
    end

    %% Flow
    Client -->|"HTTP Request"| App
    App --> RouterIndex
    RouterIndex --> LeadRoutes
    LeadRoutes --> LeadController
    LeadController -->|"calls"| CreateLead
    CreateLead -->|"uses"| LeadEntity
    CreateLead -->|"depends on"| LeadRepoIface
    CreateLead -->|"depends on"| LeadExtRepoIface

    LeadRepoIface -->|"implemented by"| Baileys
    LeadRepoIface --> Meta
    LeadRepoIface --> Twilio
    LeadRepoIface --> Venom
    LeadRepoIface --> Mock

    LeadExtRepoIface --> WS

    IoC --> LeadRepoIface
    IoC --> LeadExtRepoIface
    IoC --> Baileys
    IoC --> Meta
    IoC --> Twilio
    IoC --> Venom
    IoC --> WS
    IoC --> Mock

    Baileys --> ExtBaileys
    Meta --> ExtMeta
    Twilio --> ExtTwilio
    Venom --> ExtVenom
    WS --> ExtWS

    %% Click Events
    click App "https://github.com/leifermendez/api-whatsapp-ts/blob/main/src/app.ts"
    click IoC "https://github.com/leifermendez/api-whatsapp-ts/blob/main/src/infrastructure/ioc.ts"
    click RouterIndex "https://github.com/leifermendez/api-whatsapp-ts/blob/main/src/infrastructure/router/index.ts"
    click LeadRoutes "https://github.com/leifermendez/api-whatsapp-ts/blob/main/src/infrastructure/router/lead.route.ts"
    click LeadController "https://github.com/leifermendez/api-whatsapp-ts/blob/main/src/infrastructure/controller/lead.ctrl.ts"
    click CreateLead "https://github.com/leifermendez/api-whatsapp-ts/blob/main/src/application/lead.create.ts"
    click LeadEntity "https://github.com/leifermendez/api-whatsapp-ts/blob/main/src/domain/lead.ts"
    click LeadRepoIface "https://github.com/leifermendez/api-whatsapp-ts/blob/main/src/domain/lead.repository.ts"
    click LeadExtRepoIface "https://github.com/leifermendez/api-whatsapp-ts/blob/main/src/domain/lead-external.repository.ts"
    click Baileys "https://github.com/leifermendez/api-whatsapp-ts/blob/main/src/infrastructure/repositories/baileys.repository.ts"
    click Meta "https://github.com/leifermendez/api-whatsapp-ts/blob/main/src/infrastructure/repositories/meta.repository.ts"
    click Twilio "https://github.com/leifermendez/api-whatsapp-ts/blob/main/src/infrastructure/repositories/twilio.repository.ts"
    click Venom "https://github.com/leifermendez/api-whatsapp-ts/blob/main/src/infrastructure/repositories/venom.repository.ts"
    click WS "https://github.com/leifermendez/api-whatsapp-ts/blob/main/src/infrastructure/repositories/ws.external.ts"
    click Mock "https://github.com/leifermendez/api-whatsapp-ts/blob/main/src/infrastructure/repositories/mock.repository.ts"
    click Env "https://github.com/leifermendez/api-whatsapp-ts/blob/main/.env.example"
    click Docker "https://github.com/leifermendez/api-whatsapp-ts/tree/main/Dockerfile"
    click Package "https://github.com/leifermendez/api-whatsapp-ts/blob/main/package.json"
    click TSConfig "https://github.com/leifermendez/api-whatsapp-ts/blob/main/tsconfig.json"
    click Readme "https://github.com/leifermendez/api-whatsapp-ts/blob/main/README.MD"

    %% Styles
    classDef external fill:#fde2e2,stroke:#d90429,color:#d90429
    classDef infra fill:#e0f7fa,stroke:#006064,color:#006064
    classDef app fill:#e8f5e9,stroke:#2e7d32,color:#2e7d32
    classDef domain fill:#fff3e0,stroke:#ef6c00,color:#ef6c00
    classDef config fill:#f5f5f5,stroke:#9e9e9e,color:#424242
```
