This service acts as the main entry point for the GitHub Stats application. It provides user authentication and routes requests to the appropriate microservices.
- User authentication with JWT tokens
- SQLite database for user management
- Routes requests to the GitHub microservice
- Handles error responses
- Provides a unified API endpoint
- Create a
.envfile in the root directory with the following variables:
JWT_SECRET_KEY=your-secret-key # Change this in production
PORT=5000
SQLITE_DB_PATH=users.db
GITHUB_MICROSERVICE_URL=http://github_microservice:5001- Install dependencies:
pip install -r requirements.txt- Run the service:
python app.pyTo build and run with Docker:
docker build -t api-gateway .
docker run -p 5000:5000 \
-e JWT_SECRET_KEY=your-secret-key \
-e SQLITE_DB_PATH=users.db \
-e GITHUB_MICROSERVICE_URL=http://github_microservice:5001 \
api-gateway- GET
/- Shows available API endpoints
-
POST
/register- Register a new user{ "username": "your_username", "password": "your_password" } -
POST
/login- Login and receive JWT token{ "username": "your_username", "password": "your_password" }
- GET
/api/github/stats- Retrieves GitHub statistics (requires JWT token)curl -H "Authorization: Bearer your_jwt_token" http://localhost:5000/api/github/stats
| Variable | Required | Default | Description |
|---|---|---|---|
JWT_SECRET_KEY |
Yes | - | Secret key for JWT token generation |
PORT |
No | 5000 | Port to run the service on |
SQLITE_DB_PATH |
Yes | - | Path to SQLite database file |
GITHUB_MICROSERVICE_URL |
No | http://github_microservice:5001 | URL of the GitHub microservice |
The service uses SQLite for user management. The database file (specified by SQLITE_DB_PATH) will be automatically created when the service starts.
See requirements.txt for a full list of Python dependencies.
- Change the JWT_SECRET_KEY in production to a secure value
- Ensure the JWT_SECRET_KEY matches the one used in the github_microservice
- Keep your database file secure and regularly backed up