How hugoamoraes/geradordelinkwhatsapp works
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