# rajshrey7/aapda-mitra architecture

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

- Interactive diagram: https://gitdiagram.com/rajshrey7/aapda-mitra
- Repository: https://github.com/rajshrey7/aapda-mitra

## Overview

##### Project Type and Purpose
- This is a full-stack, MERN-based disaster preparedness platform (“Aapda Mitra”) with real-time features (Socket.IO) and VR modules.
- It serves three user groups (Students, Teachers, Administrators), offering quizzes, VR drills, chat, analytics, and external integrations (weather, SMS, AI).

##### Main Components
a. User Interfaces
- Student/Teacher/Admin on Web Browser or Mobile (PWA)
- VR Client (A-Frame scenes)
b. Frontend
- React/Vite app (UI, routing, state & context, theming, i18n)
- Socket.IO client for live updates
c. Backend
- Express.js API server (REST endpoints, controllers, middleware)
- WebSocket service (real-time chat & game sync)
d. Database
- MongoDB (collections for users, quizzes, sessions, scores, drills, modules)
e. External Services
- OpenWeather API (weather alerts)
- Twilio (SMS alerts)
- OpenAI/Gemini (chatbot & quiz generation)
- Google Maps API (interactive maps)

##### Relationships & Data Flows
- Web UI ↔ HTTP REST API (login, quizzes, modules, analytics)
- Web UI ↔ WebSocket Server (chat messages, live leaderboards, game state)
- API Server ↔ MongoDB (CRUD for all data)
- API Server ↔ External Services (weather, SMS, AI)
- VR Client loads static HTML/GLTF assets from Frontend Public folder and reports drill results via API

##### Architectural Patterns & Principles
- Layered architecture: Presentation (React) → API (Express) → Persistence (MongoDB)
- Separation of concerns:
- UI components vs. page components vs. contexts vs. services
- Controllers, services, models, and routes on the server
- Real-time microservice: Dedicated websockets folder/server for high-volume, bidirectional events
- Modularization: Each domain (quiz, game, drill, alerts) has its own routes, controllers, and services

- Weather Alerts
- SMS Alerts
- AI Chatbot & Quiz Gen
- Maps & Geolocation

- Who uses the system
- Where they interact (browser/VR)
- How data flows to/from the server and database
- Which third‐party services enrich the platform

## Diagram (Mermaid)

```mermaid
flowchart TD
    Users["Users\n(Student, Teacher, Admin)"]:::ui-layer
    Clients["Web & VR Clients\n(React + A-Frame)"]:::ui-layer
    API["API Server\n(Express.js)"]:::api-layer
    Realtime["Realtime Service\n(Socket.IO)"]:::api-layer
    DB[(MongoDB)]:::db-layer

    subgraph "External Services"
        Weather["Weather Alerts"]:::ext-layer
        SMS["SMS Alerts"]:::ext-layer
        AI["AI Chatbot & Quiz Gen"]:::ext-layer
        Maps["Maps & Geolocation"]:::ext-layer
    end

    Users -->|"Interact via UI & VR Drills"| Clients
    Clients -->|"HTTP Requests"| API
    Clients -.->|"WebSocket"| Realtime
    API -->|"Store/Retrieve Data"| DB
    API -->|"Fetch weather info"| Weather
    API -->|"Send SMS alerts"| SMS
    API -->|"Generate quizzes & chat"| AI
    Clients -->|"Load maps"| Maps

    click Clients "https://github.com/rajshrey7/aapda-mitra/tree/main/client/"
    click Clients "https://github.com/rajshrey7/aapda-mitra/blob/main/client/src/main.jsx"
    click API "https://github.com/rajshrey7/aapda-mitra/blob/main/server/index.js"
    click Realtime "https://github.com/rajshrey7/aapda-mitra/blob/main/websockets/index.js"
    click DB "https://github.com/rajshrey7/aapda-mitra/blob/main/server/config/db.js"
    click Weather "https://github.com/rajshrey7/aapda-mitra/blob/main/server/services/weatherService.js"
    click SMS "https://github.com/rajshrey7/aapda-mitra/blob/main/server/services/sms.services.js"
    click AI "https://github.com/rajshrey7/aapda-mitra/blob/main/server/services/aiService.js"
    click Maps "https://github.com/rajshrey7/aapda-mitra/blob/main/client/src/components/DisasterMap.jsx"

    classDef ui-layer fill:#D0E6FF,stroke:#0366d6,color:#0366d6;
    classDef api-layer fill:#DFF6DD,stroke:#28a745,color:#28a745;
    classDef db-layer fill:#FFEFD5,stroke:#d2691e,color:#d2691e;
    classDef ext-layer fill:#F3E5FF,stroke:#6f42c1,color:#6f42c1;
```
