# shamapar/playwright-api-test-framework architecture

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

- Interactive diagram: https://gitdiagram.com/shamapar/playwright-api-test-framework
- Repository: https://github.com/shamapar/playwright-api-test-framework

## Overview

##### Project type and purpose
- This is an API Automation Test Framework built on Playwright. Its sole purpose is to define, execute, and report API tests against any HTTP-based service. It is not a user-facing frontend or a backend service—it’s a test automation tool.

##### File structure
- Top level
- package.json / package-lock.json / eslint.config.mjs – node project metadata, lint rules
- playwright.config.ts – Playwright test runner configuration
- readme.md – usage instructions
- tests folder
- config/env.ts – environment and global settings (base URLs, auth tokens)
- helper/utility.ts – shared helper functions (request builders, response parsers)
- interface/page.ts – TypeScript interfaces or request payload schemas (e.g., User objects)
- pages/*.json – sample payloads or fixture data
- specs/*.spec.ts – individual test suites for GET, POST, PUT, PATCH, DELETE operations
- testData/userData.ts – structured test data (valid/invalid users)

##### README for additional insights
- Shows prerequisites (NodeJS, VS Code) and commands to install (npm install) and run tests (npx playwright test)
- References external JWT/OAuth token tutorials—framework likely supports secured endpoints

##### Main components and their relationships
a. Test Runner (Playwright CLI)
- Entry point: playwright.config.ts → loads global settings and test project definitions
b. Configuration Module
- env.ts provides baseURL, headers, authentication token logic
c. Test Spec Suites
- One suite per HTTP verb (get.spec.ts, post.spec.ts, etc.)
- Each imports testData, interfaces, utilities, and calls utility.request(…)
d. Helper/Utility Layer
- Builds HTTP requests, injects headers/payloads, parses responses, centralizes common assertions
e. Interface/Schema Definitions
- Type-safe definitions of request/response objects to ensure consistency
f. Test Data Module
- Houses reusable payloads and parameter sets for positive/negative tests
g. Reporting & CI Integration
- Playwright’s built-in HTML reporter, can be wired into pipelines (not shown in file tree)
h. External Service Under Test

Data flow:
1. Runner reads playwright.config.ts → loads env.ts
2. For each spec file
- Loads testData & interface definitions
- Calls helper.utility to construct and send HTTP requests to the API under test
- Receives responses → asserts against expected schema/values
3. Aggregated results → Playwright reporter → console/HTML output

##### Architectural patterns & design principles
- Separation of concerns: config vs. data vs. test logic vs. utilities
- Page-Object/Interface pattern repurposed for API payloads and responses
- DRY: shared utilities abstract common HTTP operations
- Type safety: interfaces ensure payload correctness

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Nodes
    Runner["Test Runner<br/>(Playwright CLI)"]:::executable
    subgraph "Framework Core"
        Config["Configuration Module<br/>(env.ts)"]:::internal
        Interfaces["Interface Definitions<br/>(page.ts)"]:::internal
        TestData["Test Data Module<br/>(userData.ts)"]:::internal
        Utility["Helper/Utility Layer<br/>(utility.ts)"]:::internal
    end
    subgraph "Test Specifications"
        GET["GET Tests<br/>(get.spec.ts)"]:::executable
        POST["POST Tests<br/>(post.spec.ts)"]:::executable
        PUT["PUT Tests<br/>(put.spec.ts)"]:::executable
        PATCH["PATCH Tests<br/>(patch.spec.ts)"]:::executable
        DELETE["DELETE Tests<br/>(delete.spec.ts)"]:::executable
    end
    subgraph "Fixture Data"
        JSON1["1.json"]:::internal
        JSON2["2.json"]:::internal
        Unknown["unknowUser.ts"]:::internal
    end
    ExternalAPI["External API Service"]:::external
    Report["Test Report<br/>(HTML/Console)"]:::report
    Docs["Documentation<br/>(readme.md)"]:::doc

    %% Connections
    Runner -->|loads| Config
    Runner -->|executes| GET
    Runner -->|executes| POST
    Runner -->|executes| PUT
    Runner -->|executes| PATCH
    Runner -->|executes| DELETE
    Runner -->|outputs| Report
    Runner -->|references| Docs

    GET -->|loads| Interfaces
    GET -->|loads| TestData
    GET -->|calls| Utility
    POST -->|loads| Interfaces
    POST -->|loads| TestData
    POST -->|calls| Utility
    PUT -->|loads| Interfaces
    PUT -->|loads| TestData
    PUT -->|calls| Utility
    PATCH -->|loads| Interfaces
    PATCH -->|loads| TestData
    PATCH -->|calls| Utility
    DELETE -->|loads| Interfaces
    DELETE -->|loads| TestData
    DELETE -->|calls| Utility

    Utility -->|injects headers/payloads| Config
    Utility -->|sends requests| ExternalAPI
    ExternalAPI -->|returns responses| Utility
    Utility -->|parses/asserts| Interfaces

    TestData -->|provides payloads| GET
    TestData -->|provides payloads| POST
    TestData -->|provides payloads| PUT
    TestData -->|provides payloads| PATCH
    TestData -->|provides payloads| DELETE

    JSON1 -->|fixture| GET
    JSON2 -->|fixture| POST
    Unknown -->|fixture| DELETE

    %% Click Events
    click Runner "https://github.com/shamapar/playwright-api-test-framework/blob/main/playwright.config.ts"
    click Config "https://github.com/shamapar/playwright-api-test-framework/blob/main/tests/config/env.ts"
    click GET "https://github.com/shamapar/playwright-api-test-framework/blob/main/tests/specs/get.spec.ts"
    click POST "https://github.com/shamapar/playwright-api-test-framework/blob/main/tests/specs/post.spec.ts"
    click PUT "https://github.com/shamapar/playwright-api-test-framework/blob/main/tests/specs/put.spec.ts"
    click PATCH "https://github.com/shamapar/playwright-api-test-framework/blob/main/tests/specs/patch.spec.ts"
    click DELETE "https://github.com/shamapar/playwright-api-test-framework/blob/main/tests/specs/delete.spec.ts"
    click Utility "https://github.com/shamapar/playwright-api-test-framework/blob/main/tests/helper/utility.ts"
    click Interfaces "https://github.com/shamapar/playwright-api-test-framework/blob/main/tests/interface/page.ts"
    click TestData "https://github.com/shamapar/playwright-api-test-framework/blob/main/tests/testData/userData.ts"
    click JSON1 "https://github.com/shamapar/playwright-api-test-framework/blob/main/tests/pages/1.json"
    click JSON2 "https://github.com/shamapar/playwright-api-test-framework/blob/main/tests/pages/2.json"
    click Unknown "https://github.com/shamapar/playwright-api-test-framework/blob/main/tests/pages/unknowUser.ts"
    click Docs "https://github.com/shamapar/playwright-api-test-framework/blob/main/readme.md"

    %% Styles
    classDef internal fill:#D0E8FF,stroke:#0366D6,color:#0366D6;
    classDef executable fill:#E6FFEA,stroke:#28A745,color:#28A745;
    classDef external fill:#F0F0F0,stroke:#6C757D,color:#6C757D;
    classDef report fill:#FFF4E5,stroke:#FFC107,color:#856404;
    classDef doc fill:#FFF5F5,stroke:#D73A49,color:#D73A49;
```
