# mehmetgul/playwright-template-framework architecture

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

- Interactive diagram: https://gitdiagram.com/mehmetgul/playwright-template-framework
- Repository: https://github.com/mehmetgul/playwright-template-framework

## Overview

##### Main Components
- Test Runner & Framework: Central to the design is the Playwright test runner (as configured in playwright.config.ts) that orchestrates the execution of tests. Indicate that Playwright is the core technology used.
- Page Object Model (POM): In the src/pageObjects directory, there are modules for different pages such as HomePage, CartPage, and ProductPage. Represent these as separate components/classes that encapsulate UI interactions.
- API Layer: The src/api directory, containing files like UserAPI.ts, represents the API testing functionality. This component should be linked to tests that call API endpoints.
- Fixtures and Data: The src/fixtures directory (including custom fixtures and test-data JSON) shows the framework’s support for dynamic test setup and data management. These can be represented as “Test Fixtures” that feed data into tests.
- Configuration & Environment Management: The config directory holds environment-specific JSON configuration files (dev.json, prod.json, qa.json, uat.json). These should connect to a “Configuration Manager” component (represented via utils/config-loader.ts and utils/environment.ts) that dynamically sets up test parameters.
- Cleanup & Reporting: Introduce components for automated artifact cleanup (cleanup.ts script) and reporting mechanisms. The README also mentions Allure and Playwright HTML report generation (with specific commands and possibly a dedicated “artifacts” directory). Represent these as reporting and artifact management modules.

##### Relationships and Data Flow
- The Test Runner (Playwright) orchestrates test execution, calling the appropriate test files (e.g., tests/ui/ecommerce.spec.ts).
- Some tests also trigger API calls that route through the API layer (UserAPI.ts). Show bi-directional interactions if needed (e.g., for data validation or setup/teardown).
- The Configuration Manager loads environment variables from the config folder and feeds them into the tests and utilities.
- Utility modules (Logger, File Utils, Test Data Generator) support both Page Objects and API calls, and influence reporting results (e.g., log outputs connect to reports).
- Post-test execution, the Cleanup module is triggered to clear artifacts before/running tests, ensuring a clean state. Indicate data flow back to the test runner.

##### Architectural Patterns & Technologies
- The Page Object Model (POM) is explicitly used for UI abstraction.
- Separation of concerns is achieved by keeping tests, fixtures, page objects, API testing, and utilities in distinct directories.
- Environment-based configuration (via JSON files and config-loader) makes the framework highly adaptable.
- The framework is modular and supports advanced reporting using Allure and Playwright’s built-in HTML reporting.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Dependencies
    subgraph "External Dependencies"
        NJS["Node.js"]:::external
        PL["Playwright"]:::external
        AL["Allure"]:::external
    end

    %% Test Automation Framework Components
    subgraph "Test Automation Framework"
        TR["Test Runner & Framework"]:::blue
        TS["UI Test Spec"]:::blue

        PO["Page Objects"]:::blue
        HP["Home Page"]:::blue
        CP["Cart Page"]:::blue
        PP["Product Page"]:::blue

        API["API Layer"]:::blue

        FIX["Fixtures & Data"]:::blue
        CFIX["Custom Fixtures"]:::blue
        TD["Test Data"]:::blue

        UT["Utility Functions"]:::blue
        CL["Config Loader"]:::blue
        ENV["Environment Setup"]:::blue
        FU["File Utils"]:::blue
        LOG["Logger"]:::blue
        TDG["Test Data Generator"]:::blue
        UII["UI Interactions"]:::blue

        CM["Configuration Manager"]:::green
        CF["Config Files"]:::green

        CR["Cleanup & Reporting"]:::orange
        CCleanup["Cleanup Script"]:::orange
        CRP["Reporting (Allure & HTML)"]:::orange
    end

    %% Relationships & Data Flow
    NJS --> TR
    PL --> TR

    TR --> TS
    TR --> PO
    PO --> HP
    PO --> CP
    PO --> PP

    TR --> API

    TR --> FIX
    FIX --> CFIX
    FIX --> TD

    TR --> CR

    CM --> TR
    CM --> UT
    CF --> CM

    UT --> PO
    UT --> API
    UT --> CL
    UT --> ENV
    UT --> FU
    UT --> LOG
    UT --> TDG
    UT --> UII

    TS --> CRP
    TR --> CRP
    CR --> CCleanup
    CR --> CRP

    %% External Reporting Flow
    PL --- CRP

    %% Click Events
    click TR "https://github.com/mehmetgul/playwright-template-framework/blob/main/playwright.config.ts"
    click TS "https://github.com/mehmetgul/playwright-template-framework/blob/main/tests/ui/ecommerce.spec.ts"
    click PO "https://github.com/mehmetgul/playwright-template-framework/tree/main/src/pageObjects"
    click HP "https://github.com/mehmetgul/playwright-template-framework/blob/main/src/pageObjects/home/HomePage.ts"
    click CP "https://github.com/mehmetgul/playwright-template-framework/blob/main/src/pageObjects/cart/CartPage.ts"
    click PP "https://github.com/mehmetgul/playwright-template-framework/blob/main/src/pageObjects/product/ProductPage.ts"
    click API "https://github.com/mehmetgul/playwright-template-framework/blob/main/src/api/UserAPI.ts"
    click FIX "https://github.com/mehmetgul/playwright-template-framework/tree/main/src/fixtures"
    click CFIX "https://github.com/mehmetgul/playwright-template-framework/blob/main/src/fixtures/custom-fixtures.ts"
    click TD "https://github.com/mehmetgul/playwright-template-framework/blob/main/src/fixtures/data/test-data.json"
    click UT "https://github.com/mehmetgul/playwright-template-framework/tree/main/src/utils"
    click CL "https://github.com/mehmetgul/playwright-template-framework/blob/main/src/utils/config-loader.ts"
    click ENV "https://github.com/mehmetgul/playwright-template-framework/blob/main/src/utils/environment.ts"
    click FU "https://github.com/mehmetgul/playwright-template-framework/blob/main/src/utils/file-utils.ts"
    click LOG "https://github.com/mehmetgul/playwright-template-framework/blob/main/src/utils/logger.ts"
    click TDG "https://github.com/mehmetgul/playwright-template-framework/blob/main/src/utils/test-data-generator.ts"
    click UII "https://github.com/mehmetgul/playwright-template-framework/blob/main/src/utils/ui-interactions.ts"
    click CF "https://github.com/mehmetgul/playwright-template-framework/tree/main/config"
    click CCleanup "https://github.com/mehmetgul/playwright-template-framework/blob/main/cleanup.ts"

    %% Styles
    classDef blue fill:#cce5ff,stroke:#004085,stroke-width:2px;
    classDef green fill:#d4edda,stroke:#155724,stroke-width:2px;
    classDef orange fill:#ffe5b4,stroke:#e65c00,stroke-width:2px;
    classDef external fill:#e2e3e5,stroke:#6c757d,stroke-width:2px;
```
