# manojbaniya444/currency-converter4 architecture

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

## Overview

##### Project Type and Purpose
- This is a backend microservice (FastAPI) that exposes a RESTful API for fetching and converting currency exchange rates.
- It supports both direct invocation via `fastapi dev ./app/main.py` and containerized deployment (Docker + Redis for caching).

##### File Structure Analysis
- Top-level:
- Dockerfile & docker-compose.yml → container definitions (app + Redis)
- .github/workflows → CI steps (lint, deploy)
- requirements.txt → package dependencies
- tests/ → basic health-check test
- app/ directory:
- app/main.py → FastAPI application entry point
- app/api/ → HTTP layer
– dependencies.py → DI for config & cache client
– routes/converter.py → currency-convert endpoint
- app/services/ → business logic
– exchange_service.py → fetch & cache exchange rates
- app/core/ → shared components
– config.py → settings (API keys, Redis URL)
– errors.py → custom exception definitions

##### README Insights
- Describes two modes: local dev & Docker-Compose (Redis + service).
- Highlights use of FastAPI’s auto-generated Swagger UI (docs at /docs).
- Implies an external “rates” API behind the scenes (in exchange_service) and Redis as cache.

a. Main Components
- Client (Browser / Postman)
- FastAPI Service Container
– API Layer (routes)
– Dependency Layer (config + cache client)
– Service Layer (exchange_service)
- Redis Cache Container
- External Exchange Rate Provider (third-party HTTP API)
b. Relationships & Data Flow
1. Client sends HTTP request to FastAPI (port 8000).
2. FastAPI route handler invokes dependency to obtain Redis connection & config.
3. exchange_service checks Redis for cached rate.
4a. If cached → return cached value.
4b. If miss → exchange_service calls external provider over HTTP, stores result in Redis, then returns.
5. FastAPI serializes response to JSON and returns to client.
c. Architectural Patterns & Principles
- Layered architecture (API → Dependencies → Services → External)
- Dependency Injection (injections defined in dependencies.py)
- Cache-Aside pattern (Redis caching in exchange_service)
- Containerization & service isolation (app vs. Redis in Docker Compose)
d. Relevant Technologies
- Python + FastAPI (uvicorn)
- Redis (caching)
- Docker & Docker Compose
- CI/CD via GitHub Actions (lint, deploy)

## Diagram (Mermaid)

```mermaid
flowchart TD
    Client["Client (Browser/Postman)"]:::client
    subgraph "Docker Host"
        subgraph "FastAPI Service"
            FastAPIApp["FastAPI App\n(app/main.py)"]:::service
            subgraph "API Layer"
                DEP["Dependency Injection\n(app/api/dependencies.py)"]:::component
                ROUTE["Converter Route\n(app/api/routes/converter.py)"]:::component
            end
            subgraph "Business Logic Layer"
                SERVICE["Exchange Service\n(app/services/exchange_service.py)"]:::component
            end
            subgraph "Core Components"
                CONFIG["Config Settings\n(app/core/config.py)"]:::component
                ERRORS["Custom Errors\n(app/core/errors.py)"]:::component
            end
        end
        Redis["Redis Cache"]:::cache
    end
    External["External Rates API"]:::external

    Client -->|HTTP Request| FastAPIApp
    FastAPIApp -->|calls route| ROUTE
    ROUTE -->|uses DI| DEP
    DEP -->|provides| CONFIG
    DEP -->|provides| ERRORS
    DEP -->|injects cache| SERVICE
    ROUTE -->|invokes| SERVICE
    SERVICE -->|check cache| Redis
    Redis -->|cache hit| SERVICE
    SERVICE -->|cache miss fetch| External
    External -->|returns rates| SERVICE
    SERVICE -->|store result| Redis
    SERVICE -->|returns data| FastAPIApp
    FastAPIApp -->|JSON Response| Client

    subgraph "Infrastructure"
        Dockerfile["Dockerfile"]:::infra
        DockerCompose["docker-compose.yml"]:::infra
    end

    subgraph "CI/CD Workflows"
        Lint["Lint Workflow\n(.github/workflows/lint.yml)"]:::infra
        Deploy["Deploy Workflow\n(.github/workflows/deploy.yml)"]:::infra
    end

    subgraph "Project Files"
        Req["requirements.txt"]:::infra
        HealthTest["Health-Check Test\n(tests/test_health.py)"]:::infra
        Readme["README.md"]:::infra
        EnvExample[".env.example"]:::infra
    end

    click FastAPIApp "https://github.com/manojbaniya444/currency-converter4/blob/main/app/main.py"
    click DEP "https://github.com/manojbaniya444/currency-converter4/blob/main/app/api/dependencies.py"
    click ROUTE "https://github.com/manojbaniya444/currency-converter4/blob/main/app/api/routes/converter.py"
    click SERVICE "https://github.com/manojbaniya444/currency-converter4/blob/main/app/services/exchange_service.py"
    click CONFIG "https://github.com/manojbaniya444/currency-converter4/blob/main/app/core/config.py"
    click ERRORS "https://github.com/manojbaniya444/currency-converter4/blob/main/app/core/errors.py"
    click Dockerfile "https://github.com/manojbaniya444/currency-converter4/tree/main/Dockerfile"
    click DockerCompose "https://github.com/manojbaniya444/currency-converter4/blob/main/docker-compose.yml"
    click Lint "https://github.com/manojbaniya444/currency-converter4/blob/main/.github/workflows/lint.yml"
    click Deploy "https://github.com/manojbaniya444/currency-converter4/blob/main/.github/workflows/deploy.yml"
    click Req "https://github.com/manojbaniya444/currency-converter4/blob/main/requirements.txt"
    click HealthTest "https://github.com/manojbaniya444/currency-converter4/blob/main/tests/test_health.py"
    click Readme "https://github.com/manojbaniya444/currency-converter4/blob/main/README.md"
    click EnvExample "https://github.com/manojbaniya444/currency-converter4/blob/main/.env.example"

    classDef client fill:#BEE,stroke:#333,stroke-width:1px
    classDef service fill:#CCF,stroke:#333,stroke-width:1px
    classDef component fill:#AAF,stroke:#333,stroke-width:1px
    classDef cache fill:#AFA,stroke:#333,stroke-width:1px,shape:cylinder
    classDef external fill:#DDD,stroke:#333,stroke-width:1px,shape:cloud
    classDef infra fill:#FFD,stroke:#333,stroke-width:1px
```
