# arpitahaque/phi-guard architecture

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

- Interactive diagram: https://gitdiagram.com/arpitahaque/phi-guard
- Repository: https://github.com/arpitahaque/phi-guard

## Overview

PHI-Guard is a synthetic-clinic security and compliance toolkit. Its main workflow initializes a clinic database, simulates role-controlled activity that is audit-logged, then detects anomalies and produces a Safe Harbor research export and compliance report. Separate commands verify audit integrity and evaluate the note scrubber. The excerpts show the CLI orchestration and key module calls; other module behavior is included only where the README documents it, so no external storage or integrations are inferred.

Main entry points: [`phiguard/cli.py`](https://github.com/arpitahaque/phi-guard/blob/main/phiguard/cli.py) (Command dispatcher), [`phiguard/schema.py`](https://github.com/arpitahaque/phi-guard/blob/main/phiguard/schema.py) (Clinic database), [`phiguard/report.py`](https://github.com/arpitahaque/phi-guard/blob/main/phiguard/report.py) (Compliance report), [`phiguard/deidentify.py`](https://github.com/arpitahaque/phi-guard/blob/main/phiguard/deidentify.py) (Research export)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interface["Command interface"]
  node_module_entry["Module entry<br/>[__main__.py]"]
  node_cli["Command dispatcher<br/>[cli.py]"]
end

subgraph group_clinic["Clinic access"]
  node_schema["Clinic schema<br/>[schema.py]"]
  node_clinic_db[("Clinic database<br/>[schema.py]")]
  node_simulator["Synthetic activity<br/>[synthetic.py]"]
  node_access["Role access control<br/>[access.py]"]
end

subgraph group_oversight["Audit oversight"]
  node_audit["Hash-chain audit<br/>[audit.py]"]
  node_anomaly["Anomaly detection<br/>[anomaly.py]"]
end

subgraph group_privacy["Privacy and reporting"]
  node_deidentify["Research export<br/>[deidentify.py]"]
  node_scrubber["Text scrubber<br/>[deidentify.py]"]
  node_evaluation["Scrubber evaluation<br/>[evaluation.py]"]
  node_report["Compliance report<br/>[report.py]"]
end

node_operator(("CLI user"))

node_operator -->|"runs module"| node_module_entry
node_module_entry -->|"calls main"| node_cli
node_operator -->|"runs command"| node_cli
node_cli -->|"initializes"| node_schema
node_schema -->|"creates schema"| node_clinic_db
node_cli -->|"seeds and simulates"| node_simulator
node_simulator -->|"requests records"| node_access
node_access -->|"reads and writes"| node_clinic_db
node_access -->|"logs events"| node_audit
node_audit -->|"appends and verifies"| node_clinic_db
node_cli -->|"verifies chain"| node_audit
node_cli -->|"detects events"| node_anomaly
node_anomaly -->|"reads audit trail"| node_clinic_db
node_cli -->|"exports dataset"| node_deidentify
node_deidentify -->|"reads clinic records"| node_clinic_db
node_deidentify -->|"scrubs note text"| node_scrubber
node_cli -->|"runs evaluation"| node_evaluation
node_evaluation -->|"scores patterns"| node_scrubber
node_cli -->|"builds report"| node_report
node_report -->|"verifies chain"| node_audit
node_report -->|"summarizes findings"| node_anomaly
node_report -->|"checks export"| node_deidentify

click node_module_entry "https://github.com/arpitahaque/phi-guard/blob/main/phiguard/__main__.py"
click node_cli "https://github.com/arpitahaque/phi-guard/blob/main/phiguard/cli.py"
click node_schema "https://github.com/arpitahaque/phi-guard/blob/main/phiguard/schema.py"
click node_clinic_db "https://github.com/arpitahaque/phi-guard/blob/main/phiguard/schema.py"
click node_simulator "https://github.com/arpitahaque/phi-guard/blob/main/phiguard/synthetic.py"
click node_access "https://github.com/arpitahaque/phi-guard/blob/main/phiguard/access.py"
click node_audit "https://github.com/arpitahaque/phi-guard/blob/main/phiguard/audit.py"
click node_anomaly "https://github.com/arpitahaque/phi-guard/blob/main/phiguard/anomaly.py"
click node_deidentify "https://github.com/arpitahaque/phi-guard/blob/main/phiguard/deidentify.py"
click node_scrubber "https://github.com/arpitahaque/phi-guard/blob/main/phiguard/deidentify.py"
click node_evaluation "https://github.com/arpitahaque/phi-guard/blob/main/phiguard/evaluation.py"
click node_report "https://github.com/arpitahaque/phi-guard/blob/main/phiguard/report.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_module_entry,node_cli,node_operator toneBlue
class node_schema,node_clinic_db,node_simulator,node_access toneAmber
class node_audit,node_anomaly toneMint
class node_deidentify,node_scrubber,node_evaluation,node_report toneRose
```

## Components

### Command interface

- [Module entry](https://github.com/arpitahaque/phi-guard/blob/main/phiguard/__main__.py): `phiguard/__main__.py`
- [Command dispatcher](https://github.com/arpitahaque/phi-guard/blob/main/phiguard/cli.py): `phiguard/cli.py`

### Clinic access

- [Clinic schema](https://github.com/arpitahaque/phi-guard/blob/main/phiguard/schema.py): `phiguard/schema.py`
- [Clinic database](https://github.com/arpitahaque/phi-guard/blob/main/phiguard/schema.py): `phiguard/schema.py`
- [Synthetic activity](https://github.com/arpitahaque/phi-guard/blob/main/phiguard/synthetic.py): `phiguard/synthetic.py`
- [Role access control](https://github.com/arpitahaque/phi-guard/blob/main/phiguard/access.py): `phiguard/access.py`

### Audit oversight

- [Hash-chain audit](https://github.com/arpitahaque/phi-guard/blob/main/phiguard/audit.py): `phiguard/audit.py`
- [Anomaly detection](https://github.com/arpitahaque/phi-guard/blob/main/phiguard/anomaly.py): `phiguard/anomaly.py`

### Privacy and reporting

- [Research export](https://github.com/arpitahaque/phi-guard/blob/main/phiguard/deidentify.py): `phiguard/deidentify.py`
- [Text scrubber](https://github.com/arpitahaque/phi-guard/blob/main/phiguard/deidentify.py): `phiguard/deidentify.py`
- [Scrubber evaluation](https://github.com/arpitahaque/phi-guard/blob/main/phiguard/evaluation.py): `phiguard/evaluation.py`
- [Compliance report](https://github.com/arpitahaque/phi-guard/blob/main/phiguard/report.py): `phiguard/report.py`

### Other components

- **CLI user**

## Connections

- CLI user → Module entry: runs module (evidence: `README.md`)
- Module entry → Command dispatcher: calls main (evidence: `phiguard/__main__.py`)
- CLI user → Command dispatcher: runs command (evidence: `README.md`)
- Command dispatcher → Clinic schema: initializes (evidence: `phiguard/cli.py`)
- Clinic schema → Clinic database: creates schema (evidence: `phiguard/schema.py`)
- Command dispatcher → Synthetic activity: seeds and simulates (evidence: `phiguard/cli.py`)
- Synthetic activity → Role access control: requests records (evidence: `phiguard/synthetic.py`)
- Role access control → Clinic database: reads and writes (evidence: `phiguard/access.py`)
- Role access control → Hash-chain audit: logs events (evidence: `phiguard/access.py`)
- Hash-chain audit → Clinic database: appends and verifies (evidence: `phiguard/audit.py`)
- Command dispatcher → Hash-chain audit: verifies chain (evidence: `phiguard/cli.py`)
- Command dispatcher → Anomaly detection: detects events (evidence: `phiguard/cli.py`)
- Anomaly detection → Clinic database: reads audit trail (evidence: `phiguard/anomaly.py`)
- Command dispatcher → Research export: exports dataset (evidence: `phiguard/cli.py`)
- Research export → Clinic database: reads clinic records (evidence: `phiguard/deidentify.py`)
- Research export → Text scrubber: scrubs note text (evidence: `phiguard/deidentify.py`)
- Command dispatcher → Scrubber evaluation: runs evaluation (evidence: `phiguard/cli.py`)
- Scrubber evaluation → Text scrubber: scores patterns (evidence: `phiguard/evaluation.py`)
- Command dispatcher → Compliance report: builds report (evidence: `phiguard/cli.py`)
- Compliance report → Hash-chain audit: verifies chain (evidence: `phiguard/report.py`)
- Compliance report → Anomaly detection: summarizes findings (evidence: `phiguard/report.py`)
- Compliance report → Research export: checks export (evidence: `phiguard/report.py`)
