# acodexm/tinklink architecture

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

- Interactive diagram: https://gitdiagram.com/acodexm/tinklink
- Repository: https://github.com/acodexm/tinklink

## Overview

##### Main Components

A. Frontend (Client)
- React Application Layer
- Component Structure
- API Integration Layer
- Authentication Flow
- State Management

B. Backend (Server)
- Express Server
- Controllers Layer
- Services Layer
- External API Integration
- Database Integration

C. External Services
- Tink API (v1)
- Clearbit API (for merchant logos)
- MongoDB

**[Client Layer] <---> [Server Layer] <---> [External Services Layer]**

##### Detailed Component Breakdown

A. Client Layer (Top to Bottom):
**React Components**
- ↓
**Layout & Pages**
- ↓
**API Integration Layer**
- ↓
**Authentication Handler**

B. Server Layer (Top to Bottom):
**Express Routes**
- ↓
**Controllers**
- ↓
**Services**
- ↓
**Data Access Layer**

C. External Services (Side):
**Tink API**
**Clearbit API**
**MongoDB**

##### Key Interactions to Highlight

a. Authentication Flow:
- Client → Tink Link → Server → MongoDB (token storage)
- Token refresh mechanism

b. Data Flow:
- Account aggregation path
- Merchant logo fetching
- Transaction data processing

##### Additional Elements

- Security layers
- Error boundaries
- Loading states
- Data transformation services

##### Data flow through the system

Key Architectural Patterns to Highlight:
- MVC pattern in the backend
- Component-based architecture in the frontend
- Service-oriented architecture for merchant handling
- Repository pattern for data access

- Special indicators

Keep the abstraction level high enough to show the overall architecture while including crucial implementation details like the merchant mapping service and token management system.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Styles and classes
    classDef frontend fill:#3498db,stroke:#2980b9,color:white
    classDef backend fill:#2ecc71,stroke:#27ae60,color:white
    classDef external fill:#f1c40f,stroke:#f39c12,color:black
    classDef auth fill:#e74c3c,stroke:#c0392b,color:white
    classDef data fill:#9b59b6,stroke:#8e44ad,color:white

    %% Frontend Layer
    subgraph Client
        App["React App"]:::frontend
        Layout["Layout Component"]:::frontend
        Pages["Pages/Routes"]:::frontend
        Components["Component Structure"]:::frontend
        APIIntegration["API Integration Layer"]:::frontend
        AuthHandler["Authentication Handler"]:::frontend
        ErrorBoundary["Error Boundary"]:::frontend
        LoadingStates["Loading Handler"]:::frontend
        TransactionComp["Transaction Components"]:::frontend
        FrontendModels["Frontend Models"]:::frontend
    end

    %% Backend Layer
    subgraph Server
        Express["Express Server"]:::backend
        Controllers["Controllers Layer"]:::backend
        Services["Services Layer"]:::backend
        DataAccess["Data Access Layer"]:::backend
        AuthController["Auth Controller"]:::backend
        MerchantMapper["Merchant Mapper"]:::backend
        MerchantAgg["Merchant Aggregation"]:::backend
        TransactionController["Transaction Controller"]:::backend
        ErrorHandler["Error Handler"]:::backend
        BackendModels["Backend Models"]:::backend
    end

    %% External Services Layer
    subgraph External
        TinkAPI["Tink API"]:::external
        ClearbitAPI["Clearbit API"]:::external
        MongoDB[(MongoDB)]:::external
    end

    %% Relationships
    App --> Layout
    Layout --> Pages
    Pages --> Components
    Components --> APIIntegration
    Components --> AuthHandler
    Components --> ErrorBoundary
    Components --> LoadingStates
    Components --> TransactionComp
    APIIntegration --> Express

    Express --> Controllers
    Controllers --> Services
    Services --> DataAccess
    DataAccess --> MongoDB
    Controllers --> AuthController
    Services --> MerchantMapper
    Services --> MerchantAgg
    Controllers --> TransactionController
    Controllers --> ErrorHandler

    Services --> TinkAPI
    MerchantMapper --> ClearbitAPI

    %% Click events
    click App "https://github.com/acodexm/TinkLink/blob/main/client/src/App.tsx"
    click Layout "https://github.com/acodexm/TinkLink/blob/main/client/src/Layout/Layout.tsx"
    click Pages "https://github.com/acodexm/TinkLink/tree/main/client/src/pages/"
    click Components "https://github.com/acodexm/TinkLink/tree/main/client/src/components/"
    click APIIntegration "https://github.com/acodexm/TinkLink/tree/main/client/src/api/"
    click AuthHandler "https://github.com/acodexm/TinkLink/tree/main/client/src/components/AuthLink/"
    click ErrorBoundary "https://github.com/acodexm/TinkLink/tree/main/client/src/components/ErrorBoundary/"
    click LoadingStates "https://github.com/acodexm/TinkLink/tree/main/client/src/components/LoadingHandler/"
    click TransactionComp "https://github.com/acodexm/TinkLink/tree/main/client/src/components/Transactions/"
    click FrontendModels "https://github.com/acodexm/TinkLink/tree/main/client/src/model/"
    click Controllers "https://github.com/acodexm/TinkLink/tree/main/server/src/controllers/"
    click Services "https://github.com/acodexm/TinkLink/tree/main/server/src/services/"
    click AuthController "https://github.com/acodexm/TinkLink/blob/main/server/src/controllers/auth.ts"
    click MerchantMapper "https://github.com/acodexm/TinkLink/blob/main/server/src/services/MerchantMapper/MerchantMapper.ts"
    click MerchantAgg "https://github.com/acodexm/TinkLink/blob/main/server/src/services/MerchantAggregation/MerchantAggregation.ts"
    click TransactionController "https://github.com/acodexm/TinkLink/blob/main/server/src/controllers/transactions.ts"
    click ErrorHandler "https://github.com/acodexm/TinkLink/blob/main/server/src/controllers/helpers/sendError.ts"
    click BackendModels "https://github.com/acodexm/TinkLink/tree/main/server/src/models/"

    %% Legend
    subgraph Legend
        Frontend["Frontend Component"]:::frontend
        Backend["Backend Component"]:::backend
        ExternalService["External Service"]:::external
        AuthComponent["Auth Component"]:::auth
        DataComponent["Data Component"]:::data
    end
```
