# reubensg/ipc_insight architecture

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

- Interactive diagram: https://gitdiagram.com/reubensg/ipc_insight
- Repository: https://github.com/reubensg/ipc_insight

## Overview

##### Project Type & Purpose
- This is a full-stack Flask application aimed at predicting the relevant sections of the Indian Penal Code (IPC) from crime narratives.
- It processes both textual and audio data, calculates vector embeddings, and then uses ChromaDB (a vector database) along with MongoDB for data storage and rapid retrieval.
- The application supports legal professionals and law enforcement by automating the analysis of crime narratives.

##### Analyzing the File Structure
- Key Python files:
- app.py, main.py, and audio.py likely contain application routes, request handling, and perhaps audio processing functions.
- Data Preprocessing:
- The data_preprocessing directory, with data.py and CSV files (ipc_dataset_nlp.csv, ipc_dataset.csv), suggests initial cleaning/feature extraction and NLP preparatory work.
- Front-end Components:
- The “templates” folder holds HTML files (index.html, menu.html, sign.html, etc.) that represent user interfaces like the homepage, sign-up or login, and various interaction screens.
- The “static” folder contains CSS and JavaScript files that are used for styling and interactive client-side functions including chat, recording, and overall app control.

##### Identifying Main System Components
a. User Interface:
- HTML Templates: Display forms for crime narrative input, results, and other page content.
- Static Assets: CSS and JavaScript that manage presentation and interactions (e.g., recording audio).
b. Web Server / Application Layer:
- Flask Application (app.py, main.py): Hosts the API endpoints for receiving user input, processing it, and communicating with the back-end services.
- Audio Handling (audio.py): Likely processes incoming audio files and converts them into a suitable text or embedding format for analysis.
c. Data Processing & NLP Pipeline:
- Data Preprocessing Scripts (data_preprocessing/data.py): Clean and transform raw datasets (CSV files), generating vector embeddings.
- Integration with NLP components that convert crime narratives into high-dimensional vectors.
d. Storage & Retrieval:
- ChromaDB: A vector database for storing and retrieving embedding-based representations quickly.
- MongoDB: Possibly used for managing additional application data (user data, logs, etc.).
e. External & Auxiliary Services:
- Any external dependencies or APIs that support vector computation, additional NLP, or data storage.

##### Relationships & Data Flow
- User interacts with the front-end (templates and static JS/CSS) to submit crime narratives via forms or audio recordings.
- The Flask backend (app.py/main.py) receives the data and, if necessary, routes the audio input to audio.py for conversion.
- Processed text data flows into the data transformation layer (data_preprocessing) to compute vector embeddings.
- These embeddings are stored/retrieved from the ChromaDB, with MongoDB serving other structured data requirements.
- Based on vector similarity searches and NLP processing, the system returns relevant IPC sections back to the frontend for display.

##### Architectural Patterns & Design Principles
- Separation of Concerns: Distinct layers for presentation (templates/static), business logic (Flask app and controllers), data processing (preprocessing scripts), and data storage (ChromaDB, MongoDB).
- Modularity: Clear boundaries between audio processing, textual data processing, and database interactions.
- Scalability: Use of vector databases like ChromaDB ensures fast and efficient embedding retrieval.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "User Interface"
        UI1["Templates (HTML)"]:::ui
        UI2["Static Assets (CSS/JS)"]:::ui
    end

    subgraph "Web Server / Application Layer"
        WS["Flask Application (app.py & main.py)"]:::backend
        AP["Audio Processing (audio.py)"]:::audio
    end

    subgraph "Data Processing & NLP Pipeline"
        DP["Data Preprocessing (data_preprocessing)"]:::dp
        DPS["Data Script (data_preprocessing/data.py)"]:::dp
        CS["IPC Dataset (ipc_dataset.csv)"]:::dp
        CNS["IPC NLP Dataset (ipc_dataset_nlp.csv)"]:::dp
    end

    subgraph "Storage & Retrieval"
        DB1["ChromaDB (Vector DB)"]:::storage
        DB2["MongoDB (NoSQL DB)"]:::storage
    end

    UI1 -->|"submit_request"| WS
    UI2 -->|"asset_request"| WS
    WS -->|"process_audio"| AP
    WS -->|"process_text"| DP
    DP -->|"generate_vectors"| DB1
    DP -->|"store_structured"| DB2
    DB1 -->|"vector_search_results"| DP
    DB2 -->|"data_query_results"| DP
    DP -->|"analysis_results"| WS
    AP -->|"audio_conversion"| WS
    WS -->|"respond"| UI1
    WS -->|"respond"| UI2

    click UI1 "https://github.com/reubensg/ipc_insight/tree/main/templates/"
    click UI2 "https://github.com/reubensg/ipc_insight/tree/main/static/"
    click WS "https://github.com/reubensg/ipc_insight/blob/main/app.py"
    click WS "https://github.com/reubensg/ipc_insight/blob/main/main.py"
    click AP "https://github.com/reubensg/ipc_insight/blob/main/audio.py"
    click DP "https://github.com/reubensg/ipc_insight/tree/main/data_preprocessing/"
    click DPS "https://github.com/reubensg/ipc_insight/blob/main/data_preprocessing/data.py"
    click CS "https://github.com/reubensg/ipc_insight/blob/main/data_preprocessing/ipc_dataset.csv"
    click CNS "https://github.com/reubensg/ipc_insight/blob/main/data_preprocessing/ipc_dataset_nlp.csv"

    classDef ui fill:#ADD8E6,stroke:#000,stroke-width:1px;
    classDef backend fill:#FFA500,stroke:#000,stroke-width:1px;
    classDef audio fill:#9370DB,stroke:#000,stroke-width:1px;
    classDef dp fill:#FFFF99,stroke:#000,stroke-width:1px;
    classDef storage fill:#90EE90,stroke:#000,stroke-width:1px;
```
