How rohan-bhau/grocio works
1. Overall shape
- This is a role-based grocery ordering and delivery platform built on Next.js App Router + TypeScript.
- The codebase is split into three main user experiences: customer, admin, and delivery agent.
2. Frontend application structure
- UI pages live under src/app/..., with separate route areas for user, admin, and delivery.
- Role-specific layouts (admin/layout.tsx, delivery/layout.tsx) provide distinct shells/navigation for each dashboard.
- Shared UI lives in src/components, while dashboard-specific composites are in src/components/dashboards.
3. Server/API boundary
- Business logic is primarily exposed through Next.js route handlers under src/app/api/....
- The app uses the framework’s built-in server/client split: pages and interactive components on the client, data access and integrations through API routes.
4. Authentication and authorization
- Authentication is handled with NextAuth (src/auth.ts, src/app/api/auth/[...nextauth]/route.ts).
- Registration is custom (/api/auth/register), and user/role lookup is exposed via /api/me and /api/check-for-admin.
- proxy.ts likely guards routes and enforces access to admin/delivery/user areas based on auth state and role.
5. Core domain model
- The main persistent entities are defined in src/models:
- user
- grocery
- order
- deliveryAssignment
- message
- src/lib/db.ts indicates a centralized database connection, likely MongoDB/Mongoose-based given the model structure.
6. Customer ordering flow
- Customers browse groceries, manage a cart, and place orders from src/app/user/cart, checkout, and order pages.
- Order lifecycle routes include /api/user/order, /api/user/payment, /api/user/my-orders, /api/user/get-order/[id], and /api/user/stripe/webhook.
- Success/cancel outcomes are surfaced through dedicated pages in src/app/user/order-success and order-cancel.
7. Payments
- Payment processing is integrated on the backend through a Stripe webhook route.
- This implies orders are finalized/updated server-side from payment events rather than only from the client checkout flow.
8. Admin subsystem
- Admin pages cover grocery CRUD and order oversight: add, view, edit/delete groceries, and manage orders.
- Corresponding API routes in src/app/api/admin/... provide grocery and order management operations.
- This subsystem is the operational back office for inventory and order status control.
9. Delivery subsystem
- Delivery agents have their own dashboard for assignment requests, active orders, and history.
- API routes support assignment retrieval/acceptance, current order lookup, and OTP send/verify for delivery confirmation.
- src/app/api/socket/update-location and related delivery pages suggest live delivery progress tracking.
10. Real-time and messaging
- The app has a chat/message subsystem with routes for saving messages, fetching messages, and AI suggestions.
- src/lib/socket.ts and src/app/api/socket/connect indicate real-time socket infrastructure.
- src/lib/emitEventHandlers.ts suggests server-emitted events are used to push updates such as location or order state changes.
11. Media, notification, and support integrations
- src/lib/cloudinary.ts indicates image/file upload handling, likely for grocery assets.
- src/lib/mailer.ts supports email notifications, probably for registration, OTP, or order events.
12. Client state and app wiring
- Global state is managed with Redux (cartSlice, userSlice, store.ts) and exposed through StoreProvider.
- Provider.tsx and InitUser.tsx suggest the app initializes authenticated user state before rendering protected UI.
- Hooks like useGetMe help synchronize client state with the authenticated server session.
13. Maps and location-aware UI
- Components like CheckoutMap, LiveMap, and GeoUpdater show that location is a first-class part of the product.
- These likely support delivery tracking, checkout address selection, and real-time courier movement.
14. Static assets and presentation
- Static assets live in public/assets, while shared presentation components such as Navbar, Footer, HeroSection, and CategorySlider support the marketing/home experience.
- The root app page is separate from the authenticated dashboards, so the public landing experience is distinct from the operational app.
15. Key architectural boundary
- The most important boundary is between role-based client dashboards and server-side API/domain logic.
- The app’s data flow is: client dashboard → API route → database/integrations (Stripe, socket, email, cloud upload) → updated state back to client via fetch/socket/session.
Main entry points: user.model.ts Domain models · layout.tsx App shell · page.tsx Delivery UI · mailer.ts Integrations
Components 21
Public app
Landing and authentication entry points
- App shell · Root layout, landing page, and app-wide styling
src/app/layout.tsx - Home · Public marketing and entry page
src/app/page.tsx - Auth pages · Login, register, and unauthorized screens
src/app/login/page.tsx
Role dashboards
Customer, admin, and delivery experiences
- Customer UI · Customer cart, checkout, orders, and tracking
src/app/user/cart/page.tsx - Admin shell · Admin navigation and page shell
src/app/admin/layout.tsx - Admin UI · Grocery and order management screens
src/app/admin/page.tsx - Delivery shell · Delivery agent navigation and page shell
src/app/delivery/layout.tsx - Delivery UI · Requests, active orders, and history
src/app/delivery/page.tsx
API boundary
Route handlers for auth, domain, and integrations
- Auth API · NextAuth session and custom registration
src/app/api/auth/[...nextauth]/route.ts - Me API · Current user and role lookup
src/app/api/me/route.ts - Customer orders · Order creation, history, lookup, and payment flow
src/app/api/user/order/route.ts - Admin API · Grocery CRUD and order status management
src/app/api/admin/add-grocery/route.ts - Delivery API · Assignments, current orders, and OTP delivery steps
src/app/api/delivery/get-assignments/route.ts - Chat API · Message persistence and AI suggestions
src/app/api/chat/messages/route.ts - Socket API · Socket connection and live location updates
src/app/api/socket/connect/route.ts
Shared UI & state
Reusable components, providers, and client state
- Store provider · Redux provider and app initialization
src/redux/StoreProvider.tsx - Redux state · Cart and authenticated user state
src/redux/store.ts - Shared UI · Reusable UI and dashboard composites
src/components/Navbar.tsx
Domain & infra
Models, persistence, and external integrations
- Domain models · User, grocery, order, assignment, and message entities
src/models/user.model.ts - Database · Central database connection layer
src/lib/db.ts - Integrations · Stripe, Cloudinary, mailer, and socket/event helpers
src/lib/mailer.ts
Connections 30
- App shell → Home: renders · Root app presents the public landing experience
- App shell → Auth pages: hosts · Public authentication and error pages live in the app shell
- App shell → Customer UI: contains · Customer routes are mounted under the app router
- App shell → Admin UI: contains · Admin routes are mounted under the app router
- App shell → Delivery UI: contains · Delivery routes are mounted under the app router
- Admin shell → Admin UI: wraps · Admin shell provides dashboard navigation and layout
- Delivery shell → Delivery UI: wraps · Delivery shell provides dashboard navigation and layout
- Customer UI → Customer orders: fetches · Customer UI interacts with order and payment routes
- Admin UI → Admin API: manages · Admin UI drives grocery and order operations
- Delivery UI → Delivery API: uses · Delivery UI retrieves assignments and updates delivery state
- Shared UI → Store provider: uses · Shared client components are rendered inside the provider tree
- Store provider → Redux state: provides · Redux store is exposed to the client app
- Auth API → Domain models: reads/writes · Authentication and registration touch user records
- Me API → Auth API: depends on · Current-user lookup is session-aware
- Customer orders → Domain models: reads/writes · Order and payment endpoints persist order data
- Admin API → Domain models: reads/writes · Admin CRUD and status changes operate on grocery and order data
- Delivery API → Domain models: reads/writes · Delivery assignment and OTP flows use assignment and order data
- Chat API → Domain models: reads/writes · Message routes persist chat content
- Socket API → Integrations: streams · Realtime events and location updates use socket helpers
- Customer orders → Integrations: integrates · Payment webhook and order events depend on Stripe and notifications
- Admin API → Integrations: integrates · Admin workflows may trigger uploads and notifications
- Delivery API → Integrations: integrates · OTP and delivery updates rely on notification and realtime helpers
- Chat API → Integrations: integrates · AI suggestions and chat persistence use external helpers
- Domain models → Database: uses · Models are backed by the central database connection
- Auth pages → Auth API: submits to · Login and registration screens use auth endpoints
- Customer UI → Me API: hydrates · Client state is synchronized from the current-user endpoint
- Delivery UI → Socket API: tracks · Live delivery pages subscribe to location and event updates
- Customer UI → Shared UI: composes · Customer views are built from shared UI pieces
- Admin UI → Shared UI: composes · Admin screens reuse shared dashboard components
- Delivery UI → Shared UI: composes · Delivery screens reuse shared dashboard components