# mordecai42/pwa architecture

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

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

## Overview

##### Project type and purpose
- This is a full-stack Progressive Web App template built with React, TypeScript, and Vite plus a minimal Node.js server.
- It serves a React SPA, supports offline capabilities via a Service Worker (sw.js + workbox-config.js), and uses IndexedDB (via src/utils/idb.js) to queue/offline-store form submissions (OfflineForm.tsx).

##### File structure
- Top-level:
- src/ (React/TypeScript source: components, assets, CSS, utility libs)
- server/ (Node.js server: server.js, .env)
- config files: tsconfig.*, vite.config.ts, workbox-config.js, ESLint/Husky/GitHub workflows
- Patterns & responsibilities:
- src/components – UI components including OfflineForm
- src/utils/idb.js – client-side storage library for offline data
- public/sw.js & workbox-config.js – PWA caching strategies
- server/server.js – API endpoint(s) to receive submissions

##### README for additional insights
- Focus is on development setup (Vite + React + TS), ESLint configuration, Fast Refresh plugins.

##### Elements
- “React SPA”
- “Service Worker”
- “IndexedDB (idb.js)”
- “Network / Fetch API”
- “Node.js Server (server.js)”
- “External DB/Service”
- User input → React SPA → (if offline) → IndexedDB
- React SPA / SW → Network → Server
- Server → (external DB)
- Green for PWA/Cache
- Orange for server
- Gray for external systems

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Frontend Layer
    subgraph "Frontend Layer"
        direction TB
        ReactSPA["React SPA (src/)"]:::frontend
        OfflineForm["OfflineForm Component"]:::frontend
        BuildTools["Build & Dev Tools"]:::frontend
    end

    %% PWA Layer
    subgraph "PWA Layer"
        direction TB
        SW["Service Worker"]:::pwa
        Workbox["Workbox Config"]:::pwa
        PWAAssets["PWA Assets"]:::pwa
        IdB["IndexedDB (idb.js)"]:::pwa
    end

    %% Network Layer
    subgraph "Network Layer"
        direction TB
        Network["Network / Fetch API"]:::network
    end

    %% Backend Layer
    subgraph "Backend Layer"
        direction TB
        NodeServer["Node.js Server"]:::server
        EnvConfig["Env Config (.env)"]:::server
    end

    %% External Systems
    ExternalDB["External DB / Service"]:::external

    %% Connections
    User["User"]:::external
    User -->|"interacts with"| ReactSPA
    ReactSPA -->|"uses OfflineForm"| OfflineForm
    ReactSPA -->|"queues data when offline"| IdB
    OfflineForm -->|"stores to"| IdB
    ReactSPA -->|"registers"| SW
    SW -->|"caches assets & offline.html"| PWAAssets
    SW -->|"background sync"| IdB
    SW -->|"calls API via"| Network
    ReactSPA -->|"fetches data via"| Network
    Network -->|"API requests"| NodeServer
    NodeServer -->|"reads config"| EnvConfig
    NodeServer -->|"persists data to"| ExternalDB

    %% Build & QA Tools
    BuildTools -->|"configured by"| ViteConfig["Vite Config"]:::frontend
    BuildTools -->|"configured by"| ESLintHooks["ESLint & Husky"]:::frontend

    %% Click Events
    click ReactSPA "https://github.com/mordecai42/pwa/tree/main/src/"
    click OfflineForm "https://github.com/mordecai42/pwa/blob/main/src/components/OfflineForm.tsx"
    click IdB "https://github.com/mordecai42/pwa/blob/main/src/utils/idb.js"
    click SW "https://github.com/mordecai42/pwa/blob/main/public/sw.js"
    click Workbox "https://github.com/mordecai42/pwa/blob/main/workbox-config.js"
    click PWAAssets "https://github.com/mordecai42/pwa/tree/main/public/"
    click NodeServer "https://github.com/mordecai42/pwa/blob/main/server/server.js"
    click EnvConfig "https://github.com/mordecai42/pwa/blob/main/server/.env"
    click ViteConfig "https://github.com/mordecai42/pwa/blob/main/vite.config.ts"
    click ESLintHooks "https://github.com/mordecai42/pwa/tree/main/.husky/"

    %% Styles
    classDef frontend fill:#D0E8FF,stroke:#0366d6,color:#0366d6,stroke-width:1px
    classDef pwa fill:#DFFFE0,stroke:#28a745,color:#155724,stroke-width:1px
    classDef network fill:#FFF4D0,stroke:#e69500,color:#8a5000,stroke-width:1px
    classDef server fill:#FFE0D0,stroke:#d73a49,color:#831c2c,stroke-width:1px
    classDef external fill:#E1E4E8,stroke:#6a737d,color:#24292e,stroke-width:1px
```
