# priyanshsaxena01/whatsapp-chatbot architecture

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

- Interactive diagram: https://gitdiagram.com/priyanshsaxena01/whatsapp-chatbot
- Repository: https://github.com/priyanshsaxena01/whatsapp-chatbot

## Overview

##### Project type and purpose
- This is a single-service chatbot application (backend only) that uses Python/Flask to expose a webhook endpoint. It integrates with the Meta WhatsApp Business Cloud API to present users with an interactive, button-driven conversation flow, backed by an in-memory session store and static content.

##### File structure
- Top-level files:
– app.py: contains the Flask server, webhook routes, conversation logic, state management, and outbound HTTP calls to WhatsApp.
– requirements.txt: lists dependencies (Flask, requests, python-dotenv).
– readme.md: project overview, setup, and runtime instructions.
– .gitignore: standard ignore patterns.
- No separate frontend, database, or microservices—everything lives in one Flask service.

##### README for architectural insights
- The service exposes a single `/webhook` route (for GET verification and POST message events).
- Outgoing messages use the WhatsApp Graph API via HTTP requests.
- User state is managed in a Python dict (`user_sessions`).
- All interactive content is hard-coded in the script.
- Deployment is flexible: locally via ngrok, on Heroku/Codespaces, etc.

##### Elements
- Clear labeled components (User, WhatsApp Cloud API, Flask Service, Session Store, Env Config, Deployment Layer).
– User → WhatsApp Cloud → Flask `/webhook`
– Flask → WhatsApp Cloud (sendMessage API) → User
– Internal service components (Flask app, session store) in another
– Configuration/deployment in a third

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Services
    subgraph "External Layer"
        direction TB
        User["WhatsApp User"]:::external
        WhatsAppCloud["Meta WhatsApp Business Cloud API"]:::external
    end

    %% Deployment / Ingress
    subgraph "Deployment Layer"
        direction TB
        Ingress["ngrok / Heroku Router"]:::deployment
    end

    %% Internal Service
    subgraph "Cityscope Chatbot Service"
        direction TB
        EnvConfig["Environment Configuration (.env)"]:::config
        FlaskService["Flask Service (app.py)"]:::service
        SessionStore["In-memory Session Store"]:::store
    end

    %% Documentation & Config Files
    subgraph "Project Files"
        direction TB
        Dependencies["requirements.txt"]:::config
        Gitignore[".gitignore"]:::config
        Readme["readme.md"]:::docs
    end

    %% Data Flow
    User -->|"Sends message (HTTPS)"| WhatsAppCloud
    WhatsAppCloud -->|"POST /webhook"| Ingress
    Ingress -->|"Routes to /webhook"| FlaskService
    FlaskService -->|"Loads ENV vars"| EnvConfig
    FlaskService -->|"Reads/Writes session"| SessionStore
    FlaskService -->|"HTTP POST Graph API"| WhatsAppCloud
    WhatsAppCloud -->|"Delivers response"| User

    %% Click Events
    click FlaskService "https://github.com/priyanshsaxena01/whatsapp-chatbot/blob/main/app.py"
    click SessionStore "https://github.com/priyanshsaxena01/whatsapp-chatbot/blob/main/app.py"
    click Dependencies "https://github.com/priyanshsaxena01/whatsapp-chatbot/blob/main/requirements.txt"
    click Gitignore "https://github.com/priyanshsaxena01/whatsapp-chatbot/blob/main/.gitignore"
    click Readme "https://github.com/priyanshsaxena01/whatsapp-chatbot/blob/main/readme.md"

    %% Styles
    classDef external fill:#D0E6FF,stroke:#0366D6,color:#0366D6;
    classDef deployment fill:#F0F0F0,stroke:#888888,color:#555555;
    classDef service fill:#DFFFE0,stroke:#28A745,color:#22863A;
    classDef store fill:#FFF5B1,stroke:#DBAB09,color:#735C0F;
    classDef config fill:#FFF0F5,stroke:#C61A4A,color:#C61A4A;
    classDef docs fill:#EFEFEF,stroke:#444444,color:#333333;
```
