# manojbaniya444/currency-converter5 architecture

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

- Interactive diagram: https://gitdiagram.com/manojbaniya444/currency-converter5
- Repository: https://github.com/manojbaniya444/currency-converter5

## Overview

##### Project Type and Purpose
- This is a single‐service, full‐stack (API‐only) application built with FastAPI.
- Purpose: Provide a currency exchange “converter” API that fetches live rates from an external provider, caches them in Redis, and exposes endpoints for clients to query and convert currencies.

##### File Structure Analysis
- Top‐level
- app/ – the FastAPI application code
- Dockerfile & docker-compose.yml – containerization and Redis service
- tests/ – automated tests (e.g., health check)
- requirements.txt – Python dependencies
- app/
- api/ – request handlers
– dependencies.py: shared DI bindings (e.g., Redis client)
– routes/converter.py: the conversion endpoints
- core/ – configuration and global utilities
– config.py: env loading (API keys, Redis URL)
– errors.py: custom exception definitions
- services/exchange_service.py – business logic to fetch and cache rates
- main.py – FastAPI app initialization and router mounting

##### Key Insights from README
- Built on FastAPI, can run locally or via Docker Compose (includes Redis).
- Endpoints documented under /docs (Swagger UI).
- Uses Redis as a cache layer to avoid redundant external API calls.

##### Main Components
a. Client(s)
– Web/Mobile/CLI clients invoking HTTP requests
b. API Layer (FastAPI)
– main.py: app entry
– Routes: converter endpoints
– Dependencies: middleware, Redis injection
c. Service Layer
– ExchangeService:
- Checks Redis cache
- Calls external FX API if needed
- Parses and stores results
d. Cache Layer
– Redis instance (provided via docker-compose or ENV)
e. External Service
– Third‐party Exchange Rate Provider (REST API)
f. Auxiliary Components
– Config (env variables via core/config.py)
– Error handling (core/errors.py)
– CI/CD (GitHub Actions: lint & deploy workflows)
– Test Harness (tests/test_health.py)

##### Relationships and Data Flows
1. Client → HTTP Request → FastAPI Router (converter)
2. Router invokes ExchangeService via Dependency Injection
3. ExchangeService:
– Checks Redis (GET rate)
– If cache miss: HTTP call → External FX API → parse JSON
– Stores fresh rate in Redis (SET with TTL)
4. Service returns result → Router formats JSON response → Client
5. Redis and External API run in parallel; FastAPI orchestrates both

##### Architectural Patterns & Design Principles
- Layered Architecture: API Layer → Service Layer → Cache/External
- Dependency Injection: centralized in app/api/dependencies.py
- Single Responsibility:
- Routes handle HTTP concerns only
- Services handle business rules and caching
- Config and errors are decoupled
- Containerization: isolates Redis and app for reproducible deployments

##### Technologies, Frameworks, Libraries
- FastAPI (app framework, OpenAPI docs)
- Uvicorn (ASGI server via `fastapi dev`)
- Redis (cache store via docker-compose)
- HTTPX or requests (within ExchangeService for external calls)
- Pydantic (for request/response validation, likely in converter models)
- GitHub Actions (CI: lint.yml, deploy.yml)

- Client → API Layer
- API Layer → Service Layer
- Service Layer → Redis (GET/SET)
- Service Layer → External FX API
- Redis → Service Layer (cache hit)
- External FX API → Service Layer (fresh data)
- Service Layer → API Layer → Client (response)
- Blue for internal application modules (API, Service)
- Green for data stores (Redis)
- Gray for external dependencies (FX API)
- Orange for clients

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Clients
    Client["Client (Web/Mobile/CLI)"]:::client

    %% Docker Compose Cluster
    subgraph "Docker Compose"
        direction TB

        %% FastAPI Service
        subgraph "FastAPI Service"
            direction TB

            %% API Layer
            subgraph "API Layer"
                direction TB
                Dependencies["Dependency Injection (Redis Client)"]:::internal
                ConverterRoutes["Converter Routes"]:::internal
            end

            %% Service Layer
            subgraph "Service Layer"
                direction TB
                ExchangeService["ExchangeService"]:::internal
            end

            %% Core Components
            subgraph "Core"
                direction TB
                Config["Configuration"]:::internal
                Errors["Error Handling"]:::internal
            end
        end

        %% Redis Cache
        RedisDB[(Redis Cache)]:::datastore
    end

    %% External Service
    ExternalFX((External FX API)):::external

    %% CI/CD Workflows
    subgraph "CI/CD"
        direction TB
        Lint["Lint Workflow"]:::cicd
        Deploy["Deploy Workflow"]:::cicd
        HealthTest["Health Check Test"]:::cicd
    end

    %% Data Flows
    Client -->|HTTP Request| ConverterRoutes
    ConverterRoutes -->|invoke| ExchangeService
    ExchangeService -->|GET rate| RedisDB
    RedisDB -->|cache hit| ExchangeService
    ExchangeService -->|fetch fresh rate| ExternalFX
    ExternalFX -->|rate data| ExchangeService
    ExchangeService -->|SET rate| RedisDB
    ExchangeService -->|return data| ConverterRoutes
    ConverterRoutes -->|HTTP Response| Client

    %% CI/CD Connections
    Lint -->|runs tests & lint| DockerCompose["Docker Compose"]
    Deploy -->|deploy container| DockerCompose

    %% Click Events
    click Main "https://github.com/manojbaniya444/currency-converter5/blob/main/app/main.py"
    click Dependencies "https://github.com/manojbaniya444/currency-converter5/blob/main/app/api/dependencies.py"
    click ConverterRoutes "https://github.com/manojbaniya444/currency-converter5/blob/main/app/api/routes/converter.py"
    click ExchangeService "https://github.com/manojbaniya444/currency-converter5/blob/main/app/services/exchange_service.py"
    click Config "https://github.com/manojbaniya444/currency-converter5/blob/main/app/core/config.py"
    click Errors "https://github.com/manojbaniya444/currency-converter5/blob/main/app/core/errors.py"
    click Compose "https://github.com/manojbaniya444/currency-converter5/blob/main/docker-compose.yml"
    click Dockerfile "https://github.com/manojbaniya444/currency-converter5/tree/main/Dockerfile"
    click Lint "https://github.com/manojbaniya444/currency-converter5/blob/main/.github/workflows/lint.yml"
    click Deploy "https://github.com/manojbaniya444/currency-converter5/blob/main/.github/workflows/deploy.yml"
    click HealthTest "https://github.com/manojbaniya444/currency-converter5/blob/main/tests/test_health.py"

    %% Styles
    classDef client fill:#f39c12,stroke:#333,stroke-width:1px;
    classDef internal fill:#87ceeb,stroke:#333,stroke-width:1px;
    classDef datastore fill:#2ecc71,stroke:#333,stroke-width:1px;
    classDef external fill:#95a5a6,stroke:#333,stroke-width:1px;
    classDef cicd fill:#f1c40f,stroke:#333,stroke-width:1px;
```
