# adnankhan46/bit-innovathon architecture

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

- Interactive diagram: https://gitdiagram.com/adnankhan46/bit-innovathon
- Repository: https://github.com/adnankhan46/bit-innovathon

## Overview

##### Project type and purpose
- This is a full-stack web application called “SheShield” for women’s emergency safety.
- Frontend: React (Vite) single-page app; Backend: Node.js + Express API; Database: MongoDB; External services: Twilio SMS, OpenStreetMap.

##### File structure
- Root: environment examples, gitignore, package.json.
- api/: Express server
- config/db.js – MongoDB connection
- controllers/ – request handlers (authController)
- middleware/ – JWT auth guard
- models/User.js – Mongoose schema
- routes/ – authRoutes, alertRoutes
- services/ – TwilioService, locationServices
- index.js – server entry point
- client/: React app
- public, index.html
- src/: components (SOSButton, MapComponent, CanvasDetection, PrivateRoute, etc.), pages (Home, Login, SignUp, Landing), services (LocationService)
- tailwind.config.js, vite.config.js
- Top-level package.json orchestrates monorepo scripts.

##### Insights from README
- Key features: SOS alerts via Twilio, safe‐zone geofencing, gesture detection with Canvas, timer-based check, fake call playback.
- Tech stack: React, Node/Express, MongoDB, JWT, Twilio, OpenStreetMap.

a. Main components
- Frontend SPA (React/Vite)
- Backend API (Express)
- MongoDB database
- Twilio SMS service
- OpenStreetMap geocoding API
- Authentication (JWT)
b. Relationships & interactions
- User interacts with React UI → issues actions (SOS button, map view, gestures).
- React → sends HTTP(S) requests to Express endpoints (e.g., /login, /send-alert).
- Express middleware validates JWT tokens, routes requests to controllers.
- Controllers call services:
– locationServices queries OpenStreetMap for geodata or safe-zone lookup
– TwilioService sends SMS alerts to configured emergency contacts
- Express uses Mongoose to read/write User data and alert logs in MongoDB.
c. Architectural patterns/design principles
- Client-Server (RESTful API)
- Layered pattern: Presentation (React) → API Layer (Express routes/controllers) → Service layer → Data layer (MongoDB)
- Token-based stateless authentication (JWT)
- Modular separation: controllers, services, models
d. Key technologies/frameworks
- React.js, Vite, Tailwind CSS on client
- Node.js, Express.js, Mongoose on server
- MongoDB as document store
- Twilio API for SMS
- OpenStreetMap API for geolocation

