# awslabs/aws-mobile-appsync-sdk-js architecture

> Architecture diagram of the GitHub repository awslabs/aws-mobile-appsync-sdk-js, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-31). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/awslabs/aws-mobile-appsync-sdk-js
- Repository: https://github.com/awslabs/aws-mobile-appsync-sdk-js

## Overview

##### Main Components

a. Core Components:
- Auth Link Package (`aws-appsync-auth-link`)
- Subscription Link Package (`aws-appsync-subscription-link`)
- Apollo Client Integration Layer
- AWS AppSync Service Connection

b. Authentication Components:
- API Key Auth
- Cognito User Pools
- IAM Authentication
- OpenID Connect

c. Communication Layers:
- HTTP/HTTPS Layer
- WebSocket Layer (for subscriptions)
- Signing/Authorization Layer

**[Client Application Layer]**
- ↓
**[Apollo Client V3]**
- ↓
**[AWS AppSync Links Layer]**
- Auth Link
- Signer Module
- Subscription Link
- Handshake Module
- WebSocket Handler

**[AWS AppSync Service]**
- GraphQL API
- Authentication
- Data Sources

##### Specific Implementation Details

Key architectural elements:
**[Auth Link Implementation]**
- Platform-specific auth handling
- Request signing
- Multiple auth mode support

**[Subscription Link Implementation]**
- Real-time subscription handling
- Connection management
- Retry logic

##### Integration Points

Clear integration points for:
- Apollo Client configuration
- Authentication providers
- WebSocket connections
- HTTP/HTTPS endpoints

##### Additional Elements

A section for:
- Configuration options
- Environment-specific settings
- Platform-specific implementations (React Native vs Web)

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        App[Client Application]
        Apollo[Apollo Client V3]
    end

    subgraph Links["AWS AppSync Links Layer"]
        AuthLink["Auth Link"]:::authlink
        SubLink["Subscription Link"]:::sublink
        
        subgraph AuthComponents["Auth Components"]
            Signer["Signer Module"]:::signer
            Platform["Platform Auth Handler"]:::platform
            AuthModes["Auth Modes"]
            AuthModes --> |API Key| AuthLink
            AuthModes --> |Cognito| AuthLink
            AuthModes --> |IAM| AuthLink
            AuthModes --> |OpenID| AuthLink
        end
        
        subgraph SubComponents["Subscription Components"]
            WSHandler["WebSocket Handler"]:::wshandler
            HandshakeLink["Handshake Module"]:::handshake
            HTTPLayer["HTTP Layer"]:::http
            RetryLogic["Retry Logic"]:::retry
            Logger["Logging System"]:::logger
            Types["Type Definitions"]:::types
        end
    end

    subgraph AWS["AWS AppSync Service"]
        GraphQLAPI["GraphQL API"]
        Auth["Authentication"]
        DataSources["Data Sources"]
    end

    %% Main Flow
    App --> Apollo
    Apollo --> AuthLink
    Apollo --> SubLink
    AuthLink --> GraphQLAPI
    SubLink --> GraphQLAPI
    
    %% Auth Components Relations
    AuthLink --> Signer
    AuthLink --> Platform
    Signer --> Auth
    
    %% Subscription Components Relations
    SubLink --> WSHandler
    SubLink --> HandshakeLink
    SubLink --> HTTPLayer
    WSHandler --> RetryLogic
    HandshakeLink --> RetryLogic
    WSHandler --> Logger
    HandshakeLink --> Logger
    
    %% AWS Internal Relations
    GraphQLAPI --> Auth
    GraphQLAPI --> DataSources

    %% Styling
    classDef authlink fill:#a8e6cf
    classDef sublink fill:#dcedc1
    classDef signer fill:#ffd3b6
    classDef platform fill:#ffaaa5
    classDef wshandler fill:#ff8b94
    classDef handshake fill:#a8e6cf
    classDef http fill:#dcedc1
    classDef retry fill:#ffd3b6
    classDef logger fill:#ffaaa5
    classDef types fill:#ff8b94

    %% Click Events
    click AuthLink "https://github.com/awslabs/aws-mobile-appsync-sdk-js/blob/master/packages/aws-appsync-auth-link/src/auth-link.ts"
    click SubLink "https://github.com/awslabs/aws-mobile-appsync-sdk-js/blob/master/packages/aws-appsync-subscription-link/src/index.ts"
    click Signer "https://github.com/awslabs/aws-mobile-appsync-sdk-js/blob/master/packages/aws-appsync-auth-link/src/signer/signer.ts"
    click Platform "https://github.com/awslabs/aws-mobile-appsync-sdk-js/blob/master/packages/aws-appsync-auth-link/src/platform.ts"
    click WSHandler "https://github.com/awslabs/aws-mobile-appsync-sdk-js/blob/master/packages/aws-appsync-subscription-link/src/realtime-subscription-handshake-link.ts"
    click HTTPLayer "https://github.com/awslabs/aws-mobile-appsync-sdk-js/blob/master/packages/aws-appsync-subscription-link/src/non-terminating-http-link.ts"
    click HandshakeLink "https://github.com/awslabs/aws-mobile-appsync-sdk-js/blob/master/packages/aws-appsync-subscription-link/src/subscription-handshake-link.ts"
    click RetryLogic "https://github.com/awslabs/aws-mobile-appsync-sdk-js/blob/master/packages/aws-appsync-subscription-link/src/utils/retry.ts"
    click Logger "https://github.com/awslabs/aws-mobile-appsync-sdk-js/blob/master/packages/aws-appsync-subscription-link/src/utils/logger.ts"
    click Types "https://github.com/awslabs/aws-mobile-appsync-sdk-js/blob/master/packages/aws-appsync-subscription-link/src/types/index.ts"
```
