# saranambiar/nirikshan-sahai architecture

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

- Interactive diagram: https://gitdiagram.com/saranambiar/nirikshan-sahai
- Repository: https://github.com/saranambiar/nirikshan-sahai

## Overview

##### Project Type & Purpose
- Nirikshan SahAI is a **full-stack web application** with integrated **AI/ML pipelines**.
- It uses **Django** as the primary backend framework (apps: aicte_admin, core, inspector, institute, etc.), serves HTML/CSS/JS frontend, orchestrates multiple AI services (document analysis, image inspection, anomaly detection, GenAI reporting), and offers REST endpoints via **FastAPI**.

##### File Structure
– Top-level “inspection_system” directory: the Django project (settings, URLs, WSGI/ASGI).
– Django apps:
- aicte_admin – admin dashboard and controls
- inspector – inspector‐specific views & forms
- institute – institute‐specific views & forms
- core – shared models, views, URLs
– “templates” and “static” directories: frontend assets (HTML, CSS).
– “media”: file uploads (documents, images, reports).
– Standalone scripts and notebooks:
- GenAI-Model folder (BERT, notebooks, `main.py`)
- Anomaly_Detection and AICTE_Region_Norms notebooks and outputs
- `fastapi_app.py` – ML inference endpoints (YOLOv8, custom CNNs in Endpoints/CNNs)
- `final_certificate_verification.py`
– Database: SQLite (`db.sqlite3`) for prototyping (models defined in each app).

##### README Insights
- Multi-stage workflow: document upload → AI verification → image inspection → anomaly detection → report generation → region mapping → role-based dashboards
- Technologies: TAPAS LLM + OCR, YOLOv8 + custom CNNs, Isolation Forest, GenAI for summaries, Django + FastAPI

##### Main Components & Their Interactions
A. **Frontend Layer** (Browser/UI)
– HTML templates (templates/) + CSS/JS (static/)
– Role-based UIs: inspector, institute, admin dashboards
B. **Web Backend** (Django Monolith)
– Handles authentication, routing, form processing, REST views
– Persists state in SQLite (or a production RDBMS)
– Saves uploaded docs/images to `media/`
– Orchestrates ML tasks (calls scripts or HTTP APIs)
C. **ML Inference Service** (FastAPI)
– `fastapi_app.py` loads YOLOv8 (`yolov8l.pt`) and CNN models (`washroom.h5`)
– Exposes HTTP endpoints for image classification/detection
D. **AI/ML Modules**
1. **Document Analysis**: TAPAS LLM + OCR pipelines (triggered via Python scripts or Django-Celery tasks)
2. **Image Inspection**: YOLOv8 + custom CNN via FastAPI or local import
3. **Anomaly Detection**: Isolation Forest implemented in `Anomaly_Detection/anomaly.py`
4. **GenAI Reporting**: BERT‐based summarization and Q&A (`GenAI-Model/main.py`)
5. **Region Mapping & Norms**: Jupyter notebooks in AICTE_Region_Norms generate maps and CSV outputs
E. **Data Stores & Artifacts**
– Relational data: SQLite
– Uploaded assets & generated reports: `media/`
– Static reports & HTML exports: `Anomaly_Detection/*.html`, `AICTE_Region_Norms/*.html`

