How manojbaniya444/currency-converter5 works
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