How karan-meshram-code/safe-qr works
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.