# sanchikb01/securex architecture

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

- Interactive diagram: https://gitdiagram.com/sanchikb01/securex
- Repository: https://github.com/sanchikb01/securex

## Overview

##### Project type and purpose
- This is a full-stack online exam-proctoring application (“SecureX”).
- Frontend: a React single-page-app under securex-main (teachers’ and students’ UIs).
- Backend: a Python service (Flask or similar) in backend/app.py with OpenCV-based face detection using the Haar cascade XMLs.
- Purpose: deliver exams, stream/process webcam, detect faces in real time, log suspicious activity, manage tests, and show a leaderboard.

##### File structure
- Top level:
- backend/ – Python API service & face-detection logic.
- haarcascades/ – XML files for OpenCV classifiers.
- securex-main/ – React app (public/, src/, package.json).
- React side: typical create-react-app structure → components (Login, Create, CustomNavbars), containers (Auth, Exam, MPage, StPage, TcPage), index.js.
- No explicit DB folder → likely an external database or in-code ORM.
- Config files: package.json (frontend), potential requirements.txt or implicit in backend.

##### README
- Real-time webcam monitoring (face detection).
- Teachers manage tests.
- Students take full-screen exams.
- Activity tracking + performance leaderboard.

##### Main components & relationships
a. Components
- Student Browser (React SPA).
- Teacher Browser (React SPA).
- API Gateway / Backend Server (Flask)
- Face Detection Engine (OpenCV + Haar cascades)
- Data Store (e.g., relational DB for users, exams, logs, scores)
- Leaderboard Service (could be part of backend)
- External Services (e.g., authentication, CDN for static assets).
b. Interactions
1. Student/Teacher load SPA → HTTP(S) GET → CDN/Backend serves bundle.
2. Teacher SPA → REST API calls → create/manage exams → DB.
3. Student SPA → “Start Exam” → full-screen mode → webcam capture → WebRTC or periodic POST of frames → Backend.
4. Backend invokes Face Detection Engine → uses haarcascade XMLs → returns pass/fail or activity logs → store in DB.
5. Backend pushes real-time events (e.g., via WebSocket) → SPA displays alerts or status.
6. After exam → Backend computes results → updates leaderboard → Teacher/Student SPA GETs leaderboard.
c. Architectural patterns & principles
- Separation of concerns: React UI vs. Python API vs. vision-processing engine.
- Modularization: Haar cascades loaded dynamically.
- Real-time streaming or polling for face-detection results.
- Stateless frontend, stateful backend (DB).
d. Key technologies
- Frontend: React, JSX, CSS Modules, create-react-app.
- Backend: Flask (or similar), Python 3.x, OpenCV.
- Face models: haarcascade_*.xml.
- Data Store: MySQL/Postgres/Mongo (not shown but implied).
- Communication: REST + optional WebSockets/WebRTC.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Swimlanes
    subgraph "Frontend Layer" 
        direction TB
        ReactSPA["React SPA"]:::frontend
        ReactSPA --> StudentUI
        ReactSPA --> TeacherUI
        ReactSPA --> AuthUI
        ReactSPA --> ExamUI
        ReactSPA --> NavComponent
        ReactSPA --> LoginForms
        ReactSPA --> LeaderboardUI
    end

    subgraph "Backend Layer"
        direction TB
        APIServer["Flask API Server\n(Python + Flask)"]:::backend
        FaceEngine["OpenCV Engine\n(Haarcascade)"]:::backend
        HaarModels["Haarcascade XMLs"]:::data
        DataStore["Database"]:::database
        LeaderService["Leaderboard Service"]:::backend
    end

    subgraph "External Services"
        direction TB
        CDN["CDN / Static Assets"]:::external
        AuthService["External Auth"]:::external
    end

    %% Frontend components
    StudentUI["Student UI Container"]:::frontend
    TeacherUI["Teacher UI Container"]:::frontend
    AuthUI["Authentication Container"]:::frontend
    ExamUI["Exam Container"]:::frontend
    NavComponent["Custom Navbars"]:::frontend
    LoginForms["Login Components"]:::frontend
    LeaderboardUI["Leaderboard View"]:::frontend

    %% Data flows
    CDN -->|"Serve JS bundle\n(HTTP GET)"| ReactSPA
    ReactSPA -->|"REST API calls"| APIServer
    ReactSPA -->|"WebSocket\nsubscribe"| APIServer
    ExamUI -->|"POST frames\n(WebRTC / HTTP)"| APIServer
    APIServer -->|"invoke detect(frame)"| FaceEngine
    FaceEngine -->|"load XMLs"| HaarModels
    FaceEngine -->|"return results"| APIServer
    APIServer -->|"read/write"| DataStore
    APIServer -->|"compute/update"| LeaderService
    LeaderService -->|"read/write"| DataStore
    APIServer -->|"push events"| ReactSPA
    AuthService -->|"auth tokens"| APIServer

    %% Click events
    click ReactSPA "https://github.com/sanchikb01/securex/tree/main/securex-main/"
    click StudentUI "https://github.com/sanchikb01/securex/blob/main/securex-main/src/Containers/StPage/StdPage.js"
    click TeacherUI "https://github.com/sanchikb01/securex/blob/main/securex-main/src/Containers/TcPage/TrPage.js"
    click TeacherUI "https://github.com/sanchikb01/securex/blob/main/securex-main/src/Containers/TcPage/Modal.js"
    click AuthUI "https://github.com/sanchikb01/securex/blob/main/securex-main/src/Containers/Auth/Auth.js"
    click ExamUI "https://github.com/sanchikb01/securex/blob/main/securex-main/src/Containers/Exam/ExamPage.js"
    click NavComponent "https://github.com/sanchikb01/securex/blob/main/securex-main/src/Components/CustomNavbars.js"
    click LoginForms "https://github.com/sanchikb01/securex/blob/main/securex-main/src/Components/Login.js"
    click LeaderboardUI "https://github.com/sanchikb01/securex/blob/main/securex-main/src/Containers/LeaderBoard.js"
    click ReactSPA "https://github.com/sanchikb01/securex/blob/main/securex-main/src/index.js"
    click ReactSPA "https://github.com/sanchikb01/securex/blob/main/securex-main/package.json"
    click APIServer "https://github.com/sanchikb01/securex/blob/main/backend/app.py"
    click FaceEngine "https://github.com/sanchikb01/securex/blob/main/backend/app.py"
    click HaarModels "https://github.com/sanchikb01/securex/tree/main/haarcascades/"

    %% Styles
    classDef frontend fill:#D0E8FF,stroke:#0366d6,color:#0366d6;
    classDef backend fill:#D0F0C0,stroke:#228B22,color:#228B22;
    classDef database fill:#F2F2F2,stroke:#666666,color:#333333,shape:cylinder;
    classDef external fill:#FFE4B5,stroke:#FFA500,color:#FFA500;
```
