# slavapislyakov/demo_playwright architecture

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

- Interactive diagram: https://gitdiagram.com/slavapislyakov/demo_playwright
- Repository: https://github.com/slavapislyakov/demo_playwright

## Overview

##### Project type and purpose
- This is an end‑to‑end UI/API test automation framework built on Playwright.
- It uses a Page Object Model (page‑objects), service wrappers for API calls (servicies), structured test data (data), utilities (utils), and Allure for reporting.

##### Main architectural components
a. Test Runner & Configuration
- Playwright CLI (playwright.config.ts) invokes the test suite.
- NPM scripts in package.json (`run:test`, `run:test:ui`, `allure:reporter`).
b. Test Suite
- `tests/*.spec.ts`: orchestration layer where individual test scenarios live (e.g., enotes.spec.ts).
c. Page Object Layer
- `page-objects/pages/*.ts`: high‑level page abstractions (HomePage, BasketPage, LoginPage).
- `page-objects/components/*.ts`: reusable UI widgets (NavBar, BasketModal).
- `page-objects/fixtures/pageFixtures.ts`: fixture definitions to wire Page Objects into tests.
d. Services Layer
- `servicies/*.ts`: wrappers around backend API endpoints (BasketApi).
e. Data Layer
- `data/*.ts`: configuration and test data (endpoint_urls.ts, products.ts, modals, urls).
- `data/credentials.ts`: auth credentials.
f. Utilities
- `utils/apiServiceUtil.ts`: generic HTTP request helpers.
- `utils/stringUtils.ts`: text‑manipulation helpers.
g. Browser & Network Actors
- Browser instance managed by Playwright.
- External HTTP APIs called by service layer.
h. Reporting
- Allure reporter plugin collects and visualizes test results.

##### Relationships & data flow
1. The Test Runner reads playwright.config.ts and launches tests.
2. A spec file imports page fixtures and data, invokes high‑level flows:
- Calls Page Objects that use Playwright to manipulate the browser.
- Calls Service wrappers to perform direct HTTP calls.
3. Page Objects and Service wrappers leverage Utils and Data modules.
4. All interactions (UI and API) against the System Under Test (web application or backend).
5. Test outcomes (pass/fail, logs, screenshots) are fed to the Allure reporter.

##### Architectural patterns & design principles
- Page Object Model (POM) for UI abstraction.
- Single‑responsibility for each layer: tests orchestrate, page‑objects drive UI, services drive APIs, data centralizes test fixtures, utils factor out common code.
- Dependency injection via fixtures.
- Separation of concerns: clear layering prevents brittle tests.

## Diagram (Mermaid)