##### Details
- Every layer: UI events, API endpoints, middleware, services, data store.
- Where authentication occurs (JWT header check in authMiddleware).
- Deployment targets if needed (localhost:5173 for client, localhost:5000 for server).

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% User interaction
    User["User (Mobile/Browser)"]:::external
    User -->|"1. Interact\n(UI Events)"| ReactContainer

    %% Frontend SPA
    subgraph "React SPA (Client)" 
        direction TB
        SOSButton["SOSButton"]:::frontend
        MapComponent["MapComponent"]:::frontend
        CanvasDetection["CanvasDetection"]:::frontend
        SafetyTimer["SafetyTimer"]:::frontend
        PrivateRoute["PrivateRoute"]:::frontend
        LocationServiceClient["LocationService"]:::frontend
        HomePage["Home.jsx"]:::frontend
        LoginPage["Login.jsx"]:::frontend
        SignUpPage["SignUp.jsx"]:::frontend
        LandingPage["LandingPage.jsx"]:::frontend
    end
    ReactContainer["React SPA"]:::frontend
    ReactContainer --> SOSButton
    ReactContainer --> MapComponent
    ReactContainer --> CanvasDetection
    ReactContainer --> SafetyTimer
    ReactContainer --> PrivateRoute
    ReactContainer --> LocationServiceClient
    ReactContainer --> HomePage
    ReactContainer --> LoginPage
    ReactContainer --> SignUpPage
    ReactContainer --> LandingPage

    %% Frontend to Backend
    ReactContainer -->|"2. POST /send-alert\n(JSON over HTTPS)"| ExpressContainer
    ReactContainer -->|"Auth Requests\n/login, /signup"| ExpressContainer

    %% Backend API
    subgraph "Express API (Server)" 
        direction TB
        APIEntry["index.js"]:::backend
        DBConfig["db.js"]:::backend
        AuthMiddleware["authMiddleware.js"]:::backend
        subgraph "Routes"
            direction TB
            AuthRoutes["authRoutes.js"]:::backend
            AlertRoutes["alertRoutes.js"]:::backend
        end
        subgraph "Controllers"
            direction TB
            AuthController["authController.js"]:::backend
        end
        subgraph "Services"
            direction TB
            TwilioService["TwilioService.js"]:::backend
            LocationServiceServer["locationServices.js"]:::backend
        end
        UserModel["User.js"]:::backend
    end
    ExpressContainer["Express API"]:::backend

    APIEntry --> DBConfig
    APIEntry --> AuthRoutes
    APIEntry --> AlertRoutes
    AuthRoutes --> AuthController
    AlertRoutes --> AuthController
    AuthRoutes --> AuthMiddleware
    AlertRoutes --> AuthMiddleware
    AuthController --> TwilioService
    AuthController --> LocationServiceServer
    AuthController --> UserModel

    %% Backend to Database
    ExpressContainer -->|"Mongoose\nCRUD Operations"| MongoDB

    %% Backend to External Services
    ExpressContainer -->|"REST API\n(HTTP)"| Twilio
    ExpressContainer -->|"REST API\n(HTTP)"| OSM

    %% Datastore
    MongoDB["MongoDB\n(Users & Alerts)"]:::db

    %% External Services
    subgraph "External Services"
        direction TB
        Twilio["Twilio SMS"]:::external
        OSM["OpenStreetMap API"]:::external
    end

    %% Emergency contacts
    Twilio -->|"4. SMS Alert Sent"| Contacts["Emergency Contacts"]:::external

    %% Click events for mapping
    click SOSButton "https://github.com/adnankhan46/bit-innovathon/blob/main/client/src/components/SOSButton.jsx"
    click MapComponent "https://github.com/adnankhan46/bit-innovathon/blob/main/client/src/components/MapCompnonet.jsx"
    click CanvasDetection "https://github.com/adnankhan46/bit-innovathon/blob/main/client/src/components/CanvasDetection.jsx"
    click SafetyTimer "https://github.com/adnankhan46/bit-innovathon/blob/main/client/src/components/SafetyTimer.jsx"
    click PrivateRoute "https://github.com/adnankhan46/bit-innovathon/blob/main/client/src/components/PrivateRoute.jsx"
    click LocationServiceClient "https://github.com/adnankhan46/bit-innovathon/blob/main/client/src/components/LocationService.js"
    click HomePage "https://github.com/adnankhan46/bit-innovathon/blob/main/client/src/pages/Home.jsx"
    click LoginPage "https://github.com/adnankhan46/bit-innovathon/blob/main/client/src/pages/Login.jsx"
    click SignUpPage "https://github.com/adnankhan46/bit-innovathon/blob/main/client/src/pages/SignUp.jsx"
    click LandingPage "https://github.com/adnankhan46/bit-innovathon/blob/main/client/src/pages/LandingPage.jsx"
    click APIEntry "https://github.com/adnankhan46/bit-innovathon/blob/main/api/index.js"
    click DBConfig "https://github.com/adnankhan46/bit-innovathon/blob/main/api/config/db.js"
    click AuthController "https://github.com/adnankhan46/bit-innovathon/blob/main/api/controllers/authController.js"
    click AuthRoutes "https://github.com/adnankhan46/bit-innovathon/blob/main/api/routes/authRoutes.js"
    click AlertRoutes "https://github.com/adnankhan46/bit-innovathon/blob/main/api/routes/alertRoutes.js"
    click AuthMiddleware "https://github.com/adnankhan46/bit-innovathon/blob/main/api/middleware/authMiddleware.js"
    click UserModel "https://github.com/adnankhan46/bit-innovathon/blob/main/api/models/User.js"
    click TwilioService "https://github.com/adnankhan46/bit-innovathon/blob/main/api/services/TwilioService.js"
    click LocationServiceServer "https://github.com/adnankhan46/bit-innovathon/blob/main/api/services/locationServices.js"
    click PackageJSON "https://github.com/adnankhan46/bit-innovathon/blob/main/package.json"
    click PackageLock "https://github.com/adnankhan46/bit-innovathon/blob/main/package-lock.json"

    %% Styles
    classDef frontend fill:#ADD8E6,stroke:#000,stroke-width:1px
    classDef backend fill:#87CEFA,stroke:#000,stroke-width:1px
    classDef db fill:#9ACD32,stroke:#000,stroke-width:1px
    classDef external fill:#FFA500,stroke:#000,stroke-width:1px
```
