# vlyon07/pwa-diagram architecture

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

- Interactive diagram: https://gitdiagram.com/vlyon07/pwa-diagram
- Repository: https://github.com/vlyon07/pwa-diagram

## Overview

Para diseñar un diagrama de arquitectura preciso para “WeShare – Galería Compartida PWA”, sigue estos pasos:

##### Identificar el tipo y propósito del proyecto
- Es una aplicación **PWA full‑stack**:
- Frontend (cliente web) construido con Vite + Tailwind CSS.
- Backend en Node.js + Express que gestiona uploads, almacenamiento de archivos y notificaciones.
- Soporte offline (Service Worker + IndexedDB) y actualizaciones en tiempo real (SSE + Push API).

##### Analizar la estructura de ficheros
- Top‑level:
- `/backend`: servidor Express, rutas, servicios y utilidades (Multer para uploads, pushService para notificaciones, VAPID keys).
- Archivos de configuración de PWA en la raíz (`service-worker.js`, `manifest.json`, `tailwind.config.js`, `postcss.config.js`).
- `/src`: lógica de la UI (captura de cámara, subida de archivos, consumo de APIs).
- `/public`: assets estáticos, íconos, capturas.

##### Componentes principales a representar
a. Frontend (Cliente PWA)
- App shell (index.html + main.js + estilo Tailwind).
- Módulos de UI: upload.js, camera.js, galería paginada.
- Service Worker:
- Cache de recursos estáticos.
- Intercepta fetch y gestiona modo offline.
- Suscripción a Push API.
- IndexedDB: almacena imágenes/videos offline.
- Web APIs del navegador: MediaDevices, Web Share, Notifications, Fetch, SSE.

b. Backend (Express Server)
- Endpoints HTTP (rutas: `/images`, `/notifications`).
- Multer para recepción y guardado de archivos en `/backend/uploads`.
- Servicio SSE para broadcast en tiempo real.
- pushService con VAPID keys para enviar Push Notifications.
- Carpeta de utilidades y configuración.

c. Almacenamiento
- Sistema de archivos en el servidor (uploads).
- IndexedDB en el navegador.

d. Canales de comunicación
- HTTP REST (Fetch API) para subir/obtener lista de archivos.
- Server‑Sent Events (SSE) para notificaciones en tiempo real.
- Push API + Notifications API para alertas.

##### Relaciones e interacciones
- Usuario → UI Client
- Selecciona o captura imagen/video (MediaDevices API).
- Envía archivo al backend (`POST /images`).
- Frontend → Service Worker
- Intercepta peticiones y cachea.
- Permite operación offline y sincroniza con IndexedDB.
- Frontend ↔ Backend
- Fetch API para CRUD de medios.
- SSE mantiene conexión abierta para actualizaciones.
- Backend → Client
- SSE envía eventos “nuevo recurso” → Service Worker o UI los recibe.
- pushService dispara Push API usando VAPID → Browser muestra notificaciones.

##### Patrones y principios de diseño
- Separación de responsabilidades:
- Capa UI vs lógica de offline vs persistencia local vs servicios de red.
- Arquitectura orientada a eventos (SSE y Push API).
- Offline‑First y App‑Shell (PWA).

##### Guía para el diagrama
- Usa rectángulos para representar componentes de software (Cliente, Service Worker, Express App).
- Usa cilindros para almacenes de datos (IndexedDB, File System).
- Usa nubes o íconos de “nube/internet” para Web APIs externas (Push API, SSE).
- Dibuja flechas direccionales:
- Sólidas para solicitudes HTTP.
- Punteadas para eventos SSE y Push Notifications.

##### Elementos que no pueden faltar
- Etiquetas claras: nombre de cada componente (e.g., “Service Worker”, “pushService”).
- Flechas con texto explicativo (e.g., “POST /images”, “SSE stream”).
- Leyenda con colores/estilos de línea para diferenciar:
- HTTP REST
- SSE (event‑driven)
- Push Notifications

