# kshruthii/pii-detection-and-privacy-protection-system architecture

> Architecture diagram of the GitHub repository kshruthii/pii-detection-and-privacy-protection-system, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-06). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/kshruthii/pii-detection-and-privacy-protection-system
- Repository: https://github.com/kshruthii/pii-detection-and-privacy-protection-system

## Overview

This is a local, policy-driven privacy proxy for unstructured objects. A client authenticates, uploads an object, and the proxy stores it before triggering Presidio analysis and saving PII spans. On retrieval, the verified identity selects a policy; the proxy sends the object, spans’ lookup key, and policy to the anonymizer, which returns transformed bytes without changing the stored original. Separate branches provide admin policy management and guarded LLM chat. The README documents the overall flow; several internal links are supported by excerpts, while unsampled implementation details are not inferred.

Main entry points: [`proxy-server/app.py`](https://github.com/kshruthii/pii-detection-and-privacy-protection-system/blob/main/proxy-server/app.py) (HTTP proxy), [`consumer_analyzer/pii_analyser/pii_analyser.py`](https://github.com/kshruthii/pii-detection-and-privacy-protection-system/blob/main/consumer_analyzer/pii_analyser/pii_analyser.py) (PII processor), [`proxy-server/auth.py`](https://github.com/kshruthii/pii-detection-and-privacy-protection-system/blob/main/proxy-server/auth.py) (JWT authentication), [`proxy-server/policies.py`](https://github.com/kshruthii/pii-detection-and-privacy-protection-system/blob/main/proxy-server/policies.py) (Policy management API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["Proxy and identity"]
  node_proxy["HTTP proxy<br/>[app.py]"]
  node_auth["JWT authentication<br/>[auth.py]"]
  node_security["Password and JWT helpers<br/>[security.py]"]
end

subgraph group_analysis["PII analysis"]
  node_upload_trigger["Local upload trigger<br/>[kafka_consumer.py]"]
  node_processor["PII processor<br/>[pii_analyser.py]"]
  node_object_reader["Object text reader<br/>[pii_analyser.py]"]
  node_presidio["Presidio analyzer<br/>[pii_analyser.py]"]
end

subgraph group_privacy["Policy and anonymization"]
  node_policy_api["Policy management API<br/>[policies.py]"]
  node_grpc_server["Anonymizer gRPC server<br/>[server.py]"]
  node_grpc_handler["Anonymizer request handler<br/>[handler.py]"]
  node_transformer["Policy transformer<br/>[pii_anonymizer.py]"]
end

subgraph group_state["Local state"]
  node_storage[("Object files<br/>[app.py]")]
  node_pii_metadata[("PII metadata<br/>[pii_analyser.py]")]
  node_policy_store[("Users and policies<br/>[sqlite_db.py]")]
end

subgraph group_llm["LLM protection"]
  node_llm_guard["LLM prompt protection<br/>[app.py]"]
end

node_client(("API client"))
node_ollama["Ollama service"]

node_client -->|"sends requests"| node_proxy
node_proxy -->|"routes auth"| node_auth
node_auth -->|"verifies tokens"| node_security
node_auth -->|"reads credentials"| node_policy_store
node_proxy -->|"reads and writes"| node_storage
node_proxy -->|"triggers analysis"| node_upload_trigger
node_upload_trigger -->|"invokes processing"| node_processor
node_processor -->|"reads object text"| node_object_reader
node_processor -->|"analyzes text"| node_presidio
node_processor -->|"stores spans"| node_pii_metadata
node_proxy -->|"loads user policy"| node_policy_store
node_proxy -->|"sends anonymize request"| node_grpc_server
node_grpc_server -->|"dispatches requests"| node_grpc_handler
node_grpc_handler -->|"reads spans"| node_pii_metadata
node_grpc_handler -->|"applies policy"| node_transformer
node_proxy -->|"routes policy APIs"| node_policy_api
node_policy_api -->|"checks admin role"| node_auth
node_policy_api -->|"updates assignments"| node_policy_store
node_proxy -->|"handles chat"| node_llm_guard
node_llm_guard -->|"detects prompt PII"| node_presidio
node_llm_guard -->|"anonymizes prompt"| node_grpc_server
node_llm_guard -->|"sends protected prompt"| node_ollama

click node_proxy "https://github.com/kshruthii/pii-detection-and-privacy-protection-system/blob/main/proxy-server/app.py"
click node_auth "https://github.com/kshruthii/pii-detection-and-privacy-protection-system/blob/main/proxy-server/auth.py"
click node_security "https://github.com/kshruthii/pii-detection-and-privacy-protection-system/blob/main/security.py"
click node_policy_api "https://github.com/kshruthii/pii-detection-and-privacy-protection-system/blob/main/proxy-server/policies.py"
click node_storage "https://github.com/kshruthii/pii-detection-and-privacy-protection-system/blob/main/proxy-server/app.py"
click node_upload_trigger "https://github.com/kshruthii/pii-detection-and-privacy-protection-system/blob/main/consumer_analyzer/consumer/kafka_consumer.py"
click node_processor "https://github.com/kshruthii/pii-detection-and-privacy-protection-system/blob/main/consumer_analyzer/pii_analyser/pii_analyser.py"
click node_object_reader "https://github.com/kshruthii/pii-detection-and-privacy-protection-system/blob/main/consumer_analyzer/pii_analyser/pii_analyser.py"
click node_presidio "https://github.com/kshruthii/pii-detection-and-privacy-protection-system/blob/main/consumer_analyzer/pii_analyser/pii_analyser.py"
click node_pii_metadata "https://github.com/kshruthii/pii-detection-and-privacy-protection-system/blob/main/consumer_analyzer/pii_analyser/pii_analyser.py"
click node_policy_store "https://github.com/kshruthii/pii-detection-and-privacy-protection-system/blob/main/proxy-server/sqlite_db.py"
click node_grpc_server "https://github.com/kshruthii/pii-detection-and-privacy-protection-system/blob/main/anonymizer/anonymizer/server/server.py"
click node_grpc_handler "https://github.com/kshruthii/pii-detection-and-privacy-protection-system/blob/main/anonymizer/anonymizer/server/handler.py"
click node_transformer "https://github.com/kshruthii/pii-detection-and-privacy-protection-system/blob/main/anonymizer/anonymizer/pii_anonymizer.py"
click node_llm_guard "https://github.com/kshruthii/pii-detection-and-privacy-protection-system/blob/main/proxy-server/app.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_proxy,node_auth,node_security,node_client toneBlue
class node_upload_trigger,node_processor,node_object_reader,node_presidio toneAmber
class node_policy_api,node_grpc_server,node_grpc_handler,node_transformer toneMint
class node_storage,node_pii_metadata,node_policy_store toneRose
class node_llm_guard,node_ollama toneIndigo
```

## Components

### Proxy and identity

- [HTTP proxy](https://github.com/kshruthii/pii-detection-and-privacy-protection-system/blob/main/proxy-server/app.py): `proxy-server/app.py`
- [JWT authentication](https://github.com/kshruthii/pii-detection-and-privacy-protection-system/blob/main/proxy-server/auth.py): `proxy-server/auth.py`
- [Password and JWT helpers](https://github.com/kshruthii/pii-detection-and-privacy-protection-system/blob/main/security.py): `security.py`

### PII analysis

- [Local upload trigger](https://github.com/kshruthii/pii-detection-and-privacy-protection-system/blob/main/consumer_analyzer/consumer/kafka_consumer.py): `consumer_analyzer/consumer/kafka_consumer.py`
- [PII processor](https://github.com/kshruthii/pii-detection-and-privacy-protection-system/blob/main/consumer_analyzer/pii_analyser/pii_analyser.py): `consumer_analyzer/pii_analyser/pii_analyser.py`
- [Object text reader](https://github.com/kshruthii/pii-detection-and-privacy-protection-system/blob/main/consumer_analyzer/pii_analyser/pii_analyser.py): `consumer_analyzer/pii_analyser/pii_analyser.py`
- [Presidio analyzer](https://github.com/kshruthii/pii-detection-and-privacy-protection-system/blob/main/consumer_analyzer/pii_analyser/pii_analyser.py): `consumer_analyzer/pii_analyser/pii_analyser.py`

### Policy and anonymization

- [Policy management API](https://github.com/kshruthii/pii-detection-and-privacy-protection-system/blob/main/proxy-server/policies.py): `proxy-server/policies.py`
- [Anonymizer gRPC server](https://github.com/kshruthii/pii-detection-and-privacy-protection-system/blob/main/anonymizer/anonymizer/server/server.py): `anonymizer/anonymizer/server/server.py`
- [Anonymizer request handler](https://github.com/kshruthii/pii-detection-and-privacy-protection-system/blob/main/anonymizer/anonymizer/server/handler.py): `anonymizer/anonymizer/server/handler.py`
- [Policy transformer](https://github.com/kshruthii/pii-detection-and-privacy-protection-system/blob/main/anonymizer/anonymizer/pii_anonymizer.py): `anonymizer/anonymizer/pii_anonymizer.py`

### Local state

- [Object files](https://github.com/kshruthii/pii-detection-and-privacy-protection-system/blob/main/proxy-server/app.py): `proxy-server/app.py`
- [PII metadata](https://github.com/kshruthii/pii-detection-and-privacy-protection-system/blob/main/consumer_analyzer/pii_analyser/pii_analyser.py): `consumer_analyzer/pii_analyser/pii_analyser.py`
- [Users and policies](https://github.com/kshruthii/pii-detection-and-privacy-protection-system/blob/main/proxy-server/sqlite_db.py): `proxy-server/sqlite_db.py`

### LLM protection

- [LLM prompt protection](https://github.com/kshruthii/pii-detection-and-privacy-protection-system/blob/main/proxy-server/app.py): `proxy-server/app.py`

### Other components

- **API client**
- **Ollama service**

## Connections

- API client → HTTP proxy: sends requests (evidence: `README.md`)
- HTTP proxy → JWT authentication: routes auth (evidence: `proxy-server/app.py`)
- JWT authentication → Password and JWT helpers: verifies tokens (evidence: `proxy-server/auth.py`)
- JWT authentication → Users and policies: reads credentials (evidence: `proxy-server/auth.py`)
- HTTP proxy → Object files: reads and writes (evidence: `README.md`)
- HTTP proxy → Local upload trigger: triggers analysis (evidence: `proxy-server/app.py`)
- Local upload trigger → PII processor: invokes processing (evidence: `consumer_analyzer/consumer/kafka_consumer.py`)
- PII processor → Object text reader: reads object text (evidence: `consumer_analyzer/pii_analyser/pii_analyser.py`)
- PII processor → Presidio analyzer: analyzes text (evidence: `consumer_analyzer/pii_analyser/pii_analyser.py`)
- PII processor → PII metadata: stores spans (evidence: `consumer_analyzer/pii_analyser/pii_analyser.py`)
- HTTP proxy → Users and policies: loads user policy (evidence: `README.md`)
- HTTP proxy → Anonymizer gRPC server: sends anonymize request (evidence: `README.md`)
- Anonymizer gRPC server → Anonymizer request handler: dispatches requests (evidence: `anonymizer/anonymizer/server/server.py`)
- Anonymizer request handler → PII metadata: reads spans (evidence: `anonymizer/anonymizer/server/handler.py`)
- Anonymizer request handler → Policy transformer: applies policy (evidence: `anonymizer/anonymizer/server/handler.py`)
- HTTP proxy → Policy management API: routes policy APIs (evidence: `proxy-server/app.py`)
- Policy management API → JWT authentication: checks admin role (evidence: `proxy-server/policies.py`)
- Policy management API → Users and policies: updates assignments (evidence: `proxy-server/policies.py`)
- HTTP proxy → LLM prompt protection: handles chat (evidence: `proxy-server/app.py`)
- LLM prompt protection → Presidio analyzer: detects prompt PII (evidence: `proxy-server/app.py`)
- LLM prompt protection → Anonymizer gRPC server: anonymizes prompt (evidence: `proxy-server/app.py`)
- LLM prompt protection → Ollama service: sends protected prompt (evidence: `README.md`)
