How sarthaklad1034/secqr works
Project Type and Purpose
• SecQR is a full-stack web/mobile-responsive application for secure QR code scanning.
• Frontend: React.js SPA handling camera input, UI components, API calls.
• Backend: Python Flask server exposing REST API endpoints, loading a pre-trained Random Forest model, querying MongoDB for URL overrides and history.
• Machine Learning: scikit-learn Random Forest model (.pkl) with custom feature extraction utilities.
File Structure
• Top Level:
• backend/
• frontend/
• Backend:
• app.py – Flask entry point with route definitions.
• models/random_forest_model.pkl – serialized ML model.
• utils/feature_extraction.py – transforms URL strings into numeric features.
• requirements.txt – Python dependencies (Flask, pymongo, scikit-learn, etc.).
• Frontend:
• public/ – static HTML, manifest.
• src/
– components/ – React view components (HomeScreen, QRScanner, SafeSection, MaliciousSection) and nested UI primitives (Card, Alert).
– services/api.js – Axios wrapper for backend endpoints.
– App.js, routing setup, global CSS and tailwind config.
• package.json – JS dependencies (react, axios, react-router, tailwindcss).
README for Additional Insights
• Describes endpoints: /api/scan, /api/checksafe-url, /api/checkmalicious-url.
• Tech stack summary confirms React front, Flask back, MongoDB, scikit-learn.
• Machine learning model uses URL length, domain reputation, character frequency, TLD and path analysis.
Main Components
a. User Device (Browser/Mobile App)
• Camera module (browser media API)
• React SPA
b. Frontend Application
• QRScanner component
• UI sections (SafeSection, MaliciousSection)
• API Service (axios calls to backend)
c. Backend API
• Flask app.py
• Route handlers (/scan, /checksafe-url, /checkmalicious-url)
d. Business Logic & ML Layer
• feature_extraction.py
• random_forest_model.pkl loader
• prediction orchestrator (apply ML → get score)
e. Database Layer
• MongoDB cluster
• URLs collection (safe vs malicious overrides)
f. External Services (optional)
• Third-party threat intelligence / future enhancements
• Hosting environment / container orchestration
Relationships and Data Flow
1. User scans QR → camera API → QRScanner component captures image/data.
2. Frontend calls POST /api/scan with image or URL payload via services/api.js.
3. Flask route receives request → passes URL to feature_extraction → transforms to vector.
4. Backend checks MongoDB overrides collection (lookup safe/malicious).
• If override exists, return that result.
• Else, load RandomForest model → predict safety → optionally store result in DB.
5. Backend sends JSON response (safe/malicious + detail report).
6. Frontend receives response → renders SafeSection or MaliciousSection UI → user sees alert.
Architectural Patterns and Design Principles
• Layered Architecture: Presentation (React), API (Flask), Business/ML Logic, Data.
• Separation of Concerns:
• services/api.js isolates HTTP logic.
• utils/feature_extraction.py isolates feature engineering.
• models folder isolates ML assets.
• Extensibility: clear override mechanism in DB; future auth/history layers can be slotted in.
• Mobile-Responsive & SPA pattern: React Router, Tailwind for CSS.
Detailed Capture of Essential Elements
• API Endpoints
• Feature Extraction
• Model Loader
• DB Override Service