# fawazahmed0/exchange-api architecture

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

- Interactive diagram: https://gitdiagram.com/fawazahmed0/exchange-api
- Repository: https://github.com/fawazahmed0/exchange-api

## Overview

##### Main Components

a) Data Collection Layer:
- A scheduled GitHub Actions workflow component (from .github/workflows/run.yml)
- Data source connections for currency rates updates
- To cryptocurrency and traditional currency data sources

b) Data Processing Layer:
- Node.js processing scripts (currscript.js, semver-date.js)
- Data transformation and merging processes
- Demonstrate cache management (other/cache-jsdelivr-api.js)

c) Distribution Layer:
- Primary CDN: JSDelivr
- Fallback CDN: Cloudflare Pages
- API versioning structure (v1)

d) Data Storage:
- JSON files storage (currencies.json, cryptocurrencies.json)
- Relationship with npm package registry

##### Flow Representation

**[GitHub Actions Workflow] → [Data Collection] → [Data Processing] → [JSON Generation]**
- ↓
**[End Users] ← [CDN Layer (JSDelivr/Cloudflare)] ← [npm Package Registry]**

##### Important Elements to Highlight

a) API Structure:
- URL pattern: cdn.jsdelivr.net/npm/@fawazahmed0/currency-api@{date}/{apiVersion}/{endpoint}
- Fallback URL pattern: {date}.currency-api.pages.dev/{apiVersion}/{endpoint}

b) Data Flow:
- Daily update process
- Data transformation pipeline
- CDN distribution mechanism

##### Additional Details

Annotations for:
- Supported currency types (200+ currencies, cryptocurrencies, metals)
- Response formats (.json and .min.json)
- Update frequency (daily)
- No rate limits
- Fallback mechanism

##### Technical Specifications

Integration points for:
- GitHub Actions automation
- npm package deployment
- CDN distribution
- JSON data storage

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph CI ["CI/CD Pipeline"]
        GHA["GitHub Actions Workflow"]:::cicd
    end

    subgraph DL ["Data Layer"]
        DS1[("Currency Data Source")]:::datasource
        DS2[("Crypto Data Source")]:::datasource
        DS3[("Metals Data Source")]:::datasource
    end

    subgraph PL ["Processing Layer"]
        CS["Currency Script"]:::process
        SV["Semver Date Handler"]:::process
        MC["Currency Merger"]:::process
        CP["Country Processor"]:::process
        DA["Date Arguments Handler"]:::process
    end

    subgraph Storage ["Data Storage"]
        CD["Currency Data"]:::storage
        CRD["Crypto Data"]:::storage
        CND["Country Data"]:::storage
        SYM["Currency Symbols"]:::storage
        CCR["Common Currency Reference"]:::storage
        MCD["Merged Currency Data"]:::storage
    end

    subgraph Cache ["Cache Management"]
        CH["CDN Cache Handler"]:::cache
    end

    subgraph Dist ["Distribution Layer"]
        CDN1["JSDelivr CDN"]:::cdn
        CDN2["Cloudflare Pages"]:::cdn
        NPM["npm Registry"]:::registry
    end

    subgraph Users ["End Users"]
        API["API Consumers"]:::user
    end

    GHA --> DS1 & DS2 & DS3
    DS1 & DS2 & DS3 --> CS
    CS --> SV
    SV --> MC
    MC --> CP
    CP --> DA
    DA --> CD & CRD
    CD & CRD --> MCD
    MCD --> CH
    CH --> NPM
    NPM --> CDN1 & CDN2
    CDN1 & CDN2 --> API

    %% Click Events
    click GHA "https://github.com/fawazahmed0/exchange-api/blob/main/.github/workflows/run.yml"
    click CS "https://github.com/fawazahmed0/exchange-api/blob/main/currscript.js"
    click SV "https://github.com/fawazahmed0/exchange-api/blob/main/semver-date.js"
    click MC "https://github.com/fawazahmed0/exchange-api/blob/main/other/makemergecurr.js"
    click CP "https://github.com/fawazahmed0/exchange-api/blob/main/other/currencycountry.js"
    click CH "https://github.com/fawazahmed0/exchange-api/blob/main/other/cache-jsdelivr-api.js"
    click CD "https://github.com/fawazahmed0/exchange-api/blob/main/other/currencies.json"
    click CRD "https://github.com/fawazahmed0/exchange-api/blob/main/other/cryptocurrencies.json"
    click CND "https://github.com/fawazahmed0/exchange-api/blob/main/country.json"
    click SYM "https://github.com/fawazahmed0/exchange-api/blob/main/other/symbols.json"
    click CCR "https://github.com/fawazahmed0/exchange-api/blob/main/other/Common-Currency.json"
    click MCD "https://github.com/fawazahmed0/exchange-api/blob/main/other/mergecurr.json"
    click DA "https://github.com/fawazahmed0/exchange-api/blob/main/other/getdate-args.js"

    %% Styles
    classDef process fill:#2374ab
    classDef storage fill:#ff7f50
    classDef cdn fill:#2ecc71
    classDef cache fill:#95a5a6
    classDef cicd fill:#9b59b6
    classDef user fill:#7f8c8d
    classDef registry fill:#e67e22
    classDef datasource fill:#3498db

    %% Legend
    subgraph Legend
        L1["Process"]:::process
        L2[("Storage")]:::storage
        L3["CDN"]:::cdn
        L4["Cache"]:::cache
        L5["CI/CD"]:::cicd
        L6["User"]:::user
        L7["Registry"]:::registry
        L8[("Data Source")]:::datasource
    end
```
