# jardevson/playwrightcleancli architecture

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

- Interactive diagram: https://gitdiagram.com/jardevson/playwrightcleancli
- Repository: https://github.com/jardevson/playwrightcleancli

## Overview

##### Project type and purpose
- This is an open‑source CLI tool for API testing, built in TypeScript on top of Playwright.
- It provides a clean command‑line interface that invokes Playwright-based tests (in tests/ and tests‑examples/) against a target API (e.g., ServeRest), parameterized by environment.

##### File structure
- Top level:
- package.json / package-lock.json – defines dependencies (playwright, ts‑node, cross‑env) and CLI scripts (test.api).
- playwright.config.ts – Playwright configuration (timeouts, reporters, baseURL).
- tests/ – actual test suites (api.spec.ts) plus a runner (runTests.ts).
- tests‑examples/ – sample/demo tests (demo-todo-app.spec.ts).
- .github/workflows/playwright.yml – CI pipeline invoking the CLI.

##### Insights from the README
- Describes rationale for a CLI-driven API testing approach (speed, automation, customization).
- Shows how the runTests.ts script dynamically builds a Playwright CLI command with cross‑env for environment‑agnostic API_URL injection.
- Demonstrates a suite of CRUD tests against /login, /usuarios endpoints.

##### Main components
a. CLI Layer
- runTests.ts script (invoked via ts-node)
- Accepts parameters: environment (dev/uat/sit), optional specific suite (e.g., api.spec.ts)
- Uses cross‑env to set API_URL
b. Test Runner Layer
- Playwright Test Runner (playwright test)
- Configuration (playwright.config.ts)
- Test Suites (tests/api.spec.ts, tests-examples/demo‑todo‑app.spec.ts)
c. External System Under Test
- REST API endpoint at ${API_URL} (ServeRest or any target)
d. CI/CD Pipeline
- GitHub Actions workflow (.github/workflows/playwright.yml)
- Triggers the same CLI commands on push/PR

##### Relationships and data flows
1) Developer or CI invokes “npm run test.api <env> [suite]”
2) runTests.ts constructs: cross-env API_URL=<envUrl> npx playwright test tests/<suite>
3) Playwright runner loads config & test files
4) Each test case issues HTTP requests to ${API_URL}/…
5) Assertions validate status codes & response bodies
6) Results flow back to runner, reporter outputs pass/fail
7) CI reads test outcome and fails/builds accordingly

##### Architectural patterns & design principles
- Thin CLI orchestrator (separation of concerns: command parsing vs. test logic)
- Modular test suites (can add/remove .spec.ts files without changing runner)
- Environment abstraction via cross‑env (platform‑agnostic)
- CI integration (GitHub Actions uses the same CLI entrypoint)
- Extensibility: developers can drop new tests in tests/ or tests‑examples/

- Labels: “runTests.ts (CLI)”, “cross-env”, “npx playwright test”, “playwright.config.ts”, “tests/api.spec.ts”, “tests-examples/demo-todo-app.spec.ts”, “ServeRest API (API_URL)”, “GitHub Actions”
- CLI → cross-env → Playwright Runner
- Playwright Runner → playwright.config.ts (load)
- Playwright Runner → Test Suites (load & execute)
- Test Suites → External API (HTTP requests)
- External API → Test Suites (responses)
- Runner → Console/Reporter → CI server

## Diagram (Mermaid)

```mermaid
flowchart TD
    Dev["Developer"]:::external
    CI["GitHub Actions"]:::ci
    pkg["package.json (scripts & cross-env)"]:::internal
    cli["runTests.ts (CLI)"]:::internal
    crossEnv["cross-env"]:::external
    npxPlaywright["npx playwright test"]:::internal
    config["playwright.config.ts"]:::internal
    testsApi["tests/api.spec.ts"]:::internal
    testsDemo["tests-examples/demo-todo-app.spec.ts"]:::internal
    api["ServeRest API (API_URL)"]:::external
    reporter["Console/Reporter"]:::internal

    Dev -->|"npm run test.api"| pkg
    CI -->|"on push/PR triggers"| pkg
    pkg -->|"invokes"| cli
    cli -->|"uses"| crossEnv
    crossEnv -->|"sets API_URL"| npxPlaywright
    npxPlaywright -->|"loads config"| config
    npxPlaywright -->|"executes"| testsApi
    npxPlaywright -->|"executes"| testsDemo
    testsApi -->|"HTTP requests"| api
    testsDemo -->|"HTTP requests"| api
    api -->|"responses"| testsApi
    api -->|"responses"| testsDemo
    npxPlaywright -->|"reports results"| reporter
    reporter -->|"reports outcome"| CI

    click cli "https://github.com/jardevson/playwrightcleancli/blob/main/tests/runTests.ts"
    click config "https://github.com/jardevson/playwrightcleancli/blob/main/playwright.config.ts"
    click testsApi "https://github.com/jardevson/playwrightcleancli/blob/main/tests/api.spec.ts"
    click testsDemo "https://github.com/jardevson/playwrightcleancli/blob/main/tests-examples/demo-todo-app.spec.ts"
    click pkg "https://github.com/jardevson/playwrightcleancli/blob/main/package.json"
    click CI "https://github.com/jardevson/playwrightcleancli/blob/main/.github/workflows/playwright.yml"

    classDef internal fill:#e0f7e9,stroke:#2e7d32,color:#2e7d32
    classDef external fill:#e3f2fd,stroke:#1565c0,color:#1565c0
    classDef ci fill:#eeeeee,stroke:#757575,color:#424242
```
