# dilame/instagram-private-api architecture

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

- Interactive diagram: https://gitdiagram.com/dilame/instagram-private-api
- Repository: https://github.com/dilame/instagram-private-api

## Overview

##### Main Components

a. Core Components:
- IgApiClient (Central client class)
- State Management
- Request Handler
- Entity Factory
- Feed Factory

b. Feature Modules:
- Repositories
- Feeds
- Services
- Sticker Builder
- Error Handlers

##### Architectural Layers

**┌─────────────────────────────────────────────────────────────┐**
- Client Interface                        │
- (IgApiClient)                          │
- ┬─────────────┬──────────────┬─────────────────┤
- Repositories│    Feeds    │   Services   │  Sticker Builder │
- ┴─────────────┴──────────────┴─────────────────┤
- Core Components                         │
- ┬─────────────┬──────────────┬─────────────────┤
- State    │   Request   │    Entity    │      Feed       │
- Management │   Handler   │   Factory    │    Factory      │
- ┴─────────────┴──────────────┴─────────────────┤
- Error Handling Layer                    │
- ┘

##### Component Relationships

- IgApiClient instantiates and manages all other components
- Repositories depend on Request Handler
- Feeds depend on Entity Factory
- Services orchestrate Repositories and Feeds
- State Management is accessed by all components
- Error Handling Layer intercepts all operations

##### Detailed Component Breakdown

a. Repositories (Show key ones):
**Repositories**
- Account
- Media
- Direct
- User
- Story
- Others (20+ more)

b. Feeds:
**Feeds**
- Timeline
- User
- Location
- Tag
- Others

c. Services:
**Services**
- Insights
- Publish
- Search
- Story
- Simulate

##### Data Flow Indicators

- Authentication flow
- Media upload flow
- Feed pagination flow
- Direct messaging flow

##### External Integration Points

Connections to:
- Instagram API endpoints
- Proxy support
- File system (for media uploads)
- Session storage

##### Additional Elements

Include:
- Version information
- Key dependencies
- Authentication states
- Error handling paths

##### Implementation Notes

