# isreeharim/qrsree architecture

> Architecture diagram of the GitHub repository isreeharim/qrsree, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-15). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/isreeharim/qrsree
- Repository: https://github.com/isreeharim/qrsree

## Overview

#### Purpose and system shape
QR Manager is a two-part dynamic QR platform. Printed codes resolve to a stable backend URL, while administrators can later change the stored destination. The backend owns authentication, QR lifecycle, scan telemetry, and redirects; the React frontend is an authenticated management console.

#### Runtime entry points
- Express API/server bootstrap: `backend/server.js`; MongoDB connection setup: `backend/config/db.js`.
- React/Vite client bootstrap and root composition: `frontend/src/main.jsx`, `frontend/src/App.jsx`.
- Initial administrator provisioning is a separate process: `backend/seed/createAdmin.js`.
- Deployment configuration exists for independent frontend/backend Vercel deployments: `backend/vercel.json`, `frontend/vercel.json`.

#### Identity and protected administration
JWT-based admin authentication is implemented through auth routes/controllers and enforced middleware. Password hashing is handled server-side; the client retains auth state and gates protected routes.
- Backend boundary: `backend/routes/authRoutes.js`, `backend/controllers/authController.js`, `backend/middleware/auth.js`.
- Frontend auth/session boundary: `frontend/src/context/AuthContext.jsx`, `frontend/src/components/ProtectedRoute.jsx`, `frontend/src/api/auth.js`.
- User administration is a distinct protected domain: `backend/routes/userRoutes.js`, `backend/controllers/userController.js`, `frontend/src/pages/UserList.jsx`.

#### QR code lifecycle
Administrators create, list, inspect, update, and delete QR definitions. Each QR record has a generated short code and a mutable destination, making the encoded public URL stable while redirect behavior remains database-driven.
- QR domain model and shortcode generation: `backend/models/QRCode.js`, `backend/utils/generateShortCode.js`.
- Protected QR API orchestration: `backend/routes/qrRoutes.js`, `backend/controllers/qrController.js`.
- Client data access and main management views: `frontend/src/api/qr.js`, `frontend/src/pages/QRList.jsx`, `frontend/src/pages/QRDetail.jsx`.
- QR rendering/export UI is separated into reusable presentation components: `frontend/src/components/QRCodeDisplay.jsx`, `frontend/src/components/QRFormModal.jsx`.

#### Public scan and redirect pipeline
A scanned code targets `PUBLIC_BASE_URL/q/:shortCode`, not the final URL. The unauthenticated public handler resolves the QR code, records a scan, increments its aggregate scan count, serves a temporary GPS-permission page, and redirects to the current destination. A separate public PATCH endpoint attaches coordinates to the scan created by that request.
- Public routing and scan control flow: `backend/routes/publicRoutes.js`, `backend/controllers/scanController.js`.
- Persistent telemetry: `backend/models/ScanLog.js`, `backend/models/QRCode.js`.
- IP-derived geography is an outbound integration boundary: `backend/utils/geoLookup.js` calls ip-api.com.

#### Analytics and dashboard
Dashboard aggregation exposes total QR/scan metrics and recent scan activity, while per-QR scan history supports detail analysis. These read models depend on QR and ScanLog persistence rather than a separate analytics service.
- Backend dashboard endpoint: `backend/routes/dashboardRoutes.js`, `backend/controllers/dashboardController.js`.
- Client dashboard integration and view: `frontend/src/api/dashboard.js`, `frontend/src/pages/Dashboard.jsx`.
- QR-specific scan history remains under `backend/controllers/qrController.js` and is presented from `frontend/src/pages/QRDetail.jsx`.

#### Infrastructure and cross-cutting boundaries
MongoDB Atlas via Mongoose is the system of record. Express middleware centralizes JWT checks, request validation, async/error translation, and CORS-facing API behavior.
- Cross-cutting backend handling: `backend/middleware/validate.js`, `backend/middleware/errorHandler.js`, `backend/utils/AppError.js`.
- Frontend HTTP boundary is centralized in `frontend/src/api/axios.js`; all feature API modules consume it.
- Production requires HTTPS for browser geolocation and a correctly configured public backend origin because that origin is embedded in QR codes.

