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