How ashwinn-si/bookreview-platform-mern-be works
Project Type and Purpose
• This is the backend of a full-stack MERN application.
• It exposes a JSON/REST API for book reviews, user management, authentication (JWT + Google OAuth), file uploads (Multer), and more.
• It follows an MVC (Model-View-Controller) layered architecture and interacts with a MongoDB database.
File Structure
• Top-level:
• server.js (entry point, DB connect + server start)
• package.json / lock (dependencies)
• README.md (docs)
• src/:
• config/ (dbConnect.js, passportConfig.js)
• app.js (Express app, middleware + routes wired here)
• route/ (API route definitions: auth, user, book, admin)
• controller/ (logic per resource: auth.js, user.js, book.js, admin.js)
• service/ (business logic layer invoked by controllers)
• model/ (Mongoose schemas: UserModel, bookModel, reviewModel, etc.)
• middleware/ (auth checks, role verification, JWT validation, request validators)
• utils/ (helpers: nodeMailer)
README for Additional Insights
• Tech stack: Node.js, Express, MongoDB/Mongoose, JWT, Passport, security middlewares
• MVC architecture explicitly mentioned
• Global error-handler, rate limiting, sanitization, XSS protection
Main Components & Their Interactions
• Client (Frontend SPA) → API Gateway (Express)
• Express Layer:
a. Global Middleware (security, body parsing, CORS, logging)
b. Route Handler (src/route/*)
c. Controller Layer (src/controller/*)
d. Service Layer (src/service/*)
e. Data Access Layer (src/model/* via Mongoose)
• External Services:
• MongoDB Atlas / local DB
• Google OAuth endpoints (passport-oauth strategy)
• SMTP provider (nodeMailer for OTP/email)
• Authentication: JWT issuance & verification, Passport for OAuth flows
• File Upload: Multer (for book images)
Architectural Patterns & Design Principles
• Layered MVC + Service abstraction (separation of concerns)
• Stateless authentication (JWT)
• Third-party integration via Passport (Google OAuth)
• Centralized configuration (src/config)
• Reusable middleware for validation, authorization, error handling
• Client (React front end)
• Web/API Tier (Express app)
• Business Tier (Controllers → Services)
• Data Tier (Mongoose models → MongoDB)
• External Integrations (OAuth / Email Service)
• Client → Express (HTTP requests)
• Express.router → Controller → Service → Model → MongoDB
• Service ←→ External services (OAuth, SMTP)
• Express.js, Helmet, XSS-Clean, rateLimiter
• JWT and Passport
• Multer
• Mongoose
• Green = API / Framework layer
• Blue = Business/Service layer
• Yellow = Data layer
• Orange = External systems/services