FastAPI server for real-time alert and chat message broadcasting via WebSocket with REST API support. All data is stored in-memory.
- FastAPI application with WebSocket and REST endpoints
- In-memory storage using bounded deques for efficient message handling
- Asynchronous broadcast to all connected WebSocket clients
- Thread-safe connection management with per-socket locks
.
├── main.py # Application entry point
├── config.py # Configuration settings
├── dependencies.py # Dependency injection setup
├── controllers/ # Request/WebSocket handlers
│ ├── alert.py
│ └── websocket.py
├── managers/ # Connection management
│ └── connection_manager.py
├── models/ # Data models
│ ├── alert.py
│ └── message.py
├── repositories/ # Data storage
│ ├── alert.py
│ ├── base.py
│ └── chat.py
├── routes/ # API routes
│ ├── alert.py
│ └── websocket.py
├── services/ # Business logic
│ └── alert_generator.py
└── tests/ # Test suite
├── managers/
├── repositories/
├── routes/
└── services/
- Python 3.8+
- uv (package manager)
-
Install uv:
curl -sSfL https://astral.sh/uv/install.sh | sh
-
Install dependencies:
uv pip install -e .
uv run fastapi run main:app --reload
Note: If port 8000 is in use, specify another port with
--port
:uv run fastapi run main:app --reload --port 8001
uv run pytest
- Stored in-memory using a bounded deque (FIFO)
- Maximum capacity: 100 alerts (configurable)
- Automatically pruned when capacity is reached
- Broadcast to all connected WebSocket clients on creation
- Stored in-memory using a bounded deque (FIFO)
- Maximum capacity: 100 messages (configurable)
- Broadcast to all connected WebSocket clients on new message
- Includes sender information and timestamp
GET /alerts/history
- Retrieve recent alertsPOST /alerts/
- Create and broadcast a new alert
GET /ws
- Connect to the WebSocket for real-time chat messages