How vengurlekarmayuresh/cafe works
1. This repository is a two-tier full-stack application for a gated-society ordering and POS workflow: a Node/Express backend API and a React/Vite frontend. The system is split by user role into customer ordering, staff operations/POS, and admin oversight.
2. The backend is the application core. backend/src/index.js is the server entrypoint, with HTTP routes organized under routes/ and business logic in controllers/. The structure suggests a fairly standard API layering: routes handle URL boundaries, controllers orchestrate use cases, and models represent persistence.
3. Persistence is PostgreSQL through Sequelize. The domain model is centered around User, Product, Order, OrderItem, Review, and Notification, which indicates the main data flow: users browse products, create orders, order items capture line-level contents, reviews attach to purchases/products, and notifications track operational events.
4. Authentication and authorization are first-class concerns. JWT helpers, auth middleware, and rbac middleware enforce identity and role-based access control across the API. The README’s approval/blocking flows and the adminController indicate that user lifecycle is not just login-based; some users are gated by admin approval before full access.
5. The order subsystem is the main transactional boundary. orderController and /routes/orders support both customer online orders and staff-created onsite POS orders. The documented state machine is important for diagrams: online orders move through pending/accepted/delivered or rejected, while POS orders are created in an already accepted/paid state.
6. Product management is a separate operational subsystem. productController and /routes/products expose browse/create/update/toggle-delete behavior with role restrictions. This is likely the shared catalog used by both customers and staff POS screens, so product availability changes affect both ordering channels.
7. Real-time feedback is handled with notifications. The backend includes notificationController, Notification model, and a Firebase config file, while the README calls out Socket.io for real-time notifications. The front end also has a NewOrderAlert component, so the architecture includes asynchronous push-style updates for staff when new orders arrive.
8. Media and integration hooks are present but secondary. utils/cloudinary.js suggests external image storage for product/media assets, and Firebase config on both backend and frontend suggests a messaging or notification integration point. These are supporting services rather than the primary system of record.
9. The frontend is a role-driven SPA built with React, Tailwind, and Vite. AuthContext holds session state, ProtectedRoute enforces access on the client side, and api.js centralizes backend calls. Routing is organized by audience: public auth pages, customer pages, staff pages, and admin pages.
10. The customer UI is focused on browsing and self-service ordering. Pages like Home, Menu, Cart, Orders, and Profile, plus components such as InvoiceModal and ConfirmationModal, show a flow from product discovery to checkout, order tracking, and post-order interaction.
11. The staff UI is an operational console. staff/Dashboard, POS, and Products indicate that staff can both process walk-in sales and manage the catalog. The presence of NewOrderAlert and order-management backend endpoints reinforces that staff are the live execution layer for incoming customer orders.
12. The admin UI is supervisory rather than transactional. admin/Dashboard, Users, Orders, and Customers align with approval workflows, account moderation, and reporting/analytics. The backend’s admin routes support these boundaries with user approval/blocking and revenue/order aggregation.
13. Bootstrap and lifecycle support are explicit. setup.sql and scripts/seed.js indicate the database can be initialized and seeded independently of the runtime app, which is useful for local development or demo environments. Frontend deployment configuration (vercel.json) suggests the UI is intended for static hosting, while the API remains a separate service.
14. For an architecture diagram, the key flows are: browser user authenticates against the API, receives JWT-based session state, reads/writes domain data through the REST endpoints, and receives live order notifications through the realtime channel. PostgreSQL is the system of record, while the frontend is a role-aware presentation layer over the backend domain services.
Main entry points: api.js API client · models/index.js Domain models · src/index.js Server entry · admin.js Admin API
Components 26
Backend API
Node/Express service that owns auth, catalog, orders, admin workflows, and notifications.
- Server entry · Starts the API server and wires the application runtime.
backend/src/index.js - Auth API · Login, registration, and session-facing auth endpoints.
backend/src/routes/auth.js - Auth logic · Coordinates authentication and account onboarding flows.
backend/src/controllers/authController.js - Admin API · Approval, moderation, and oversight endpoints.
backend/src/routes/admin.js - Admin logic · Handles user approval, blocking, and administrative reporting flows.
backend/src/controllers/adminController.js - Product API · Catalog endpoints for browsing and staff management.
backend/src/routes/products.js - Product logic · Implements product create, update, toggle, and browse behavior.
backend/src/controllers/productController.js - Order API · Customer and staff order endpoints.
backend/src/routes/orders.js - Order logic · Coordinates online orders, POS orders, and order state transitions.
backend/src/controllers/orderController.js - Notif API · Notification endpoints used by the live order workflow.
backend/src/routes/notifications.js - Notif logic · Creates and serves notifications for operational updates.
backend/src/controllers/notificationController.js - Auth guard · Verifies JWT identity on protected API requests.
backend/src/middleware/auth.js - Role guard · Enforces role-based access for customer, staff, and admin actions.
backend/src/middleware/rbac.js - Domain models · Persistence layer for users, products, orders, items, reviews, and notifications.
backend/src/models/index.js
Frontend SPA
React/Vite client organized by customer, staff, and admin roles.
- SPA shell · Top-level client shell, routing, and presentation composition.
frontend/src/App.jsx - Session state · Holds user session, role, and auth state in the client.
frontend/src/context/AuthContext.jsx - Route gate · Client-side access control for authenticated and role-scoped pages.
frontend/src/utils/ProtectedRoute.jsx - API client · Centralized frontend entry for backend requests.
frontend/src/utils/api.js - Customer UI · Browsing, cart, orders, and profile experience for end customers.
frontend/src/pages/customer/Home.jsx - Staff UI · Operational console for POS, dashboard, and catalog handling.
frontend/src/pages/staff/Dashboard.jsx - Admin UI · Supervisory pages for users, customers, orders, and reporting.
frontend/src/pages/admin/Dashboard.jsx - Order alerts · Live notification component used to surface new orders to staff.
frontend/src/components/NewOrderAlert.jsx
Data & Services
Persistent storage and external integrations used by the app.
- PostgreSQL · System of record for application data and transactional state.
backend/setup.sql - Firebase · Messaging/notification integration point used by backend and frontend.
backend/src/config/firebase.js - Cloudinary · External image storage for product and media assets.
backend/src/utils/cloudinary.js - Seed setup · Initial database schema and seed data for local or demo environments.
backend/src/scripts/seed.js
Connections 41
- Server entry → Auth API: mounts · Registers authentication endpoints on the server.
- Server entry → Admin API: mounts · Registers administrative endpoints on the server.
- Server entry → Product API: mounts · Registers catalog endpoints on the server.
- Server entry → Order API: mounts · Registers order endpoints on the server.
- Server entry → Notif API: mounts · Registers notification endpoints on the server.
- Auth API → Auth logic: uses · Routes delegate auth use cases to controller logic.
- Admin API → Admin logic: uses · Routes delegate admin workflows to controller logic.
- Product API → Product logic: uses · Routes delegate catalog actions to controller logic.
- Order API → Order logic: uses · Routes delegate ordering actions to controller logic.
- Notif API → Notif logic: uses · Routes delegate notification actions to controller logic.
- Auth logic → Domain models: reads/writes · Auth flows persist and load user records.
- Admin logic → Domain models: reads/writes · Admin workflows update user and order state.
- Product logic → Domain models: reads/writes · Catalog operations persist product data.
- Order logic → Domain models: reads/writes · Order workflows persist orders and line items.
- Notif logic → Domain models: reads/writes · Notification workflows persist event state.
- Auth API → Auth guard: protects · Protected auth-adjacent paths use JWT verification.
- Admin API → Auth guard: protects · Admin paths require authenticated users.
- Admin API → Role guard: restricts · Admin paths are role-restricted.
- Product API → Auth guard: protects · Catalog mutations require authentication.
- Product API → Role guard: restricts · Write operations are role-restricted.
- Order API → Auth guard: protects · Order operations require authenticated users.
- Notif API → Auth guard: protects · Notification access is authenticated.
- Notif API → Role guard: restricts · Operational notification actions are role-scoped.
- SPA shell → Session state: holds · Client shell uses shared session state.
- SPA shell → Route gate: guards · Client routing is gated by auth and role checks.
- SPA shell → API client: calls · UI uses a centralized backend API client.
- Route gate → Session state: checks · Route gating reads session and role state.
- Customer UI → API client: calls · Customer screens load products, orders, and profile data.
- Staff UI → API client: calls · Staff screens interact with POS, product, and order endpoints.
- Admin UI → API client: calls · Admin screens interact with oversight endpoints.
- Staff UI → Order alerts: contains · Staff console surfaces live incoming order alerts.
- API client → Auth API: requests · Frontend auth flows talk to the auth API.
- API client → Product API: requests · Frontend catalog views and edits hit the product API.
- API client → Order API: requests · Frontend order flows hit the order API.
- API client → Admin API: requests · Frontend admin screens hit oversight APIs.
- API client → Notif API: requests · Frontend notification views hit the notification API.
- Domain models → PostgreSQL: persists to · Sequelize stores domain data in PostgreSQL.
- Notif logic → Firebase: integrates · Backend notification flows can use Firebase as an external channel.
- Order alerts → Firebase: integrates · Client alerting is aligned with Firebase-backed messaging.
- Product logic → Cloudinary: uploads · Product media may be stored in external image storage.
- Seed setup → PostgreSQL: initializes · Schema and seed data prepare the database.