From 6abbddf4a6a47f3d0071a6bdb26a2373edd8056d Mon Sep 17 00:00:00 2001 From: Florian Date: Sat, 18 Oct 2025 20:12:18 +0200 Subject: [PATCH] Updated readme --- README.md | 98 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 96 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 8a81b98..dc078df 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,97 @@ -# backend-api-internal +# Internal Notifier API -The internal part of the API. Duh! \ No newline at end of file +A FastAPI-based internal service that receives notification requests and forwards them to RabbitMQ for asynchronous processing and delivery to end users. + +## Features + +- **RabbitMQ Integration**: Asynchronous message queuing for reliable notification delivery +- **Internal API Key Authentication**: Secure service-to-service communication +- **MySQL Connection Pooling**: Database connection management with automatic health checks +- **Prometheus Metrics**: Built-in request monitoring and tracking + +## Architecture + +This service acts as a gateway between internal services and the notification delivery system: + +``` +Internal Services → Internal Notifier API → RabbitMQ → Notification Workers → End Users +``` + +## Prerequisites + +- Python 3.8+ +- MySQL database +- RabbitMQ server +- Required Python packages (see Installation) + +## Installation + +```bash +pip install -r requirements.txt +``` + +## Running the Application + +```bash +python main.py +``` + +This starts two servers: +- **Main API**: `http://0.0.0.0:8101` +- **Metrics Server**: `http://0.0.0.0:9000` + +## API Endpoints + +### Receive Notifications +``` +POST /internal/receive-notifications +``` + +Receives notification data from internal services and queues it to RabbitMQ for delivery. + +**Headers:** +- `X-API-Key-Internal`: Your internal API key + +**Request Body:** +```json +{ + "receipent_user_id": 12345, + "message": { + "title": "New Message", + "body": "You have a new notification", + "data": { + "category": "utility", + "link": "https://example.com", + "timestamp": "1760734800" + } + } +} +``` + +- `category` - Optional. +- `link` - Optional. +- `timestamp` - Optional. + +**Response:** +```json +{ + "status": "queued" +} +``` + +**Success:** Returns 200 status code when message is successfully queued to RabbitMQ + +## Error Responses + +- `403 Forbidden`: Invalid, missing, or inactive API key +- `500 Internal Server Error`: Database, RabbitMQ, or server error + +## Monitoring + +### Prometheus Metrics + +Prometheus metrics are exposed on port 9000 and include: +- HTTP request counters by method, path, and status code +- Custom metrics from the metrics server + +Access metrics at: `http://0.0.0.0:9000/metrics` \ No newline at end of file