# meeds-io/pwa architecture

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

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

## Overview

##### Project type and purpose
- This is a multi-module Maven project delivering a Progressive Web App (PWA) addon for a Java portal platform.
- It comprises a build/packaging module, a Maven plugin for analytics and notification‐hook injection, a backend microservice exposing PWA REST endpoints, and a portlet‐based webapp client that serves the PWA manifest, service worker, and settings UI.

##### Top-level modules & their roles
- pwa-plugin: a Maven plugin that hooks into the host app’s event bus (gamification, social, tasks, wallet, etc.) to collect statistics and emit push notification payloads.
- pwa-service: a Spring-style backend microservice providing REST endpoints for manifest retrieval, push subscription management, service-worker registration, and push notification dispatch. It persists subscriptions and notification records.
- pwa-webapp: a portlet/web module (with Vue.js components) that runs in the portal, loads the PWA client scripts, displays settings screens, interacts with the pwa-service REST API, and registers the service worker in the browser.

##### Main components
a. Developer/CI system (Maven + GitHub Actions)
b. pwa-plugin (Maven extension during build)
c. pwa-packaging (assembly step produces static assets)
d. Artifact repository/Docker registry (optional)
e. pwa-service (Java microservice)
– REST API layer (PwaManifestRest, PwaPushSubscriptionRest, PwaNotificationRest, ServiceWorkerRest)
– Service layer (PwaManifestService, PwaSubscriptionService, PwaNotificationService, PwaSwService)
– Storage layer (PwaSubscriptionStorage, PwaNotificationStorage)
– Plugins SPI (PwaNotificationPlugin implementations, DefaultPwaNotificationPlugin)
– Event listeners (WebNotificationSentListener)
f. Database (or key‐value store) backing subscription and notification records
g. pwa-webapp (Portlet client)
– Portlet container (eXo/GateIn) hosting the portlet UI and configuration files (portlet.xml, web.xml)
– Vue.js frontend (PwaSettings, UserSettings components)
– Static assets (manifest.json, service-worker.js) served from classpath / resources
– Browser (Chrome, Firefox) running the PWA UI and registering service worker
h. Web Push Service (browser push endpoint, e.g., Mozilla WebPush, FCM)

##### Interactions & data flows
1. CI / Developer kicks off Maven build → pwa-plugin executes, gathers event hooks, generates plugin artifacts → pwa-packaging bundles manifest and service worker → artifacts published.
2. Deployment: pwa-service deployed to app server (or container); pwa-webapp deployed to portal.
3. User opens portal page → pwa-webapp serves HTML + JS → Browser fetches manifest.json & service-worker.js.
4. Browser registers service worker → service-worker uses Push API to subscribe user → subscription object sent to pwa-service via PwaPushSubscriptionRest.
5. Events occur in host system (e.g., new content, task assigned) → pwa-plugin captures the event payload → pwa-service’s plugin SPI processes and sends push messages via WebPush (VAPID keys).
6. pwa-service persists subscription & notification messages → WebNotificationSentListener logs success/failure → pwa-service REST notifies client if needed.
7. Browser service worker receives push notifications → displays via Notification API.

