# shreyasskrishna/pii_masking_with_opik_security architecture

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

- Interactive diagram: https://gitdiagram.com/shreyasskrishna/pii_masking_with_opik_security
- Repository: https://github.com/shreyasskrishna/pii_masking_with_opik_security

## Overview

This is a privacy-preserving customer-support chatbot exposed through a FastAPI service. The main workflow accepts a chat request, masks personal information, obtains a Groq-generated response, restores PII for the user-facing result, and records quality/trace data. The API also offers masked search results, trace-linked feedback, and a report of unmasked conversation history. The excerpts show the API routes and major processing stages, but omit some calls inside the bot; the persistence edge from bot to database is therefore marked unverified.

Main entry points: [`customer_support_ai/customer_support_bot.py`](https://github.com/shreyasskrishna/pii_masking_with_opik_security/blob/main/customer_support_ai/customer_support_bot.py) (Support Bot), [`customer_support_ai/api.py`](https://github.com/shreyasskrishna/pii_masking_with_opik_security/blob/main/customer_support_ai/api.py) (FastAPI Service), [`customer_support_ai/db_manager.py`](https://github.com/shreyasskrishna/pii_masking_with_opik_security/blob/main/customer_support_ai/db_manager.py) (DB Manager)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["API and Reporting"]
  node_api["FastAPI Service<br/>[api.py]"]
  node_search["Masked Search<br/>[api.py]"]
  node_report["History Report<br/>[api.py]"]
  node_feedback["Feedback Route<br/>[api.py]"]
end

subgraph group_processing["Chat Processing"]
  node_bot["Support Bot"]
  node_validation["Input Validation"]
  node_masking["PII Masking"]
  node_prompt["Prompt Construction"]
  node_groq_client["Groq Client"]
  node_unmask["Response Unmasking"]
end

subgraph group_observability["Observability"]
  node_evaluation["Quality Evaluation"]
  node_opik["Opik Tracing"]
end

subgraph group_storage["Conversation Storage"]
  node_db_manager["DB Manager<br/>[db_manager.py]"]
  node_mongo[("MongoDB")]
end

node_user(("Chat User"))
node_groq["Groq LLM"]
node_opik_service["Opik Service"]

node_user -->|"submits chat"| node_api
node_api -->|"routes search"| node_search
node_search -->|"processes message"| node_bot
node_bot -->|"validates input"| node_validation
node_bot -->|"masks PII"| node_masking
node_bot -->|"builds prompt"| node_prompt
node_bot -->|"invokes client"| node_groq_client
node_groq_client -->|"sends request"| node_groq
node_bot -->|"unmasks response"| node_unmask
node_bot -->|"scores response"| node_evaluation
node_bot -->|"records trace"| node_opik
node_feedback -->|"logs feedback"| node_opik_service
node_opik -.->|"exports traces"| node_opik_service
node_api -->|"routes report"| node_report
node_report -->|"reads history"| node_db_manager
node_db_manager -->|"queries and inserts"| node_mongo
node_bot -.->|"persists turns"| node_db_manager

click node_api "https://github.com/shreyasskrishna/pii_masking_with_opik_security/blob/main/customer_support_ai/api.py"
click node_search "https://github.com/shreyasskrishna/pii_masking_with_opik_security/blob/main/customer_support_ai/api.py"
click node_report "https://github.com/shreyasskrishna/pii_masking_with_opik_security/blob/main/customer_support_ai/api.py"
click node_feedback "https://github.com/shreyasskrishna/pii_masking_with_opik_security/blob/main/customer_support_ai/api.py"
click node_bot "https://github.com/shreyasskrishna/pii_masking_with_opik_security/blob/main/customer_support_ai/customer_support_bot.py"
click node_validation "https://github.com/shreyasskrishna/pii_masking_with_opik_security/blob/main/customer_support_ai/customer_support_bot.py"
click node_masking "https://github.com/shreyasskrishna/pii_masking_with_opik_security/blob/main/customer_support_ai/customer_support_bot.py"
click node_prompt "https://github.com/shreyasskrishna/pii_masking_with_opik_security/blob/main/customer_support_ai/customer_support_bot.py"
click node_groq_client "https://github.com/shreyasskrishna/pii_masking_with_opik_security/blob/main/customer_support_ai/customer_support_bot.py"
click node_unmask "https://github.com/shreyasskrishna/pii_masking_with_opik_security/blob/main/customer_support_ai/customer_support_bot.py"
click node_evaluation "https://github.com/shreyasskrishna/pii_masking_with_opik_security/blob/main/customer_support_ai/customer_support_bot.py"
click node_opik "https://github.com/shreyasskrishna/pii_masking_with_opik_security/blob/main/customer_support_ai/customer_support_bot.py"
click node_db_manager "https://github.com/shreyasskrishna/pii_masking_with_opik_security/blob/main/customer_support_ai/db_manager.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_api,node_search,node_report,node_feedback,node_user toneBlue
class node_bot,node_validation,node_masking,node_prompt,node_groq_client,node_unmask toneAmber
class node_evaluation,node_opik toneMint
class node_db_manager,node_mongo toneRose
class node_groq,node_opik_service toneIndigo
```

## Components

### API and Reporting

- [FastAPI Service](https://github.com/shreyasskrishna/pii_masking_with_opik_security/blob/main/customer_support_ai/api.py): `customer_support_ai/api.py`
- [Masked Search](https://github.com/shreyasskrishna/pii_masking_with_opik_security/blob/main/customer_support_ai/api.py): `customer_support_ai/api.py`
- [History Report](https://github.com/shreyasskrishna/pii_masking_with_opik_security/blob/main/customer_support_ai/api.py): `customer_support_ai/api.py`
- [Feedback Route](https://github.com/shreyasskrishna/pii_masking_with_opik_security/blob/main/customer_support_ai/api.py): `customer_support_ai/api.py`

### Chat Processing

- [Support Bot](https://github.com/shreyasskrishna/pii_masking_with_opik_security/blob/main/customer_support_ai/customer_support_bot.py): `customer_support_ai/customer_support_bot.py`
- [Input Validation](https://github.com/shreyasskrishna/pii_masking_with_opik_security/blob/main/customer_support_ai/customer_support_bot.py): `customer_support_ai/customer_support_bot.py`
- [PII Masking](https://github.com/shreyasskrishna/pii_masking_with_opik_security/blob/main/customer_support_ai/customer_support_bot.py): `customer_support_ai/customer_support_bot.py`
- [Prompt Construction](https://github.com/shreyasskrishna/pii_masking_with_opik_security/blob/main/customer_support_ai/customer_support_bot.py): `customer_support_ai/customer_support_bot.py`
- [Groq Client](https://github.com/shreyasskrishna/pii_masking_with_opik_security/blob/main/customer_support_ai/customer_support_bot.py): `customer_support_ai/customer_support_bot.py`
- [Response Unmasking](https://github.com/shreyasskrishna/pii_masking_with_opik_security/blob/main/customer_support_ai/customer_support_bot.py): `customer_support_ai/customer_support_bot.py`

### Observability

- [Quality Evaluation](https://github.com/shreyasskrishna/pii_masking_with_opik_security/blob/main/customer_support_ai/customer_support_bot.py): `customer_support_ai/customer_support_bot.py`
- [Opik Tracing](https://github.com/shreyasskrishna/pii_masking_with_opik_security/blob/main/customer_support_ai/customer_support_bot.py): `customer_support_ai/customer_support_bot.py`

### Conversation Storage

- [DB Manager](https://github.com/shreyasskrishna/pii_masking_with_opik_security/blob/main/customer_support_ai/db_manager.py): `customer_support_ai/db_manager.py`
- **MongoDB**

### Other components

- **Chat User**
- **Groq LLM**
- **Opik Service**

## Connections

- Chat User → FastAPI Service: submits chat (evidence: `customer_support_ai/api.py`)
- FastAPI Service → Masked Search: routes search (evidence: `customer_support_ai/api.py`)
- Masked Search → Support Bot: processes message (evidence: `customer_support_ai/api.py`)
- Support Bot → Input Validation: validates input (evidence: `customer_support_ai/customer_support_bot.py`)
- Support Bot → PII Masking: masks PII (evidence: `customer_support_ai/customer_support_bot.py`)
- Support Bot → Prompt Construction: builds prompt (evidence: `customer_support_ai/customer_support_bot.py`)
- Support Bot → Groq Client: invokes client (evidence: `customer_support_ai/customer_support_bot.py`)
- Groq Client → Groq LLM: sends request (evidence: `customer_support_ai/customer_support_bot.py`)
- Support Bot → Response Unmasking: unmasks response (evidence: `customer_support_ai/customer_support_bot.py`)
- Support Bot → Quality Evaluation: scores response (evidence: `customer_support_ai/customer_support_bot.py`)
- Support Bot → Opik Tracing: records trace (evidence: `customer_support_ai/customer_support_bot.py`)
- Feedback Route → Opik Service: logs feedback (evidence: `customer_support_ai/api.py`)
- Opik Tracing → Opik Service: exports traces
- FastAPI Service → History Report: routes report (evidence: `customer_support_ai/api.py`)
- History Report → DB Manager: reads history (evidence: `customer_support_ai/api.py`)
- DB Manager → MongoDB: queries and inserts (evidence: `customer_support_ai/db_manager.py`)
- Support Bot → DB Manager: persists turns (evidence: `customer_support_ai/customer_support_bot.py`)