Annotations for:
- TypeScript types and interfaces
- Observable patterns in feeds
- Entity relationships
- State persistence

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Client
        IgApiClient["IgApiClient"]:::core
    end

    subgraph Features
        direction TB
        subgraph Repositories
            direction TB
            AccountRepo["Account Repository"]:::repo
            MediaRepo["Media Repository"]:::repo
            DirectRepo["Direct Repository"]:::repo
            UserRepo["User Repository"]:::repo
            StoryRepo["Story Repository"]:::repo
        end

        subgraph Feeds
            direction TB
            TimelineFeed["Timeline Feed"]:::feed
            UserFeed["User Feed"]:::feed
            LocationFeed["Location Feed"]:::feed
            TagFeed["Tag Feed"]:::feed
        end

        subgraph Services
            direction TB
            InsightsService["Insights Service"]:::service
            PublishService["Publish Service"]:::service
            SearchService["Search Service"]:::service
            StoryService["Story Service"]:::service
            SimulateService["Simulate Service"]:::service
        end

        StickerBuilder["Sticker Builder"]:::feature
    end

    subgraph Core
        direction TB
        StateManager["State Management"]:::core
        RequestHandler["Request Handler"]:::core
        EntityFactory["Entity Factory"]:::core
        FeedFactory["Feed Factory"]:::core
    end

    subgraph ErrorHandling
        direction TB
        BaseError["Base Error"]:::error
        NetworkError["Network Error"]:::error
        ResponseError["Response Error"]:::error
        RequestLimitError["Request Limit Error"]:::error
    end

    subgraph Entities
        direction TB
        MediaEntity["Media Entity"]:::entity
        ProfileEntity["Profile Entity"]:::entity
        DirectThreadEntity["Direct Thread Entity"]:::entity
        LiveEntity["Live Entity"]:::entity
    end

    %% Relationships
    IgApiClient --> |manages| Core
    IgApiClient --> |uses| Features
    Core --> |handles| ErrorHandling
    Features --> |uses| Core
    Features --> |creates| Entities
    Repositories --> RequestHandler
    Feeds --> EntityFactory
    Services --> Repositories
    Services --> Feeds

    %% Click Events
    click IgApiClient "https://github.com/dilame/instagram-private-api/blob/master/src/core/client.ts"
    click StateManager "https://github.com/dilame/instagram-private-api/blob/master/src/core/state.ts"
    click RequestHandler "https://github.com/dilame/instagram-private-api/blob/master/src/core/request.ts"
    click EntityFactory "https://github.com/dilame/instagram-private-api/blob/master/src/core/entity.factory.ts"
    click FeedFactory "https://github.com/dilame/instagram-private-api/blob/master/src/core/feed.factory.ts"
    click AccountRepo "https://github.com/dilame/instagram-private-api/blob/master/src/repositories/account.repository.ts"
    click MediaRepo "https://github.com/dilame/instagram-private-api/blob/master/src/repositories/media.repository.ts"
    click DirectRepo "https://github.com/dilame/instagram-private-api/blob/master/src/repositories/direct.repository.ts"
    click UserRepo "https://github.com/dilame/instagram-private-api/blob/master/src/repositories/user.repository.ts"
    click StoryRepo "https://github.com/dilame/instagram-private-api/blob/master/src/repositories/highlights.repository.ts"
    click TimelineFeed "https://github.com/dilame/instagram-private-api/blob/master/src/feeds/timeline.feed.ts"
    click UserFeed "https://github.com/dilame/instagram-private-api/blob/master/src/feeds/user.feed.ts"
    click LocationFeed "https://github.com/dilame/instagram-private-api/blob/master/src/feeds/location.feed.ts"
    click TagFeed "https://github.com/dilame/instagram-private-api/blob/master/src/feeds/tag.feed.ts"
    click InsightsService "https://github.com/dilame/instagram-private-api/blob/master/src/services/insights.service.ts"
    click PublishService "https://github.com/dilame/instagram-private-api/blob/master/src/services/publish.service.ts"
    click SearchService "https://github.com/dilame/instagram-private-api/blob/master/src/services/search.service.ts"
    click StoryService "https://github.com/dilame/instagram-private-api/blob/master/src/services/story.service.ts"
    click SimulateService "https://github.com/dilame/instagram-private-api/blob/master/src/services/simulate.service.ts"
    click StickerBuilder "https://github.com/dilame/instagram-private-api/blob/master/src/sticker-builder/sticker-builder.ts"
    click BaseError "https://github.com/dilame/instagram-private-api/blob/master/src/errors/ig-client.error.ts"
    click NetworkError "https://github.com/dilame/instagram-private-api/blob/master/src/errors/ig-network.error.ts"
    click ResponseError "https://github.com/dilame/instagram-private-api/blob/master/src/errors/ig-response.error.ts"
    click RequestLimitError "https://github.com/dilame/instagram-private-api/blob/master/src/errors/ig-requests-limit.error.ts"
    click MediaEntity "https://github.com/dilame/instagram-private-api/blob/master/src/entities/media.entity.ts"
    click ProfileEntity "https://github.com/dilame/instagram-private-api/blob/master/src/entities/profile.entity.ts"
    click DirectThreadEntity "https://github.com/dilame/instagram-private-api/blob/master/src/entities/direct-thread.entity.ts"
    click LiveEntity "https://github.com/dilame/instagram-private-api/blob/master/src/entities/live.entity.ts"

    %% Styling
    classDef core fill:#2374ab
    classDef repo fill:#48a9a6
    classDef feed fill:#4ad66d
    classDef service fill:#d4b483
    classDef feature fill:#c1666b
    classDef error fill:#e4572e
    classDef entity fill:#17bebb

    %% Legend
    subgraph Legend
        direction TB
        L1["Core Components"]:::core
        L2["Repositories"]:::repo
        L3["Feeds"]:::feed
        L4["Services"]:::service
        L5["Features"]:::feature
        L6["Error Handling"]:::error
        L7["Entities"]:::entity
    end
```
