# shiva2410/document_verification architecture

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

- Interactive diagram: https://gitdiagram.com/shiva2410/document_verification
- Repository: https://github.com/shiva2410/document_verification

## Overview

##### Project Type and Purpose
- This is a Python-based open-source library/tool for automated document verification (KYC) using AI/Computer Vision and OCR.
- Its core features are:
- Classify uploaded images into Aadhaar Card, PAN Card, Voter ID Card or Other Documents via a pre-trained RCNN model.
- Extract text content using Tesseract-OCR and Google OCR.
- Provide a ready-to-use library that can be plugged into customer onboarding pipelines.

##### File Structure Analysis
- Top-level files:
- .gitignore, LICENSE, README.md
- Three Python packages (one per document type):
- aadhaar_card/aadhaar_object.py
- pancard/opclass.py
- voter_card/voter_card.py
- No explicit “src” or “tests” directory—each package encapsulates its classification and OCR logic.
- Dependencies and configuration are declared in README; model weights likely loaded at runtime by these modules.

##### Key Components
a. Data Ingestion & Augmentation (Training Pipeline)
- Input: Raw customer document images (Aadhaar, PAN, Voter, Others).
- ImageDataGenerator (Keras) for upsampling: rotation, blurring.
- Dataset Split: training, validation.
b. Model Trainer
- Base RCNN convolutional layers (frozen).
- Custom fully connected layers + dropout.
- Training engine (Keras/TensorFlow backend).
- Model artifacts output (saved weights).
c. Model Evaluation
- Accuracy computation.
- Manual verification loop feeding back corrections.
d. Inference Engine (Library)
- DocumentClassifier core module (abstract): loads model weights.
- Per-document modules:
- aadhaar_object.py
- opclass.py (PAN)
- voter_card.py
- OCR Integrations:
- Local Tesseract
- Google OCR API
- Output: Document type + extracted fields.
e. Client Application / API Layer
- Upstream systems invoke the library (could be a web API, batch script or desktop app).
f. External Services
- Google OCR endpoint
- Possibly a database or message queue (not in file tree but typical in KYC pipelines).

##### Relationships and Interactions
- Training pipeline writes model artifacts to a model store or file system.
- Inference Engine reads model artifacts.
- Inference components call Tesseract and Google OCR, parse results.
- Client Application calls the Inference Engine API and receives classification + text.
- Manual verification feedback can update training data.

##### Architectural Patterns and Design Principles
- Modular design: one Python package per document class.
- Separation of concerns:
- Data augmentation & training
- Model inference
- OCR integration
- Reuse of pre-trained convolutional layers (transfer learning).
- Dependency injection for OCR providers (abstract interface, two implementations).
- Stateless inference library (can be scaled horizontally).

##### Essential Elements
- Clear labels on every component (e.g. “ImageDataGenerator”, “RCNN Trainer”, “aadhaar_object.py”).
- Annotations for key design decisions (e.g. “Frozen conv layers for transfer learning”, “Dropout to prevent overfitting”).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Training Pipeline (Blue)
    subgraph "Training Pipeline" 
        direction TB
        DataIngest["Raw Images\n(Aadhaar, PAN, Voter, Other)"]:::blue
        Augmentor["ImageDataGenerator\n(Keras Augmentation)"]:::blue
        Trainer["RCNN Trainer\n(TensorFlow/Keras)"]:::blue
        Evaluation["Model Evaluation\n(Accuracy & Manual Loop)"]:::blue
        ModelArtifacts["Model Artifacts\n(Weights)"]:::blue
    end

    %% Inference Engine (Green)
    subgraph "Inference Engine\n(DocumentClassifier Library)"
        direction TB
        CoreClassifier["DocumentClassifier\nCore Module"]:::green
        subgraph "Per-Document Modules"
            direction TB
            AadhaarMod["aadhaar_object.py"]:::green
            PANMod["opclass.py"]:::green
            VoterMod["voter_card.py"]:::green
        end
        subgraph "OCR Integration"
            direction TB
            Tesseract["Local Tesseract OCR"]:::green
            GoogleOCR["Google OCR API"]:::green
        end
        Output["Classification + Extracted Fields"]:::green
    end

    %% Client & External (Gray & Orange)
    subgraph "Client Application / API Layer"
        direction TB
        ClientApp["Client App / Web API / Script"]:::gray
    end

    subgraph "External Services"
        direction TB
        GoogleService["Google OCR Endpoint"]:::orange
        ManualVerif["Manual Verification"]:::orange
    end

    %% Connections
    DataIngest -->|"images"| Augmentor
    Augmentor -->|"augmented images"| Trainer
    Trainer -->|"model weights"| ModelArtifacts
    ModelArtifacts -.->|"load weights"| CoreClassifier
    CoreClassifier -->|"route to module"| AadhaarMod
    CoreClassifier -->|"route to module"| PANMod
    CoreClassifier -->|"route to module"| VoterMod
    AadhaarMod -->|"image"| Tesseract
    PANMod -->|"image"| Tesseract
    VoterMod -->|"image"| Tesseract
    AadhaarMod -->|"image"| GoogleOCR
    PANMod -->|"image"| GoogleOCR
    VoterMod -->|"image"| GoogleOCR
    Tesseract -->|"text"| Output
    GoogleOCR -->|"text"| Output
    ClientApp -->|"inference request"| CoreClassifier
    CoreClassifier -->|"classification + text"| ClientApp
    ClientApp -.->|"feedback data"| ManualVerif
    ManualVerif -.->|"corrected labels"| Evaluation
    Evaluation -->|"updated data"| Trainer

    %% Click Events
    click AadhaarMod "https://github.com/shiva2410/document_verification/blob/master/aadhaar_card/aadhaar_object.py"
    click PANMod "https://github.com/shiva2410/document_verification/blob/master/pancard/opclass.py"
    click VoterMod "https://github.com/shiva2410/document_verification/blob/master/voter_card/voter_card.py"
    click README["README.md"] "README.md"

    %% Legend
    subgraph Legend
        direction TB
        L1["Solid → Synchronous Call"]:::legend
        L2["-- dashed → File I/O"]:::legend
        L3["-.-> dot-dash → Async Process"]:::legend
    end

    %% Styling
    classDef blue fill:#D0E6FF,stroke:#0284C7,color:#000
    classDef green fill:#D6F5D6,stroke:#28A745,color:#000
    classDef orange fill:#FFE5B4,stroke:#FF8C00,color:#000
    classDef gray fill:#E0E0E0,stroke:#6B7280,color:#000
    classDef legend fill:#FFF,stroke:#000,color:#000
    class README legend-node
    README["Project Docs\nREADME.md"]:::gray
```