##### Architectural patterns & principles
- Multi-module Maven: clear separation of build/plugin, packaging, backend service, and client UI
- Plugin SPI & listener pattern for extensibility (new notification plugins can be added under pwa-plugin)
- Layered architecture in pwa-service (REST → service → storage → external push)
- PWA best practices: manifest.json, service worker caching, Push API and Notification API
- MVC/Portlet for the webapp layer, combined with a modern Vue.js single-page settings UI

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Build & Deployment
    subgraph "Build & Deployment"
        DevCI["Developer/CI System"]:::build
        Plugin["pwa-plugin (Maven Plugin)"]:::build
        Packaging["pwa-packaging"]:::build
        Repo["Artifact Repository/Docker Registry"]:::external
    end

    DevCI -->|"runs Maven"| Plugin
    Plugin -->|"assembly hooks"| Packaging
    Packaging -->|"publish artifacts"| Repo

    %% Runtime Environment
    subgraph "Runtime"
        %% Backend Service
        subgraph "pwa-service (Backend Microservice)" 
            subgraph "REST API Layer"
                ManifestRest["PwaManifestRest"] 
                SubscriptionRest["PwaPushSubscriptionRest"]
                NotificationRest["PwaNotificationRest"]
                SwRest["ServiceWorkerRest"]
            end
            subgraph "Service Layer"
                ManifestSvc["PwaManifestService"]
                SubscriptionSvc["PwaSubscriptionService"]
                NotificationSvc["PwaNotificationService"]
                SwSvc["PwaSwService"]
            end
            subgraph "Storage Layer"
                SubStorage["PwaSubscriptionStorage"]
                NotifStorage["PwaNotificationStorage"]
            end
            subgraph "Plugins SPI"
                SPI["PwaNotificationPlugin"]
                DefaultSPI["DefaultPwaNotificationPlugin"]
            end
            Listener["WebNotificationSentListener"]
            DB[(Database)]:::database
            WebPush["Web Push Service"]:::external
        end

        %% Frontend Client
        subgraph "pwa-webapp (Portlet Client)"
            Browser["Browser"]:::external
            Portlet["Portlet Container"] 
            PwaApp["PwaApplication"] 
            PortletXML["portlet.xml"]
            WebXML["web.xml"]
            PwaJS["pwa.js"]
            subgraph "Vue.js Frontend"
                PwaSettings["PwaSettings.vue"]
                UserSettings["UserSettingPwa.vue"]
                ManifestServiceJS["PwaManifestService.js"]
            end
            subgraph "Static Assets"
                ManifestJSON["manifest.json"]
                SWFile["service-worker.js"]
            end
        end
    end

    %% User & Browser interactions
    Browser -->|"loads portlet"| Portlet
    Portlet -->|"serves HTML/JS"| PwaApp
    PwaApp --> PwaJS
    Browser -->|"fetch"| ManifestJSON
    Browser -->|"fetch"| SWFile
    Browser -->|"register SW"| SwRest
    Browser -->|"subscribe Push"| SubscriptionRest

    %% REST to Service
    ManifestRest --> ManifestSvc
    SubscriptionRest --> SubscriptionSvc
    NotificationRest --> NotificationSvc
    SwRest --> SwSvc

    %% Service to Storage
    ManifestSvc --> SubStorage
    SubscriptionSvc --> SubStorage
    NotificationSvc --> NotifStorage
    SwSvc --> SubStorage

    %% Notification pipeline
    NotificationSvc -->|"invoke"| SPI
    SPI -->|"default impl"| DefaultSPI
    DefaultSPI -->|"push to"| WebPush
    WebPush -->|"deliver"| Browser
    WebPush -->|"status"| Listener
    Listener --> NotificationSvc

    %% Service storage
    SubStorage --> DB
    NotifStorage --> DB

    %% Click Events
    click DevCI "https://github.com/meeds-io/pwa/blob/develop/.github/workflows/prbuild.yml"
    click Plugin "https://github.com/meeds-io/pwa/blob/develop/pwa-plugin/pom.xml"
    click Plugin "https://github.com/meeds-io/pwa/tree/develop/pwa-plugin/src/main/java/io/meeds/pwa/plugin"
    click Packaging "https://github.com/meeds-io/pwa/tree/develop/pwa-packaging/"
    click ManifestRest "https://github.com/meeds-io/pwa/blob/develop/pwa-service/src/main/java/io/meeds/pwa/rest/PwaManifestRest.java"
    click SubscriptionRest "https://github.com/meeds-io/pwa/blob/develop/pwa-service/src/main/java/io/meeds/pwa/rest/PwaPushSubscriptionRest.java"
    click NotificationRest "https://github.com/meeds-io/pwa/blob/develop/pwa-service/src/main/java/io/meeds/pwa/rest/PwaNotificationRest.java"
    click SwRest "https://github.com/meeds-io/pwa/blob/develop/pwa-service/src/main/java/io/meeds/pwa/rest/ServiceWorkerRest.java"
    click ManifestSvc "https://github.com/meeds-io/pwa/blob/develop/pwa-service/src/main/java/io/meeds/pwa/service/PwaManifestService.java"
    click SubscriptionSvc "https://github.com/meeds-io/pwa/blob/develop/pwa-service/src/main/java/io/meeds/pwa/service/PwaSubscriptionService.java"
    click NotificationSvc "https://github.com/meeds-io/pwa/blob/develop/pwa-service/src/main/java/io/meeds/pwa/service/PwaNotificationService.java"
    click SwSvc "https://github.com/meeds-io/pwa/blob/develop/pwa-service/src/main/java/io/meeds/pwa/service/PwaSwService.java"
    click SubStorage "https://github.com/meeds-io/pwa/blob/develop/pwa-service/src/main/java/io/meeds/pwa/storage/PwaSubscriptionStorage.java"
    click NotifStorage "https://github.com/meeds-io/pwa/blob/develop/pwa-service/src/main/java/io/meeds/pwa/storage/PwaNotificationStorage.java"
    click SPI "https://github.com/meeds-io/pwa/blob/develop/pwa-service/src/main/java/io/meeds/pwa/plugin/PwaNotificationPlugin.java"
    click DefaultSPI "https://github.com/meeds-io/pwa/blob/develop/pwa-service/src/main/java/io/meeds/pwa/plugin/DefaultPwaNotificationPlugin.java"
    click Listener "https://github.com/meeds-io/pwa/blob/develop/pwa-service/src/main/java/io/meeds/pwa/listener/WebNotificationSentListener.java"
    click PortletXML "https://github.com/meeds-io/pwa/blob/develop/pwa-webapp/src/main/webapp/WEB-INF/portlet.xml"
    click WebXML "https://github.com/meeds-io/pwa/blob/develop/pwa-webapp/src/main/webapp/WEB-INF/web.xml"
    click PwaApp "https://github.com/meeds-io/pwa/blob/develop/pwa-webapp/src/main/java/io/meeds/pwa/PwaApplication.java"
    click PwaJS "https://github.com/meeds-io/pwa/blob/develop/pwa-webapp/src/main/webapp/js/pwa.js"
    click PwaSettings "https://github.com/meeds-io/pwa/blob/develop/pwa-webapp/src/main/webapp/vue-app/settings/components/PwaSettings.vue"
    click UserSettings "https://github.com/meeds-io/pwa/blob/develop/pwa-webapp/src/main/webapp/vue-app/user-settings/components/UserSettingPwa.vue"
    click ManifestServiceJS "https://github.com/meeds-io/pwa/blob/develop/pwa-webapp/src/main/webapp/vue-app/settings/js/PwaManifestService.js"
    click ManifestJSON "https://github.com/meeds-io/pwa/blob/develop/pwa-service/src/main/resources/pwa/manifest.json"
    click SWFile "https://github.com/meeds-io/pwa/blob/develop/pwa-service/src/main/resources/pwa/service-worker.js"

    %% Styles
    classDef build fill:#ADD8E6,stroke:#000,stroke-width:1px
    classDef backend fill:#90EE90,stroke:#000,stroke-width:1px
    classDef frontend fill:#FFA500,stroke:#000,stroke-width:1px
    classDef database fill:#FFD700,stroke:#000,stroke-width:1px
    classDef external fill:#D3D3D3,stroke:#000,stroke-width:1px
```
