# crawlbase/crawlbase-node architecture

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

- Interactive diagram: https://gitdiagram.com/crawlbase/crawlbase-node
- Repository: https://github.com/crawlbase/crawlbase-node

## Overview

##### Project Type Analysis
This is an API wrapper library that provides interfaces to multiple Crawlbase services. It's a dependency-free Node.js module designed for making HTTP requests to different Crawlbase API endpoints.

##### Main Components

A. Client Layer:
- Main API classes (CrawlingAPI, ScraperAPI, LeadsAPI, ScreenshotsAPI)
- Each class inherits from BaseAPI (visible in src/base-api.js)

B. External Service Layer:
- Crawlbase API Services
- Different endpoints for each service type

**[Client Application] → [Crawlbase Node.js Library]**
- ↓
- ┌──────────────────────┴───────────────────────┐
- ↓                      ↓                        ↓
- [Base API Layer]    [Configuration Layer]    [Utility Layer]
- ↓
- ┬──────────┬──────────┬─────────┐
- ↓             ↓          ↓          ↓         ↓
**[Crawling API] [Scraper API] [Leads API] [Screenshots API] [Utils]**
- ↓             ↓          ↓          ↓
- ┴──────────┴──────────┴─────────┐
- ↓
- [Crawlbase REST APIs]

##### Component Details

a) Client Layer:
- Supported HTTP methods (GET, POST, PUT)
- Promise-based async operations
- Configuration options input

b) Base API Layer:
- Common functionality shared across all API types
- Error handling mechanisms
- Request/response processing

c) Service-Specific APIs:
- CrawlingAPI: Show both normal and JavaScript token support
- ScraperAPI: Indicate JSON response handling
- LeadsAPI: Show domain-based querying
- ScreenshotsAPI: Indicate binary response handling

d) External Services:
- Connection to Crawlbase's different API endpoints
- Authentication token flow

##### Important Flows to Highlight

- Authentication flow using tokens
- Request transformation and handling
- Response processing and error handling
- Binary data handling (especially for Screenshots API)

##### Additional Elements

- Different request types (GET, POST, PUT)
- Response formats (JSON, binary, HTML)
- Authentication mechanisms
- Error handling patterns

##### Technical Details to Note

- That it's a dependency-free implementation
- TypeScript support (note the .d.ts files)
- Configuration options handling
- Promise-based async operations

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        CA[Client Application]:::client
    end

    subgraph Library["Crawlbase Node.js Library"]
        subgraph Core
            BL[Base API Layer]:::core
            CL[Configuration Layer]:::core
            UL[Utility Layer]:::core
        end

        subgraph APIs
            CR[Crawling API]:::api
            SC[Scraper API]:::api
            LD[Leads API]:::api
            SS[Screenshots API]:::api
            UT[Utils]:::api
        end
    end

    subgraph External
        CB["Crawlbase REST APIs"]:::external
    end

    %% Connections
    CA --> BL
    CA --> CL
    
    BL --> CR
    BL --> SC
    BL --> LD
    BL --> SS
    
    CL --> CR
    CL --> SC
    CL --> LD
    CL --> SS
    
    UL --> UT
    
    CR -.-> CB
    SC -.-> CB
    LD -.-> CB
    SS -.-> CB

    %% Click Events
    click BL "https://github.com/crawlbase/crawlbase-node/blob/main/src/base-api.js"
    click CL "https://github.com/crawlbase/crawlbase-node/blob/main/src/config.js"
    click UL "https://github.com/crawlbase/crawlbase-node/blob/main/src/utils.js"
    click CR "https://github.com/crawlbase/crawlbase-node/blob/main/src/crawling-api.js"
    click SC "https://github.com/crawlbase/crawlbase-node/blob/main/src/scraper-api.js"
    click LD "https://github.com/crawlbase/crawlbase-node/blob/main/src/leads-api.js"
    click SS "https://github.com/crawlbase/crawlbase-node/blob/main/src/screenshots-api.js"

    %% Styles
    classDef client fill:#2374ab
    classDef core fill:#57a773
    classDef api fill:#4392f1
    classDef external fill:#ed8b00
    
    %% Legend
    subgraph Legend
        CLL[Client Layer]:::client
        COL[Core Layer]:::core
        APL[API Layer]:::api
        EXL[External Services]:::external
        
        %% Legend Connections
        CLL --- COL
        COL -.- APL
        APL -.-> EXL
    end
```
