# treasureproject/tdk-js architecture

> Architecture diagram of the GitHub repository treasureproject/tdk-js, 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/treasureproject/tdk-js
- Repository: https://github.com/treasureproject/tdk-js

## Overview

##### Main Components

a. Core Components:
- API Service (apps/api)
- Core SDK Package (packages/core)
- Authentication Package (packages/auth)
- React Components Package (packages/react)
- Launcher Package (packages/launcher)

b. Integration Layer:
- Example Applications
- Third-party Services (Discord, Google, Apple, etc.)
- Blockchain Integration

**┌─ Client Layer ─────────────────────────────────┐**
- React Components (@treasure-dev/tdk-react)    │
- Example Apps (Connect, Magicswap, Electron)   │
- ┘
- ↕
**┌─ Core Layer ──────────────────────────────────┐**
- TDK Core (@treasure-dev/tdk-core)           │
- Authentication (@treasure-dev/auth)          │
- Launcher (@treasure-dev/launcher)            │
- ┘
- ↕
**┌─ API Layer ───────────────────────────────────┐**
- TDK API Service                             │
- Prisma Database Layer                       │
- ┘
- ↕
**┌─ External Services ────────────────────────────┐**
- Authentication Providers                     │
- Blockchain Networks                         │
- Smart Contracts                             │
- ┘

##### Component Details

For each major component, include:
- Main responsibilities
- Key dependencies
- Integration points

##### Integration Flows

Workflows with numbered steps:

##### Technical Details

- Database schema references
- API endpoints
- Authentication methods
- Smart contract interactions
- State management flow

- The modular nature of the SDK
- Clear separation of concerns
- Integration possibilities
- Security boundaries
- Scalability points

Remember to:
- Keep components grouped logically
- Clear relationships between packages
- Authentication flow
- Demonstrate blockchain integration points
- Example application integration paths