Siguiendo estas pautas y usando la estructura y tecnologías detectadas en el file tree y el README, obtendrás un diagrama completo, detallado y fácil de entender tanto por desarrolladores como por stakeholders.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client-side PWA
    subgraph "Client-side (PWA)"
        direction TB
        AppShell["App Shell<br/>(index.html)"]:::frontend
        MainJS["Main Entry<br/>(src/main.js)"]:::frontend
        Styles["Tailwind Styles<br/>(src/style.css)"]:::frontend
        UI_Camera["Camera Module<br/>(src/camera.js)"]:::frontend
        UI_Upload["Upload Module<br/>(src/upload.js)"]:::frontend
        ServiceWorker["Service Worker<br/>(public/service-worker.js)"]:::frontend
        IndexedDB["IndexedDB<br/>(Local Store)"]:::data
        Manifest["PWA Manifest<br/>(public/manifest.json)"]:::frontend
        StaticAssets["Static Assets<br/>(public/icons, images, screenshots)"]:::frontend
    end

    %% Server-side Express
    subgraph "Server-side (Express)"
        direction TB
        ExpressApp["Express App<br/>(backend/index.js)"]:::backend
        ImagesRoute["Images Route<br/>(backend/routes/images.js)"]:::backend
        NotifRoute["Notifications Route<br/>(backend/routes/notifications.js)"]:::backend
        PushService["pushService<br/>(backend/services/pushService.js)"]:::backend
        VapidKeys["VAPID Keys Config<br/>(backend/utils/vapidKeys.js)"]:::backend
        FileSystem["File System<br/>(backend/uploads)"]:::data
        BackendPkg["Backend package.json<br/>(backend/package.json)"]:::backend
        RootPkg["Frontend package.json<br/>(package.json)"]:::frontend
    end

    %% External Browser APIs
    subgraph "Browser APIs"
        direction TB
        MediaDevices["MediaDevices API"]:::api
        FetchAPI["Fetch API"]:::api
        SSE_API["EventSource (SSE)"]:::api
        PushAPI["Push API<br/>Notifications API"]:::api
    end

    %% Legend
    subgraph "Legend"
        direction TB
        L1["Solid arrow: HTTP REST"] 
        L2["--- dotted: SSE"] 
        L3["-.-.- dotted: Push Notifications"] 
    end

    %% Client interactions
    MediaDevices -->|captures media| UI_Camera
    UI_Camera -->|passes file| UI_Upload
    UI_Upload -->|POST /images| FetchAPI
    FetchAPI -->|HTTP| ImagesRoute
    ServiceWorker -->|intercepts fetch| FetchAPI
    ServiceWorker -->|caches resources| StaticAssets
    ServiceWorker -->|syncs offline| IndexedDB
    IndexedDB -->|serve offline| UI_Upload

    %% PWA setup
    AppShell --> MainJS
    AppShell --> Styles
    AppShell --> Manifest
    AppShell --> StaticAssets
    MainJS --> UI_Camera
    MainJS --> UI_Upload
    MainJS --> ServiceWorker

    %% SSE and Push
    SSE_API -.->|SSE stream| NotifRoute
    NotifRoute -->|broadcast SSE| SSE_API
    SSE_API -->|receives event| ServiceWorker
    PushService -.->|Push| PushAPI
    VapidKeys --> PushService
    PushAPI -->|notification| ServiceWorker

    %% Server internals
    ExpressApp --> ImagesRoute
    ExpressApp --> NotifRoute
    ImagesRoute --> FileSystem
    NotifRoute --> PushService
    ExpressApp --> VapidKeys
    ExpressApp --> BackendPkg

    %% Package connections
    RootPkg --> MainJS

    %% Click events
    click AppShell "https://github.com/vlyon07/pwa-diagram/blob/main/index.html"
    click MainJS "https://github.com/vlyon07/pwa-diagram/blob/main/src/main.js"
    click Styles "https://github.com/vlyon07/pwa-diagram/blob/main/src/style.css"
    click Styles "https://github.com/vlyon07/pwa-diagram/blob/main/tailwind.config.js"
    click Styles "https://github.com/vlyon07/pwa-diagram/blob/main/postcss.config.js"
    click UI_Camera "https://github.com/vlyon07/pwa-diagram/blob/main/src/camera.js"
    click UI_Upload "https://github.com/vlyon07/pwa-diagram/blob/main/src/upload.js"
    click ServiceWorker "https://github.com/vlyon07/pwa-diagram/blob/main/public/service-worker.js"
    click Manifest "https://github.com/vlyon07/pwa-diagram/blob/main/public/manifest.json"
    click StaticAssets "https://github.com/vlyon07/pwa-diagram/tree/main/public/icons"
    click StaticAssets "https://github.com/vlyon07/pwa-diagram/tree/main/public/images"
    click StaticAssets "https://github.com/vlyon07/pwa-diagram/tree/main/public/screenshots"
    click ExpressApp "https://github.com/vlyon07/pwa-diagram/blob/main/backend/index.js"
    click ImagesRoute "https://github.com/vlyon07/pwa-diagram/blob/main/backend/routes/images.js"
    click NotifRoute "https://github.com/vlyon07/pwa-diagram/blob/main/backend/routes/notifications.js"
    click PushService "https://github.com/vlyon07/pwa-diagram/blob/main/backend/services/pushService.js"
    click VapidKeys "https://github.com/vlyon07/pwa-diagram/blob/main/backend/utils/vapidKeys.js"
    click BackendPkg "https://github.com/vlyon07/pwa-diagram/blob/main/backend/package.json"
    click RootPkg "https://github.com/vlyon07/pwa-diagram/blob/main/package.json"

    %% Styles
    classDef frontend fill:#E0F7FA,stroke:#006064,color:#004D40
    classDef backend fill:#FFF3E0,stroke:#E65100,color:#BF360C
    classDef data fill:#E8F5E9,stroke:#2E7D32,color:#1B5E20
    classDef api fill:#F3E5F5,stroke:#6A1B9A,color:#4A148C
```
