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