# ashishpatel26/consent-ai architecture

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

- Interactive diagram: https://gitdiagram.com/ashishpatel26/consent-ai
- Repository: https://github.com/ashishpatel26/consent-ai

## Overview

##### Project Type and Purpose
- This is a full-stack, single-page application built with Streamlit that acts as both a UI and basic back-end for managing consent-related cases and providing AI-powered risk assessments.
- Its main purpose is to allow users to add, update, delete, and view cases, while using an SVM-based AI model to predict risk levels based on textual case descriptions.

##### Analyzing the File Structure
- Top-level files include:
- Consent_Management_System_with_AI_Case_Analysis.ipynb: Likely used for exploration or demonstration.
- README.md: Contains the project overview, features, and detailed usage instructions.
- consentai-1742893099136.mp4: A demo video for the application.
- The “app” folder contains:
- consentAI.py: The core Python module for the application that implements AI assessment and case management functions.
- There are no separate directories for frontend and backend because Streamlit seamlessly integrates UI and backend logic into one application.

##### Key Components Identified
a. User Interface (UI) Layer:
- Built using Streamlit. This handles all user interactions such as navigation (sidebar for case view, add, update, delete, train model) and displaying outputs.

b. Business Logic / Case Management Module:
- Implemented in the “consentAI.py” module to orchestrate case operations (add, update, delete, viewing) and interact with the AI model.
- Maintains case data using an in-memory list of dictionaries with fields such as id, description, category, consent status, etc.

c. AI Model Component:
- Uses scikit-learn’s Support Vector Machine (SVM) for risk assessment.
- The text input is processed using TfidfVectorizer to generate numerical features.
- Functions include train_model() for model training, assess_case() for case risk prediction, and retraining the model after data changes.

d. Data Component:
- The case data structure is a list of dictionaries representing individual cases with details such as description, date, risk level, and resolution.

##### Relationships and Interactions Between Components
- The UI (Streamlit front-end) directly interacts with the Business Logic, invoking functions implemented in consentAI.py.
- When a user adds, updates, or deletes a case via the UI, the corresponding function in the business logic performs the operation on the in-memory data store.
- After any modification to the data, the AI Model component is triggered to retrain the SVM, ensuring predictions remain accurate.
- The assess_case function is called when a user inputs new case descriptions for risk assessment; the data flows from the UI into the AI module, and the resulting risk levels and probabilities are sent back to the UI.

##### Architectural Patterns and Design Principles
- The application follows a straightforward layered architecture, separating the presentation (Streamlit UI) from the logic (case management and AI assessment).
- It uses a modular approach with a distinct separation of functions (e.g., data handling versus AI prediction).
- Although it doesn’t implement heavy microservices or database abstraction, the design emphasizes clear division of responsibilities that can be easily extended.

## Diagram (Mermaid)

```mermaid
graph TD
    %% UI Layer
    subgraph "UI Layer"
        UI["Streamlit Interface (Python/Streamlit)"]:::ui
    end

    %% Business Logic Layer
    subgraph "Business Logic Layer"
        BL["Case Management / ConsentAI Module"]:::logic
    end

    %% AI Model Component
    subgraph "AI Model Component"
        AI["SVM Risk Assessment Module (scikit-learn, TfidfVectorizer)"]:::ai
    end

    %% Data Component
    subgraph "Data Layer"
        DB["In-memory Data Store"]:::db
    end

    %% Data Flow and Interactions
    UI -->|"Add/Update/Delete/AssessCase"| BL
    BL -->|"ProcessCaseData"| DB
    BL -->|"TrainModel"| AI
    BL -->|"TriggerRetraining"| AI
    AI -->|"RiskPredictionFeedback"| UI

    %% Click Events
    click UI "https://github.com/ashishpatel26/consent-ai/blob/main/app/consentAI.py"
    click BL "https://github.com/ashishpatel26/consent-ai/blob/main/app/consentAI.py"
    click AI "https://github.com/ashishpatel26/consent-ai/blob/main/app/consentAI.py"
    click DB "https://github.com/ashishpatel26/consent-ai/blob/main/app/consentAI.py"

    %% Styles
    classDef ui fill:#f9c2ff,stroke:#333,stroke-width:2px;
    classDef logic fill:#c2f9ff,stroke:#333,stroke-width:2px;
    classDef ai fill:#c2ffc2,stroke:#333,stroke-width:2px;
    classDef db fill:#ffe0b3,stroke:#333,stroke-width:2px;
```