##### Architectural Patterns & Design Principles
- **MVC (Django)**: models (core/models.py, inspector/models.py, etc.), views, templates
- **Service Separation**: monolith for business logic + microservice for heavy ML inference (FastAPI)
- **Pipeline Pattern**: sequential AI modules (doc analysis → image analysis → anomaly detection → reporting)
- **Role-Based Access Control**: distinct URL namespaces and templates for admins, inspectors, institutes

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer
    subgraph "Presentation Layer"
        UI["Browser (UI)"]:::frontend
        Templates["HTML Templates"]:::frontend
        Static["Static Assets"]:::frontend
    end

    UI --> Templates
    UI --> Static

    %% Application Layer
    subgraph "Application Layer"
        subgraph "Django Monolith"
            ConfigSettings["settings.py"]:::backend
            ConfigURLs["urls.py"]:::backend
            ConfigWSGI["wsgi.py"]:::backend
            ConfigASGI["asgi.py"]:::backend
            Manage["manage.py"]:::backend
            Core["Core App\n(shared models/views/urls)"]:::backend
            Admin["AICTE Admin App"]:::backend
            InspectorApp["Inspector App"]:::backend
            InstituteApp["Institute App"]:::backend
        end
        MLService["FastAPI ML Inference"]:::mlservice
    end

    Templates --> Core
    Templates --> Admin
    Templates --> InspectorApp
    Templates --> InstituteApp

    Static --> Core
    Static --> Admin
    Static --> InspectorApp
    Static --> InstituteApp

    Core --> DB
    Admin --> DB
    InspectorApp --> DB
    InstituteApp --> DB

    Core --> MediaStore
    Admin --> MediaStore
    InspectorApp --> MediaStore
    InstituteApp --> MediaStore

    Core --> MLService
    InspectorApp --> MLService

    %% AI/ML Processing Layer
    subgraph "AI/ML Processing Layer"
        DocAnalysis["Document Analysis\n(TAPAS+OCR)"]:::aimodule
        subgraph "Image Inspection Models"
            YOLO["yolov8l.pt"]:::aimodule
            YClass["yolo_classroom.py"]:::aimodule
            CNNModel["washroom.h5"]:::aimodule
            CNNCode["washroom.py"]:::aimodule
        end
        Anomaly["Anomaly Detection\n(Isolation Forest)"]:::aimodule
        AnomalyNTB["anomaly_detection.ipynb\n& anomaly_report.html"]:::aimodule
        GenAI["GenAI Reporting\n(main.py)"]:::aimodule
        GenAINTB["bert.ipynb\nmain.ipynb\nsentiment_summary_qna.json"]:::aimodule
        Region["Region Mapping & Norms\n(region.ipynb & regionmap.html)"]:::aimodule
        FinalCert["final_certificate_verification.py"]:::aimodule
    end

    Core --> DocAnalysis
    Core --> Anomaly
    Core --> GenAI
    Core --> Region
    Core --> FinalCert
    MLService --> YOLO
    MLService --> CNNModel
    Anomaly --> AnomalyNTB
    GenAI --> GenAINTB
    Region --> Region

    DocAnalysis --> DB
    Anomaly --> DB
    GenAI --> MediaStore
    Region --> MediaStore
    FinalCert --> MediaStore

    %% Data Layer
    subgraph "Data Layer"
        DB["SQLite Database\n(db.sqlite3)"]:::datastore
        MediaStore["Media Store\n(media/ docs/, images/)"]:::datastore
    end

    %% Click Events
    click Templates "https://github.com/saranambiar/nirikshan-sahai/tree/main/templates/"
    click Static "https://github.com/saranambiar/nirikshan-sahai/tree/main/static/"
    click ConfigSettings "https://github.com/saranambiar/nirikshan-sahai/blob/main/inspection_system/settings.py"
    click ConfigURLs "https://github.com/saranambiar/nirikshan-sahai/blob/main/inspection_system/urls.py"
    click ConfigWSGI "https://github.com/saranambiar/nirikshan-sahai/blob/main/inspection_system/wsgi.py"
    click ConfigASGI "https://github.com/saranambiar/nirikshan-sahai/blob/main/inspection_system/asgi.py"
    click Manage "https://github.com/saranambiar/nirikshan-sahai/blob/main/manage.py"
    click Core "https://github.com/saranambiar/nirikshan-sahai/blob/main/core/models.py"
    click Admin "https://github.com/saranambiar/nirikshan-sahai/blob/main/aicte_admin/models.py"
    click InspectorApp "https://github.com/saranambiar/nirikshan-sahai/blob/main/inspector/models.py"
    click InstituteApp "https://github.com/saranambiar/nirikshan-sahai/blob/main/institute/models.py"
    click MediaStore "https://github.com/saranambiar/nirikshan-sahai/tree/main/media/"
    click DB "https://github.com/saranambiar/nirikshan-sahai/blob/main/db.sqlite3"
    click MLService "https://github.com/saranambiar/nirikshan-sahai/blob/main/fastapi_app.py"
    click YOLO "https://github.com/saranambiar/nirikshan-sahai/blob/main/yolov8l.pt"
    click YClass "https://github.com/saranambiar/nirikshan-sahai/blob/main/yolo_classroom.py"
    click CNNModel "https://github.com/saranambiar/nirikshan-sahai/blob/main/Endpoints/CNNs/washroom.h5"
    click CNNCode "https://github.com/saranambiar/nirikshan-sahai/blob/main/Endpoints/CNNs/washroom.py"
    click Anomaly "https://github.com/saranambiar/nirikshan-sahai/blob/main/Anomaly_Detection/anomaly.py"
    click AnomalyNTB "https://github.com/saranambiar/nirikshan-sahai/blob/main/Anomaly_Detection/anomaly_detection.ipynb"
    click GenAI "https://github.com/saranambiar/nirikshan-sahai/blob/main/GenAI-Model/main.py"
    click GenAINTB "https://github.com/saranambiar/nirikshan-sahai/blob/main/GenAI-Model/bert.ipynb"
    click Region "https://github.com/saranambiar/nirikshan-sahai/blob/main/AICTE_Region_Norms/region.ipynb"
    click FinalCert "https://github.com/saranambiar/nirikshan-sahai/blob/main/final_certificate_verification.py"

    %% Styles
    classDef frontend fill:#D0E8FF,stroke:#3B83BD,color:#000;
    classDef backend fill:#DFF7D0,stroke:#4A8F29,color:#000;
    classDef mlservice fill:#FFD8A8,stroke:#DB8B00,color:#000;
    classDef aimodule fill:#FFF3B0,stroke:#C9A227,color:#000;
    classDef datastore fill:#E0E0E0,stroke:#737373,color:#000;
```
