# evaristopinto16/currency-exchange-services architecture

> Architecture diagram of the GitHub repository evaristopinto16/currency-exchange-services, 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/evaristopinto16/currency-exchange-services
- Repository: https://github.com/evaristopinto16/currency-exchange-services

## Overview

##### Project type and purpose
- This is a monolithic, full-stack (API-only) microservice written in Node.js using the Fastify framework.
- Purpose: provide informal, up-to-date currency exchange rates via two REST endpoints:
- GET /api/v1/getcoin – returns supported currency codes
- POST /api/v1/conversor – returns converted value plus informal rate tiers and past quotations

##### File structure
- Top-level files:
- app.js – Fastify initialization and server start
- package.json / package-lock.json – dependencies and scripts
- .gitignore / getGrafico.http – HTTP test snippets
- src/config/apiurlConfig.js – external API URL and credentials
- src/routers/router.js – defines /api/v1 routes
- src/controllers/…Controller.js – parse request, handle HTTP response
- src/service/cambioServices.js – core business logic orchestration
- src/utilis/*.js – stateless helper modules:
- conversaoCambioUtilis.js – calculate basic conversion
- cotacoesPassadasUtilis.js – fetch or compute past quotations
- notsleepUtilis.js – delay or retry logic

##### README for insights

a. Main components
- Client (e.g., Postman, browser, mobile app)
- Fastify HTTP Server (app.js)
- Router layer (router.js)
- Controller layer (cambioController.js & getCoinController.js)
- Service layer (cambioServices.js)
- Utility modules (conversion util, past-quotes util, non-sleep util)
- External Currency Rates API
b. Relationships & interactions
1. Client → HTTP Server (incoming request)
2. HTTP Server → Router → Controller
3. Controller → Service (pass parameters)
4. Service → Utility modules & External API
5. Utility modules call External API and perform business calculations
6. Service aggregates results and returns to Controller
7. Controller → HTTP Server → Client (response JSON)
c. Architectural patterns
- Layered architecture (HTTP → Router → Controller → Service → Utils)
- Separation of concerns: routing, request handling, business logic, helpers
- Single-responsibility utility modules for conversion, past data, retry/delay
d. Key technologies
- Node.js, Fastify (ultra-fast HTTP framework)
- JavaScript ES modules (import/exports in app.js, controllers, services)
- External REST API for live currency data

##### Final advice
- Be exhaustive: include every layer and helper module.
- Both happy-path and any retry/delay logic (notsleepUtilis).
- Labels match actual file or module names for clarity to the engineering team.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Layers
    subgraph "Client Layer"
        Client["Client"]:::client
    end

    subgraph "HTTP Layer"
        Fastify["Fastify HTTP Server"]:::http
        Router["Router"]:::http
    end

    subgraph "Controller Layer"
        GetCoin["getCoinController"]:::controller
        Cambio["cambioController"]:::controller
    end

    subgraph "Business Layer"
        Service["cambioServices"]:::service
    end

    subgraph "Configuration & Model"
        APIConfig["apiurlConfig"]:::config
        CoinList["Coin List Model"]:::model
    end

    subgraph "Utility Modules"
        ConvUtil["conversaoCambioUtilis"]:::utils
        PastUtil["cotacoesPassadasUtilis"]:::utils
        SleepUtil["notsleepUtilis"]:::utils
    end

    ExternalAPI["External Currency Rates API"]:::externalapi

    %% Connections
    Client --> Fastify
    Fastify --> Router
    Router -->|"GET /api/v1/getcoin"| GetCoin
    Router -->|"POST /api/v1/conversor"| Cambio
    GetCoin --> Service
    Cambio --> Service
    Service --> APIConfig
    Service --> ConvUtil
    Service --> PastUtil
    Service --> SleepUtil
    ConvUtil --> ExternalAPI
    PastUtil --> ExternalAPI
    Service --> CoinList
    Service --> GetCoin
    Service --> Cambio
    GetCoin --> Fastify
    Cambio --> Fastify
    Fastify --> Client

    %% Click Events
    click Fastify "https://github.com/evaristopinto16/currency-exchange-services/blob/main/src/app.js"
    click APIConfig "https://github.com/evaristopinto16/currency-exchange-services/blob/main/src/config/apiurlConfig.js"
    click Router "https://github.com/evaristopinto16/currency-exchange-services/blob/main/src/routers/router.js"
    click GetCoin "https://github.com/evaristopinto16/currency-exchange-services/blob/main/src/controllers/getCoinController.js"
    click Cambio "https://github.com/evaristopinto16/currency-exchange-services/blob/main/src/controllers/cambioController.js"
    click Service "https://github.com/evaristopinto16/currency-exchange-services/blob/main/src/service/cambioServices.js"
    click ConvUtil "https://github.com/evaristopinto16/currency-exchange-services/blob/main/src/utilis/conversaoCambioUtilis.js"
    click PastUtil "https://github.com/evaristopinto16/currency-exchange-services/blob/main/src/utilis/cotacoesPassadasUtilis.js"
    click SleepUtil "https://github.com/evaristopinto16/currency-exchange-services/blob/main/src/utilis/notsleepUtilis.js"
    click CoinList "https://github.com/evaristopinto16/currency-exchange-services/blob/main/src/models/listCointModels.js"

    %% Styles
    classDef client fill:#B0C4DE,stroke:#333,stroke-width:1px
    classDef http fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef controller fill:#98FB98,stroke:#333,stroke-width:1px
    classDef service fill:#32CD32,stroke:#333,stroke-width:1px
    classDef utils fill:#D3D3D3,stroke:#333,stroke-width:1px
    classDef externalapi fill:#FFA500,stroke:#333,stroke-width:1px
    classDef config fill:#DDA0DD,stroke:#333,stroke-width:1px
    classDef model fill:#F0E68C,stroke:#333,stroke-width:1px
```
