How raunakgarg05/onlineshoppingsite works
Project Type and Purpose
• This is a full-stack e-commerce web application built with Node.js and Express.js on the backend, EJS templates for server-side rendered views, and MongoDB (via Mongoose) as the primary database. It supports user authentication, shopping cart, orders, invoice generation, email notifications (SendGrid), and payment processing (Stripe).
File Structure Analysis
• Top-Level Files
• app.js – main Express application entrypoint
• package.json / package-lock.json – dependencies and scripts
• .gitignore, README.md
• Directories
• controllers/ – request handlers for admin, auth, shop, error
• routes/ – route definitions mapping URLs to controllers
• models/ – Mongoose schemas for Product, User, Order
• middleware/ – authentication guard
• util/ – file and path helpers
• data/ – local JSON data (cart, products) and generated PDF invoices
• public/ – static assets: CSS, JS, images
• views/ – EJS templates organized by feature (auth, admin, shop, includes)
Key Components
a. Client Layer
• Browser / User interface
• Static assets (public/css, public/js, images) delivered via Express’s static middleware
• EJS-rendered HTML views
b. Server Layer (Express Application)
• app.js (Express instance)
• Middleware stack: session handling, CSRF protection, body parsing, custom is-auth
• Route handlers: routes/auth, routes/shop, routes/admin
• Controllers: business logic for authentication, product management, cart, orders, error handling
• Utility services: file helper (saving invoices), path helper
c. Data Layer
• MongoDB Atlas (users, products, orders collections via Mongoose)
• Local JSON files for cart and products (fallback or seed data)
• File system storage for PDF invoices
d. External Services
• SendGrid Email API – signup confirmation, password reset
• Stripe API – payment processing
Relationships and Data Flow
• User → Browser → HTTP Request → Express routes
• Express middleware applies security, sessions → passes to controllers
• Controllers → Mongoose models → MongoDB (read/write)
• Controllers → util/file → PDF invoices written to disk → served back to user or emailed
• Controllers call external APIs:
• SendGrid (email delivery)
• Stripe (payment authorization)
• Express → renders EJS views injecting dynamic data → HTTP response → Browser
Architectural Patterns and Design Principles
• MVC-inspired structure: Routes → Controllers (C) → Models (M) → Views (V)
• Separation of concerns: middleware concerns vs. business logic vs. data access
• Externalized configuration (API keys, database URI) via environment variables
• Use of RESTful routes for shop/admin/auth
• File-based PDF invoice generation as a service layer