Main entry points: [`frontend/src/api/axios.js`](https://github.com/isreeharim/qrsree/blob/master/frontend/src/api/axios.js) (HTTP client), [`backend/server.js`](https://github.com/isreeharim/qrsree/blob/master/backend/server.js) (Express server), [`backend/routes/dashboardRoutes.js`](https://github.com/isreeharim/qrsree/blob/master/backend/routes/dashboardRoutes.js) (Dashboard aggregation), [`frontend/src/App.jsx`](https://github.com/isreeharim/qrsree/blob/master/frontend/src/App.jsx) (React app shell)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_backend["Backend API"]
  node_server["Express server<br/>Node.js entry point<br/>[server.js]"]
  node_database_setup["MongoDB connection<br/>Mongoose setup<br/>[db.js]"]
  node_auth_api["Auth API<br/>routes + controller<br/>[authRoutes.js]"]
  node_auth_guard["JWT guard<br/>Express middleware<br/>[auth.js]"]
  node_user_api["User administration<br/>protected API<br/>[userRoutes.js]"]
  node_qr_api["QR lifecycle API<br/>protected API<br/>[qrRoutes.js]"]
  node_qr_model[("QR codes<br/>Mongoose model<br/>[QRCode.js]")]
  node_public_scan["Public scan redirect<br/>public route + controller<br/>[publicRoutes.js]"]
  node_scan_log[("Scan logs<br/>Mongoose model<br/>[ScanLog.js]")]
  node_geo_lookup["IP geolocation<br/>outbound integration<br/>[geoLookup.js]"]
  node_dashboard_api["Dashboard aggregation<br/>analytics API<br/>[dashboardRoutes.js]"]
  node_error_handling["Validation &amp; errors<br/>Express middleware<br/>[validate.js]"]
  node_admin_seed["Admin provisioning<br/>seed process<br/>[createAdmin.js]"]
end

subgraph group_frontend["Management Console"]
  node_app["React app shell<br/>Vite entry + routes<br/>[App.jsx]"]
  node_auth_session["Auth session<br/>context + route guard<br/>[AuthContext.jsx]"]
  node_http_client["HTTP client<br/>Axios boundary<br/>[axios.js]"]
  node_qr_management["QR management UI<br/>list + detail views<br/>[QRList.jsx]"]
  node_dashboard_ui["Dashboard UI<br/>analytics view<br/>[Dashboard.jsx]"]
  node_user_management["User management UI<br/>admin view<br/>[UserList.jsx]"]
end

subgraph group_data["Data &amp; External"]
  node_mongo_atlas[("MongoDB Atlas<br/>system of record")]
end

node_server -->|"initializes"| node_database_setup
node_database_setup -->|"connects"| node_mongo_atlas
node_server -->|"mounts"| node_auth_api
node_server -->|"mounts"| node_qr_api
node_server -->|"mounts public /q route"| node_public_scan
node_server -->|"mounts"| node_dashboard_api
node_server -->|"uses"| node_error_handling
node_auth_api -->|"JWT enforced by"| node_auth_guard
node_auth_guard -->|"protects"| node_user_api
node_auth_guard -->|"protects"| node_qr_api
node_auth_guard -->|"protects"| node_dashboard_api
node_qr_api -->|"manages"| node_qr_model
node_public_scan -->|"resolves and increments"| node_qr_model
node_public_scan -->|"creates and patches GPS"| node_scan_log
node_public_scan -->|"enriches from IP"| node_geo_lookup
node_dashboard_api -->|"aggregates"| node_qr_model
node_dashboard_api -->|"reads activity"| node_scan_log
node_qr_model -->|"persists"| node_mongo_atlas
node_scan_log -->|"persists"| node_mongo_atlas
node_admin_seed -->|"creates initial admin"| node_mongo_atlas
node_app -->|"provides session"| node_auth_session
node_auth_session -->|"supplies JWT"| node_http_client
node_app -->|"routes to"| node_qr_management
node_app -->|"routes to"| node_dashboard_ui
node_app -->|"routes to"| node_user_management
node_qr_management -->|"uses QR API"| node_http_client
node_dashboard_ui -->|"uses dashboard API"| node_http_client
node_user_management -->|"uses user API"| node_http_client
node_http_client -->|"auth requests"| node_auth_api
node_http_client -->|"QR requests"| node_qr_api
node_http_client -->|"analytics requests"| node_dashboard_api
node_http_client -->|"user requests"| node_user_api

click node_server "https://github.com/isreeharim/qrsree/blob/master/backend/server.js"
click node_database_setup "https://github.com/isreeharim/qrsree/blob/master/backend/config/db.js"
click node_auth_api "https://github.com/isreeharim/qrsree/blob/master/backend/routes/authRoutes.js"
click node_auth_guard "https://github.com/isreeharim/qrsree/blob/master/backend/middleware/auth.js"
click node_user_api "https://github.com/isreeharim/qrsree/blob/master/backend/routes/userRoutes.js"
click node_qr_api "https://github.com/isreeharim/qrsree/blob/master/backend/routes/qrRoutes.js"
click node_qr_model "https://github.com/isreeharim/qrsree/blob/master/backend/models/QRCode.js"
click node_public_scan "https://github.com/isreeharim/qrsree/blob/master/backend/routes/publicRoutes.js"
click node_scan_log "https://github.com/isreeharim/qrsree/blob/master/backend/models/ScanLog.js"
click node_geo_lookup "https://github.com/isreeharim/qrsree/blob/master/backend/utils/geoLookup.js"
click node_dashboard_api "https://github.com/isreeharim/qrsree/blob/master/backend/routes/dashboardRoutes.js"
click node_error_handling "https://github.com/isreeharim/qrsree/blob/master/backend/middleware/validate.js"
click node_admin_seed "https://github.com/isreeharim/qrsree/blob/master/backend/seed/createAdmin.js"
click node_app "https://github.com/isreeharim/qrsree/blob/master/frontend/src/App.jsx"
click node_auth_session "https://github.com/isreeharim/qrsree/blob/master/frontend/src/context/AuthContext.jsx"
click node_http_client "https://github.com/isreeharim/qrsree/blob/master/frontend/src/api/axios.js"
click node_qr_management "https://github.com/isreeharim/qrsree/blob/master/frontend/src/pages/QRList.jsx"
click node_dashboard_ui "https://github.com/isreeharim/qrsree/blob/master/frontend/src/pages/Dashboard.jsx"
click node_user_management "https://github.com/isreeharim/qrsree/blob/master/frontend/src/pages/UserList.jsx"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_server,node_database_setup,node_auth_api,node_auth_guard,node_user_api,node_qr_api,node_qr_model,node_public_scan,node_scan_log,node_geo_lookup,node_dashboard_api,node_error_handling,node_admin_seed toneBlue
class node_app,node_auth_session,node_http_client,node_qr_management,node_dashboard_ui,node_user_management toneAmber
class node_mongo_atlas toneMint
```

## Components

### Backend API

Express service for administration and public QR resolution.

- [Express server](https://github.com/isreeharim/qrsree/blob/master/backend/server.js): Node.js entry point · `backend/server.js`
- [MongoDB connection](https://github.com/isreeharim/qrsree/blob/master/backend/config/db.js): Mongoose setup · `backend/config/db.js`
- [Auth API](https://github.com/isreeharim/qrsree/blob/master/backend/routes/authRoutes.js): routes + controller · Issues JWTs and handles server-side password authentication. · `backend/routes/authRoutes.js`
- [JWT guard](https://github.com/isreeharim/qrsree/blob/master/backend/middleware/auth.js): Express middleware · `backend/middleware/auth.js`
- [User administration](https://github.com/isreeharim/qrsree/blob/master/backend/routes/userRoutes.js): protected API · `backend/routes/userRoutes.js`
- [QR lifecycle API](https://github.com/isreeharim/qrsree/blob/master/backend/routes/qrRoutes.js): protected API · Creates and manages stable short-code QR definitions and scan history. · `backend/routes/qrRoutes.js`
- [QR codes](https://github.com/isreeharim/qrsree/blob/master/backend/models/QRCode.js): Mongoose model · Stores short codes, mutable destinations, and aggregate scan counts. · `backend/models/QRCode.js`
- [Public scan redirect](https://github.com/isreeharim/qrsree/blob/master/backend/routes/publicRoutes.js): public route + controller · Resolves /q/:shortCode, records a scan, requests GPS, then redirects. · `backend/routes/publicRoutes.js`
- [Scan logs](https://github.com/isreeharim/qrsree/blob/master/backend/models/ScanLog.js): Mongoose model · Persistent per-scan telemetry including later coordinates. · `backend/models/ScanLog.js`
- [IP geolocation](https://github.com/isreeharim/qrsree/blob/master/backend/utils/geoLookup.js): outbound integration · Looks up approximate geography through ip-api.com. · `backend/utils/geoLookup.js`
- [Dashboard aggregation](https://github.com/isreeharim/qrsree/blob/master/backend/routes/dashboardRoutes.js): analytics API · Builds totals and recent activity from QR and scan records. · `backend/routes/dashboardRoutes.js`
- [Validation & errors](https://github.com/isreeharim/qrsree/blob/master/backend/middleware/validate.js): Express middleware · Central validation and async/error translation. · `backend/middleware/validate.js`
- [Admin provisioning](https://github.com/isreeharim/qrsree/blob/master/backend/seed/createAdmin.js): seed process · Creates the initial administrator independently of the server. · `backend/seed/createAdmin.js`

### Management Console

React/Vite authenticated administrator UI.

- [React app shell](https://github.com/isreeharim/qrsree/blob/master/frontend/src/App.jsx): Vite entry + routes · Composes the management console and protected pages. · `frontend/src/App.jsx`
- [Auth session](https://github.com/isreeharim/qrsree/blob/master/frontend/src/context/AuthContext.jsx): context + route guard · Retains client auth state and gates administration routes. · `frontend/src/context/AuthContext.jsx`
- [HTTP client](https://github.com/isreeharim/qrsree/blob/master/frontend/src/api/axios.js): Axios boundary · Shared transport consumed by feature API modules. · `frontend/src/api/axios.js`
- [QR management UI](https://github.com/isreeharim/qrsree/blob/master/frontend/src/pages/QRList.jsx): list + detail views · Manages QR definitions, rendering/export, and per-QR scan history. · `frontend/src/pages/QRList.jsx`
- [Dashboard UI](https://github.com/isreeharim/qrsree/blob/master/frontend/src/pages/Dashboard.jsx): analytics view · `frontend/src/pages/Dashboard.jsx`
- [User management UI](https://github.com/isreeharim/qrsree/blob/master/frontend/src/pages/UserList.jsx): admin view · `frontend/src/pages/UserList.jsx`

### Data & External

System-of-record persistence and IP geolocation dependency.

- **MongoDB Atlas**: system of record

## Connections

- Express server → MongoDB connection: initializes
- MongoDB connection → MongoDB Atlas: connects
- Express server → Auth API: mounts
- Express server → QR lifecycle API: mounts
- Express server → Public scan redirect: mounts public /q route
- Express server → Dashboard aggregation: mounts
- Express server → Validation & errors: uses
- Auth API → JWT guard: JWT enforced by
- JWT guard → User administration: protects
- JWT guard → QR lifecycle API: protects
- JWT guard → Dashboard aggregation: protects
- QR lifecycle API → QR codes: manages
- Public scan redirect → QR codes: resolves and increments
- Public scan redirect → Scan logs: creates and patches GPS
- Public scan redirect → IP geolocation: enriches from IP
- Dashboard aggregation → QR codes: aggregates
- Dashboard aggregation → Scan logs: reads activity
- QR codes → MongoDB Atlas: persists
- Scan logs → MongoDB Atlas: persists
- Admin provisioning → MongoDB Atlas: creates initial admin
- React app shell → Auth session: provides session
- Auth session → HTTP client: supplies JWT
- React app shell → QR management UI: routes to
- React app shell → Dashboard UI: routes to
- React app shell → User management UI: routes to
- QR management UI → HTTP client: uses QR API
- Dashboard UI → HTTP client: uses dashboard API
- User management UI → HTTP client: uses user API
- HTTP client → Auth API: auth requests
- HTTP client → QR lifecycle API: QR requests
- HTTP client → Dashboard aggregation: analytics requests
- HTTP client → User administration: user requests
