A full-stack e-commerce application template built with MongoDB, Express.js, React, and Node.js. This template provides a solid foundation for building modern e-commerce applications with TypeScript support.
- Full-Stack TypeScript: End-to-end type safety with TypeScript
- Modern React Frontend: Built with React 18, Vite, and TypeScript
- RESTful API: Express.js backend with MongoDB integration
- Product Management: Complete CRUD operations for products
- Advanced Filtering: Search, sort, pagination, and field limiting
- Responsive Design: Mobile-first approach with modern CSS
- Persian Font Support: Includes IRANSans font family
- Data Seeding: Built-in data seeder for development
- Error Handling: Centralized error handling with custom error classes
- Development Tools: Hot reload, linting, and formatting configured
- Node.js - Runtime environment
- Express.js - Web framework
- MongoDB - Database
- Mongoose - ODM for MongoDB
- TypeScript - Type safety
- Pug - Template engine
- Morgan - HTTP request logger
- Bcrypt - Password hashing
- React 18 - UI library
- TypeScript - Type safety
- Vite - Build tool and dev server
- ESLint - Code linting
- Nodemon - Auto-restart server
- Concurrently - Run multiple commands
- Prettier - Code formatting
- ts-node - TypeScript execution
-
Clone the repository
git clone <repository-url> cd mern-template
-
Install dependencies
npm install
-
Set up environment variables
cp .env.example .env
Configure your environment variables:
PORT=3000 MONGODB_URI=mongodb://localhost:27017/ecommerce NODE_ENV=development
-
Start the development server
npm run start:dev
npm run start:dev- Start both backend and frontend in development modenpm run server- Start backend server with nodemonnpm run client- Start frontend development servernpm run build- Build for productionnpm start- Start production servernpm run data:import- Import sample datanpm run data:destroy- Remove all data
npm run dev- Start Vite development servernpm run build- Build for productionnpm run lint- Run ESLintnpm run preview- Preview production build
mern-template/
├── client/ # React frontend
│ ├── public/ # Static assets
│ ├── src/ # Source code
│ │ ├── App.tsx # Main App component
│ │ ├── main.tsx # Entry point
│ │ └── ...
│ └── package.json # Frontend dependencies
├── src/ # Backend source code
│ ├── controllers/ # Route controllers
│ ├── data/ # Sample data and seeder
│ ├── middlewares/ # Custom middlewares
│ ├── models/ # Mongoose models
│ ├── routers/ # Route definitions
│ ├── start/ # App configuration
│ ├── types/ # TypeScript type definitions
│ ├── utils/ # Utility functions
│ ├── views/ # Pug templates
│ └── server.ts # Server entry point
└── package.json # Root dependencies
GET /api/products- Get all products with filtering, sorting, and paginationGET /api/products/:id- Get single productPOST /api/products- Create new productDELETE /api/products/:id- Delete product
page- Page number for paginationlimit- Number of items per pagesort- Sort by field (e.g.,price,-createdAt)fields- Select specific fieldssearch- Search in product names and descriptions
- Product Listing: Display products with pagination
- Type Safety: Full TypeScript integration
- Modern React: Hooks and functional components
- Responsive Design: Mobile-first approach
{
name: string; // Product name
slug: string; // URL-friendly identifier
description: string; // Product description
image: string; // Main product image
images: string[]; // Additional images
countInStock: number; // Inventory count
isAvailable: boolean; // Availability status
brand: string; // Product brand
category: string; // Product category
rating: number; // Average rating
numReviews: number; // Number of reviews
price: number; // Original price
discount: number; // Discount percentage
discountedPrice: number; // Calculated discounted price
}Create a .env file in the root directory:
# Server Configuration
PORT=3000
NODE_ENV=development
# Database
MONGODB_URI=mongodb://localhost:27017/ecommerce
# Add other environment variables as needednpm run buildnpm start- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Hossein Rezaei
- Built with modern web technologies
- Inspired by e-commerce best practices
- Persian language support included
Happy Coding! 🎉