# synapsysesprit/aigis architecture

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

- Interactive diagram: https://gitdiagram.com/synapsysesprit/aigis
- Repository: https://github.com/synapsysesprit/aigis

## Overview

##### Project Type and Purpose
- This is a full-stack application combining a browser extension (“Aigis”) with a Django-based backend.
- Purpose: real-time AI-powered detection of online threats in chat, audio, video, images, and text, plus a parental dashboard for alerts and reports.

##### File Structure
- Top-level:
- Backend/ – Django project (“Backend”)
– Backend/Backend – core Django settings, ASGI/WSGI, URLs
– manage.py
– apps: audio, chatbot, image, text, video
– cache/models… – local HuggingFace model snapshots
– tools/espeak – embedded TTS engine
– templates/*.html – chat interface & dashboard
- extension/ – Chrome extension
– manifest.json, background.js, popup.html/css/js, dashboard.html/css/js
– content_scripts/ – scripts for audio, text, video, nudity, behavior, deepfake, usage pattern

##### README for Additional Insights
- AI Models & Detection: OpenAI Whisper & Gemini, DeepFace/Deepware, MediaPipe, OpenCV, custom NLP
- External Services: HuggingFace, ElevenLabs, GROQ API
- Dashboard: React + Shadcn UI (though code shows Django templates – treat as a web UI layer)

##### Main Components & Their Interactions
a. Browser Extension
- Content Scripts (audio_script.js, video_script.js, etc.) detect events in the page.
- background.js orchestrates data collection & forwards to backend.
- popup.html/js & dashboard.html/js are the extension’s front-end UIs.
b. Backend Web Service (Django)
- URL router delegates to apps: /audio/, /text/, /image/, /video/, /chatbot/
- Views invoke local models (cache/) or external AI APIs for inference.
- Data persisted to Django ORM (DB).
- templates/ serve the parental dashboard & chat interface.
c. AI Inference Layer
- Local: HuggingFace models (cached), Espeak for TTS, OpenCV for frames.
- Remote: OpenAI/Gemini (audio/text), ElevenLabs (voice), GROQ, DeepFace/MediaPipe services.
d. Database
- Stores user sessions, alerts, logs, parental settings, knowledge base references.
e. External Services
- Cloud AI endpoints, model hubs, PDF/text knowledgebase for chatbot.

[Web Page] → content_script → background.js → HTTP POST → [Django API View]
→ AI Inference (local or external) → results → ORM → response → background.js → extension UI

##### Architectural Patterns & Principles
- Backend: MVC (Django apps separated by concern), caching layer for heavy models.
- Extension: event-driven content scripts + background page.
- Modular AI layer: abstract interface to local vs. remote inference.
- Separation of concerns: detection domains (audio, video, text, image, chatbot).

##### Essential Details to Capture
- All detection domains as separate modules.
- Local vs. external inference paths.
- Data storage & retrieval points.
- UI data flows: extension popup vs. parental dashboard.
- Model caching and espeak integration.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Browser Extension Zone
    subgraph "Browser Extension" 
        direction TB
        MAN["manifest.json"]:::extension
        BG["background.js"]:::extension
        subgraph "Content Scripts"
            direction TB
            AS["audio_script.js"]:::extension
            TS["text_content_script.js"]:::extension
            VS["video_script.js"]:::extension
            BM["behavior_monitor_script.js"]:::extension
            DF["deepfake_content_script.js"]:::extension
            NU["nudity_content_script.js"]:::extension
            UP["usage_pattern_analyzer.js"]:::extension
        end
        subgraph "Popup UI"
            direction TB
            PHTML["popup.html"]:::extension
            PJS["popup.js"]:::extension
            PCSS["popup.css"]:::extension
        end
        subgraph "Dashboard UI"
            direction TB
            DHTML["dashboard.html"]:::extension
            DJS["dashboard.js"]:::extension
            DCSS["dashboard.css"]:::extension
        end
        subgraph "Assets"
            direction TB
            IC["icons/"]:::extension
            SP["sprites/"]:::extension
            AIS["Aigisso Sprites/"]:::extension
            MA["materials/"]:::extension
        end
    end

    %% Backend Zone
    subgraph "Django Backend" 
        direction TB
        MC["manage.py"]:::backend
        subgraph "Core & Routing"
            direction TB
            SET["settings.py"]:::backend
            URL["urls.py"]:::backend
            ASGI["asgi.py"]:::backend
            WSGI["wsgi.py"]:::backend
        end
        subgraph "Detection Apps"
            direction TB
            subgraph Audio
                direction TB
                AAPP["apps.py"]:::backend
                AURL["urls.py"]:::backend
                AVIEW["views.py"]:::backend
                AMOD["models.py"]:::backend
            end
            subgraph Text
                direction TB
                TAPP["apps.py"]:::backend
                TURL["urls.py"]:::backend
                TVIEW["views.py"]:::backend
                TMOD["models.py"]:::backend
            end
            subgraph Image
                direction TB
                IAPP["apps.py"]:::backend
                IURL["urls.py"]:::backend
                IVIEW["views.py"]:::backend
                IMOD["models.py"]:::backend
            end
            subgraph Video
                direction TB
                VAPP["apps.py"]:::backend
                VURL["urls.py"]:::backend
                VVIEW["views.py"]:::backend
                VMOD["models.py"]:::backend
                VAN["video_analyzer.py"]:::backend
                VEA["epilepsy_analyzer.py"]:::backend
            end
            subgraph Chatbot
                direction TB
                CAPP["apps.py"]:::backend
                CURL["urls.py"]:::backend
                CVIEW["views.py"]:::backend
                CMOD["models.py"]:::backend
                KB["knowledgebase/"]:::backend
            end
        end
        subgraph "Model & Tools"
            direction TB
            CACHE["models--roberta-base/snapshots/"]:::inference
            ESPEAK["tools/espeak/"]:::inference
        end
        DB[(Database)]:::db
        subgraph "Templates"
            direction TB
            DASH_T["dashboard.html"]:::backend
            CHAT_T["chat_interface.html"]:::backend
        end
    end

    %% External AI Services
    subgraph "External AI Services"
        direction TB
        OA["OpenAI/Gemini"]:::external
        HF["HuggingFace API"]:::external
        EL["ElevenLabs"]:::external
        GR["GROQ API"]:::external
        DFEXT["DeepFace/MediaPipe"]:::external
    end

    %% Connections
    AS --> BG
    TS --> BG
    VS --> BG
    BM --> BG
    DF --> BG
    NU --> BG
    UP --> BG
    MAN --> BG
    BG -->|"HTTP POST /api/*"| URL
    PHTML --> BG
    PJS --> BG
    PCSS --> BG
    DHTML --> URL
    DJS --> URL
    DCSS --> URL

    URL --> AURL
    URL --> TURL
    URL --> IURL
    URL --> VURL
    URL --> CURL

    AVIEW --> CACHE
    AVIEW --> OA
    AVIEW --> DB
    TVIEW --> CACHE
    TVIEW --> OA
    TVIEW --> DB
    IVIEW --> CACHE
    IVIEW --> DFEXT
    IVIEW --> DB
    VVIEW --> CACHE
    VVIEW --> GR
    VVIEW --> DB
    CVIEW --> KB
    CVIEW --> HF
    CVIEW --> DB

    ESPEAK --> AVIEW
    ESPEAK --> TVIEW

    URL --> DASH_T
    URL --> CHAT_T

    %% Classes
    classDef extension fill:#AEDFF7,stroke:#333,stroke-width:1px
    classDef backend fill:#A3F7BF,stroke:#333,stroke-width:1px
    classDef inference fill:#FFD59E,stroke:#333,stroke-width:1px
    classDef db fill:#F7FFA3,stroke:#333,stroke-width:1px
    classDef external fill:#F7C8E0,stroke:#333,stroke-width:1px

    %% Click Events
    click SET "https://github.com/synapsysesprit/aigis/blob/main/Backend/Backend/settings.py"
    click URL "https://github.com/synapsysesprit/aigis/blob/main/Backend/Backend/urls.py"
    click ASGI "https://github.com/synapsysesprit/aigis/blob/main/Backend/Backend/asgi.py"
    click WSGI "https://github.com/synapsysesprit/aigis/blob/main/Backend/Backend/wsgi.py"
    click MC "https://github.com/synapsysesprit/aigis/blob/main/Backend/manage.py"
    click AAPP "https://github.com/synapsysesprit/aigis/blob/main/Backend/audio/apps.py"
    click AURL "https://github.com/synapsysesprit/aigis/blob/main/Backend/audio/urls.py"
    click AVIEW "https://github.com/synapsysesprit/aigis/blob/main/Backend/audio/views.py"
    click AMOD "https://github.com/synapsysesprit/aigis/blob/main/Backend/audio/models.py"
    click TAPP "https://github.com/synapsysesprit/aigis/blob/main/Backend/text/apps.py"
    click TURL "https://github.com/synapsysesprit/aigis/blob/main/Backend/text/urls.py"
    click TVIEW "https://github.com/synapsysesprit/aigis/blob/main/Backend/text/views.py"
    click TMOD "https://github.com/synapsysesprit/aigis/blob/main/Backend/text/models.py"
    click IAPP "https://github.com/synapsysesprit/aigis/blob/main/Backend/image/apps.py"
    click IURL "https://github.com/synapsysesprit/aigis/blob/main/Backend/image/urls.py"
    click IVIEW "https://github.com/synapsysesprit/aigis/blob/main/Backend/image/views.py"
    click IMOD "https://github.com/synapsysesprit/aigis/blob/main/Backend/image/models.py"
    click VAPP "https://github.com/synapsysesprit/aigis/blob/main/Backend/video/apps.py"
    click VURL "https://github.com/synapsysesprit/aigis/blob/main/Backend/video/urls.py"
    click VVIEW "https://github.com/synapsysesprit/aigis/blob/main/Backend/video/views.py"
    click VMOD "https://github.com/synapsysesprit/aigis/blob/main/Backend/video/models.py"
    click VAN "https://github.com/synapsysesprit/aigis/blob/main/Backend/video/video_analyzer.py"
    click VEA "https://github.com/synapsysesprit/aigis/blob/main/Backend/video/epilepsy_analyzer.py"
    click CAPP "https://github.com/synapsysesprit/aigis/blob/main/Backend/chatbot/apps.py"
    click CURL "https://github.com/synapsysesprit/aigis/blob/main/Backend/chatbot/urls.py"
    click CVIEW "https://github.com/synapsysesprit/aigis/blob/main/Backend/chatbot/views.py"
    click CMOD "https://github.com/synapsysesprit/aigis/blob/main/Backend/chatbot/models.py"
    click KB "https://github.com/synapsysesprit/aigis/tree/main/Backend/chatbot/knowledgebase/"
    click CACHE "https://github.com/synapsysesprit/aigis/tree/main/Backend/cache/models--roberta-base/snapshots/"
    click ESPEAK "https://github.com/synapsysesprit/aigis/tree/main/Backend/tools/espeak/"
    click DASH_T "https://github.com/synapsysesprit/aigis/blob/main/Backend/templates/dashboard.html"
    click CHAT_T "https://github.com/synapsysesprit/aigis/blob/main/Backend/templates/chat_interface.html"
    click MAN "https://github.com/synapsysesprit/aigis/blob/main/extension/manifest.json"
    click BG "https://github.com/synapsysesprit/aigis/blob/main/extension/background.js"
    click AS "https://github.com/synapsysesprit/aigis/blob/main/extension/content_scripts/audio_script.js"
    click TS "https://github.com/synapsysesprit/aigis/blob/main/extension/content_scripts/text_content_script.js"
    click VS "https://github.com/synapsysesprit/aigis/blob/main/extension/content_scripts/video_script.js"
    click BM "https://github.com/synapsysesprit/aigis/blob/main/extension/content_scripts/behavior_monitor_script.js"
    click DF "https://github.com/synapsysesprit/aigis/blob/main/extension/content_scripts/deepfake_content_script.js"
    click NU "https://github.com/synapsysesprit/aigis/blob/main/extension/content_scripts/nudity_content_script.js"
    click UP "https://github.com/synapsysesprit/aigis/blob/main/extension/content_scripts/usage_pattern_analyzer.js"
    click PHTML "https://github.com/synapsysesprit/aigis/blob/main/extension/popup.html"
    click PJS "https://github.com/synapsysesprit/aigis/blob/main/extension/popup.js"
    click PCSS "https://github.com/synapsysesprit/aigis/blob/main/extension/popup.css"
    click DHTML "https://github.com/synapsysesprit/aigis/blob/main/extension/dashboard.html"
    click DJS "https://github.com/synapsysesprit/aigis/blob/main/extension/dashboard.js"
    click DCSS "https://github.com/synapsysesprit/aigis/blob/main/extension/dashboard.css"
    click IC "https://github.com/synapsysesprit/aigis/tree/main/extension/icons/"
    click SP "https://github.com/synapsysesprit/aigis/tree/main/extension/sprites/"
    click AIS "https://github.com/synapsysesprit/aigis/tree/main/extension/Aigisso Sprites/"
    click MA "https://github.com/synapsysesprit/aigis/tree/main/extension/materials/"
    click README "https://github.com/synapsysesprit/aigis/blob/main/README.md"
    click REQ "https://github.com/synapsysesprit/aigis/blob/main/requirements.txt"
```
