# yves1da2vinci3/whatsapp-backend architecture

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

- Interactive diagram: https://gitdiagram.com/yves1da2vinci3/whatsapp-backend
- Repository: https://github.com/yves1da2vinci3/whatsapp-backend

## Overview

##### Main Components Identification

a) Core Services:
- Authentication Service (app/auth)
- Chat Service (app/chats)
- Stories Service (app/stories)
- Calls Service (app/calls)
- Upload Service (app/upload)

b) Infrastructure Components:
- FastAPI Application Server
- MongoDB Database (indicated by alembic migrations)
- Redis Cache
- MinIO Object Storage
- Socket.io Server
- Prometheus Monitoring

**External Clients (Mobile/Web Apps)**
- ↓
**API Gateway (FastAPI)**

**Auth Service → Chat Service → Stories Service → Calls Service**
- ↓             ↓              ↓               ↓
**Shared Utils (Token, OTP, Mail, Socket)**

**MongoDB → Redis → MinIO → Socket.io**

##### Specific Implementation Details

a) Authentication Flow:
**Client → Auth Service → OTP Service → Redis**
- ↘ Token Service

b) Real-time Communication:
**Client ⇔ Socket.io ⇔ Chat Service**
- ⇔ Calls Service

c) Media Handling:
**Upload Service → MinIO**
- ↓
**Chat/Stories Services**

##### Additional Elements

Important aspects:
- Database schemas (shown in ERD from README)
- API endpoints grouping
- Monitoring setup with Prometheus
- Docker container boundaries

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph "Client Layer"
        Client["External Clients"]
    end

    subgraph "API Gateway"
        API["FastAPI Server"]:::apigateway
        click API "https://github.com/yves1da2vinci3/whatsapp-backend/blob/main/app/main.py"
    end

    subgraph "Core Services"
        Auth["Authentication Service"]:::service
        Chat["Chat Service"]:::service
        Stories["Stories Service"]:::service
        Calls["Calls Service"]:::service
        Upload["Upload Service"]:::service

        click Auth "https://github.com/yves1da2vinci3/whatsapp-backend/tree/main/app/auth/"
        click Chat "https://github.com/yves1da2vinci3/whatsapp-backend/tree/main/app/chats/"
        click Stories "https://github.com/yves1da2vinci3/whatsapp-backend/tree/main/app/stories/"
        click Calls "https://github.com/yves1da2vinci3/whatsapp-backend/tree/main/app/calls/"
        click Upload "https://github.com/yves1da2vinci3/whatsapp-backend/tree/main/app/upload/"
    end

    subgraph "Utility Services"
        Token["Token Service"]:::util
        OTP["OTP Service"]:::util
        Mail["Mail Service"]:::util
        Socket["Socket.io Server"]:::util
        DBUtils["Database Utilities"]:::util
        Constants["Utility Constants"]:::util

        click Token "https://github.com/yves1da2vinci3/whatsapp-backend/blob/main/app/utils/token.py"
        click OTP "https://github.com/yves1da2vinci3/whatsapp-backend/blob/main/app/utils/otp.py"
        click Mail "https://github.com/yves1da2vinci3/whatsapp-backend/blob/main/app/utils/mail.py"
        click Socket "https://github.com/yves1da2vinci3/whatsapp-backend/blob/main/app/utils/socket.py"
        click DBUtils "https://github.com/yves1da2vinci3/whatsapp-backend/blob/main/app/utils/database.py"
        click Constants "https://github.com/yves1da2vinci3/whatsapp-backend/blob/main/app/utils/constants.py"
    end

    subgraph "Infrastructure Layer"
        MongoDB[(MongoDB)]:::db
        Redis[(Redis Cache)]:::cache
        MinIO[(MinIO Storage)]:::storage
        Prometheus[("Prometheus")]:::monitoring
        Models["Database Models"]:::db
        Migrations["Database Migrations"]:::db

        click MongoDB "https://github.com/yves1da2vinci3/whatsapp-backend/blob/main/app/database.py"
        click Redis "https://github.com/yves1da2vinci3/whatsapp-backend/blob/main/app/utils/redis_client.py"
        click MinIO "https://github.com/yves1da2vinci3/whatsapp-backend/blob/main/app/utils/minio_client.py"
        click Prometheus "https://github.com/yves1da2vinci3/whatsapp-backend/blob/main/monitoring/prometheus.yml"
        click Models "https://github.com/yves1da2vinci3/whatsapp-backend/blob/main/app/association_tables.py"
        click Migrations "https://github.com/yves1da2vinci3/whatsapp-backend/tree/main/alembic/"
    end

    %% Relationships
    Client --> API
    API --> Auth
    API --> Chat
    API --> Stories
    API --> Calls
    API --> Upload

    Auth --> Token
    Auth --> OTP
    Auth --> Mail
    Auth --> MongoDB
    Auth --> Redis

    Chat --> Socket
    Chat --> MongoDB
    Chat --> Redis

    Stories --> Upload
    Stories --> MongoDB
    Stories --> MinIO

    Calls --> Socket
    Calls --> MongoDB
    Calls --> Redis

    Upload --> MinIO

    MongoDB --> Models
    MongoDB --> Migrations
    MongoDB --> DBUtils

    %% Monitoring
    Prometheus -.-> API
    Prometheus -.-> MongoDB
    Prometheus -.-> Redis

    %% Styles
    classDef service fill:#3498db,stroke:#2980b9,color:white
    classDef util fill:#9b59b6,stroke:#8e44ad,color:white
    classDef db fill:#2ecc71,stroke:#27ae60,color:white
    classDef cache fill:#e67e22,stroke:#d35400,color:white
    classDef storage fill:#1abc9c,stroke:#16a085,color:white
    classDef monitoring fill:#95a5a6,stroke:#7f8c8d,color:white
    classDef apigateway fill:#e74c3c,stroke:#c0392b,color:white

    %% Legend
    subgraph Legend
        Service["Service"]:::service
        Utility["Utility"]:::util
        Database["Database"]:::db
        Cache["Cache"]:::cache
        Storage["Storage"]:::storage
        Monitor["Monitoring"]:::monitoring
        Gateway["API Gateway"]:::apigateway
    end
```
