This project is a microservices-based system for user authentication and mathematical computations, with a web GUI. It uses Docker Compose for orchestration.

-
auth_service (Flask, port 5001):
Handles user registration, login, and authentication. Stores user data and verifies credentials. -
math_service (Flask, port 5002):
Provides endpoints for mathematical operations: power, factorial, and Fibonacci.- Uses Redis for caching results (optional, controlled by
CACHE_ENABLED). - Logs each request to a shared SQLite database.
- Uses Redis for caching results (optional, controlled by
-
gateway (FastAPI, port 8000):
Acts as an API gateway/reverse proxy.- Routes requests from the GUI to the appropriate backend service.
- Adds user context to requests (e.g., username).
-
gui (Streamlit, port 8501):
User interface for registration, login, and performing math operations.- All interactions go through the gateway.
- User interacts with GUI (registers, logs in, requests math operations).
- GUI sends requests to Gateway (
localhost:8000). - Gateway forwards requests to either
auth_serviceormath_servicebased on the endpoint. - auth_service authenticates users.
- math_service performs calculations, optionally caches results in Redis, and logs requests in the shared database.
- Results and logs are returned to the GUI for display.
- All services use a shared SQLite database (
microservice_math.db) via a Docker volume (shared-db). - The database stores user data and logs of all math operations.
- The math service uses Redis (host:
redis, port:6379) for caching results. - Caching is controlled by the
CACHE_ENABLEDflag inmath_service/app.py.
- Python 3.10+
- Docker & Docker Compose
From the root directory, run:
docker-compose up --buildThis will:
- Build and start all microservices and the GUI.
- Set up the shared database volume.
Open your browser at:
http://localhost:8501
To stop all services:
docker-compose down- Register and log in via the GUI.
- Perform math operations (power, factorial, Fibonacci).
- View recent logs in the GUI.
- All requests are routed through the gateway for security and logging.
- If you see
ModuleNotFoundError: No module named 'redis', ensureredisis inrequirements.txtand rebuild withdocker-compose build --no-cache. - If logs do not appear, check that the database volume is mounted and the
request_logtable exists. - Make sure all services are running (
docker-compose ps).
src/auth_service/: Auth microservice codesrc/math_service/: Math microservice codesrc/gateway/app/: API gateway codesrc/gateway/gui.py: Streamlit GUI coderequirements.txt: Python dependencies (includingredis)docker-compose.yml: Service orchestrationDockerfile.*: Docker build files for each service
- All services communicate over the Docker network using service names (e.g.,
math_service,auth_service). - The shared database volume ensures persistent and consistent data across services.
- Redis must be running and accessible for caching to work.