How sortyxai/sortyx-rewards-app works
1. Overall shape
- This repo is a two-tier application: a React single-page frontend and a Node/Express backend API.
- The frontend handles all user interaction and stateful UI; the backend owns authentication, business rules, and persistent data.
2. Frontend boundary
- frontend/src/App.js and frontend/src/index.js are the SPA entry points.
- react-router-dom drives page-level navigation across pages/ such as Landing, Dashboard, Donate, Rewards, Scan, Profile, AdminPanel, and PointsDashboard.
- This is not a server-rendered app; the browser talks to the backend over HTTP.
3. Frontend feature layers
- components/ contains reusable UI and feature widgets such as login/register forms, password reset, QR scanner, bottom navigation, reward/admin managers, and route guards.
- contexts/AuthContext.js centralizes client auth state, so login status and user identity are shared across the app.
- ProtectedRoute.js is the main access-control boundary on the client side, preventing unauthenticated or unauthorized route access.
4. Frontend service layer
- services/pointsService.js, co2Service.js, and firestoreService.js isolate non-UI logic from components.
- firebase.js indicates a Firebase/Firestore integration point for client-side real-time or cloud-backed data.
- axios is the primary bridge to the backend API; this is where points, rewards, profile, and auth data likely flow in and out.
5. Backend bootstrapping
- backend/server.js is the main process entry point; app.js likely assembles middleware and route registration.
- backend/config/database.js is the persistence setup layer.
- backend/uploads/ is a dedicated filesystem boundary for uploaded assets, handled through Multer.
6. Backend layered architecture
- The backend is organized in a classic route → controller → model pattern.
- routes/ defines API surfaces, controllers/ contains request/business logic, and models/ define the domain entities and persistence access.
- middleware/auth.js is the enforcement layer for protected endpoints, most likely validating JWTs and attaching user context.
7. Domain model
- The model set shows the core business objects: User, Token, Reward, Redemption, Donation, Charity, Achievement, and UserActivity.
- This tells you the system is broader than simple login/points: it tracks user identity, token-based sessions, reward catalogs, redemptions, donation/charity flows, and user history/activity.
- Token suggests server-side support for password reset or session/token lifecycle in addition to JWT auth.
8. Primary backend API flows
- Auth flows are handled by authController and auth routes: register, login, and auth verification.
- Reward flows go through rewardController and donation/profile/admin controllers depending on whether the user is scanning QR codes, redeeming rewards, or viewing history.
- Admin flows are separated in adminController and routes/admin.js, keeping system-management actions distinct from normal user APIs.
9. Data flow from scan to points
- The most important business path is likely: frontend QR scanner → API call → backend validation → points/reward update → persisted user activity.
- The scan UI lives in components/QRScanner.js and pages/Scan.js, while points display is split into PointsDashboard and rewards views.
- This path is the main transactional loop in the system and should be a prominent arrow in any architecture diagram.
10. Authentication and authorization
- The app uses JWT-based auth on the backend, with bcryptjs for password hashing.
- The frontend keeps auth state in context and uses protected routes to gate dashboards, profile pages, and admin screens.
- Authorization is role-sensitive: normal users can scan/redeem/view profile, while admins can manage rewards, charities, and users.
11. Admin subsystem
- AdminPanel.js, AdminCharityManager.js, and AdminRewardManager.js are the main admin UI surfaces.
- Backend admin routes and controllers likely expose stats, reward management, user management, and QR generation.
- This is a clearly separated operational boundary: administrative actions do not live inside the regular user flow.
12. External/service integrations
- firebase.js and firestoreService.js show a cloud datastore or real-time sync integration on the frontend side.
- The backend also uses standard infrastructure pieces: SQLite for persistence, CORS for cross-origin browser access, and Multer for uploads.
- The README’s mention of real-time notifications aligns with Firebase being the likely external event/data layer, though it is isolated from the core REST API.
13. Operational/deployment boundary
- In development, frontend and backend run as separate processes on different ports.
- The backend is configured for API serving, while the frontend is a buildable static SPA; production may serve the built frontend separately or through the backend.
- backend/.env.example and frontend/.env.example show that environment configuration is split per tier.
14. Architecture summary for diagramming
- Draw two main boxes: React client and Express API.
- Inside the API box, show routes → controllers → models → SQLite/filesystem, with auth middleware guarding protected routes.
- Add a separate Firebase/Firestore integration on the frontend side if you want to capture real-time/cloud-backed features.
- Emphasize the primary data paths: login/auth, QR scan → points update, reward redemption, and admin management.
Main entry points: controllers Controllers · App.js App shell · pages Pages · components UI components
Components 21
React client
Single-page app handling navigation, auth state, scanning, rewards, and admin UI.
- SPA entry · Browser entry points that mount the app and initialize client routing.
frontend/src/index.js - App shell · Top-level client router and application composition.
frontend/src/App.js - Pages · Primary route-level screens such as landing, dashboard, donate, rewards, scan, profile, and admin.
frontend/src/pages - UI components · Shared widgets and feature components including auth forms, QR scanner, navigation, and admin managers.
frontend/src/components - Auth state · Centralized frontend authentication and user identity state.
frontend/src/contexts/AuthContext.js - Route guard · Client-side protection for authenticated and role-gated routes.
frontend/src/components/ProtectedRoute.js - Service layer · Non-UI logic for points, CO2, and Firestore-backed data access.
frontend/src/services - Firebase · Client integration point for realtime or cloud-backed features.
frontend/src/firebase.js - HTTP client · Browser-to-backend communication for auth, profile, rewards, points, and admin operations.
Express API
REST backend organizing routes, controllers, middleware, and persistence.
- Server entry · Main backend process entry that starts the API server.
backend/server.js - API app · Middleware and route assembly for the backend API.
backend/app.js - Routes · Endpoint definitions for auth, admin, donations, profile, and rewards.
backend/routes - Auth middleware · Protected-endpoint enforcement and user-context attachment.
backend/middleware/auth.js - Controllers · Request handling for auth, admin, donations, profile, and rewards.
backend/controllers - Domain models · User, token, reward, redemption, donation, charity, achievement, and activity entities.
backend/models - Auth API · Register, login, and auth verification path.
backend/routes/auth.js - Rewards API · Reward lookup, redemption, and related points operations.
backend/routes/rewards.js - Scan update · QR scan path that validates input, updates points, and records user activity.
backend/controllers/rewardController.js - Admin API · Operational management for users, rewards, charities, and stats.
backend/routes/admin.js
Storage
Primary persistence and upload boundaries used by the backend and client integrations.
- SQLite config · Database connection and storage configuration.
backend/config/database.js - Uploads · Filesystem boundary for uploaded assets.
backend/uploads
Connections 24
- SPA entry → App shell: boots · Mounts the SPA and initializes routing.
- App shell → Pages: navigates · Routes to page-level views.
- App shell → UI components: composes · Uses shared UI and feature widgets.
- App shell → Auth state: reads state · Consumes shared auth state across the app.
- App shell → Route guard: guards · Wraps privileged screens with client-side access control.
- UI components → HTTP client: calls · Feature components trigger backend requests through the HTTP bridge.
- Service layer → HTTP client: wraps · Service modules isolate request logic from UI components.
- Service layer → Firebase: syncs · Uses cloud-backed client data and realtime features where needed.
- Auth state → HTTP client: authenticates · Stores login state populated by API responses.
- Pages → HTTP client: requests · Pages fetch and submit data to the backend.
- HTTP client → API app: HTTP · Client traffic reaches the Express API.
- Server entry → API app: starts · Bootstraps the Express application.
- API app → Routes: registers · Mounts route modules.
- Routes → Auth middleware: protects · Applies JWT-based endpoint protection.
- Routes → Controllers: dispatches · Hands requests to controller logic.
- Controllers → Domain models: persists via · Reads and writes domain entities.
- Domain models → SQLite config: stores in · Backed by SQLite persistence.
- Controllers → Uploads: writes files · Handles uploaded assets through the filesystem boundary.
- Auth API → Controllers: implements · Authentication requests are handled in the auth controller.
- Rewards API → Controllers: implements · Reward and redemption requests are handled in reward logic.
- Scan update → Domain models: updates · Records points, redemptions, and user activity.
- Admin API → Controllers: implements · Admin operations are handled separately from user flows.
- Pages → Service layer: uses · Screens rely on client service modules for derived data and sync.
- UI components → Route guard: depends on · Privileged UI is composed through route protection.