How supanusan/e-commerce_backend works
What this project is (type + purpose)
This is a Node.js/Express REST API backend for an e-commerce-like system. The README lists API areas: auth/users, products (including admin CRUD), cart, orders, admin order management, and payments (PayHere init + webhook).
The file tree confirms a typical Express backend structure with:
• server.js (app bootstrap)
• routes/* (HTTP route modules)
• middleware/auth.js (authentication/authorization)
• config/mongoose.js (MongoDB connection)
• config/shema/* (MongoDB/Mongoose models; “schema” misspelled in path)
• config/multer.js and config/cloudinary.js (image/file upload pipeline)
Folder structure to architectural layers:
Entry / Runtime
• server.js: The main process that initializes Express, loads middleware, mounts routes, connects to MongoDB.
HTTP Interface (Controllers/Routes)
• routes/auth.js → /api/auth (register, login, logout, me)
• routes/product.js → /api/products (list/details/search; admin add/update/delete)
• routes/cart.js → /api/cart (add/update/remove/clear)
• routes/order.js → /api/orders (create, my orders, details)
• routes/admin.js → /api/admin (all orders, update status)
• routes/payment.js → /api/payments (PayHere init, webhook)
Middleware / Cross-cutting concerns
• middleware/auth.js: likely JWT/session validation + role checks (user/admin). This is important to show as a gate in front of protected endpoints.
Data layer
• config/mongoose.js: MongoDB connection + configuration
• **config/shema/*.js**:
• user.js
• product.js
• cart.js
• order.js
External integrations
• config/multer.js: upload handling (multipart/form-data)
• config/cloudinary.js: Cloudinary media storage (product images, etc.)
• PayHere: called by /api/payments routes; also calls you back via webhook.
Client(s) (even though not in repo)
• Web app / Mobile app / Admin dashboard / Postman
Express API Server (Node.js)
• broken down internally into:
• Route modules: Auth, Users (README mentions /api/users though route file isn’t shown; call out as “planned/implicit” or “missing route module” depending on what you find in server.js)
• Middleware: Auth middleware
• Domain/Model layer: Mongoose schemas (User/Product/Cart/Order)
PayHere Payment Gateway
• “init payment” outbound call
• “webhook callback” inbound call
Architectural patterns to highlight (based on repo)
• Layered architecture: Routes/Controllers → Middleware → Models/Data access
• REST resource design: auth, products, cart, orders, payments
• External service integration: Cloudinary + PayHere
• Event/callback interaction: PayHere webhook is asynchronous inbound traffic (important to show)
Elements explicitly:
Clear labels
• Use names that match the repo: “routes/auth.js”, “middleware/auth.js”, “schema/order.js”, etc.
• Also label endpoint groups: /api/auth, /api/products, etc.
• Protocol: HTTPS, MongoDB driver
• Payload concept: “JWT”, “Order status update”, “Image URL”
Boundaries
• “API Server Process” boundary around routes/middleware/models
• “External Services” boundary around Cloudinary/PayHere
• “Database” boundary around MongoDB
Open server.js and confirm
• Base path prefixes (/api/auth, etc.)
• Which route modules are actually mounted (README mentions /api/users; confirm if it exists or is embedded elsewhere)
In each routes/*.js, confirm
• Which routes are protected by middleware/auth.js
• Admin checks (role-based)
In payment route
• Confirm webhook endpoint path and how it updates orders.
In multer/cloudinary configs
• Confirm whether uploads are used in product admin routes; show that connection.