# hugoamoraes/geradordelinkwhatsapp architecture

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

- Interactive diagram: https://gitdiagram.com/hugoamoraes/geradordelinkwhatsapp
- Repository: https://github.com/hugoamoraes/geradordelinkwhatsapp

## Overview

##### Project Type and Purpose
- This is a single‐page, front‐end web application (built with Vite) that generates direct WhatsApp links from user‐entered phone numbers.
- It has no back‐end; all logic runs in the browser: input processing, validation, URL construction, copy‐to‐clipboard, and optional automatic navigation to WhatsApp’s API.

##### File Structure Analysis
- Top-level files:
- index.html – entry point and HTML shell
- main.js – bootstraps the app (imports CSS, mounts app.js)
- style.css – global styles
- src/ directory organizes code by layers:
- app.js – application root, ties components, services, and utils together
- components/ – reusable UI pieces (Header, PhoneInput, GenerateButton, ResultDisplay, ErrorNotification)
- services/ – business‐logic layer (whatsappService.js builds the WhatsApp API URL and handles opening links)
- utils/ – helper functions (phoneProcessor.js normalizes/validates numbers; clipboard.js handles copy actions)

##### Key Architectural Insights from README
- Follows a modular architecture and clean-code principles: separation of concerns (UI vs. business logic vs. utility functions).
- Uses ES6 modules, async/await, modern CSS variables and Flex/Grid.
- Build pipeline managed by Vite (dev server, bundling, production build).

##### Main Components and Their Relationships
a. User Interface Layer (Components)
- Header – static title/logo area
- PhoneInput – text input, onChange invokes phoneProcessor
- GenerateButton – onClick triggers whatsappService with processed number
- ResultDisplay – shows constructed link, offers “Open in WhatsApp”
- ErrorNotification – displays validation errors from utils or service failures
b. Utility Layer
- phoneProcessor – takes raw input, strips formatting, validates Brazilian numbers, returns normalized E.164 string or error
- clipboard – attempts to copy link to clipboard; falls back to execCommand for older browsers
c. Service Layer
- whatsappService – composes the final URL (`https://api.whatsapp.com/send?phone=...`), calls clipboard, and/or uses window.open to navigate
d. External Interactions
- WhatsApp API via redirect to `api.whatsapp.com`
- Browser Clipboard API
e. Build & Deployment
- Vite Dev Server – hot module replacement in development
- Vite Build – produces static assets (HTML, JS, CSS) ready for hosting on any static web server

##### Architectural Patterns and Principles
- Modular layering: UI components → services → utils
- Single Responsibility: each component/module handles one concern
- Dependency flow: Components depend on services; services depend on utils
- Clean code: small files, clear directory naming, ES6 module imports

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "Entry Point Layer"
        HTML["index.html"]:::entry
        Main["main.js"]:::entry
        CSS["style.css"]:::entry
    end

    subgraph "Application Core"
        App["src/app.js"]:::core
    end

    subgraph "UI Components"
        Header["Header.js"]:::ui
        Phone["PhoneInput.js"]:::ui
        Generate["GenerateButton.js"]:::ui
        Result["ResultDisplay.js"]:::ui
        Error["ErrorNotification.js"]:::ui
    end

    subgraph "Services"
        WS["whatsappService.js"]:::service
    end

    subgraph "Utils"
        PP["phoneProcessor.js"]:::util
        CB["clipboard.js"]:::util
    end

    subgraph "External APIs"
        WA["WhatsApp API"]:::external
        ClipAPI["Clipboard API"]:::external
    end

    subgraph "Build & Deployment"
        Dev["Vite Dev Server"]:::build
        Build["Vite Build"]:::build
        Assets["Production Assets"]:::build
        Public["public/"]:::entry
        Host["Static Host"]:::build
    end

    HTML -->|"loads"| Main
    Main -->|"mounts"| App
    Main -->|"imports CSS"| CSS

    App -->|"renders"| Header
    App -->|"renders"| Phone
    App -->|"renders"| Generate
    App -->|"renders"| Result
    App -->|"renders"| Error

    Phone -->|"onChange calls normalizePhone()"| PP
    PP -->|"returns normalized or error"| Phone

    Generate -->|"onClick calls sendMessage()"| WS
    WS -->|"constructURL"| WS
    WS -->|"call copyToClipboard()"| CB
    CB -->|"uses Clipboard API"| ClipAPI
    WS -->|"navigateToAPI()"| WA
    WS -->|"onSuccess show link"| Result
    WS -->|"onError show error"| Error

    HTML & Main & CSS & App & Header & Phone & Generate & Result & Error & WS & PP & CB --> Dev
    Dev --> Build
    Build --> Assets
    Assets --> Public
    Public --> Host

    click HTML "https://github.com/hugoamoraes/geradordelinkwhatsapp/blob/main/index.html"
    click Main "https://github.com/hugoamoraes/geradordelinkwhatsapp/blob/main/main.js"
    click CSS "https://github.com/hugoamoraes/geradordelinkwhatsapp/blob/main/style.css"
    click App "https://github.com/hugoamoraes/geradordelinkwhatsapp/blob/main/src/app.js"
    click Header "https://github.com/hugoamoraes/geradordelinkwhatsapp/blob/main/src/components/Header.js"
    click Phone "https://github.com/hugoamoraes/geradordelinkwhatsapp/blob/main/src/components/PhoneInput.js"
    click Generate "https://github.com/hugoamoraes/geradordelinkwhatsapp/blob/main/src/components/GenerateButton.js"
    click Result "https://github.com/hugoamoraes/geradordelinkwhatsapp/blob/main/src/components/ResultDisplay.js"
    click Error "https://github.com/hugoamoraes/geradordelinkwhatsapp/blob/main/src/components/ErrorNotification.js"
    click WS "https://github.com/hugoamoraes/geradordelinkwhatsapp/blob/main/src/services/whatsappService.js"
    click PP "https://github.com/hugoamoraes/geradordelinkwhatsapp/blob/main/src/utils/phoneProcessor.js"
    click CB "https://github.com/hugoamoraes/geradordelinkwhatsapp/blob/main/src/utils/clipboard.js"
    click Public "https://github.com/hugoamoraes/geradordelinkwhatsapp/tree/main/public/"

    classDef entry fill:#D0E1F9,stroke:#000
    classDef core fill:#B3E5FC,stroke:#000
    classDef ui fill:#AEDFFD,stroke:#000
    classDef service fill:#A8E6CF,stroke:#000
    classDef util fill:#FFD3B6,stroke:#000
    classDef external fill:#E0E0E0,stroke:#000
    classDef build fill:#F0F0F0,stroke-dasharray: 5 5,stroke:#000
```
