# wjsoftware/dr-fetch architecture

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

- Interactive diagram: https://gitdiagram.com/wjsoftware/dr-fetch
- Repository: https://github.com/wjsoftware/dr-fetch

## Overview

##### Main Components

a) Core Components:
- DrFetch Class (Central Component)
- Body Parser System
- Header Management System
- Custom Fetch Function Handler

b) Integration Points:
- Native Fetch API Integration
- Custom Fetch Function Interface
- Response Type System

**Top Layer (Client Usage):**

- Application Code
- Type Definitions (<T, R>)

**Middle Layer (dr-fetch Core):**

- DrFetch Class
- Type System
- Parser Registry
- HTTP Method Shortcuts

- Header Management
- setHeaders
- makeIterableHeaders

**Bottom Layer (Runtime):**

- Custom Fetch Function (Optional)
- Native Fetch API

##### Key Relationships to Highlight

a) Type Flow:
- How type information flows from client code through the DrFetch class
- Relationship between status codes and response types

b) Data Flow:
- Request flow from client through DrFetch to fetch implementation
- Response flow back through parsers to typed responses

##### Important Details

- Parser Registry System showing how content-type maps to parser functions
- Header Management System showing the various input formats supported
- Type System showing the relationship between HTTP status codes and response types
- HTTP Method Shortcuts (get, post, put, etc.)

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Legend
        L1[Core Component]:::core
        L2[Extensibility Point]:::extensibility
        L3[Type System]:::type
        L4[External Component]:::external
        L5[".ts file"]:::file
        style Legend fill:#f5f5f5,stroke:#333
    end

    subgraph "Client Layer"
        AC[Application Code]:::external
        TD["Type Definitions <T,R>"]:::type
    end

    subgraph "dr-fetch Core"
        DF["DrFetch Class"]:::core
        click DF "https://github.com/WJSoftware/dr-fetch/blob/main/src/DrFetch.ts"
        
        TS["Type System"]:::type
        click TS "https://github.com/WJSoftware/dr-fetch/blob/main/src/types.ts"
        
        PR["Parser Registry"]:::core
        HMS["Header Management System"]:::core
        click HMS "https://github.com/WJSoftware/dr-fetch/blob/main/src/setHeaders.ts"
        
        HTTP["HTTP Method Shortcuts"]:::core
        
        EP["Library Entry Point"]:::core
        click EP "https://github.com/WJSoftware/dr-fetch/blob/main/src/index.ts"
    end

    subgraph "Runtime Layer"
        CFF["Custom Fetch Function"]:::extensibility
        NFA["Native Fetch API"]:::external
    end

    %% Relationships
    AC --> TD
    TD --> DF
    DF --> TS
    DF --> PR
    DF --> HMS
    DF --> HTTP
    HMS --> |"Headers Format Support"| DF
    PR --> |"Content-Type Mapping"| DF
    DF --> |"Optional"| CFF
    DF --> NFA
    CFF --> NFA

    %% Tests
    HMT["Header Management Tests"]:::file
    click HMT "https://github.com/WJSoftware/dr-fetch/blob/main/src/tests/setHeaders.test.ts"
    
    DFT["DrFetch Implementation Tests"]:::file
    click DFT "https://github.com/WJSoftware/dr-fetch/blob/main/src/tests/DrFetch.test.ts"
    
    HMS --> HMT
    DF --> DFT

    %% Styling
    classDef core fill:#a8d1f0,stroke:#333
    classDef extensibility fill:#90EE90,stroke:#333
    classDef type fill:#FFE5B4,stroke:#333
    classDef external fill:#D3D3D3,stroke:#333
    classDef file fill:#FFF,stroke:#333,stroke-dasharray: 5 5
```
