The Problem

Security teams need a quick way to ingest raw logs, run them through ML models, and expose results via a lightweight API. Existing turnkey solutions are either too generic, require a lot of configuration, or lack an end‑to‑end test harness. This project delivers a ready‑made pipeline that takes log files, normalises them, runs an autoencoder and random forest model, and surfaces alerts through a FastAPI service.

What This Does

The ai‑threat‑detection folder contains a full backend and a lightweight React frontend.

  • backend/app/__main__.py starts the FastAPI server.
  • backend/app/main.py wires routes (/api/ingest, /api/alerts, /api/threats) to the service layer.
  • backend/app/services/threat_service.py orchestrates model inference (ml/autoencoder.py, ml/train_classifiers.py) and stores alerts in Redis (core/redis_manager.py).
  • frontend/src/App.tsx consumes the API via hooks in frontend/src/api/hooks/… and displays a dashboard.

The repo also ships with a Docker compose file (compose.yml) that builds both sides and runs them in isolated containers.

How It Is Wired

Entry point: backend/app/__main__.py executes uvicorn backend.app.main:app.

  1. main.py imports app/api/*.py where each route handler calls a service.
  2. The /api/ingest handler reads a log file, passes it to core/ingestion/parser.py → pipeline.py.
  3. pipeline.py feeds data to ml/autoencoder.py (ONNX inference) and ml/train_classifiers.py (RF).
  4. Results are wrapped in schemas/*.py and returned.
  5. Alerts are queued into Redis via core/redis_manager.py; a background task in main.py pulls them and pushes over WebSocket (api/websocket.py).

The frontend starts on frontend/index.html. src/api/hooks/useAlerts.ts opens a WebSocket at /ws/alerts and updates the UI. The entire flow from ingestion to alert display requires three main hops: request → service → model → Redis → WebSocket → UI.

How To Use It

# clone
git clone https://github.com/moses-y/Cybersecurity-Projects
cd Cybersecurity-Projects/PROJECTS/advanced/ai-threat-detection

# build & run containers
docker compose up --build

The backend listens on http://localhost:8000. The frontend is served at http://localhost:3000. Environment variables are defined in .env.example; copy it to .env and adjust if needed.

Real‑World Use

Deploy the stack in a SOC for continuous log monitoring. Ingest logs from syslog or docker‑compose into /api/ingest; the service returns a JSON payload of anomaly scores. Alerts are pushed to a SIEM via the WebSocket or stored in Redis for later batch export.

Code Health & Issues

  • Security – Low: secret‑shaped paths found in PROJECTS/intermediate/credential‑rotation‑enforcer/src/cre/rotators/aws_secrets.cr, PROJECTS/intermediate/docker‑security‑audit/internal/rules/secrets.go, PROJECTS/intermediate/docker‑security‑audit/tests/testdata/compose/bad‑secrets.yml.
  • Test coverage – 772 test files, many targeting the FastAPI endpoints and ML inference.
  • CI/CD – .github/workflows/*.yml deploys the API‑rate‑limiter and other subprojects; no workflow for the AI‑threat‑detection stack.
  • Documentation – 101 doc files, but the AI‑threat‑detection README is minimal; detailed API docs are missing.
  • License – LICENSE present, MIT.

The dependency graph shows a clear separation: backend relies on uvicorn, fastapi, onnxruntime, redis, while frontend depends on vite, react, typescript. The only cyclic dependency is between app/main.py and services/threat_service.py, which is acceptable given the limited scope.

The Bottom Line

The AI threat detection stack is a solid, end‑to‑end prototype that demonstrates how to combine log ingestion, ML inference, and real‑time alerting. It is well‑structured, test‑heavy, and Docker‑ready, but the lack of CI for this specific project and sparse documentation are the main gaps. It is suitable for teams wanting a quick proof of concept or a teaching tool, but production use would require adding comprehensive API docs, tightening secret handling, and integrating a CI pipeline.