# marco-antonio-rodrigues/example-puppeteer architecture

> Architecture diagram of the GitHub repository marco-antonio-rodrigues/example-puppeteer, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-14). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/marco-antonio-rodrigues/example-puppeteer
- Repository: https://github.com/marco-antonio-rodrigues/example-puppeteer

## Overview

##### Project type and purpose
- This is a small CLI‐style automation tool (an “open-source script”) written in TypeScript that uses Puppeteer to navigate to a webpage and take a screenshot.
- Its sole feature: launch a headless Chrome via Puppeteer, open https://example.com, capture a screenshot (screenshot.png), and exit.

##### File structure
- Top-level files:
- package.json / yarn.lock – dependency manifest
- tsconfig.json – TypeScript compilation settings
- jest.config.js + src/__tests__ – unit/integration tests
- .gitignore
- src/index.ts – the main entry point.
- (dist/) – generated output after `tsc`.

##### README for additional insights
- Explains two run modes: directly via ts-node or via compiled JS (dist/index.js).
- Specifies Node >=16, yarn, build/clean commands.
- No other modules/microservices—purely a single‐binary script.

a. Main components:
- Developer machine / CLI
- TypeScript compiler (tsc) / ts-node
- Node.js runtime
- Puppeteer library
- Headless Chrome/Chromium instance
- External website (https://example.com)
- Local file system (for screenshot.png & dist/)
- Test harness (Jest)
b. Relationships & interactions:
1. Developer invokes `npx ts-node src/index.ts` or `node dist/index.js`.
2. If in build mode: ts-node or tsc → compile TS → output .js.
3. Node runtime loads compiled code.
4. Code imports Puppeteer → spawns a headless Chrome process.
5. Puppeteer instructs Chrome to navigate → sends HTTP request to example.com.
6. Chrome renders the page → Puppeteer captures screenshot buffer.
7. Code writes screenshot.png to local FS.
8. Jest tests invoke the same code (or mocks) to validate behavior.
c. Architectural patterns & principles:
- Single‐process, script‐driven workflow.
- Clear separation: build (TypeScript) vs. run (Node) vs. test (Jest).
- External dependency inversion: code drives browser via Puppeteer API.
d. Key technologies & libraries:
- TypeScript
- ts-node / tsc
- Node.js
- Puppeteer (Chrome automation)
- Jest (testing)

## Diagram (Mermaid)

```mermaid
graph TB
    %% Build and Test Layer
    subgraph "Build & Test"
        DevCLI["Developer CLI"]:::build
        Scripts["Dependency Manifest & Scripts"]:::build
        TS["TypeScript Compiler / ts-node"]:::build
        BuildConfig["Build Configuration (tsconfig.json)"]:::build
        Jest["Test Harness (Jest)"]:::build
        TestConfig["Test Configuration (jest.config.js)"]:::build
    end

    %% Runtime Layer
    subgraph "Runtime"
        Node["Node.js Runtime"]:::runtime
        Puppeteer["Puppeteer Library"]:::runtime
        Chrome["Headless Chrome"]:::runtime
    end

    %% External System
    subgraph "External"
        ExtWeb["External Website (https://example.com)"]:::external
    end

    %% File System
    FS["Local File System (screenshot.png)"]:::fs

    %% Connections
    DevCLI -->|"run scripts"| Scripts
    Scripts -->|"install & run"| TS
    BuildConfig --> TS
    Scripts -.->|"npm test"| Jest
    TestConfig --> Jest
    Jest -->|"run tests against"| Node

    TS -->|"compile"| Node
    Node -->|"imports"| Puppeteer
    Puppeteer -->|"spawn"| Chrome
    Chrome -->|"HTTP request"| ExtWeb
    Puppeteer -->|"capture & send buffer"| FS

    %% Click Events
    click DevCLI "https://github.com/marco-antonio-rodrigues/example-puppeteer/blob/master/package.json"
    click TS "https://github.com/marco-antonio-rodrigues/example-puppeteer/blob/master/tsconfig.json"
    click Node "https://github.com/marco-antonio-rodrigues/example-puppeteer/blob/master/src/index.ts"
    click Puppeteer "https://github.com/marco-antonio-rodrigues/example-puppeteer/blob/master/package.json"
    click Jest "https://github.com/marco-antonio-rodrigues/example-puppeteer/blob/master/jest.config.js"

    %% Styles
    classDef build fill:#e0f7fa,stroke:#006064,color:#006064;
    classDef runtime fill:#e8f5e9,stroke:#1b5e20,color:#1b5e20;
    classDef external fill:#e0e0e0,stroke:#424242,color:#424242;
    classDef fs fill:#fff3e0,stroke:#e65100,color:#e65100;
```
