# innocentmchry/studentmonitoring architecture

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

- Interactive diagram: https://gitdiagram.com/innocentmchry/studentmonitoring
- Repository: https://github.com/innocentmchry/studentmonitoring

## Overview

##### Project type and purpose
- This is a full-stack, real-time online classroom monitoring system built on Django (Python) with a WebRTC-based video conferencing frontend and an integrated CNN emotion-detection pipeline. It supports live emotion tracking of students (via Agora’s WebRTC SDK) and aggregates session summaries.

##### File structure
- Top-level:
- manage.py, gunicorn.conf.py, requirements.txt → Django entry point & deployment
- mychat/ → Django project settings, ASGI/WSGI, URL routing
- base/ → Django “app” containing models, views, forms, templates, URL patterns, tests, migrations
- static/ → client-side assets (JS, CSS, AgoraRTC library, images)
- savedModels/ → pretrained CNN model files, Haarcascade XML for face detection
- ssl/ → self-signed SSL certificate & key
- Indicators:
- asgi.py implies support for async/WebSocket (though actual realtime video is via Agora)
- static/js/streams.js & summary.js handle client-side WebRTC logic and summary fetching
- base/views.py likely exposes REST endpoints for model inference & summary data
- db.sqlite3 for local development; recommend PostgreSQL in prod
- gunicorn.conf.py for production WSGI server

##### README for additional insights
- Architecture image (link) describes:
- Browser clients ↔ Agora Real-Time Messaging/RTC service for video
- Backend Python service: face detection + CNN inference → emotion valence/arousal → map to one of five states
- Data persistence & summary generation
- Tech stack: Django, WebRTC (via AgoraRTC_N-4.19.1.js), Keras/TensorFlow model (.h5 + .json), Haarcascade

##### Details
- Real-time video flow vs. periodic inference/summarization flow distinctly
- Where SSL/TLS is terminated and how Gunicorn/Nginx fit in

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Frontend Layer"
        Browser["Browser Client"]:::frontend
        subgraph "HTML Templates"
            Lobby["lobby.html"]:::frontend
            Room["room.html"]:::frontend
            SummaryPage["summary.html"]:::frontend
        end
        subgraph "JS Modules"
            AgoraSDK["AgoraRTC_N-4.19.1.js"]:::frontend
            Streams["streams.js"]:::frontend
            SummaryJS["summary.js"]:::frontend
        end
    end

    subgraph "External Services"
        Agora["Agora RTC Service"]:::external
    end

    subgraph "Backend Layer"
        subgraph "Django Config & Routing"
            Manage["manage.py"]:::backend
            Settings["settings.py"]:::backend
            URLs["urls.py"]:::backend
            ASGI["asgi.py"]:::backend
            WSGI["wsgi.py"]:::backend
            Deploy["deployment.py"]:::backend
        end
        subgraph "\"base\" App"
            Models["models.py"]:::backend
            Views["views.py"]:::backend
            Forms["forms.py"]:::backend
            BaseURLs["base/urls.py"]:::backend
        end
        subgraph "Emotion Detection Module"
            Haar["haarcascade_frontalface_default.xml"]:::backend
            Arousal["arousal-weights-improvement-95-0.17.h5"]:::backend
            Valence["valence-weights-improvement-137-0.23.h5"]:::backend
            ModelConfig["affect_model.json"]:::backend
        end
        StaticServer["Static Asset Server"]:::backend
    end

    Database["Database (SQLite/PostgreSQL)"]:::database

    subgraph "Infrastructure"
        Nginx["Nginx/SSL Termination"]:::infrastructure
        Gunicorn["Gunicorn Workers"]:::infrastructure
    end

    Browser -->|"Signal & Video Stream"| Agora
    Browser -->|"HTTP GET HTML/JS/CSS"| StaticServer
    Browser -->|"HTTP POST /infer"| Views
    Views -->|"detect face & infer"| Haar
    Haar -->|"emotion data"| Views
    Views -->|"DB write"| Database
    Views -->|"DB read for summary"| Database
    Database -->|"summary data"| Views
    Views -->|"summary push"| Browser

    click Lobby "https://github.com/innocentmchry/studentmonitoring/blob/main/base/templates/base/lobby.html"
    click Room "https://github.com/innocentmchry/studentmonitoring/blob/main/base/templates/base/room.html"
    click SummaryPage "https://github.com/innocentmchry/studentmonitoring/blob/main/base/templates/base/summary.html"
    click AgoraSDK "https://github.com/innocentmchry/studentmonitoring/blob/main/static/assets/AgoraRTC_N-4.19.1.js"
    click Streams "https://github.com/innocentmchry/studentmonitoring/blob/main/static/js/streams.js"
    click SummaryJS "https://github.com/innocentmchry/studentmonitoring/blob/main/static/js/summary.js"
    click Manage "https://github.com/innocentmchry/studentmonitoring/blob/main/manage.py"
    click Settings "https://github.com/innocentmchry/studentmonitoring/blob/main/mychat/settings.py"
    click URLs "https://github.com/innocentmchry/studentmonitoring/blob/main/mychat/urls.py"
    click ASGI "https://github.com/innocentmchry/studentmonitoring/blob/main/mychat/asgi.py"
    click WSGI "https://github.com/innocentmchry/studentmonitoring/blob/main/mychat/wsgi.py"
    click Deploy "https://github.com/innocentmchry/studentmonitoring/blob/main/mychat/deployment.py"
    click Models "https://github.com/innocentmchry/studentmonitoring/blob/main/base/models.py"
    click Views "https://github.com/innocentmchry/studentmonitoring/blob/main/base/views.py"
    click Forms "https://github.com/innocentmchry/studentmonitoring/blob/main/base/forms.py"
    click BaseURLs "https://github.com/innocentmchry/studentmonitoring/blob/main/base/urls.py"
    click Haar "https://github.com/innocentmchry/studentmonitoring/blob/main/savedModels/haarcascade_frontalface_default.xml"
    click Arousal "https://github.com/innocentmchry/studentmonitoring/blob/main/savedModels/arousal-weights-improvement-95-0.17.h5"
    click Valence "https://github.com/innocentmchry/studentmonitoring/blob/main/savedModels/valence-weights-improvement-137-0.23.h5"
    click ModelConfig "https://github.com/innocentmchry/studentmonitoring/blob/main/savedModels/affect_model.json"
    click Database "https://github.com/innocentmchry/studentmonitoring/blob/main/db.sqlite3"
    click StaticServer "https://github.com/innocentmchry/studentmonitoring/blob/main/static/styles/main.css"
    click Nginx "https://github.com/innocentmchry/studentmonitoring/blob/main/ssl/cert.pem"
    click Gunicorn "https://github.com/innocentmchry/studentmonitoring/blob/main/gunicorn.conf.py"

    classDef frontend fill:#E3F2FD,stroke:#2196F3,color:#0D47A1
    classDef backend fill:#E8F5E9,stroke:#4CAF50,color:#1B5E20
    classDef external fill:#FFF3E0,stroke:#FB8C00,color:#E65100
    classDef database fill:#CFD8DC,stroke:#607D8B,color:#263238
    classDef infrastructure fill:#F3E5F5,stroke:#AB47BC,color:#4A148C
```