```mermaid
graph TB
    %% Orchestration Layer
    subgraph Orchestration
        direction TB
        Config["playwright.config.ts"]:::orchestration
        Package["package.json (npm scripts)"]:::orchestration
        Runner["Playwright CLI"]:::orchestration
    end

    %% Test Suite
    subgraph "Test Suite"
        direction TB
        TestsDir["tests/"]:::orchestration
        EnotesSpec["enotes.spec.ts"]:::orchestration
    end

    %% UI Layer
    subgraph "Page Object Layer"
        direction TB
        subgraph Pages
            HomePage["HomePage"]:::ui
            LoginPage["LoginPage"]:::ui
            BasketPage["BasketPage"]:::ui
        end
        subgraph Components
            NavBar["NavBar"]:::ui
            BasketModal["BasketModal"]:::ui
        end
        PageFixtures["pageFixtures"]:::ui
    end

    Browser["Browser"]:::ui

    %% API Layer
    subgraph "Services Layer"
        direction TB
        BasketApi["BasketApi"]:::api
    end

    ExternalAPIs["External HTTP APIs"]:::api

    %% Support Layer
    subgraph "Data Layer"
        direction TB
        Credentials["credentials.ts"]:::support
        Endpoints["endpoint_urls.ts"]:::support
        Urls["urls.ts"]:::support
        Products["products.ts"]:::support
        ModalData["modals/basket_modal.ts"]:::support
    end

    subgraph "Utilities"
        direction TB
        ApiUtil["apiServiceUtil.ts"]:::support
        StringUtil["stringUtils.ts"]:::support
    end

    %% Reporting
    Reporter["Allure Reporter"]:::reporting

    %% Configuration Files
    subgraph "Configuration Files"
        direction TB
        Env[".env"]:::support
        TSConfig["tsconfig.json"]:::support
        ESLint[".eslintrc.json"]:::support
        Prettier[".prettierrc"]:::support
        GitIgnore[".gitignore"]:::support
    end

    %% Relationships
    Config -->|configures| Runner
    Package -->|defines scripts| Runner
    Runner -->|runs tests| TestsDir
    TestsDir -->|includes| EnotesSpec
    EnotesSpec -->|uses fixtures| PageFixtures
    EnotesSpec -->|calls| HomePage
    EnotesSpec -->|calls| LoginPage
    EnotesSpec -->|calls| BasketPage
    EnotesSpec -->|calls| BasketApi
    PageFixtures -->|injects into| EnotesSpec
    HomePage -->|UI actions| Browser
    LoginPage -->|UI actions| Browser
    BasketPage -->|UI actions| Browser
    BasketApi -->|HTTP request| ExternalAPIs
    EnotesSpec -->|reports results| Reporter
    Runner -->|initializes reporter| Reporter

    %% Dependencies to Data & Utils
    HomePage -.->|uses data| Endpoints
    HomePage -.->|uses utils| StringUtil
    BasketPage -.->|uses data| ModalData
    BasketApi -.->|uses utils| ApiUtil
    BasketApi -.->|uses data| Urls

    %% Click Events
    click Config "https://github.com/slavapislyakov/demo_playwright/blob/master/playwright.config.ts"
    click Package "https://github.com/slavapislyakov/demo_playwright/blob/master/package.json"
    click TestsDir "https://github.com/slavapislyakov/demo_playwright/tree/master/tests/"
    click EnotesSpec "https://github.com/slavapislyakov/demo_playwright/blob/master/tests/enotes.spec.ts"
    click HomePage "https://github.com/slavapislyakov/demo_playwright/blob/master/page-objects/pages/HomePage.ts"
    click LoginPage "https://github.com/slavapislyakov/demo_playwright/blob/master/page-objects/pages/LoginPage.ts"
    click BasketPage "https://github.com/slavapislyakov/demo_playwright/blob/master/page-objects/pages/BasketPage.ts"
    click NavBar "https://github.com/slavapislyakov/demo_playwright/blob/master/page-objects/components/NavBar.ts"
    click BasketModal "https://github.com/slavapislyakov/demo_playwright/blob/master/page-objects/components/BasketModal.ts"
    click PageFixtures "https://github.com/slavapislyakov/demo_playwright/blob/master/page-objects/fixtures/pageFixtures.ts"
    click BasketApi "https://github.com/slavapislyakov/demo_playwright/blob/master/servicies/BasketApi.ts"
    click Credentials "https://github.com/slavapislyakov/demo_playwright/blob/master/data/credentials.ts"
    click Endpoints "https://github.com/slavapislyakov/demo_playwright/blob/master/data/endpoint_urls.ts"
    click Urls "https://github.com/slavapislyakov/demo_playwright/blob/master/data/urls.ts"
    click Products "https://github.com/slavapislyakov/demo_playwright/blob/master/data/products.ts"
    click ModalData "https://github.com/slavapislyakov/demo_playwright/blob/master/data/modals/basket_modal.ts"
    click ApiUtil "https://github.com/slavapislyakov/demo_playwright/blob/master/utils/apiServiceUtil.ts"
    click StringUtil "https://github.com/slavapislyakov/demo_playwright/blob/master/utils/stringUtils.ts"
    click Reporter "https://github.com/slavapislyakov/demo_playwright/blob/master/package.json"
    click Reporter "https://github.com/slavapislyakov/demo_playwright/blob/master/playwright.config.ts"
    click Env "https://github.com/slavapislyakov/demo_playwright/blob/master/.env"
    click TSConfig "https://github.com/slavapislyakov/demo_playwright/blob/master/tsconfig.json"
    click ESLint "https://github.com/slavapislyakov/demo_playwright/blob/master/.eslintrc.json"
    click Prettier "https://github.com/slavapislyakov/demo_playwright/blob/master/.prettierrc"
    click GitIgnore "https://github.com/slavapislyakov/demo_playwright/blob/master/.gitignore"

    %% Styles
    classDef orchestration fill:#D0E8FF,stroke:#0052CC,color:#0052CC;
    classDef ui fill:#E0FFE0,stroke:#008000,color:#008000;
    classDef api fill:#FFE4B3,stroke:#FF8C00,color:#FF8C00;
    classDef support fill:#F0F0F0,stroke:#A0A0A0,color:#707070;
    classDef reporting fill:#F5E0FF,stroke:#800080,color:#800080;
```
