# supakornnetsuwan/apollo-client architecture

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

- Interactive diagram: https://gitdiagram.com/supakornnetsuwan/apollo-client
- Repository: https://github.com/supakornnetsuwan/apollo-client

## Overview

##### Main Components Structure

a) Core Layer:
- ApolloClient (central orchestrator)
- QueryManager (handles query execution)
- Cache System (InMemoryCache)
- Link Chain (network/operation handling)

b) Integration Layers:
- React Integration
- Other Framework Integrations (Angular, etc.)

##### Key Relationships

a) Data Flow:
**Client Application -> Apollo Client -> Link Chain -> GraphQL Server**
- ↕
- Cache System

b) React Integration Flow:
**React Components -> Hooks/HOCs -> Apollo Client Core**

##### Detailed Component Breakdown

a) Cache System:
- InMemoryCache
- Field Policies
- Optimistic Updates
- Garbage Collection

b) Link Chain:
- HttpLink
- WebSocketLink
- RetryLink
- ErrorLink
- BatchLink
- Context Link

##### Specific Implementation Details

Key architectural features:

**┌─ Apollo Client ─────────────────────┐**

- ┌─ Cache ─┐    ┌─ Link Chain ─┐   │
- HttpLink    │   │
- Policies│←→  │  WsLink     │   │
- Store   │    │  RetryLink  │   │
- ┘    └─────────────┘   │
- ↑              ↑           │
- ┌─ Query Manager ─┐            │
- ┘            │
- ┘

##### Integration Points

Connection points for:
- React Hooks (useQuery, useMutation)
- HOCs (graphql)
- Cache APIs
- Network Layer

##### The integration capabilities

Remember to:
- Version compatibility notes
- Extension points
- Performance considerations
- Document error handling paths

This system design should reflect Apollo Client's sophisticated architecture while remaining clear and actionable for implementation and maintenance purposes.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        AC[ApolloClient]:::core
        QM[Query Manager]:::core
        OQ[Observable Query]:::core
        LS[Local State]:::core
        NS[Network Status]:::core
    end

    subgraph Cache
        IMC[InMemory Cache]:::cache
        CC[Core Cache]:::cache
        FP[Field Policies]:::cache
        ES[Entity Store]:::cache
        OU[Optimistic Updates]:::cache
    end

    subgraph "Link Chain"
        HL[HTTP Link]:::link
        WSL[WebSocket Link]:::link
        RL[Retry Link]:::link
        EL[Error Link]:::link
        BL[Batch Link]:::link
        CL[Context Link]:::link
    end

    subgraph "React Integration"
        RH[React Hooks]:::react
        RC[React Components]:::react
        RHOC[React HOCs]:::react
        RP[Apollo Provider]:::react
        RCTX[Apollo Context]:::react
    end

    %% Core Relationships
    AC --> QM
    QM --> OQ
    QM --> LS
    QM --> NS
    
    %% Cache Relationships
    AC --> IMC
    IMC --> CC
    IMC --> FP
    IMC --> ES
    IMC --> OU
    
    %% Link Chain Relationships
    AC --> HL
    AC --> WSL
    HL --> RL
    WSL --> RL
    RL --> EL
    EL --> BL
    BL --> CL
    
    %% React Integration Relationships
    RH --> AC
    RC --> AC
    RHOC --> AC
    RP --> RCTX
    RCTX --> AC

    %% Styles
    classDef core fill:#2374ab
    classDef cache fill:#57a773
    classDef link fill:#f7a072
    classDef react fill:#984447

    %% Click Events
    click AC "https://github.com/SupakornNetsuwan/apollo-client/blob/main/src/core/ApolloClient.ts"
    click QM "https://github.com/SupakornNetsuwan/apollo-client/blob/main/src/core/QueryManager.ts"
    click OQ "https://github.com/SupakornNetsuwan/apollo-client/blob/main/src/core/ObservableQuery.ts"
    click LS "https://github.com/SupakornNetsuwan/apollo-client/blob/main/src/core/LocalState.ts"
    click NS "https://github.com/SupakornNetsuwan/apollo-client/blob/main/src/core/networkStatus.ts"
    click IMC "https://github.com/SupakornNetsuwan/apollo-client/blob/main/src/cache/inmemory/inMemoryCache.ts"
    click CC "https://github.com/SupakornNetsuwan/apollo-client/blob/main/src/cache/core/cache.ts"
    click FP "https://github.com/SupakornNetsuwan/apollo-client/blob/main/src/cache/inmemory/policies.ts"
    click ES "https://github.com/SupakornNetsuwan/apollo-client/blob/main/src/cache/inmemory/entityStore.ts"
    click OU "https://github.com/SupakornNetsuwan/apollo-client/blob/main/src/cache/inmemory/optimistic.ts"
    click HL "https://github.com/SupakornNetsuwan/apollo-client/blob/main/src/link/http/HttpLink.ts"
    click WSL "https://github.com/SupakornNetsuwan/apollo-client/blob/main/src/link/ws/index.ts"
    click RL "https://github.com/SupakornNetsuwan/apollo-client/blob/main/src/link/retry/retryLink.ts"
    click EL "https://github.com/SupakornNetsuwan/apollo-client/blob/main/src/link/error/index.ts"
    click BL "https://github.com/SupakornNetsuwan/apollo-client/blob/main/src/link/batch/batchLink.ts"
    click CL "https://github.com/SupakornNetsuwan/apollo-client/blob/main/src/link/context/index.ts"
    click RH "https://github.com/SupakornNetsuwan/apollo-client/tree/main/src/react/hooks"
    click RC "https://github.com/SupakornNetsuwan/apollo-client/tree/main/src/react/components"
    click RHOC "https://github.com/SupakornNetsuwan/apollo-client/tree/main/src/react/hoc"
    click RP "https://github.com/SupakornNetsuwan/apollo-client/blob/main/src/react/context/ApolloProvider.tsx"
    click RCTX "https://github.com/SupakornNetsuwan/apollo-client/blob/main/src/react/context/ApolloContext.ts"
```
