A production-ready, full-stack e-commerce solution architected for scalability, performance, and security. Built with a Smart Routing System, Hybrid Cart Architecture, and Advanced Server-State Management.
This project goes beyond basic CRUD apps by implementing advanced software engineering patterns:
I engineered a custom Protected Routing System to handle security and navigation dynamically:
- Intelligent Redirection: Automatically inspects user roles (
Adminvs.User) and authentication state before rendering. - Security Layer: Instantly redirects unauthorized users (e.g., a normal user attempting to access
/admin/dashboard) to safe zones. - State Awareness: Preserves the user's intended destination and redirects them back seamlessly after login.
A complex cart logic designed for maximum conversion:
- Guest Persistence: Cart items are stored in
LocalStoragefor guest users. - Database Synchronization: Cart items are stored in
MongoDBfor logged-in users. - Auto-Merge Logic: Automatically merges the local guest cart with the database cart upon authentication, ensuring no data loss.
- Centralized Error Handling: Implemented a Global Error Handler middleware to catch operational errors and ensure consistent JSON responses.
- Async Wrapper Pattern: Replaced repetitive try-catch blocks with a custom wrapper for cleaner controllers.
- Advanced API Features: A reusable class handling Server-Side Filtering, Sorting, Pagination, and Field Limiting.
- Request Interceptors: Automatically injects JWT tokens into secure requests.
- Response Interceptors: Global error catching (e.g., auto-logout on
401 Unauthorized& session expiry handling).
Designed for a seamless user experience.
- High-Performance Data: Utilized TanStack Query for aggressive caching, background updates, and zero-loading states.
- Fully Responsive Design: A Mobile-First UI built with Tailwind CSS that adapts perfectly to all screen sizes.
- Advanced Product Discovery: Real-time search and multi-criteria filtering (Category, Price).
- Secure Checkout: Integrated Stripe payment flow with order summary.
- User Hub: Profile management and order history tracking.
- Authentication: Secure Sign Up/Login with data sanitization.
A complete Content Management System for business control.
- Dynamic Category Management: Create and manage product categories dynamically (not hardcoded).
- Inventory Control: Full CRUD operations for products with Multer & Cloudinary image pipelines.
- Order Workflow: Track and update order status (Processing โ Delivered).
- User Management: Monitor active users and manage system roles.
Immersive dark-themed landing page with premium aesthetics.
Real-time server-side filtering by category, price range, and search keywords.
Robust cart management with dynamic calculations and secure checkout capability.
Complete control panel for analytics, product management, orders, and users.
The application follows a robust MVC (Model-View-Controller) architecture with a dedicated Service Layer to separate business logic from request handling.
/
โโโ /backend
โ โโโ /config # โ๏ธ DB Connection & Env Configuration
โ โโโ /controllers # ๐ฎ Request Processors (Input/Output only)
โ โโโ /middleware # ๐ก๏ธ Auth (JWT), Error Handling, Validation
โ โโโ /models # ๐๏ธ Mongoose Schemas (Data Layer)
โ โโโ /routes # ๐ฃ๏ธ API Endpoints Declaration
โ โโโ /utils # ๐ง Helpers (APIFeatures, Stripe)
โ โโโ index.js # ๐ App Entry Point
โ
โโโ /frontend # โ๏ธ Frontend (React + Vite + Tailwind)
โ โโโ /src
โ โ โโโ /components # ๐งฉ Reusable UI Components
โ โ โโโ /pages # ๐ Route Views
โ โ โโโ /store # โก State Management (Slices/Services)
โ โ โโโ /utils # ๐ ๏ธ Client-side Helpers
โ โ โโโ /services # ๐ก API Services (Axios wrappers & Endpoints)
โ โ โโโ /hooks # ๐ฃ Custom Hooks (Logic Reuse)
โ โโโ ...
โโโ ...
| Domain | Technologies |
|---|---|
| Frontend | React.js, TanStack Query (Server State), Redux/Context (Client State), Tailwind CSS |
| Backend | Node.js, Express.js, Async Wrapper, Global Error Handler |
| Database | MongoDB, Mongoose (Advanced Schema Methods) |
| Network | Axios Instances & Interceptors |
| Media | Multer, Cloudinary API |
| Payment | Stripe API |
| Security | JWT, Bcrypt, Express-Mongo-Sanitize, XSS-Clean |
I am actively working on upgrading this architecture to industry-standard microservices and type-safe environments:
- TypeScript Migration: To ensure strict type safety and reduce runtime errors.
- Dockerization: Containerizing the application for consistent Dev/Prod environments.
- Next.js: Moving towards Server-Side Rendering (SSR) for better SEO.
-
Clone the repository:
git clone https://github.com/akx86/mern-ecommerce.git
-
Install Dependencies:
npm install && npm install --prefix frontend -
Configure Environment Variables:
Step A: Backend (.env in Root) Create a
.envfile in the main folder:NODE_ENV=development PORT=5000 MONGO_URI=your_mongodb_connection_string JWT_SECRET=your_jwt_secret_key STRIPE_SECRET_KEY=your_stripe_secret_key CLOUDINARY_CLOUD_NAME=your_cloud_name CLOUDINARY_API_KEY=your_api_key CLOUDINARY_API_SECRET=your_api_secret
Step B: Frontend (.env in /frontend) Create a .env file inside the frontend folder:
# Vite variables must start with VITE_ VITE_API_URL=http://localhost:5000/api VITE_STRIPE_PUBLIC_KEY=your_stripe_publishable_key
-
Run Development Server:
# Run both frontend and backend concurrently npm run dev
Ahmed Khaled
Full Stack Developer (MERN)
๐ง Email: ahmedali245699@gmail.com