# soumadeep46/sarvadrishthi architecture

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

- Interactive diagram: https://gitdiagram.com/soumadeep46/sarvadrishthi
- Repository: https://github.com/soumadeep46/sarvadrishthi

## Overview

##### Project Type and Purpose
- Sarvadrishti is a full-stack, locally hosted web application built with Streamlit (frontend) and Python (backend) that performs decentralized facial recognition for law enforcement.
- It leverages AI/ML (OpenCV, face_recognition), decentralized storage (IPFS via Pinata Cloud), local CSV for offline operation, and JWT+encryption for security.

##### File Structure
- Top-level files:
- app.py → single entry point combining UI and backend logic
- requirements.txt → Python dependencies (Streamlit, OpenCV, face_recognition, web3/IPFS libraries, JWT, encryption libs)
- .env → secrets (Pinata API key, JWT secret)
- No separate “frontend” or “backend” folders means the app is monolithic but internally layered.

a. Client (Browser/Terminal)
b. Streamlit Frontend (UI layer inside app.py)
c. Authentication Module
- JWT generator/validator
- Encryption/decryption routines
d. Facial Recognition Engine
- Uses OpenCV & face_recognition libraries
e. Data Manager
- Local CSV handler (offline DB)
- IPFS Manager (Pinata API client)
f. External IPFS Network (Pinata Cloud & peer nodes)
g. Hosting Environment
- Local machine/VM/container, offline-capable

##### Relationships & Data Flows
- Client → Streamlit UI: HTTP(S) request to upload/query face image
- Streamlit UI → Auth Module: attach/validate JWT, decrypt payload
- UI → Facial Recognition Engine: pass image for feature extraction
- Recognition Engine ↔ Data Manager:
- Query: CSV first → if not found → Pinata/IPFS API call → IPFS network
- Store new record: encrypt data → send to Pinata → pin on IPFS
- Data Manager → Pinata Cloud → IPFS Network (decentralized storage)
- Recognition results → Streamlit UI → Client

##### Architectural Patterns & Principles
- Layered architecture: UI → Business logic (Auth + Recognition) → Data layer
- Offline-first design: local CSV as fallback for environment with no internet
- Decentralized storage pattern: IPFS for redundancy and security
- Security-first: JWT for access control, end-to-end encryption

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client
    Client["Client (Browser/Terminal)"]:::external

    %% Offline Environment
    subgraph "Offline Environment"
        direction TB
        UI["Streamlit UI\n(app.py)"]:::frontend
        Auth["Authentication Module\n(PyJWT, Encryption)\n(app.py)"]:::logic
        Recognition["Facial Recognition Engine\n(OpenCV + face_recognition)\n(app.py)"]:::logic
        subgraph "Data Manager"
            direction TB
            CSV["Local CSV\n(Cylinder)"]:::storage
            IPFSMgr["IPFS Manager\n(Pinata API)\n(app.py)"]:::storage
        end
        Config["Environment Config\n(.env)"]:::external
        Deps["Python Dependencies\n(requirements.txt)"]:::external
    end

    %% External Services
    Pinata["Pinata Cloud"]:::external
    IPFSNet["IPFS Network\n(Peer Nodes)"]:::external

    %% Flows
    Client -->|"HTTPS Upload/Query"| UI
    UI -->|"Attach/Validate JWT"| Auth
    UI -->|"Pass Image"| Recognition
    Recognition -.->|"Read (offline)"| CSV
    Recognition -->|"If not found"| IPFSMgr
    Recognition -->|"Encrypt & Store"| CSV
    CSV -.->|"Fallback Read"| Recognition
    IPFSMgr -->|"Pin/Fetch"| Pinata
    Pinata -->|"Decentralized Storage"| IPFSNet
    IPFSMgr -->|"Fetch Data"| CSV
    Recognition -->|"Results"| UI
    UI -->|"Display Results"| Client

    %% Click Events
    click UI "https://github.com/soumadeep46/sarvadrishthi/blob/main/app.py"
    click Auth "https://github.com/soumadeep46/sarvadrishthi/blob/main/app.py"
    click Recognition "https://github.com/soumadeep46/sarvadrishthi/blob/main/app.py"
    click CSV "https://github.com/soumadeep46/sarvadrishthi/blob/main/app.py"
    click IPFSMgr "https://github.com/soumadeep46/sarvadrishthi/blob/main/app.py"
    click Config "https://github.com/soumadeep46/sarvadrishthi/blob/main/.env"
    click Deps "https://github.com/soumadeep46/sarvadrishthi/blob/main/requirements.txt"
    click Client "https://github.com/soumadeep46/sarvadrishthi/blob/main/README.md"

    %% Styles
    classDef frontend fill:#FFA500,stroke:#333,stroke-width:1px;
    classDef logic fill:#1E90FF,stroke:#333,stroke-width:1px;
    classDef storage fill:#32CD32,stroke:#333,stroke-width:1px;
    classDef external fill:#A9A9A9,stroke:#333,stroke-width:1px;
    class Client,Pinata,IPFSNet,Config,Deps external;
```
