# shivamgoyal03/privydoc architecture

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

- Interactive diagram: https://gitdiagram.com/shivamgoyal03/privydoc
- Repository: https://github.com/shivamgoyal03/privydoc

## Overview

##### Project Type & Purpose
- This is an open-source, on-device document analysis tool (“PrivyDoc”) that processes PDF and DOCX files locally using Microsoft Foundry Local. It provides both a Chainlit-based web UI and a CLI interface, orchestrates a multi-agent AI workflow, and stores results in a local JSON file for audit and export.

##### Main Architectural Components
a. User Interfaces
- Chainlit Web UI (HTTP server on localhost:8000)
- Command-Line Interface (CLI entrypoint)
b. Document Processor
- pdfplumber for PDF extraction
- python-docx for DOCX extraction
- Normalization & text cleaning module
c. Agent Orchestration / AI Engine
- Agent Framework coordinating multiple agents
- Foundry Local SDK executing models (qwen2.5, phi-3.5, phi-4)
- Sub-agents:
– Section Extraction Agent
– Entity Recognition Agent
– Summarization & Sentiment Agent
d. Storage Layer
- Local JSON database (analysis_history.json)
- Document fingerprinting & processing logs
e. Export Module
- Markdown, JSON, CSV serializers
f. External Dependency
- Microsoft Foundry Local runtime & models

##### Component Interactions & Data Flow
- User uploads file via Web UI or invokes CLI → Document Processor extracts raw text → Passes to Agent Orchestration →
1) Section Extraction → 2) Entity Recognition → 3) Summarization & Sentiment →
Results aggregated → Written to analysis_history.json → Web UI retrieves and displays results, offering export.
- In CLI mode, skip Web UI retrieval: Agent results go directly to JSON.

##### Architectural Patterns & Principles
- Pipeline pattern: sequential multi-stage processing.
- Modular agents: separation of concerns (extraction, NER, summarization).
- Local-first, zero-trust: all data stays on disk; no external calls.
- Extensibility: add new agents or export formats by plugging into the framework.

##### Technologies & Frameworks
- Python 3.10+
- pdfplumber, python-docx
- Microsoft Foundry Local SDK (`foundrylocal`)
- Chainlit for UI
- Custom Agent Framework
- JSON file for storage

##### Diagramming Recommendations
- Rounded rectangles for UI components (blue)
- Rectangles for processing modules/agents (green)
User → Processor → Agents → Storage → UI/Export
- Technologies next to each component.
- Agent stages in a container labeled “AI Engine / Agent Framework.”

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Entry Points
    subgraph "Entry Points"
        DOC["Sample Input Document"]:::doc
        UI["Chainlit Web UI"]:::ui
        CLI["Command-Line Interface"]:::ui
    end

    %% Document Processor
    Processor["Document Processor\n(pdfplumber, python-docx,\nnormalization & cleaning)"]:::proc

    %% AI Engine / Agent Framework
    subgraph "AI Engine / Agent Framework"
        SE["Section Extraction Agent"]:::agent
        ER["Entity Recognition Agent"]:::agent
        SS["Summarization & Sentiment Agent"]:::agent
        Foundry["Microsoft Foundry Local SDK"]:::external
    end

    %% Storage Layer
    Storage["Local JSON Database\n(analysis_history.json,\nfingerprinting & logs)"]:::storage

    %% Export Module
    Export["Export Module\n(Markdown, JSON, CSV serializers)"]:::proc

    %% Documentation & License
    Docu["Project Documentation & Usage"]:::external
    License["License Information"]:::external

    %% Flow
    DOC --> Processor
    UI --> Processor
    CLI --> Processor
    Processor --> SE
    SE --> ER
    ER --> SS
    SS --> Storage
    Storage --> Export
    Export --> UI

    %% External Dependencies
    Foundry -.-> SE
    Foundry -.-> ER
    Foundry -.-> SS

    %% Additional Links
    UI --> Docu
    UI --> License

    %% Click Events
    click UI "https://github.com/shivamgoyal03/privydoc/blob/main/multi_agent_doc_analysis.py"
    click CLI "https://github.com/shivamgoyal03/privydoc/blob/main/multi_agent_doc_analysis.py"
    click Processor "https://github.com/shivamgoyal03/privydoc/blob/main/multi_agent_doc_analysis.py"
    click SE "https://github.com/shivamgoyal03/privydoc/blob/main/multi_agent_doc_analysis.py"
    click ER "https://github.com/shivamgoyal03/privydoc/blob/main/multi_agent_doc_analysis.py"
    click SS "https://github.com/shivamgoyal03/privydoc/blob/main/multi_agent_doc_analysis.py"
    click Storage "https://github.com/shivamgoyal03/privydoc/blob/main/multi_agent_doc_analysis.py"
    click Export "https://github.com/shivamgoyal03/privydoc/blob/main/multi_agent_doc_analysis.py"
    click Foundry "https://github.com/shivamgoyal03/privydoc/blob/main/requirements.txt"
    click DOC "https://github.com/shivamgoyal03/privydoc/blob/main/Urban_Mobility_Consultation_Briefing_Detailed.docx"
    click Docu "https://github.com/shivamgoyal03/privydoc/blob/main/README.md"
    click License "https://github.com/shivamgoyal03/privydoc/tree/main/LICENSE"

    %% Styles
    classDef ui fill:#D0E1FF,stroke:#333,stroke-width:1px;
    classDef proc fill:#D0FFD8,stroke:#333,stroke-width:1px;
    classDef agent fill:#C8FACC,stroke:#333,stroke-width:1px;
    classDef storage fill:#FFE0B2,stroke:#333,stroke-width:1px;
    classDef external fill:#E0E0E0,stroke:#333,stroke-width:1px;
    classDef doc fill:#FFF3B0,stroke:#333,stroke-width:1px;
```
