# manojbaniya444/currency-converter3 architecture

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

## Overview

##### Project type and purpose
- This is a backend-only, RESTful API service built in FastAPI.
- It provides currency exchange rates & conversion endpoints.
- It optionally uses Redis (via docker-compose) to cache exchange data and offload repeated requests.

##### File structure
Top-level directories & files:
- app/ – application code
– api/routes/converter.py: HTTP endpoints for conversion
– api/dependencies.py: DI for cache, config, services
– core/config.py: environment & config loading
– services/exchange_service.py: business logic, external-API & cache calls
– main.py: FastAPI app instance & router registration
- requirements.txt: Python dependencies (FastAPI, redis, httpx, etc.)
- docker-compose.yml: Redis service + FastAPI service definition
- Dockerfile: containerizes the FastAPI app
- tests/: simple smoke-test for health check
- .github/workflows: CI for linting & deployment

##### Extract README insights
- App exposes documentation at /docs (Swagger UI).
- Supports Docker Compose (“docker-compose up” spins up Redis & app).
- Screenshots demonstrate request→response on converter endpoint.

##### Main components to reflect
a. Client / Consumer (e.g. browser, curl, mobile app)
b. API Layer
- FastAPI application (containerized)
- Router (converter endpoints)
c. Service Layer
- ExchangeService: orchestrates cache lookups & external API calls
d. Cache Layer
- Redis instance (caching exchange rates)
e. External Currency Provider
- Third-party REST API (e.g. exchangeratesapi.io)
f. Configuration & DI
- Config service loads .env
- Dependencies inject cache & service into routes

##### Relationships & interactions
1. Client → HTTP request → FastAPI converter endpoint
2. Endpoint → Dependency-injected ExchangeService
3. ExchangeService:
a. Checks Redis for cached rate
b. If missing, calls external API → gets rate → stores in Redis
c. Applies conversion logic → returns result
4. FastAPI → HTTP response → Client

##### Architectural patterns & principles
- Layered architecture: API layer → Service layer → Cache/External API
- Dependency Injection (app/api/dependencies.py) to decouple components
- Single responsibility: routes only marshal requests; business logic in services
- Containerization: each service in own Docker container; networked via docker-compose

##### Essential elements to capture
- Component names & responsibilities
- Data-flow directions & decision points (cache hit vs. miss)
- Deployment context (Docker, Compose network)
- Technology labels: FastAPI, Python 3.x, Redis, Docker

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Client
    Client["Client (Browser/Curl/Mobile)"]:::external

    %% Docker Compose Boundary
    subgraph "Docker Compose Network"
        direction TB

        %% FastAPI App Container
        subgraph "FastAPI App Container" 
            direction TB
            Config["Configuration Loader (.env)"]:::config
            DI["Dependency Injection"]:::config
            Errors["Error Definitions"]:::config
            Router["Converter Router"]:::compute
            Service["ExchangeService"]:::compute
            MainApp["FastAPI App"]:::compute
        end

        Redis["Redis Cache"]:::cache
    end

    %% External API
    ExternalAPI["Third-Party Currency API"]:::external

    %% CI/CD Workflows
    subgraph "CI/CD Pipelines"
        Lint["Lint Workflow"]:::ci
        Deploy["Deploy Workflow"]:::ci
    end

    %% Smoke Test
    Test["Health-Check Smoke Test"]:::test

    %% Relationships
    Client -->|HTTP Request| MainApp
    MainApp -->|includes router| Router
    MainApp -->|includes DI| DI
    MainApp -->|reads config| Config
    DI -->|injects into| Router
    DI -->|injects into| Service
    Router -->|calls convert endpoint| Service
    Service -->|GET/SET rate| Redis
    Service -->|HTTP Request| ExternalAPI
    ExternalAPI -->|returns rate| Service
    Service -->|returns result| Router
    Router -->|HTTP Response| MainApp
    MainApp -->|HTTP Response| Client

    Test -->|requests /health| MainApp

    Lint -->|checks code| MainApp
    Deploy -->|deploys container| MainApp

    %% Click Events
    click MainApp "https://github.com/manojbaniya444/currency-converter3/blob/main/app/main.py"
    click Router "https://github.com/manojbaniya444/currency-converter3/blob/main/app/api/routes/converter.py"
    click DI "https://github.com/manojbaniya444/currency-converter3/blob/main/app/api/dependencies.py"
    click Config "https://github.com/manojbaniya444/currency-converter3/blob/main/app/core/config.py"
    click Service "https://github.com/manojbaniya444/currency-converter3/blob/main/app/services/exchange_service.py"
    click Errors "https://github.com/manojbaniya444/currency-converter3/blob/main/app/core/errors.py"
    click Redis "https://github.com/manojbaniya444/currency-converter3/blob/main/docker-compose.yml"
    click Lint "https://github.com/manojbaniya444/currency-converter3/blob/main/.github/workflows/lint.yml"
    click Deploy "https://github.com/manojbaniya444/currency-converter3/blob/main/.github/workflows/deploy.yml"
    click Test "https://github.com/manojbaniya444/currency-converter3/blob/main/tests/test_health.py"
    click Dockerfile "https://github.com/manojbaniya444/currency-converter3/tree/main/Dockerfile"

    %% Styles
    classDef compute fill:#ADD8E6,stroke:#000,stroke-width:1px
    classDef cache fill:#90EE90,stroke:#000,stroke-width:1px
    classDef external fill:#D3D3D3,stroke:#000,stroke-width:1px
    classDef config fill:#FFFFE0,stroke:#000,stroke-width:1px
    classDef ci fill:#E6E6FA,stroke:#000,stroke-width:1px
    classDef test fill:#FFDAB9,stroke:#000,stroke-width:1px
```
