# ananaya-agarwal/women-safety-analytics-protecting-women-from-safety-threats architecture

> Architecture diagram of the GitHub repository ananaya-agarwal/women-safety-analytics-protecting-women-from-safety-threats, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-08-26). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ananaya-agarwal/women-safety-analytics-protecting-women-from-safety-threats
- Repository: https://github.com/ananaya-agarwal/women-safety-analytics-protecting-women-from-safety-threats

## Overview

##### Project Type & Purpose
- This is a prototype full‐stack AI‐powered surveillance solution, combining a mobile (or web) front‐end with a backend gender‐detection engine.
- Purpose: capture camera frames, run gender‐detection in real time (using the YOLOv8 model), detect risky situations (e.g., lone woman with many men or unsafe hours), and automatically trigger an SOS alert with live location.

##### File Structure & README
- Top‐level files:
- web.py – likely your backend service (e.g., Flask/FastAPI) that loads yolov8n.pt and serves detection endpoints.
- new.html – simple front‐end page (for demo or web‐based camera capture).
- first.ipynb – experiment notebook (proof of concept).
- gender_detection_results.csv – sample output/data.
- yolov8n.pt – pre‐trained YOLOv8 model.
- No explicit “frontend/” or “backend/” folders, so treat web.py + new.html as the minimal full‐stack PoC.

##### Main Components & How They Interact
a. Mobile/Web Client
- Captures video frames (camera)
- Obtains geolocation via HTML5 or native APIs
- Displays live video and SOS prompt
––> Sends frames (or frame URLs) + location to the backend.
b. Backend AI Service (web.py)
- HTTP endpoint to receive frames
- Loads yolov8n.pt via PyTorch or Ultralytics API
- Runs OpenCV preprocessing + gender‐detection inference
––> Returns counts of males/females + risk flag.
c. Risk Detection Engine
- Business logic: if (woman count ==1 && male count ≥ N) or (time ∈ unsafe hours) → risk = TRUE
––> Triggers SOS event.
d. Notification Service
- On SOS event, pushes a pop‐up on the client or sends push/SMS/email via a third‐party API (e.g., Twilio, FCM, APNs)
––> Optionally logs event to a database.
e. Data Store (optional)
- Stores event logs, locations, gender counts for analytics (CSV or lightweight DB).
f. External Services
- Geolocation API (Google Maps / native)
- Emergency contact endpoints or police‐station APIs

##### Architectural Patterns & Design Principles
- Separation of concerns: UI vs. AI inference vs. notification logic
- Event‐driven flow: camera frames → inference → decision → alert
- Stateless inference microservice (scalable horizontally)
- Use of a single reusable model artifact (yolov8n.pt)
- Fail‐safe / fallback: if backend is unreachable, client should notify user gracefully.

##### Putting It All Together
- Lay out the components in logical left‐to‐right or top‐to‐bottom flow
- Related elements (e.g., camera + geolocation under “Client”)
- AI model load point (yolov8n.pt) and runtime inference step
- Critical SOS decision branch (“If risk → SOS”)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    A["Mobile/Web Client<br/>Camera Capture + Geo API"]:::frontend
    click A "https://github.com/ananaya-agarwal/women-safety-analytics-protecting-women-from-safety-threats/blob/main/new.html"

    %% Backend AI Service Layer
    B["Backend AI Service<br/>(web.py)"]:::backend
    click B "https://github.com/ananaya-agarwal/women-safety-analytics-protecting-women-from-safety-threats/blob/main/web.py"
    C["AI Model Artifact<br/>yolov8n.pt"]:::backend
    click C "https://github.com/ananaya-agarwal/women-safety-analytics-protecting-women-from-safety-threats/blob/main/yolov8n.pt"

    %% Risk Detection & Alert Manager
    D["Risk Detection Engine<br/>(web.py)"]:::backend
    click D "https://github.com/ananaya-agarwal/women-safety-analytics-protecting-women-from-safety-threats/blob/main/web.py"

    %% Notification Service
    E["Notification Service<br/>(web.py)"]:::notification
    click E "https://github.com/ananaya-agarwal/women-safety-analytics-protecting-women-from-safety-threats/blob/main/web.py"

    %% Data Store
    DS[(Event Data Store<br/>gender_detection_results.csv)]:::datastore
    click DS "https://github.com/ananaya-agarwal/women-safety-analytics-protecting-women-from-safety-threats/blob/main/gender_detection_results.csv"

    %% Proof of Concept Notebook
    F["Experiment Notebook<br/>first.ipynb"]:::datastore
    click F "https://github.com/ananaya-agarwal/women-safety-analytics-protecting-women-from-safety-threats/blob/main/first.ipynb"

    %% External Services
    subgraph "External Services"
        Geo["Geolocation API"]:::external
        Police["Police API / Emergency Contacts"]:::external
    end

    %% Data Flows
    A -->|"Video frame + coords"| B
    Geo -->|"Location data"| B
    B -->|"Gender counts + timestamp"| D
    D -->|"If risk: SOS trigger"| E
    E -->|"Push/SMS to Client"| A
    D -->|"Log event"| DS
    E -->|"Notify authorities"| Police

    %% Styles
    classDef frontend fill:#ADD8E6,stroke:#000,stroke-width:1px
    classDef backend fill:#90EE90,stroke:#000,stroke-width:1px
    classDef notification fill:#FFA500,stroke:#000,stroke-width:1px
    classDef datastore fill:#D3D3D3,stroke:#000,stroke-width:1px
    classDef external fill:#E0E0E0,stroke:#000,stroke-width:1px
```
