How hariharjeevan/pii-personally-identifiable-information-detection-redaction-tool works
1. This repository is a single Python desktop application for PII detection and redaction in PDF documents. It is not structured as a server or distributed system; the architecture is centered on a local processing pipeline with a GUI front end.
2. The main user-facing boundary appears to be gui.py, which likely handles file selection, parameter input, progress display, and result visualization. This is the presentation layer and should be drawn as the entry point for human interaction.
3. main.py is the likely application bootstrap/orchestration layer. It probably wires the GUI to the document-processing functions, coordinating the flow from input PDF to detected/redacted output and any reporting.
4. The core business capability is a PII processing pipeline described in the README:
- detect PII such as Aadhaar, PAN, email addresses, and phone numbers,
- redact matched content,
- optionally create a searchable version of scanned PDFs using OCR,
- produce accuracy measurements/visualizations.
5. The document-handling subsystem is PDF-centric and likely depends on multiple libraries for different extraction modes:
- PyMuPDF (fitz) for PDF reading/editing/redaction,
- pdfplumber for text extraction,
- pdf2image for converting pages to images when OCR is needed,
- OpenCV (cv2) and pytesseract for image preprocessing and OCR.
6. Detection is a second major subsystem, using both regex-based rules and presidio-analyzer for NLP-style entity detection. This suggests a hybrid architecture: deterministic pattern matching for known IDs plus analyzer-driven detection for broader PII types.
7. Redaction is a separate step from detection. The flow is likely: extract text / OCR → identify PII spans → map spans back to page coordinates → apply redaction marks to the PDF → save sanitized output. The important architectural boundary here is between text analysis and PDF rendering/editing.
8. The README also mentions accuracy reporting and visualization via matplotlib. That makes reporting another distinct subsystem, probably consuming detected counts and expected counts to generate charts or summaries for the user after processing.
9. The presence of encryption.py and decryption.py indicates an additional security-related utility layer. From the file tree alone, these appear to be separate modules rather than part of the main redaction pipeline, so an architecture diagram should show them as auxiliary services/functions used for protecting or restoring sensitive artifacts if needed.
10. The repository has a small, modular structure: UI layer (gui.py), orchestration (main.py), document/OCR processing, PII detection, redaction/output generation, and security utilities (encryption.py, decryption.py). There is no indication of persistent storage, external APIs, or cloud dependencies; all processing appears to happen locally in-process.
11. The key runtime constraint is Python 3.11+, and the external dependencies materially shape the design: PDF libraries for structure-aware editing, OCR libraries for scanned inputs, Presidio for entity recognition, and Matplotlib for post-run analytics. A good diagram should show these as the technical backend behind the local application flow.
Main entry points: main.py Main · gui.py GUI · encryption.py Encrypt · decryption.py Decrypt
Components 19
Application
User-facing desktop app and entry orchestration
Processing
Document analysis, redaction, OCR, and reporting
- PDF Flow · End-to-end document processing flow from input to sanitized output
- Extract · Reads PDF text and page content from mixed document sources
- OCR · Turns scanned pages into searchable text
- Detect PII · Finds sensitive entities using rules and NLP detection
- Regex Rules · Deterministic detection for IDs, emails, and phone numbers
- Presidio · Broader entity recognition for PII detection
- Map Spans · Maps detected text spans back to page coordinates
- Redact · Applies redaction marks and removes sensitive content
- Report · Produces accuracy summaries and visualizations
- PyMuPDF · PDF reading, editing, and redaction library
- pdfplumber · PDF text extraction helper
- pdf2image · Converts PDF pages to images for OCR
- OpenCV · Image preprocessing before OCR
- Tesseract · OCR engine for scanned document text
- Matplotlib · Visualization backend for run summaries
Connections 19
- GUI → Main: launches · The GUI hands control to the application bootstrap
- Main → PDF Flow: orchestrates · Main coordinates the processing pipeline
- PDF Flow → Extract: starts · Initial document ingestion step
- PDF Flow → OCR: branches · Routes scanned pages into OCR when needed
- Extract → pdfplumber: uses · Text extraction backend
- Extract → PyMuPDF: uses · PDF structure and page access
- OCR → pdf2image: uses · Render pages to images for OCR
- OCR → OpenCV: preprocesses · Image cleanup before recognition
- OCR → Tesseract: recognizes · OCR text extraction
- PDF Flow → Detect PII: feeds · Extracted text is analyzed for PII
- Detect PII → Regex Rules: matches · Rule-based entity detection
- Detect PII → Presidio: analyzes · NLP-style entity detection
- Detect PII → Map Spans: outputs · Detected entities become page-aligned spans
- Map Spans → Redact: drives · Coordinate mapping guides PDF redaction
- Redact → PyMuPDF: applies · Redaction and output writing
- PDF Flow → Report: summarizes · Run results are turned into metrics and charts
- Report → Matplotlib: renders · Chart generation backend
- Main → Encrypt: optional · Optional protection of outputs or artifacts
- Main → Decrypt: optional · Optional restoration of protected artifacts