# arghajit47/playwright-lighthouse-performance-testing architecture

> Architecture diagram of the GitHub repository arghajit47/playwright-lighthouse-performance-testing, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-06-09). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/arghajit47/playwright-lighthouse-performance-testing
- Repository: https://github.com/arghajit47/playwright-lighthouse-performance-testing

## Overview

##### Project Type and Purpose
- This is an **automated performance-testing framework** built on Node.js, combining **Playwright** (browser automation) with **Lighthouse** (performance auditing).
- It supports two user flows—**Authorized** and **Unauthorized**—and runs tests in both **desktop** and **mobile** modes.
- In addition to test suites, the repo contains:
- A **static “performance-report”** viewer (HTML/JS/CSS) to render raw Lighthouse output.
- A **“dashboard”** mini-application (Node backend + HTML/JS/CSS frontend) to display consolidated results.
- A **downloadImages.mjs** helper to fetch Lighthouse report screenshots for the dashboard.

##### File Structure
- **tests/Auth & tests/UnAuth**
- Playwright test specs (TypeScript) driving login flows (Auth) or public pages (UnAuth).
- **utils/**
- Common helpers for running audits and parsing results.
- **test-data/enum.ts**
- Canonical URLs and constants for tests.
- **lighthouse/base.ts**
- Shared Lighthouse configuration.
- **playwright.config.ts**
- Playwright settings (browsers, timeouts).
- **CI Workflow (.github/workflows/playwright.yml)**
- Installs dependencies, runs tests, uploads artifacts.
- **performance-report/**
- Static viewer showing raw Lighthouse HTML reports.
- **dashboard/**
- backend/server.mjs: Node HTTP server or Express app serving an API to fetch test results/images.
- **downloadImages.mjs**
- Script that pulls screenshots from generated Lighthouse reports for inclusion in dashboard.

##### Main Components & Relationships
A. **Test Runner Pipeline**
1. **CLI / npm Scripts**
- `npm run test:Auth | test:UnAuth | test` triggers the test runner.
2. **Playwright Test Suite** (Auth & UnAuth specs)
- Uses `@playwright/test` + `dotenv` for credentials.
- Invokes **playwright-lighthouse** to run Lighthouse audits under different device emulations.
3. **Lighthouse Audit Engine**
- Runs performance audits; outputs JSON/HTML reports.
4. **Results Storage**
- Reports written to disk under workspace (e.g., `performance-report/` or temp folders).
B. **Report Generation & Viewing**
1. **performance-report/**
- Static site loads raw Lighthouse HTML/JSON, presents charts and metrics.
2. **downloadImages.mjs**
- Parses Lighthouse JSON to extract screenshot assets.
3. **dashboard Backend**
- Serves an API that aggregates JSON metrics and images.
4. **dashboard Frontend**
- Fetches from backend, displays trend graphs and comparison across runs.
C. **CI/CD Integration**
- **GitHub Actions** uses `playwright.yml` to run tests on push/PR.
- Artifacts (reports) are uploaded for 30 days.
- Secrets (EMAIL/PASSWORD) are provided via GitHub secrets.

##### Architectural Patterns & Design Principles
- **Modular Test Pipeline**: Separation of Playwright specs, shared helpers, and configuration enables reuse.
- **Data-Pipeline Style**: Test → Audit → Report → Visualization.
- **MVC-Like Dashboard**: Node.js backend (Model/API), frontend UI (View), routing logic (Controller).
- **CI as Orchestrator**: External service triggering automated runs and storing artifacts.

- Components: CLI scripts, Playwright test suite, Lighthouse engine, JSON/HTML report files, downloadImages script, dashboard backend, dashboard frontend, performance-report viewer, GitHub Actions, target web application.
- Legends or annotations for environment variables, secrets, and configuration files.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% CI/CD Layer
    subgraph "CI/CD Layer"
        CI["GitHub Actions"]:::ci
    end

    %% Testing Layer
    subgraph "Testing Layer"
        CLI["CLI / npm Scripts"]:::testComp
        Config["playwright.config.ts"]:::testComp
        Auth["Playwright Test Suite (Auth)"]:::testComp
        UnAuth["Playwright Test Suite (UnAuth)"]:::testComp
        Utils["Shared Test Utilities"]:::testComp
        LHHelpers["Lighthouse Audit Helpers"]:::testComp
        Data["Test Data Constants"]:::testComp
        LHConfig["Shared Lighthouse Configuration"]:::testComp
    end

    %% Audit Engine
    subgraph "Audit Engine"
        Lighthouse["Lighthouse Audit Engine\n(mobile & desktop)"]:::testComp
    end

    %% Reports Storage
    subgraph "Reports Storage"
        JSON["JSON Reports"]:::report
        HTML["HTML Reports"]:::report
    end

    %% Reporting Layer
    subgraph "Reporting Layer"
        Static["Performance-Report Viewer"]:::report
        Download["downloadImages.mjs"]:::report
        subgraph "Dashboard"
            DBBackend["Dashboard Backend API"]:::dashboard
            DBFrontend["Dashboard Frontend UI"]:::dashboard
        end
    end

    %% External System Under Test
    External["External Web App"]:::external

    %% Data Flow
    CI -->|"triggers"| CLI
    CLI -->|"runs tests"| Auth
    CLI -->|"runs tests"| UnAuth
    Config --> Auth
    Config --> UnAuth
    Utils --> Auth
    LHHelpers --> Auth
    Data --> Auth
    LHConfig --> Auth
    Utils --> UnAuth
    LHHelpers --> UnAuth
    Data --> UnAuth
    LHConfig --> UnAuth
    External --> Auth
    External --> UnAuth
    Auth -->|"invokes"| Lighthouse
    UnAuth -->|"invokes"| Lighthouse
    Lighthouse -->|"generates"| JSON
    Lighthouse -->|"generates"| HTML
    JSON -->|"view raw reports"| Static
    HTML -->|"view raw reports"| Static
    JSON -->|"post-process"| Download
    Download -->|"feeds images"| DBBackend
    JSON -->|"feeds metrics"| DBBackend
    DBBackend -->|"serves API"| DBFrontend
    DBFrontend -->|"renders UI"| User["End User"]:::external

    %% Click Events
    click Auth "https://github.com/arghajit47/playwright-lighthouse-performance-testing/blob/main/tests/Auth/performance.spec.ts"
    click UnAuth "https://github.com/arghajit47/playwright-lighthouse-performance-testing/blob/main/tests/UnAuth/performance.spec.ts"
    click Utils "https://github.com/arghajit47/playwright-lighthouse-performance-testing/blob/main/utils/common.ts"
    click LHHelpers "https://github.com/arghajit47/playwright-lighthouse-performance-testing/blob/main/utils/helpers.ts"
    click Data "https://github.com/arghajit47/playwright-lighthouse-performance-testing/blob/main/test-data/enum.ts"
    click LHConfig "https://github.com/arghajit47/playwright-lighthouse-performance-testing/blob/main/lighthouse/base.ts"
    click Config "https://github.com/arghajit47/playwright-lighthouse-performance-testing/blob/main/playwright.config.ts"
    click CI "https://github.com/arghajit47/playwright-lighthouse-performance-testing/blob/main/.github/workflows/playwright.yml"
    click Static "https://github.com/arghajit47/playwright-lighthouse-performance-testing/blob/main/performance-report/index.html"
    click Static "https://github.com/arghajit47/playwright-lighthouse-performance-testing/blob/main/performance-report/app.js"
    click Static "https://github.com/arghajit47/playwright-lighthouse-performance-testing/blob/main/performance-report/script.js"
    click Static "https://github.com/arghajit47/playwright-lighthouse-performance-testing/blob/main/performance-report/style.css"
    click Download "https://github.com/arghajit47/playwright-lighthouse-performance-testing/blob/main/downloadImages.mjs"
    click DBBackend "https://github.com/arghajit47/playwright-lighthouse-performance-testing/blob/main/dashboard/backend/server.mjs"
    click DBFrontend "https://github.com/arghajit47/playwright-lighthouse-performance-testing/blob/main/dashboard/index.html"
    click DBFrontend "https://github.com/arghajit47/playwright-lighthouse-performance-testing/blob/main/dashboard/frontend/script.js"
    click DBFrontend "https://github.com/arghajit47/playwright-lighthouse-performance-testing/blob/main/dashboard/frontend/style.css"

    %% Styles
    classDef testComp fill:#cce5ff,stroke:#0366d6,color:#000;
    classDef report fill:#d4edda,stroke:#155724,color:#000;
    classDef dashboard fill:#e2d7f2,stroke:#6f42c1,color:#000;
    classDef ci fill:#f0f0f0,stroke:#6c757d,color:#000;
    classDef external fill:#f8f9fa,stroke:#adb5bd,color:#000;
```
