# tayyaba-amin/privacyguard architecture

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

- Interactive diagram: https://gitdiagram.com/tayyaba-amin/privacyguard
- Repository: https://github.com/tayyaba-amin/privacyguard

## Overview

PrivacyGuard is a web app for scanning text and images for sensitive information, explaining sharing risk, producing protected copies, and rescanning them. The user workflow runs from the React interface through API calls to in-memory server routes: OCR for images, deterministic detection, optional AI commentary on existing findings, and risk scoring or redaction. The graph preserves the documented image and text branches, session-only scan metadata, and optional Featherless integration. Some route and UI links are documented or indexed but their full implementations were not sampled; those links are dashed where source evidence is limited.

Main entry points: [`apps/server/src/ai/service.ts`](https://github.com/tayyaba-amin/privacyguard/blob/main/apps/server/src/ai/service.ts) (Context orchestration), [`apps/server/src/app.ts`](https://github.com/tayyaba-amin/privacyguard/blob/main/apps/server/src/app.ts) (Express API), [`apps/server/src/routes/rescan-image.ts`](https://github.com/tayyaba-amin/privacyguard/blob/main/apps/server/src/routes/rescan-image.ts) (Image rescan), [`apps/web/src/lib/api.ts`](https://github.com/tayyaba-amin/privacyguard/blob/main/apps/web/src/lib/api.ts) (API client)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Web application"]
  node_webapp["React interface<br/>[App.tsx]"]
  node_api_client["API client<br/>[api.ts]"]
  node_finding_view["Finding and risk view models<br/>[findings.ts]"]
  node_results["Results and protection panels<br/>[ResultsPanel.tsx]"]
  node_dashboard["Session dashboard<br/>[Dashboard.tsx]"]
end

subgraph group_api["API routes"]
  node_api_app["Express API<br/>[app.ts]"]
  node_text_analyze["Text analysis<br/>[analyze.ts]"]
  node_image_analyze["Image analysis<br/>[analyze-image.ts]"]
  node_text_protect["Text protection<br/>[protect.ts]"]
  node_image_protect["Image protection<br/>[protect-image.ts]"]
  node_text_rescan["Text rescan<br/>[rescan.ts]"]
  node_image_rescan["Image rescan<br/>[rescan-image.ts]"]
end

subgraph group_analysis["Detection and assessment"]
  node_detection["Sensitive-data detectors<br/>[index.ts]"]
  node_ocr["Image OCR<br/>[ocr.ts]"]
  node_risk["Risk scoring<br/>[score.ts]"]
end

subgraph group_protection["Protection and verification"]
  node_text_redact["Text redaction<br/>[redact.ts]"]
  node_image_redact["Image redaction<br/>[protect.ts]"]
end

subgraph group_context["Optional AI context"]
  node_ai_service["Context orchestration<br/>[service.ts]"]
  node_ai_context["Finding-centered context<br/>[context.ts]"]
  node_ai_prompt["Prompt construction<br/>[prompt.ts]"]
  node_ai_schema["Model response validation<br/>[schema.ts]"]
  node_featherless["Featherless provider<br/>[featherless.ts]"]
end

node_user(("User"))
node_provider_service{{"Featherless API"}}

node_user -->|"uses"| node_webapp
node_webapp -->|"requests"| node_api_client
node_webapp -->|"formats findings"| node_finding_view
node_webapp -.->|"renders"| node_results
node_webapp -.->|"shows session metadata"| node_dashboard
node_api_client -->|"calls API"| node_api_app
node_api_app -->|"routes"| node_text_analyze
node_api_app -->|"routes"| node_image_analyze
node_api_app -->|"routes"| node_text_protect
node_api_app -->|"routes"| node_image_protect
node_api_app -->|"routes"| node_text_rescan
node_api_app -->|"routes"| node_image_rescan
node_text_analyze -.->|"detects"| node_detection
node_text_analyze -.->|"scores findings"| node_risk
node_image_analyze -->|"extracts text"| node_ocr
node_image_analyze -->|"detects"| node_detection
node_image_analyze -->|"scores findings"| node_risk
node_text_analyze -.->|"adds context"| node_ai_service
node_image_analyze -->|"adds context"| node_ai_service
node_text_protect -.->|"finds spans"| node_detection
node_text_protect -.->|"redacts text"| node_text_redact
node_image_protect -->|"finds spans"| node_detection
node_image_protect -.->|"reads image"| node_ocr
node_image_protect -->|"creates protected copy"| node_image_redact
node_text_rescan -.->|"checks content"| node_detection
node_text_rescan -.->|"scores findings"| node_risk
node_image_rescan -.->|"extracts text"| node_ocr
node_image_rescan -.->|"checks content"| node_detection
node_image_rescan -.->|"scores findings"| node_risk
node_text_rescan -.->|"adds context"| node_ai_service
node_image_rescan -.->|"adds context"| node_ai_service
node_ai_service -->|"builds batches"| node_ai_context
node_ai_service -->|"builds prompt"| node_ai_prompt
node_ai_service -->|"validates response"| node_ai_schema
node_ai_service -.->|"requests completion"| node_featherless
node_featherless -.->|"calls provider"| node_provider_service
node_text_protect -.->|"returns protected copy"| node_api_client
node_image_protect -.->|"returns protected image"| node_api_client
node_api_client -.->|"submits protected text"| node_text_rescan
node_api_client -.->|"submits protected image"| node_image_rescan

click node_webapp "https://github.com/tayyaba-amin/privacyguard/blob/main/apps/web/src/App.tsx"
click node_api_client "https://github.com/tayyaba-amin/privacyguard/blob/main/apps/web/src/lib/api.ts"
click node_finding_view "https://github.com/tayyaba-amin/privacyguard/blob/main/apps/web/src/lib/findings.ts"
click node_results "https://github.com/tayyaba-amin/privacyguard/blob/main/apps/web/src/components/ResultsPanel.tsx"
click node_dashboard "https://github.com/tayyaba-amin/privacyguard/blob/main/apps/web/src/components/Dashboard.tsx"
click node_api_app "https://github.com/tayyaba-amin/privacyguard/blob/main/apps/server/src/app.ts"
click node_text_analyze "https://github.com/tayyaba-amin/privacyguard/blob/main/apps/server/src/routes/analyze.ts"
click node_image_analyze "https://github.com/tayyaba-amin/privacyguard/blob/main/apps/server/src/routes/analyze-image.ts"
click node_text_protect "https://github.com/tayyaba-amin/privacyguard/blob/main/apps/server/src/routes/protect.ts"
click node_image_protect "https://github.com/tayyaba-amin/privacyguard/blob/main/apps/server/src/routes/protect-image.ts"
click node_text_rescan "https://github.com/tayyaba-amin/privacyguard/blob/main/apps/server/src/routes/rescan.ts"
click node_image_rescan "https://github.com/tayyaba-amin/privacyguard/blob/main/apps/server/src/routes/rescan-image.ts"
click node_detection "https://github.com/tayyaba-amin/privacyguard/blob/main/apps/server/src/detection/index.ts"
click node_ocr "https://github.com/tayyaba-amin/privacyguard/blob/main/apps/server/src/image/ocr.ts"
click node_risk "https://github.com/tayyaba-amin/privacyguard/blob/main/apps/server/src/risk/score.ts"
click node_text_redact "https://github.com/tayyaba-amin/privacyguard/blob/main/apps/server/src/protection/redact.ts"
click node_image_redact "https://github.com/tayyaba-amin/privacyguard/blob/main/apps/server/src/image/protect.ts"
click node_ai_service "https://github.com/tayyaba-amin/privacyguard/blob/main/apps/server/src/ai/service.ts"
click node_ai_context "https://github.com/tayyaba-amin/privacyguard/blob/main/apps/server/src/ai/context.ts"
click node_ai_prompt "https://github.com/tayyaba-amin/privacyguard/blob/main/apps/server/src/ai/prompt.ts"
click node_ai_schema "https://github.com/tayyaba-amin/privacyguard/blob/main/apps/server/src/ai/schema.ts"
click node_featherless "https://github.com/tayyaba-amin/privacyguard/blob/main/apps/server/src/ai/featherless.ts"

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_webapp,node_api_client,node_finding_view,node_results,node_dashboard,node_user toneBlue
class node_api_app,node_text_analyze,node_image_analyze,node_text_protect,node_image_protect,node_text_rescan,node_image_rescan toneAmber
class node_detection,node_ocr,node_risk,node_provider_service toneMint
class node_text_redact,node_image_redact toneRose
class node_ai_service,node_ai_context,node_ai_prompt,node_ai_schema,node_featherless toneIndigo
```

## Components

### Web application

- [React interface](https://github.com/tayyaba-amin/privacyguard/blob/main/apps/web/src/App.tsx): `apps/web/src/App.tsx`
- [API client](https://github.com/tayyaba-amin/privacyguard/blob/main/apps/web/src/lib/api.ts): `apps/web/src/lib/api.ts`
- [Finding and risk view models](https://github.com/tayyaba-amin/privacyguard/blob/main/apps/web/src/lib/findings.ts): `apps/web/src/lib/findings.ts`
- [Results and protection panels](https://github.com/tayyaba-amin/privacyguard/blob/main/apps/web/src/components/ResultsPanel.tsx): `apps/web/src/components/ResultsPanel.tsx`
- [Session dashboard](https://github.com/tayyaba-amin/privacyguard/blob/main/apps/web/src/components/Dashboard.tsx): `apps/web/src/components/Dashboard.tsx`

### API routes

- [Express API](https://github.com/tayyaba-amin/privacyguard/blob/main/apps/server/src/app.ts): `apps/server/src/app.ts`
- [Text analysis](https://github.com/tayyaba-amin/privacyguard/blob/main/apps/server/src/routes/analyze.ts): `apps/server/src/routes/analyze.ts`
- [Image analysis](https://github.com/tayyaba-amin/privacyguard/blob/main/apps/server/src/routes/analyze-image.ts): `apps/server/src/routes/analyze-image.ts`
- [Text protection](https://github.com/tayyaba-amin/privacyguard/blob/main/apps/server/src/routes/protect.ts): `apps/server/src/routes/protect.ts`
- [Image protection](https://github.com/tayyaba-amin/privacyguard/blob/main/apps/server/src/routes/protect-image.ts): `apps/server/src/routes/protect-image.ts`
- [Text rescan](https://github.com/tayyaba-amin/privacyguard/blob/main/apps/server/src/routes/rescan.ts): `apps/server/src/routes/rescan.ts`
- [Image rescan](https://github.com/tayyaba-amin/privacyguard/blob/main/apps/server/src/routes/rescan-image.ts): `apps/server/src/routes/rescan-image.ts`

### Detection and assessment

- [Sensitive-data detectors](https://github.com/tayyaba-amin/privacyguard/blob/main/apps/server/src/detection/index.ts): `apps/server/src/detection/index.ts`
- [Image OCR](https://github.com/tayyaba-amin/privacyguard/blob/main/apps/server/src/image/ocr.ts): `apps/server/src/image/ocr.ts`
- [Risk scoring](https://github.com/tayyaba-amin/privacyguard/blob/main/apps/server/src/risk/score.ts): `apps/server/src/risk/score.ts`

### Protection and verification

- [Text redaction](https://github.com/tayyaba-amin/privacyguard/blob/main/apps/server/src/protection/redact.ts): `apps/server/src/protection/redact.ts`
- [Image redaction](https://github.com/tayyaba-amin/privacyguard/blob/main/apps/server/src/image/protect.ts): `apps/server/src/image/protect.ts`

### Optional AI context

- [Context orchestration](https://github.com/tayyaba-amin/privacyguard/blob/main/apps/server/src/ai/service.ts): `apps/server/src/ai/service.ts`
- [Finding-centered context](https://github.com/tayyaba-amin/privacyguard/blob/main/apps/server/src/ai/context.ts): `apps/server/src/ai/context.ts`
- [Prompt construction](https://github.com/tayyaba-amin/privacyguard/blob/main/apps/server/src/ai/prompt.ts): `apps/server/src/ai/prompt.ts`
- [Model response validation](https://github.com/tayyaba-amin/privacyguard/blob/main/apps/server/src/ai/schema.ts): `apps/server/src/ai/schema.ts`
- [Featherless provider](https://github.com/tayyaba-amin/privacyguard/blob/main/apps/server/src/ai/featherless.ts): `apps/server/src/ai/featherless.ts`

### Other components

- **User**
- **Featherless API**

## Connections

- User → React interface: uses
- React interface → API client: requests (evidence: `apps/web/src/App.tsx`)
- React interface → Finding and risk view models: formats findings (evidence: `apps/web/src/App.tsx`)
- React interface → Results and protection panels: renders (evidence: `apps/web/src/App.tsx`)
- React interface → Session dashboard: shows session metadata (evidence: `apps/web/src/App.tsx`)
- API client → Express API: calls API (evidence: `apps/web/src/lib/api.ts`)
- Express API → Text analysis: routes (evidence: `apps/server/src/app.ts`)
- Express API → Image analysis: routes (evidence: `apps/server/src/app.ts`)
- Express API → Text protection: routes (evidence: `apps/server/src/app.ts`)
- Express API → Image protection: routes (evidence: `apps/server/src/app.ts`)
- Express API → Text rescan: routes (evidence: `apps/server/src/app.ts`)
- Express API → Image rescan: routes (evidence: `apps/server/src/app.ts`)
- Text analysis → Sensitive-data detectors: detects
- Text analysis → Risk scoring: scores findings
- Image analysis → Image OCR: extracts text (evidence: `apps/server/src/routes/analyze-image.ts`)
- Image analysis → Sensitive-data detectors: detects (evidence: `apps/server/src/routes/analyze-image.ts`)
- Image analysis → Risk scoring: scores findings (evidence: `apps/server/src/routes/analyze-image.ts`)
- Text analysis → Context orchestration: adds context
- Image analysis → Context orchestration: adds context (evidence: `apps/server/src/routes/analyze-image.ts`)
- Text protection → Sensitive-data detectors: finds spans
- Text protection → Text redaction: redacts text
- Image protection → Sensitive-data detectors: finds spans (evidence: `apps/server/src/routes/protect-image.ts`)
- Image protection → Image OCR: reads image (evidence: `apps/server/src/routes/protect-image.ts`)
- Image protection → Image redaction: creates protected copy (evidence: `apps/server/src/routes/protect-image.ts`)
- Text rescan → Sensitive-data detectors: checks content
- Text rescan → Risk scoring: scores findings
- Image rescan → Image OCR: extracts text (evidence: `apps/server/src/routes/rescan-image.ts`)
- Image rescan → Sensitive-data detectors: checks content (evidence: `apps/server/src/routes/rescan-image.ts`)
- Image rescan → Risk scoring: scores findings (evidence: `apps/server/src/routes/rescan-image.ts`)
- Text rescan → Context orchestration: adds context
- Image rescan → Context orchestration: adds context (evidence: `apps/server/src/routes/rescan-image.ts`)
- Context orchestration → Finding-centered context: builds batches (evidence: `apps/server/src/ai/service.ts`)
- Context orchestration → Prompt construction: builds prompt (evidence: `apps/server/src/ai/service.ts`)
- Context orchestration → Model response validation: validates response (evidence: `apps/server/src/ai/service.ts`)
- Context orchestration → Featherless provider: requests completion (evidence: `apps/server/src/ai/index.ts`)
- Featherless provider → Featherless API: calls provider
- Text protection → API client: returns protected copy (evidence: `apps/web/src/lib/api.ts`)
- Image protection → API client: returns protected image (evidence: `apps/web/src/lib/api.ts`)
- API client → Text rescan: submits protected text (evidence: `apps/web/src/lib/api.ts`)
- API client → Image rescan: submits protected image (evidence: `apps/web/src/lib/api.ts`)
