How 24markjr/ai-compliance-gateway works
Purpose and Deployment Shape
This repository implements an AI privacy/compliance gateway: sensitive text is detected and masked before LLM inference, then selectively rehydrated for the caller while audit/history records are retained. The current tree contains both an original Node/Express application and a more extensive Python gateway implementation. Deployment and monitoring assets support containerized services and Prometheus/Grafana.
• docker-compose.yml
• render.yaml
• gateway/app/main.py
Client Application and Entry Points
The React/Vite client is the user-facing application. It provides login/registration, protected analysis, and history views; API service modules connect it to a backend/gateway. Browser startup is through Vite’s React entry point.
• frontend/src/main.jsx
• frontend/src/App.jsx
• frontend/src/pages/Analyze.jsx
Primary Gateway Runtime
The Python gateway is the architecture-rich service boundary for clients and LLM providers. Its FastAPI-style application assembly registers health, auth, chat, analysis, history, dashboard, and administrative routes; dependency wiring and middleware establish shared request behavior.
• gateway/app/main.py
• gateway/app/routers/chat.py
• gateway/app/routers/analyze.py
Compliance Processing Pipeline
Incoming text passes through policy-driven compliance scanning before provider dispatch. The engine coordinates detectors for regex, Presidio, secrets, and prompt injection; overlap resolution produces a consistent set of findings. The masker converts findings to safe replacements, and the vault supports reversible values needed for server-side restoration. Policies separate healthcare, HIPAA, PCI-DSS, GDPR, and DPDP rules from application logic.
• gateway/app/compliance/engine.py
• gateway/app/compliance/masker.py
• gateway/app/compliance/vault.py
LLM Provider Boundary
The gateway isolates model-specific API behavior behind a provider interface and router. Implementations include OpenAI, Gemini, Claude, DeepSeek, and Ollama, allowing routing changes without exposing raw sensitive content outside the compliance stage. Streaming support is modeled within the compliance layer, so masking behavior can remain applicable to streamed interactions.
• gateway/app/providers/base.py
• gateway/app/providers/router.py
• gateway/app/compliance/streaming.py
Identity, Persistence, and Auditability
Authentication middleware and security utilities protect gateway routes. Database modules manage users and request history, while audit models/logger/reader provide compliance records. History is additionally abstracted behind a sink. The original Node backend separately exposes analysis and log routes and uses Supabase, matching the README’s stated React → Express → Gemini → Supabase deployment; it appears to be a legacy or parallel implementation relative to the Python gateway.
• gateway/app/middleware/auth.py
• gateway/app/db/history.py
• gateway/app/audit/logger.py
• backend/server.js
• backend/config/supabase.js
Observability and Operations
Request context, logging, and metrics middleware instrument gateway traffic. Prometheus scrapes metrics and Grafana provisions a gateway dashboard. Runtime configuration, secrets, database/provider endpoints, and policies are externalized rather than embedded in request handlers.
• gateway/app/middleware/metrics.py
• gateway/app/observability/metrics.py
• prometheus/prometheus.yml
• grafana/dashboards/gateway.json
Main entry points: main.py Gateway application · masker.py Masker · router.py Provider router · engine.py Compliance engine
Components 20
Client
- React/Vite client · Login, protected analysis, and history UI.
frontend/src/main.jsx - Client routes
frontend/src/App.jsx - Analysis view
frontend/src/pages/Analyze.jsx
Python Gateway
- Gateway application · Registers API routes, shared dependencies, and middleware.
gateway/app/main.py - Chat API
gateway/app/routers/chat.py - Analysis API
gateway/app/routers/analyze.py - Authentication
gateway/app/middleware/auth.py - Request history
gateway/app/db/history.py - Audit logger
gateway/app/audit/logger.py
Compliance Pipeline
- Compliance engine · Runs detection and resolves overlapping findings.
gateway/app/compliance/engine.py - Masker · Replaces findings before model dispatch.
gateway/app/compliance/masker.py - Rehydration vault · Holds values needed for server-side restoration.
gateway/app/compliance/vault.py - Safe streaming
gateway/app/compliance/streaming.py
LLM Providers
- Provider router · Selects OpenAI, Gemini, Claude, DeepSeek, or Ollama implementations.
gateway/app/providers/router.py - Provider interface
gateway/app/providers/base.py
Operations
- Metrics middleware
gateway/app/middleware/metrics.py - Prometheus · Scrapes gateway metrics.
prometheus/prometheus.yml - Gateway dashboard
grafana/dashboards/gateway.json
Legacy Node Stack
Parallel or legacy React–Express deployment path.
- Express backend · Original analysis and log route implementation.
backend/server.js - Supabase
backend/config/supabase.js
Connections 21
- React/Vite client → Client routes: boots
- Client routes → Analysis view: renders
- Analysis view → Gateway application: API requests
- Gateway application → Authentication: protects routes
- Gateway application → Chat API: registers
- Gateway application → Analysis API: registers
- Chat API → Compliance engine: submits text
- Analysis API → Compliance engine: submits text
- Compliance engine → Masker: findings
- Masker → Rehydration vault: stores reversible values
- Masker → Provider router: masked prompt
- Provider router → Provider interface: dispatches through
- Provider router → Safe streaming: streamed responses
- Safe streaming → Rehydration vault: restores authorized values
- Gateway application → Request history: records requests
- Gateway application → Audit logger: writes compliance events
- Gateway application → Metrics middleware: instruments traffic
- Prometheus → Metrics middleware: scrapes
- Gateway dashboard → Prometheus: queries
- React/Vite client → Express backend: legacy API path
- Express backend → Supabase: stores logs and users