# vinayraj75/-built-a-real-time-facial-emotion-detection-system-using-ai-ml- architecture

> Architecture diagram of the GitHub repository vinayraj75/-built-a-real-time-facial-emotion-detection-system-using-ai-ml-, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-07). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/vinayraj75/-built-a-real-time-facial-emotion-detection-system-using-ai-ml-
- Repository: https://github.com/vinayraj75/-built-a-real-time-facial-emotion-detection-system-using-ai-ml-

## Overview

This is a real-time webcam facial-emotion dashboard. The browser captures frames and sends them to FastAPI, which decodes images, detects and crops faces, classifies emotions, and returns results for live overlays, statistics, and snapshots. A separate model-development branch prepares data, trains the CNN, and evaluates it. The principal inference and UI relationships are supported by excerpts or README documentation; links in the training branch rely on documented workflow where source call details were not sampled.

Main entry points: [`frontend/src/App.jsx`](https://github.com/vinayraj75/-built-a-real-time-facial-emotion-detection-system-using-ai-ml-/blob/main/frontend/src/App.jsx) (Dashboard State), [`backend/app/main.py`](https://github.com/vinayraj75/-built-a-real-time-facial-emotion-detection-system-using-ai-ml-/blob/main/backend/app/main.py) (FastAPI Routes), [`backend/app/emotion_classifier.py`](https://github.com/vinayraj75/-built-a-real-time-facial-emotion-detection-system-using-ai-ml-/blob/main/backend/app/emotion_classifier.py) (Emotion Inference), [`model/train.py`](https://github.com/vinayraj75/-built-a-real-time-facial-emotion-detection-system-using-ai-ml-/blob/main/model/train.py) (Model Training)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Browser Dashboard"]
  node_app["Dashboard State<br/>[App.jsx]"]
  node_hero["Landing Panel<br/>[HeroSection.jsx]"]
  node_navbar["Server Status<br/>[Navbar.jsx]"]
  node_controls["Camera Controls<br/>[ControlBar.jsx]"]
  node_video["Video HUD"]
  node_dominant["Dominant Emotion"]
  node_stats["Emotion Statistics"]
  node_snapshots["Snapshot Gallery<br/>[SnapshotModal.jsx]"]
  node_emotionmeta["Emotion Metadata<br/>[emotions.js]"]
  node_api["API Client<br/>[api.js]"]
end

subgraph group_backend["Inference Service"]
  node_server["FastAPI Routes<br/>[main.py]"]
  node_config["Inference Config<br/>[config.py]"]
  node_detector["Face Detection<br/>[detector.py]"]
  node_classifier["Emotion Inference"]
  node_schemas["Result Schemas<br/>[schemas.py]"]
  node_cascade["Haar Cascade"]
end

subgraph group_model["Model Development"]
  node_cnn["CNN Architecture<br/>[architecture.py]"]
  node_training["Model Training<br/>[train.py]"]
  node_evaluation["Model Evaluation<br/>[evaluate.py]"]
  node_trainedmodel["Trained CNN"]
end

subgraph group_data["Dataset Preparation"]
  node_datasetprep["Dataset Preparation<br/>[prepare_dataset.py]"]
  node_samples["Sample Images"]
end

node_visitor(("Camera User"))

node_visitor -->|"uses dashboard"| node_app
node_app -->|"renders"| node_hero
node_app -->|"renders"| node_navbar
node_app -->|"renders"| node_controls
node_app -->|"renders"| node_video
node_app -->|"renders"| node_dominant
node_app -->|"renders"| node_stats
node_app -->|"renders"| node_snapshots
node_app -->|"requests status and predictions"| node_api
node_video -->|"styles emotion overlay"| node_emotionmeta
node_dominant -->|"loads emotion display"| node_emotionmeta
node_stats -->|"loads emotion display"| node_emotionmeta
node_app -->|"streams captured frames"| node_server
node_api -->|"calls REST endpoints"| node_server
node_server -->|"loads settings"| node_config
node_server -->|"decodes and detects faces"| node_detector
node_server -->|"classifies face crops"| node_classifier
node_server -->|"formats responses"| node_schemas
node_detector -.->|"loads cascade"| node_cascade
node_classifier -->|"loads model settings"| node_config
node_classifier -->|"loads model artifact"| node_trainedmodel
node_datasetprep -->|"generates sample data"| node_samples
node_samples -->|"supplies training images"| node_training
node_training -->|"builds network"| node_cnn
node_training -->|"saves trained model"| node_trainedmodel
node_evaluation -.->|"evaluates classifier"| node_trainedmodel

click node_app "https://github.com/vinayraj75/-built-a-real-time-facial-emotion-detection-system-using-ai-ml-/blob/main/frontend/src/App.jsx"
click node_hero "https://github.com/vinayraj75/-built-a-real-time-facial-emotion-detection-system-using-ai-ml-/blob/main/frontend/src/components/HeroSection.jsx"
click node_navbar "https://github.com/vinayraj75/-built-a-real-time-facial-emotion-detection-system-using-ai-ml-/blob/main/frontend/src/components/Navbar.jsx"
click node_controls "https://github.com/vinayraj75/-built-a-real-time-facial-emotion-detection-system-using-ai-ml-/blob/main/frontend/src/components/ControlBar.jsx"
click node_video "https://github.com/vinayraj75/-built-a-real-time-facial-emotion-detection-system-using-ai-ml-/blob/main/frontend/src/components/VideoCanvasOverlay.jsx"
click node_dominant "https://github.com/vinayraj75/-built-a-real-time-facial-emotion-detection-system-using-ai-ml-/blob/main/frontend/src/components/DominantEmotion.jsx"
click node_stats "https://github.com/vinayraj75/-built-a-real-time-facial-emotion-detection-system-using-ai-ml-/blob/main/frontend/src/components/EmotionStatsCard.jsx"
click node_snapshots "https://github.com/vinayraj75/-built-a-real-time-facial-emotion-detection-system-using-ai-ml-/blob/main/frontend/src/components/SnapshotModal.jsx"
click node_emotionmeta "https://github.com/vinayraj75/-built-a-real-time-facial-emotion-detection-system-using-ai-ml-/blob/main/frontend/src/utils/emotions.js"
click node_api "https://github.com/vinayraj75/-built-a-real-time-facial-emotion-detection-system-using-ai-ml-/blob/main/frontend/src/utils/api.js"
click node_server "https://github.com/vinayraj75/-built-a-real-time-facial-emotion-detection-system-using-ai-ml-/blob/main/backend/app/main.py"
click node_config "https://github.com/vinayraj75/-built-a-real-time-facial-emotion-detection-system-using-ai-ml-/blob/main/backend/app/config.py"
click node_detector "https://github.com/vinayraj75/-built-a-real-time-facial-emotion-detection-system-using-ai-ml-/blob/main/backend/app/detector.py"
click node_classifier "https://github.com/vinayraj75/-built-a-real-time-facial-emotion-detection-system-using-ai-ml-/blob/main/backend/app/emotion_classifier.py"
click node_schemas "https://github.com/vinayraj75/-built-a-real-time-facial-emotion-detection-system-using-ai-ml-/blob/main/backend/app/schemas.py"
click node_cascade "https://github.com/vinayraj75/-built-a-real-time-facial-emotion-detection-system-using-ai-ml-/blob/main/backend/haarcascades/haarcascade_frontalface_default.xml"
click node_cnn "https://github.com/vinayraj75/-built-a-real-time-facial-emotion-detection-system-using-ai-ml-/blob/main/model/architecture.py"
click node_training "https://github.com/vinayraj75/-built-a-real-time-facial-emotion-detection-system-using-ai-ml-/blob/main/model/train.py"
click node_evaluation "https://github.com/vinayraj75/-built-a-real-time-facial-emotion-detection-system-using-ai-ml-/blob/main/model/evaluate.py"
click node_trainedmodel "https://github.com/vinayraj75/-built-a-real-time-facial-emotion-detection-system-using-ai-ml-/blob/main/model/emotion_model.keras"
click node_datasetprep "https://github.com/vinayraj75/-built-a-real-time-facial-emotion-detection-system-using-ai-ml-/blob/main/dataset/prepare_dataset.py"
click node_samples "https://github.com/vinayraj75/-built-a-real-time-facial-emotion-detection-system-using-ai-ml-/tree/main/dataset/sample_data"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_app,node_hero,node_navbar,node_controls,node_video,node_dominant,node_stats,node_snapshots,node_emotionmeta,node_api,node_visitor toneBlue
class node_server,node_config,node_detector,node_classifier,node_schemas,node_cascade toneAmber
class node_cnn,node_training,node_evaluation,node_trainedmodel toneMint
class node_datasetprep,node_samples toneRose
```

## Components

### Browser Dashboard

- [Dashboard State](https://github.com/vinayraj75/-built-a-real-time-facial-emotion-detection-system-using-ai-ml-/blob/main/frontend/src/App.jsx): `frontend/src/App.jsx`
- [Landing Panel](https://github.com/vinayraj75/-built-a-real-time-facial-emotion-detection-system-using-ai-ml-/blob/main/frontend/src/components/HeroSection.jsx): `frontend/src/components/HeroSection.jsx`
- [Server Status](https://github.com/vinayraj75/-built-a-real-time-facial-emotion-detection-system-using-ai-ml-/blob/main/frontend/src/components/Navbar.jsx): `frontend/src/components/Navbar.jsx`
- [Camera Controls](https://github.com/vinayraj75/-built-a-real-time-facial-emotion-detection-system-using-ai-ml-/blob/main/frontend/src/components/ControlBar.jsx): `frontend/src/components/ControlBar.jsx`
- [Video HUD](https://github.com/vinayraj75/-built-a-real-time-facial-emotion-detection-system-using-ai-ml-/blob/main/frontend/src/components/VideoCanvasOverlay.jsx): `frontend/src/components/VideoCanvasOverlay.jsx`
- [Dominant Emotion](https://github.com/vinayraj75/-built-a-real-time-facial-emotion-detection-system-using-ai-ml-/blob/main/frontend/src/components/DominantEmotion.jsx): `frontend/src/components/DominantEmotion.jsx`
- [Emotion Statistics](https://github.com/vinayraj75/-built-a-real-time-facial-emotion-detection-system-using-ai-ml-/blob/main/frontend/src/components/EmotionStatsCard.jsx): `frontend/src/components/EmotionStatsCard.jsx`
- [Snapshot Gallery](https://github.com/vinayraj75/-built-a-real-time-facial-emotion-detection-system-using-ai-ml-/blob/main/frontend/src/components/SnapshotModal.jsx): `frontend/src/components/SnapshotModal.jsx`
- [Emotion Metadata](https://github.com/vinayraj75/-built-a-real-time-facial-emotion-detection-system-using-ai-ml-/blob/main/frontend/src/utils/emotions.js): `frontend/src/utils/emotions.js`
- [API Client](https://github.com/vinayraj75/-built-a-real-time-facial-emotion-detection-system-using-ai-ml-/blob/main/frontend/src/utils/api.js): `frontend/src/utils/api.js`

### Inference Service

- [FastAPI Routes](https://github.com/vinayraj75/-built-a-real-time-facial-emotion-detection-system-using-ai-ml-/blob/main/backend/app/main.py): `backend/app/main.py`
- [Inference Config](https://github.com/vinayraj75/-built-a-real-time-facial-emotion-detection-system-using-ai-ml-/blob/main/backend/app/config.py): `backend/app/config.py`
- [Face Detection](https://github.com/vinayraj75/-built-a-real-time-facial-emotion-detection-system-using-ai-ml-/blob/main/backend/app/detector.py): `backend/app/detector.py`
- [Emotion Inference](https://github.com/vinayraj75/-built-a-real-time-facial-emotion-detection-system-using-ai-ml-/blob/main/backend/app/emotion_classifier.py): `backend/app/emotion_classifier.py`
- [Result Schemas](https://github.com/vinayraj75/-built-a-real-time-facial-emotion-detection-system-using-ai-ml-/blob/main/backend/app/schemas.py): `backend/app/schemas.py`
- [Haar Cascade](https://github.com/vinayraj75/-built-a-real-time-facial-emotion-detection-system-using-ai-ml-/blob/main/backend/haarcascades/haarcascade_frontalface_default.xml): `backend/haarcascades/haarcascade_frontalface_default.xml`

### Model Development

- [CNN Architecture](https://github.com/vinayraj75/-built-a-real-time-facial-emotion-detection-system-using-ai-ml-/blob/main/model/architecture.py): `model/architecture.py`
- [Model Training](https://github.com/vinayraj75/-built-a-real-time-facial-emotion-detection-system-using-ai-ml-/blob/main/model/train.py): `model/train.py`
- [Model Evaluation](https://github.com/vinayraj75/-built-a-real-time-facial-emotion-detection-system-using-ai-ml-/blob/main/model/evaluate.py): `model/evaluate.py`
- [Trained CNN](https://github.com/vinayraj75/-built-a-real-time-facial-emotion-detection-system-using-ai-ml-/blob/main/model/emotion_model.keras): `model/emotion_model.keras`

### Dataset Preparation

- [Dataset Preparation](https://github.com/vinayraj75/-built-a-real-time-facial-emotion-detection-system-using-ai-ml-/blob/main/dataset/prepare_dataset.py): `dataset/prepare_dataset.py`
- [Sample Images](https://github.com/vinayraj75/-built-a-real-time-facial-emotion-detection-system-using-ai-ml-/tree/main/dataset/sample_data): `dataset/sample_data`

### Other components

- **Camera User**

## Connections

- Camera User → Dashboard State: uses dashboard (evidence: `README.md`)
- Dashboard State → Landing Panel: renders (evidence: `frontend/src/App.jsx`)
- Dashboard State → Server Status: renders (evidence: `frontend/src/App.jsx`)
- Dashboard State → Camera Controls: renders (evidence: `frontend/src/App.jsx`)
- Dashboard State → Video HUD: renders (evidence: `frontend/src/App.jsx`)
- Dashboard State → Dominant Emotion: renders (evidence: `frontend/src/App.jsx`)
- Dashboard State → Emotion Statistics: renders (evidence: `frontend/src/App.jsx`)
- Dashboard State → Snapshot Gallery: renders (evidence: `frontend/src/App.jsx`)
- Dashboard State → API Client: requests status and predictions (evidence: `frontend/src/App.jsx`)
- Video HUD → Emotion Metadata: styles emotion overlay (evidence: `frontend/src/components/VideoCanvasOverlay.jsx`)
- Dominant Emotion → Emotion Metadata: loads emotion display (evidence: `frontend/src/components/DominantEmotion.jsx`)
- Emotion Statistics → Emotion Metadata: loads emotion display (evidence: `frontend/src/components/EmotionStatsCard.jsx`)
- Dashboard State → FastAPI Routes: streams captured frames (evidence: `README.md`)
- API Client → FastAPI Routes: calls REST endpoints (evidence: `README.md`)
- FastAPI Routes → Inference Config: loads settings (evidence: `backend/app/main.py`)
- FastAPI Routes → Face Detection: decodes and detects faces (evidence: `backend/app/main.py`)
- FastAPI Routes → Emotion Inference: classifies face crops (evidence: `backend/app/main.py`)
- FastAPI Routes → Result Schemas: formats responses (evidence: `backend/app/main.py`)
- Face Detection → Haar Cascade: loads cascade
- Emotion Inference → Inference Config: loads model settings (evidence: `backend/app/emotion_classifier.py`)
- Emotion Inference → Trained CNN: loads model artifact
- Dataset Preparation → Sample Images: generates sample data (evidence: `README.md`)
- Sample Images → Model Training: supplies training images (evidence: `README.md`)
- Model Training → CNN Architecture: builds network (evidence: `model/train.py`)
- Model Training → Trained CNN: saves trained model (evidence: `README.md`)
- Model Evaluation → Trained CNN: evaluates classifier
