Ecom is a comprehensive e-commerce ecosystem and multi-role web platform built for retail customers and store administrators. The platform seamlessly bridges consumer shopping experiences with enterprise administration through dynamic product discovery, product comparison, AI-assisted customer support, real-time chat, automated order lifecycle tracking, role-based access control (RBAC), an automated SEO & OpenGraph engine, cascading media synchronization, and a dedicated media storage microservice.
- Account & OAuth2 Authentication: Secure registration and credential login alongside OTP email verification and one-click Google & Facebook OAuth2 integration.
- Product Catalog & Atlas Search: Keyword search powered by MongoDB
Atlas Searchwith multi-field regex fallback, dynamic slugification, attribute-based filtering (color, size), category tree navigation, and product comparison. - Cart & Dynamic Checkout: Interactive shopping cart persisted client-side (
localStorage) with server-side stock/quantity revalidation, coupon application, shipping address management, and order placement. - Real-Time Support Chat & Rate Feedback: Live customer-to-admin instant messaging powered by WebSockets (
Socket.io) with online/active status tracking, open/locked conversation control, unread indicators, and a 5-star conversation rating widget (chat.pug) reviewable by admins (chat-rate.pug). - Order Lifecycle & History: Customer dashboard tracking purchase history and real-time status transitions (
Pending,Confirmed,Shipping,Completed,Cancelled,Returned). - Product Reviews, Recommendations & Flash Sales: 5-star rating system with order-verified review submission, wishlist bookmarking, reward points tracking, flash sales (
flash-sale.pug), and frequently bought together recommendations (bought-together-products.pug).
- Catalog & Rich Editor: Rich-text product editor (TinyMCE) supporting image uploads, variant/attribute management, stock caps, and soft-delete trash recovery across all entities.
- AI-Powered Support Assistant: LLM-driven semantic analysis of support conversations (smart reply suggestions, draft response refinement, conversation summarization, and customer sentiment/emotion detection), powered by Groq API (
LLaMA 3.1 8B Instant), separate from the real-time chat transport itself. - SEO & Social OpenGraph Engine: Custom SEO metadata management (
title,description,keywords,robots index/follow), OpenGraph social sharing tags (og:image), canonical URL middleware (canonical), and Google Search Console sitemap indexing helper. - Inventory & Order Processing: Searchable order management inbox with direct status updates (
Pending,Confirmed,Shipping,Completed,Cancelled,Returned), shipping carrier integration (GoShip), and customer dispatch emails. - Sales Analytics & CSV Export Reporting: Advanced analytics dashboards for time-series revenue (
dashboard-revenue-by-time.pug), top-selling products, order metrics, customer growth statistics, and one-click CSV data export (json2csv).
- Role-Based Access Control (RBAC): Permission-matrix administration protecting core management routes across staff roles.
- Account & Content Moderation: User account status management, product review moderation, and administrative audit logs (
admin-log.model.ts). - System Integration Settings: Centralized configuration management for Payment Gateways (ZaloPay, VNPay), Shipping Providers (GoShip), Social Auth API Keys, and App Passwords.
- Token Rotation & Theft Detection: Refresh Token Rotation with a 15-second grace period for concurrent requests and instant global token revocation upon token reuse attempt (
token-rotation.helper.ts). - Media Microservice & Cascading Sync: Standalone media storage service (
FileManager) with streamed multi-file batch upload, temp staging, UTF-8 sanitization, and automated cross-collection media rename/delete propagation (media-propagate.helper.ts).
- Frontend: Server-Side Rendering with Pug Templates, CSS3, JavaScript ES6+, Socket.IO Client, OpenLayers Map Picker with OpenStreetMap/Nominatim Geocoding.
- Backend: Node.js, Express 5, TypeScript, Socket.IO Server, Groq API (LLaMA 3.1), Passport.js (OAuth2), Nodemailer, Bcryptjs, Joi, Axios, json2csv, OpenMap.vn Reverse Geocoding (GoShip address resolution).
- Database & Storage: MongoDB Atlas (Mongoose ORM), Atlas Search Engine with Regex Fallback, NodeCache (In-Memory Chat & Settings Cache), Dynamic SEO Sub-Schema (
SeoSchema), Standalone FileManager Microservice. - Infrastructure: Layered Architecture, Admin Audit Trail Logging, Token Theft Detection & Refresh Token Rotation, Cascading Media Propagation, HttpOnly Cookies, Multer Disk Staging, OS Graceful Shutdown.
Ecom/
├── FileManager/ # Standalone Media & Asset Storage Microservice (Port 4000)
│ ├── controllers/ # Media upload, file streaming, & folder management handlers
│ ├── media/ # Physical disk storage (temp staging & user assets)
│ │ ├── temp/ # Staging directory for partial / stream uploads
│ │ └── users/ # Sanitized user uploaded media storage
│ ├── middlewares/ # Auth token verification & storage error handling
│ ├── routes/ # Express routes for media & file-manager APIs
│ ├── index.ts # Storage server entry point & Multer upload limits
│ └── package.json # Microservice dependencies & scripts
│
└── Web/ # Main E-Commerce Web Application (Port 3000)
├── configs/ # Database connection, OAuth strategies, & env validation
├── controllers/ # HTTP request handlers (admin/, client/)
│ ├── admin/ # Admin dashboard, products, categories, orders & role controllers
│ └── client/ # Customer shop, cart, checkout, chat & user account controllers
├── helpers/ # 18 Utilities (slugify, mailer, AI helper, Atlas search, etc.)
├── interfaces/ # Express request & custom type definitions
├── jobs/ # Background cron jobs (stale chat cleanup, unpaid order cancellation)
├── middlewares/ # Security guards, RBAC matrices, & request logger (admin/, client/)
│ ├── admin/ # Admin authentication & permission guards
│ └── client/ # Customer auth & session verification
├── models/ # 22 Mongoose data schemas & plugins
│ └── schemas/ # Embedded sub-documents & reusable schema definitions
├── public/ # Client & Admin static web assets (CSS, JS, images)
│ ├── admin/ # Admin panel custom scripts, styles, & plugins
│ └── client/ # Storefront styles, JS scripts, & icons
├── routes/ # Express routing modules (admin/, client/)
│ ├── admin/ # Admin management routes & RBAC endpoints
│ └── client/ # Customer-facing shopping & account routes
├── sockets/ # Real-time WebSocket handlers (support chat, auth events)
├── validates/ # Joi request payload validation schemas (admin/, client/)
├── views/ # Server-rendered Pug templates (admin/, client/)
│ ├── admin/ # Admin dashboard layouts, pages, & partials
│ └── client/ # Storefront layouts, product detail, checkout, & chat views
├── index.ts # App server entry point & OS Graceful Shutdown handler
└── package.json # Web application dependencies & scripts
- Node.js (v18+)
- Yarn or npm
- MongoDB Atlas or Local MongoDB instance
# Clone the repository
git clone https://github.com/thaihadefi/Ecom.git
cd Ecom- Start the Media Storage Microservice (
FileManager- Port 4000):
cd FileManager
# Install dependencies
yarn install
# Configure Environment Variables (.env)
cp .env.example .env
# Run development server
yarn dev- In a new terminal window, start the Main Web Application (
Web- Port 3000):
cd Web
# Install dependencies
yarn install
# Configure Environment Variables (.env)
cp .env.example .env
# Run development server
yarn devThis project is licensed under the MIT License.