This system design should provide a clear understanding of how the TDK components work together while maintaining the flexibility needed for different implementation scenarios.

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles and Classes
    classDef client fill:#90EE90,stroke:#333,stroke-width:2px
    classDef core fill:#87CEEB,stroke:#333,stroke-width:2px
    classDef api fill:#FFD700,stroke:#333,stroke-width:2px
    classDef external fill:#DDA0DD,stroke:#333,stroke-width:2px
    classDef auth fill:#FF6B6B,stroke:#333,stroke-width:2px

    %% Client Layer
    subgraph ClientLayer["Client Layer"]
        ReactComponents["React Components"]
        ConnectComps["Connect Components"]
        UIComps["UI Components"]
        UserComps["User Components"]
        ContextProviders["Context Providers"]
        ExampleApps["Example Applications"]
        ConnectReact["Connect React Example"]
        ConnectElectron["Connect Electron Example"]
        Magicswap["Magicswap Example"]
        BackendExample["Backend Integration Example"]
    end

    %% Core Layer
    subgraph CoreLayer["Core Layer"]
        TDKCore["TDK Core"]
        BlockchainIntegration["Blockchain Integration"]
        SmartContractInt["Smart Contract Interactions"]
        AnalyticsManagement["Analytics Management"]
        UserSession["User Session Handling"]
        AuthPackage["Authentication Package"]
        KeyManagement["Key Management"]
        LauncherPackage["Launcher Package"]
        SessionMgmt["Session Management"]
    end

    %% API Layer
    subgraph APILayer["API Layer"]
        APIService["API Service"]
        Database["Prisma Database"]
        AuthRoutes["Authentication Routes"]
        TransactionRoutes["Transaction Routes"]
        UserRoutes["User Routes"]
    end

    %% External Services
    subgraph ExternalServices["External Services"]
        AuthProviders["Authentication Providers"]
        BlockchainNetworks["Blockchain Networks"]
        SmartContracts["Smart Contracts"]
    end

    %% Relationships
    ReactComponents --> TDKCore
    TDKCore --> APIService
    APIService --> Database
    AuthPackage --> AuthProviders
    TDKCore --> BlockchainNetworks
    TDKCore --> SmartContracts
    LauncherPackage --> TDKCore
    ExampleApps --> ReactComponents

    %% Component Details
    ConnectComps --> ReactComponents
    UIComps --> ReactComponents
    UserComps --> ReactComponents
    ContextProviders --> ReactComponents
    
    BlockchainIntegration --> TDKCore
    SmartContractInt --> TDKCore
    AnalyticsManagement --> TDKCore
    UserSession --> TDKCore
    
    KeyManagement --> AuthPackage
    SessionMgmt --> LauncherPackage
    
    AuthRoutes --> APIService
    TransactionRoutes --> APIService
    UserRoutes --> APIService
    
    ConnectReact --> ExampleApps
    ConnectElectron --> ExampleApps
    Magicswap --> ExampleApps
    BackendExample --> ExampleApps

    %% Click Events
    click APIService "https://github.com/TreasureProject/tdk-js/tree/main/apps/api"
    click Database "https://github.com/TreasureProject/tdk-js/tree/main/apps/api/prisma"
    click AuthRoutes "https://github.com/TreasureProject/tdk-js/blob/main/apps/api/src/routes/auth.ts"
    click TransactionRoutes "https://github.com/TreasureProject/tdk-js/blob/main/apps/api/src/routes/transactions.ts"
    click UserRoutes "https://github.com/TreasureProject/tdk-js/blob/main/apps/api/src/routes/users.ts"
    
    click TDKCore "https://github.com/TreasureProject/tdk-js/tree/main/packages/core"
    click BlockchainIntegration "https://github.com/TreasureProject/tdk-js/tree/main/packages/core/src/abis"
    click SmartContractInt "https://github.com/TreasureProject/tdk-js/tree/main/packages/core/src/magicswap"
    click AnalyticsManagement "https://github.com/TreasureProject/tdk-js/tree/main/packages/core/src/analytics"
    click UserSession "https://github.com/TreasureProject/tdk-js/tree/main/packages/core/src/connect"
    
    click AuthPackage "https://github.com/TreasureProject/tdk-js/tree/main/packages/auth"
    click KeyManagement "https://github.com/TreasureProject/tdk-js/blob/main/packages/auth/src/kms.ts"
    
    click ReactComponents "https://github.com/TreasureProject/tdk-js/tree/main/packages/react"
    click ConnectComps "https://github.com/TreasureProject/tdk-js/tree/main/packages/react/src/components/connect"
    click UIComps "https://github.com/TreasureProject/tdk-js/tree/main/packages/react/src/components/ui"
    click UserComps "https://github.com/TreasureProject/tdk-js/tree/main/packages/react/src/components/user"
    click ContextProviders "https://github.com/TreasureProject/tdk-js/tree/main/packages/react/src/contexts"
    
    click LauncherPackage "https://github.com/TreasureProject/tdk-js/tree/main/packages/launcher"
    click SessionMgmt "https://github.com/TreasureProject/tdk-js/blob/main/packages/launcher/src/session.ts"
    
    click ConnectReact "https://github.com/TreasureProject/tdk-js/tree/main/examples/connect-react"
    click ConnectElectron "https://github.com/TreasureProject/tdk-js/tree/main/examples/connect-electron"
    click Magicswap "https://github.com/TreasureProject/tdk-js/tree/main/examples/magicswap"
    click BackendExample "https://github.com/TreasureProject/tdk-js/tree/main/examples/backend-to-backend"

    %% Style Applications
    class ReactComponents,ConnectComps,UIComps,UserComps,ContextProviders,ExampleApps,ConnectReact,ConnectElectron,Magicswap,BackendExample client
    class TDKCore,BlockchainIntegration,SmartContractInt,AnalyticsManagement,UserSession,LauncherPackage,SessionMgmt core
    class APIService,Database,AuthRoutes,TransactionRoutes,UserRoutes api
    class AuthProviders,BlockchainNetworks,SmartContracts external
    class AuthPackage,KeyManagement auth
```
