# derfirm/pornhub-api architecture

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

- Interactive diagram: https://gitdiagram.com/derfirm/pornhub-api
- Repository: https://github.com/derfirm/pornhub-api

## Overview

##### Main Components

a) Client Layer:
- Main `PornhubApi` class as the entry point
- Three supported backend implementations (Requests, AIOHTTP, HTTPX)

b) Module Layer:
- Core modules (Search, Video, Stars)
- How they inherit from the base module

c) Schema Layer:
- Pydantic models for data validation
- Related schemas (video, search, star, etc.)

d) External Integration:
- Connection to the Pornhub.com API
- HTTP/HTTPS communication

**[Client Applications]**
- ↓
**[PornhubApi Client]**
- ↓
**[Backend Implementations] → [Base Backend]**
- Requests
- AIOHTTP
- HTTPX
- ↓
**[API Modules] → [Base Module]**
- Search
- Video
- Stars
- ↓
**[Schema Layer]**
- Video Schema
- Search Schema
- Star Schema
- etc.
- ↓
**[External Pornhub API]**

##### Important Details to Highlight

a) Async Support:
- Parallel paths for synchronous and asynchronous operations
- Different backend implementations

b) Data Flow:
- How requests flow from client through backends
- How responses are validated through schemas

c) Modularity:
- Plugin-like backend system
- Inheritance structure of modules

##### Additional Elements

- Version compatibility (Python 3.7+)
- Supported backend installation options
- Error handling flow through exceptions package

##### Technical Specifications

- Use of Pydantic for response validation
- Relationship between test snapshots and actual responses
- Separation between core functionality and examples

##### Implementation Notes

- Keep the main flow clear and centered
- Related components together
- Use clear labels for all components
- Brief descriptions for key interactions

##### The modular architecture

This architecture represents a well-structured API client library with multiple backend support, strong typing through Pydantic, and a clear separation of concerns between different components.

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Legend
        A[Client Component]:::client
        B[Backend Component]:::backend
        C[Module Component]:::module
        D[Schema Component]:::schema
        E[External Service]:::external
    end

    Client[Client Applications]:::client
    PHA["PornhubApi Client"]:::client
    click PHA "https://github.com/Derfirm/pornhub-api/blob/master/pornhub_api/api.py"

    subgraph "Backend Layer"
        BB["Base Backend"]:::backend
        click BB "https://github.com/Derfirm/pornhub-api/blob/master/pornhub_api/backends/base.py"
        
        RB["Requests Backend"]:::backend
        click RB "https://github.com/Derfirm/pornhub-api/blob/master/pornhub_api/backends/requests.py"
        
        AB["AIOHTTP Backend"]:::backend
        click AB "https://github.com/Derfirm/pornhub-api/blob/master/pornhub_api/backends/aiohttp.py"
        
        HB["HTTPX Backend"]:::backend
        click HB "https://github.com/Derfirm/pornhub-api/blob/master/pornhub_api/backends/httpx.py"
    end

    subgraph "Module Layer"
        BM["Base Module"]:::module
        click BM "https://github.com/Derfirm/pornhub-api/blob/master/pornhub_api/modules/base.py"
        
        SM["Search Module"]:::module
        click SM "https://github.com/Derfirm/pornhub-api/blob/master/pornhub_api/modules/search.py"
        
        VM["Video Module"]:::module
        click VM "https://github.com/Derfirm/pornhub-api/blob/master/pornhub_api/modules/video.py"
        
        STM["Stars Module"]:::module
        click STM "https://github.com/Derfirm/pornhub-api/blob/master/pornhub_api/modules/stars.py"
    end

    subgraph "Schema Layer"
        VS["Video Schema"]:::schema
        click VS "https://github.com/Derfirm/pornhub-api/blob/master/pornhub_api/schemas/video.py"
        
        SS["Search Schema"]:::schema
        click SS "https://github.com/Derfirm/pornhub-api/blob/master/pornhub_api/schemas/search.py"
        
        STS["Star Schema"]:::schema
        click STS "https://github.com/Derfirm/pornhub-api/blob/master/pornhub_api/schemas/star.py"
        
        CS["Category Schema"]:::schema
        click CS "https://github.com/Derfirm/pornhub-api/blob/master/pornhub_api/schemas/category.py"
        
        TS["Tag Schema"]:::schema
        click TS "https://github.com/Derfirm/pornhub-api/blob/master/pornhub_api/schemas/tag.py"
        
        THS["Thumbnail Schema"]:::schema
        click THS "https://github.com/Derfirm/pornhub-api/blob/master/pornhub_api/schemas/thumb.py"
    end

    EX["Exception Handler"]:::client
    click EX "https://github.com/Derfirm/pornhub-api/blob/master/pornhub_api/exceptions/response.py"
    
    PHAPI["Pornhub.com API"]:::external

    Client --> PHA
    PHA --> RB & AB & HB
    RB & AB & HB --> BB
    BB --> BM
    BM --> SM & VM & STM
    SM & VM & STM --> VS & SS & STS & CS & TS & THS
    VS & SS & STS & CS & TS & THS --> PHAPI
    BB --> EX

    classDef client fill:#a8d1ff,stroke:#000
    classDef backend fill:#90EE90,stroke:#000
    classDef module fill:#FFE5B4,stroke:#000
    classDef schema fill:#FFA07A,stroke:#000
    classDef external fill:#FF6961,stroke:#000
```
