How shagor-mia/multivendor-e-commerce-backend- works
Project Type and Purpose
• This is a backend RESTful API for a multivendor e-commerce platform.
• Built with Node.js, Express, TypeScript and MongoDB; integrates with Stripe for payments and Cloudinary for image uploads.
File Structure
• Entry Point: src/index.ts
• Configuration: src/config (stripe.ts, database URI)
• Routing Layer: src/routes (separate route files per resource)
• Middleware Layer: src/middleware (authentication, rate limiting, file uploads)
• Controller Layer: src/controllers (business logic per domain: auth, user, product, order, payment, etc.)
• Data Layer: src/models (Mongoose schemas for User, Product, Order, Payment, Category, Cart, ReviewRating)
• Utilities & Validation: src/utils (OTP, JWT token functions), src/validation (Joi or Zod schemas)
• Database Connection: src/database/connect.ts
• Environment / Types: src/types/environment.d.ts
README for Insights
• Role-based access control (Admin, Vendor, User)
• Stripe payment intent creation and webhook handling
• MongoDB as primary data store
Main Components & Their Relationships
a. Client Applications
– Web or Mobile front-ends consuming the API over HTTP(S).
b. API Gateway / Express Server
– Entry point (index.ts)
– Global middleware (authMiddleware, rateLimiters)
– Route definitions → Controller handlers
c. Controllers (Business Logic)
– Handle requests for auth, user management, product/catalog, cart, orders, payments, reviews, vendor operations.
– Token generation (JWT), OTP sending, Cloudinary upload, Stripe SDK calls
e. Data Access Layer (Models)
– Mongoose models mapping to MongoDB collections
f. Database
– MongoDB cluster (cloud or local)
g. External Services
– Stripe (payment intents, webhooks)
– Cloudinary or local file store (image uploads)
Architectural Patterns & Design Principles
• Layered (Presentation → Middleware → Controllers → Models → Database)
• MVC-inspired: Routes map to Controllers, Controllers invoke Models
• Separation of concerns: Authentication/authorization isolated in middleware
• Dependency injection via config modules (e.g., stripe key, DB URI)
• Event-driven webhook handling for Stripe