# manojbaniya444/currency-converter2 architecture

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

## Overview

##### Project type and purpose
- This is a backend microservice (a REST API) built with FastAPI that provides currency exchange rates and conversion functionality. It’s not a full-stack UI app but a single-purpose service that can be deployed standalone or in Docker (with Redis for caching).

##### File structure
- Top‐level:
- Dockerfile, docker-compose.yml – containerize the FastAPI app and spin up Redis.
- .github/workflows – CI/CD pipelines (linting and deploy).
- requirements.txt, .pre-commit-config.yaml – Python dependencies and lint/format hooks.
- tests/ – simple health‐check test.
- app/
- api/ – FastAPI route definitions (converter endpoint) and shared dependencies.
- services/ – business logic (exchange_service.py) that fetches or computes rates.
- core/ – configuration loader (config.py) and custom error definitions.
- main.py – app instantiation, middleware, router inclusion.

##### Key insights from README
- The service fetches live exchange rates (likely from an external provider).
- Can run locally via `fastapi dev` or via Docker Compose (App + Redis).
- Swagger UI available at /docs.

a. Main components
1. Client (cURL, Postman, Browser)
2. FastAPI App
- API Layer (app/main.py + app/api/routes/converter.py)
- Dependency Layer (app/api/dependencies.py)
- Service Layer (app/services/exchange_service.py)
- Config & Error Handling (app/core/config.py, app/core/errors.py)
3. Redis Cache (docker-compose service)
4. External Currency Rate Provider (third‐party REST API)
5. CI/CD Pipeline (GitHub Actions workflows)
b. Relationships and interactions
- Client → HTTP request → FastAPI API Layer
- API Layer injects dependencies (e.g., rate service, Redis client)
- Service Layer checks Redis cache; on miss, calls External Provider → stores result in Redis
- FastAPI serializes response → Client
- Git push → GitHub Actions (lint.yml, deploy.yml) → build/publish Docker image → deploy container
c. Architectural patterns & principles
- Layered architecture (Routing → Dependencies → Business Logic → External I/O)
- Dependency Injection via FastAPI’s Depends
- Cache‐Aside pattern with Redis
- Twelve-factor app principles (config via env vars, build vs run stages)
d. Key technologies
- Python 3.x, FastAPI, Uvicorn
- Redis for caching
- Docker & Docker Compose
- GitHub Actions for CI/CD
- Pre-commit hooks for linting/formatting

## Diagram (Mermaid)

```mermaid
flowchart TD
    Client["Client\n(cURL/Postman)"]:::client

    subgraph "FastAPI Application"
        main["FastAPI App\n(app/main.py)"]:::app
        api["API Layer\n(app/api/routes/converter.py)"]:::api
        deps["Dependency Layer\n(app/api/dependencies.py)"]:::dep
        svc["Service Layer\n(app/services/exchange_service.py)"]:::svc
        cfg["Config Loader\n(app/core/config.py)"]:::config
        err["Error Definitions\n(app/core/errors.py)"]:::config
    end

    subgraph Infrastructure
        redis["Redis Cache"]:::infra
        extapi["External Currency API"]:::external
        dockerfile["Dockerfile"]:::infra
        dockercompose["docker-compose.yml"]:::infra
    end

    subgraph "CI/CD Pipeline"
        lint["Lint & Test\n(.github/workflows/lint.yml)"]:::cicd
        health["Health-Check Test\n(tests/test_health.py)"]:::cicd
        deploywf["Deploy\n(.github/workflows/deploy.yml)"]:::cicd
        lint --> health
        lint --> deploywf
    end

    Client -->|"HTTP request"| api
    api -->|"Depends on"| deps
    deps -->|"Loads config"| cfg
    deps -->|"Loads errors"| err
    deps -->|"Inject Redis client"| redis
    api -->|"calls"| svc
    svc -->|"Cache lookup"| redis
    redis -->|"cache hit?"| svc
    svc -->|"on miss: fetch rates"| extapi
    extapi -->|"rates data"| svc
    svc -->|"store rates"| redis
    svc -->|"return data"| api
    api -->|"HTTP response"| Client

    deploywf --> dockerfile
    deploywf --> dockercompose

    classDef client fill:#cce5ff,stroke:#3399ff,color:#000;
    classDef app fill:#e6f7ff,stroke:#3399ff,color:#000;
    classDef api fill:#e6f7ff,stroke:#3399ff,color:#000;
    classDef dep fill:#e6f7ff,stroke:#3399ff,color:#000;
    classDef svc fill:#e6f7ff,stroke:#3399ff,color:#000;
    classDef config fill:#f0f0f0,stroke:#999999,color:#000;
    classDef infra fill:#d4edda,stroke:#28a745,color:#000;
    classDef external fill:#fff3cd,stroke:#ffcd39,color:#000;
    classDef cicd fill:#f8f9fa,stroke:#6c757d,color:#000;

    click main "https://github.com/manojbaniya444/currency-converter2/blob/main/app/main.py"
    click api "https://github.com/manojbaniya444/currency-converter2/blob/main/app/api/routes/converter.py"
    click deps "https://github.com/manojbaniya444/currency-converter2/blob/main/app/api/dependencies.py"
    click svc "https://github.com/manojbaniya444/currency-converter2/blob/main/app/services/exchange_service.py"
    click cfg "https://github.com/manojbaniya444/currency-converter2/blob/main/app/core/config.py"
    click err "https://github.com/manojbaniya444/currency-converter2/blob/main/app/core/errors.py"
    click dockerfile "https://github.com/manojbaniya444/currency-converter2/tree/main/Dockerfile"
    click dockercompose "https://github.com/manojbaniya444/currency-converter2/blob/main/docker-compose.yml"
    click lint "https://github.com/manojbaniya444/currency-converter2/blob/main/.github/workflows/lint.yml"
    click deploywf "https://github.com/manojbaniya444/currency-converter2/blob/main/.github/workflows/deploy.yml"
    click health "https://github.com/manojbaniya444/currency-converter2/blob/main/tests/test_health.py"
```
