# bomzj/cryptofair architecture

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

- Interactive diagram: https://gitdiagram.com/bomzj/cryptofair
- Repository: https://github.com/bomzj/cryptofair

## Overview

##### Project Type and Purpose
- CryptoFair is a full-stack, single-page application (SPA) built with Vue.js that aggregates peer-to-peer cryptocurrency exchange offers (LocalBitcoins, Paxful, Binance P2P, etc.) and presents them to the user without requiring KYC. It’s hosted as a static site on Netlify and uses serverless functions (AWS Lambda via Netlify) to proxy external APIs and handle dynamic tasks.

##### Main Components
a. Frontend (Vue.js SPA)
- Located under src/ – key files: app.js, store.js, main.css, layout/, ui/, filter/, offer/, currency/, cryptocurrency/
- Renders the UI, handles routing, state management, user interactions and search/filter forms.
- Uses http-client.js to make AJAX requests.
b. Hosting & CDN
- Netlify for static asset hosting (public/, index.html, CSS, JS bundles) and serving the SPA.
- netlify.toml configures routing and function endpoints.
c. Serverless Functions (Netlify Lambdas)
- src/lambda/currency-rates.js – fetches live forex rates
- src/lambda/proxy-fetch.js – proxies calls to P2P exchange REST endpoints (Binance, LocalBitcoins, etc.) to avoid CORS issues
- src/lambda/send-mail.js – processes contact form submissions and sends emails via an SMTP or transactional email API
d. External Services
- P2P Exchange APIs (Binance-Exchange, LocalBitcoins, Paxful, HodlHodl, LocalCryptos, LocalCoinSwap)
- Currency rates providers (e.g., fixer.io, openexchangerates)
- Email delivery service (SMTP or 3rd-party provider)

##### Relationships & Data Flow
- User loads the SPA from the Netlify CDN.
- SPA components invoke Vuex store actions → call http-client.js → send HTTP requests to Netlify function endpoints (/ .netlify/functions/*).
- proxy-fetch Lambda forwards requests to external P2P exchange REST APIs → returns raw offers → SPA normalizes and displays them.
- currency-rates Lambda fetches live exchange rates → SPA converts prices into local currencies.
- send-mail Lambda handles form submissions from the ContactForm component → sends email.

##### Architectural Patterns & Design Principles
- SPA + API-driven architecture
- Serverless microservices: each Lambda does one job (proxy, rates, mail)
- Separation of concerns: UI components vs. service modules (src/exchange, src/currency, src/cryptocurrency) vs. static JSON resources (currencies.json, cryptocurrencies.json, payment-methods.json)
- Modular code: each external exchange wrapped in its own service file under src/exchange/

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Layer
    Browser["User Browser"]:::frontend
    subgraph "Frontend (Vue.js SPA)"
        direction TB
        appEntry["app.js"]:::frontend
        store["store.js"]:::frontend
        styles["main.css"]:::frontend
        httpClient["http-client.js"]:::frontend
        subgraph Layout Components
            direction TB
            layout["src/layout/"]:::frontend
        end
        subgraph UI Components
            direction TB
            ui["src/ui/"]:::frontend
        end
        subgraph Filter Components
            direction TB
            filters["src/filter/"]:::frontend
        end
        subgraph Offer Module
            direction TB
            offer["src/offer/"]:::frontend
        end
        subgraph Currency Module
            direction TB
            currency["src/currency/"]:::frontend
        end
        subgraph Cryptocurrency Module
            direction TB
            crypto["src/cryptocurrency/"]:::frontend
        end
        subgraph Exchange Services Wrappers
            direction TB
            exchange["src/exchange/"]:::frontend
        end
        staticJSON["countries.json"]:::frontend
    end

    %% CDN Layer
    CDN["Netlify CDN & Hosting\n(public/, index.html, assets)"]:::frontend

    %% API Layer
    subgraph "Netlify Functions (Lambda)"
        direction TB
        proxy["proxy-fetch"]:::serverless
        rates["currency-rates"]:::serverless
        mail["send-mail"]:::serverless
    end

    %% External Services Layer
    subgraph "External Services"
        direction TB
        P2P["P2P Exchange APIs"]:::external
        FX["Currency Rates API"]:::external
        Email["Email Service"]:::external
    end

    %% Connections
    Browser -->|"GET /"| CDN
    CDN -->|"Serve SPA"| appEntry
    appEntry -->|"initializes"| store
    appEntry -->|"loads styles"| styles
    appEntry -->|"uses HTTP client"| httpClient

    httpClient -->|"GET /offers"| proxy
    httpClient -->|"GET /rates"| rates
    httpClient -->|"POST /send-mail"| mail

    proxy -->|"proxy to exchanges"| P2P
    rates -->|"fetch FX rates"| FX
    mail -->|"send email"| Email

    %% Click Events
    click appEntry "https://github.com/bomzj/cryptofair/blob/master/src/app.js"
    click store "https://github.com/bomzj/cryptofair/blob/master/src/store.js"
    click styles "https://github.com/bomzj/cryptofair/blob/master/src/main.css"
    click httpClient "https://github.com/bomzj/cryptofair/blob/master/src/http-client.js"
    click layout "https://github.com/bomzj/cryptofair/tree/master/src/layout/"
    click ui "https://github.com/bomzj/cryptofair/tree/master/src/ui/"
    click filters "https://github.com/bomzj/cryptofair/tree/master/src/filter/"
    click offer "https://github.com/bomzj/cryptofair/tree/master/src/offer/"
    click currency "https://github.com/bomzj/cryptofair/tree/master/src/currency/"
    click crypto "https://github.com/bomzj/cryptofair/tree/master/src/cryptocurrency/"
    click exchange "https://github.com/bomzj/cryptofair/tree/master/src/exchange/"
    click staticJSON "https://github.com/bomzj/cryptofair/blob/master/src/countries.json"
    click proxy "https://github.com/bomzj/cryptofair/blob/master/src/lambda/proxy-fetch.js"
    click rates "https://github.com/bomzj/cryptofair/blob/master/src/lambda/currency-rates.js"
    click mail "https://github.com/bomzj/cryptofair/blob/master/src/lambda/send-mail.js"
    click CDN "https://github.com/bomzj/cryptofair/tree/master/public/"

    %% Styles
    classDef frontend fill:#cce5ff,stroke:#4da3ff,color:#000
    classDef serverless fill:#d4edda,stroke:#28a745,color:#000
    classDef external fill:#e2e3e5,stroke:#6c757d,color:#000
```
