# karan-meshram-code/safe-qr architecture

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

- Interactive diagram: https://gitdiagram.com/karan-meshram-code/safe-qr
- Repository: https://github.com/karan-meshram-code/safe-qr

## Overview

##### Project Type and Purpose
- SafeQR is a client-heavy, BaaS-backed full-stack web application. It uses static hosting for HTML/CSS/JS assets and relies on Firebase for authentication, data storage, and hosting. Its purpose is to let users register medical and emergency data, generate a QR code pointing at that data, and allow first responders to scan and view it.

##### File Structure Analysis
- Top-level HTML pages: index.html, login.html, signup.html, dashboard.html, profile.html, emergency.html.
- css/styles.css for styling; js/*.js for client logic:
- firebase-config.js: your Firebase project settings
- auth.js: signup/login flows (email/password & Google)
- app.js: application bootstrap
- dashboard.js: profile completeness check & QR code generation (uses QRCode.js)
- profile.js: user profile CRUD
- emergency.js: scanning flow—reads query parameter, fetches data
- package.json, node_modules, and the Firebase CLI installers indicate optional local tooling but primary runtime is client in browser.
- No dedicated backend code—Firebase Authentication and Firestore are the “server side.”

##### Key Architectural Insights from README
- Firebase Authentication (Email/Password, Google) for user identity.
- Firestore as document store for user profiles, medical info, contacts, and privacy settings.
- QRCode.js library to render QR codes in the browser.
- Firebase Hosting (optional) to serve static files.

##### Main Components and Their Relationships
a. Frontend (Browser)
- Static files served via Firebase Hosting (or any web server).
- JavaScript modules handle:
- Authentication flows (auth.js) ←→ Firebase Auth REST/SDK
- Profile and medical data CRUD (profile.js) ←→ Firestore
- Dashboard & QR generation (dashboard.js) uses QRCode.js lib + Firestore
- Emergency page (emergency.js) fetches Firestore docs by ID in URL
b. Firebase Services
- Authentication service issues JWTs, manages user sessions.
- Firestore stores user documents (personal, medical, contacts).
- Hosting serves static assets; can enforce HTTPS and redirect rules.
c. External Dependencies
- Google Identity Platform (via Firebase) for OAuth sign-in
- QRCode.js (client-side JS library)
d. Data Flow
1. User signs up/logs in → frontend calls Firebase Auth.
2. On success, get UID and token.
3. profile.js reads/writes Firestore under “users/{uid}”.
4. When profile is valid, dashboard.js calls QRCode.js to generate a URL like https://your-host/emergency.html?uid={uid}.
5. end-user or responder scans QR → opens emergency.html?uid={uid} → emergency.js fetches Firestore document and renders data.

##### Architectural Patterns & Principles
- Client-centric SPA behavior (each page is a mini-SPA module).
- BaaS pattern (Firebase as “backend”).
- Separation of concerns:
- auth.js handles all identity.
- profile.js handles data model.
- dashboard.js and emergency.js handle view logic.
- Secure data access: Firestore rules keyed on UID.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Static Hosting Layer
    subgraph "Static Hosting"
        Hosting["Firebase Hosting\n(static assets)"]:::hosting
    end

    %% Client Browser Layer
    subgraph "Client Browser"
        subgraph "Application Bootstrap"
            AppJS["js/app.js"]:::frontend
            IndexHTML["index.html"]:::frontend
        end
        subgraph "Authentication Flow"
            AuthJS["js/auth.js"]:::frontend
            FireConfig["js/firebase-config.js"]:::frontend
            LoginHTML["login.html"]:::frontend
            SignupHTML["signup.html"]:::frontend
        end
        subgraph "Profile Management"
            ProfileJS["js/profile.js"]:::frontend
            ProfileHTML["profile.html"]:::frontend
        end
        subgraph "Dashboard & QR Generation"
            DashboardJS["js/dashboard.js"]:::frontend
            DashboardHTML["dashboard.html"]:::frontend
            QRCODE["QRCode.js"]:::library
        end
        subgraph "Emergency Data Viewer"
            EmergencyJS["js/emergency.js"]:::frontend
            EmergencyHTML["emergency.html"]:::frontend
        end
        subgraph "Styling"
            CSS["css/styles.css"]:::frontend
        end
        subgraph "Tooling & Dependencies"
            PackageJSON["package.json"]:::tooling
            PackageLock["package-lock.json"]:::tooling
            NodeModules["node_modules/"]:::tooling
        end
    end

    %% Backend Services Layer
    subgraph "Backend Services"
        AuthService["Firebase Auth"]:::backend
        Firestore["Firestore\n(users collection)"]:::backend
        GoogleOAuth["Google Identity Platform"]:::external
    end

    %% Connections
    Hosting -->|"Serves HTML/CSS/JS"| AppJS
    Hosting --> IndexHTML
    Hosting --> AuthJS
    Hosting --> FireConfig
    Hosting --> LoginHTML
    Hosting --> SignupHTML
    Hosting --> ProfileJS
    Hosting --> ProfileHTML
    Hosting --> DashboardJS
    Hosting --> DashboardHTML
    Hosting --> EmergencyJS
    Hosting --> EmergencyHTML
    Hosting --> CSS

    AuthJS -->|"Auth request / JWT token"| AuthService
    FireConfig --> AuthService
    AuthService -->|"OAuth redirect"| GoogleOAuth

    ProfileJS -->|"CRUD operations"| Firestore
    DashboardJS -->|"Read profile data"| Firestore
    EmergencyJS -->|"Fetch user data by UID"| Firestore

    DashboardJS -->|"Generate QR code"| QRCODE

    %% Click Events
    click AuthJS "https://github.com/karan-meshram-code/safe-qr/blob/master/js/auth.js"
    click FireConfig "https://github.com/karan-meshram-code/safe-qr/blob/master/js/firebase-config.js"
    click LoginHTML "https://github.com/karan-meshram-code/safe-qr/blob/master/login.html"
    click SignupHTML "https://github.com/karan-meshram-code/safe-qr/blob/master/signup.html"
    click ProfileJS "https://github.com/karan-meshram-code/safe-qr/blob/master/js/profile.js"
    click ProfileHTML "https://github.com/karan-meshram-code/safe-qr/blob/master/profile.html"
    click DashboardJS "https://github.com/karan-meshram-code/safe-qr/blob/master/js/dashboard.js"
    click DashboardHTML "https://github.com/karan-meshram-code/safe-qr/blob/master/dashboard.html"
    click EmergencyJS "https://github.com/karan-meshram-code/safe-qr/blob/master/js/emergency.js"
    click EmergencyHTML "https://github.com/karan-meshram-code/safe-qr/blob/master/emergency.html"
    click AppJS "https://github.com/karan-meshram-code/safe-qr/blob/master/js/app.js"
    click IndexHTML "https://github.com/karan-meshram-code/safe-qr/blob/master/index.html"
    click CSS "https://github.com/karan-meshram-code/safe-qr/blob/master/css/styles.css"
    click PackageJSON "https://github.com/karan-meshram-code/safe-qr/blob/master/package.json"
    click PackageLock "https://github.com/karan-meshram-code/safe-qr/blob/master/package-lock.json"
    click NodeModules "https://github.com/karan-meshram-code/safe-qr/tree/master/node_modules/"

    %% Styles
    classDef frontend fill:#c5fbc5,stroke:#2d862d
    classDef backend fill:#c5dcf7,stroke:#1a4b8d
    classDef library fill:#ffe0b2,stroke:#e65100
    classDef external fill:#e1bee7,stroke:#8e24aa
    classDef hosting fill:#b3e5fc,stroke:#0277bd
    classDef tooling fill:#eeeeee,stroke:#999999
```
