This is the backend repository for the E-Commerce web application for a Online Store. Built using the MERN Stack (MongoDB, Express, React, Node.js), this backend provides RESTful APIs to manage users, products, orders, reviews, and admin functionalities.
- Users can register and log in.
- Users can browse products.
- Customers can create orders containing multiple products.
- Customers can track their order status.
- Customers can post reviews on products.
- Customers can view reviews posted by other users.
- Customers can save multiple addresses and reuse them during checkout.
- Admins can create and manage products with multiple images.
- Admins can create new admin accounts.
- Admins can manage user accounts (block/unblock users).
- Admins can manage product reviews (hide inappropriate reviews).
- Admins can view all user orders.
- Admins can change order statuses.
- Admins can access customer order history.
- Backend: Node.js, Express.js
- Database: MongoDB
- Authentication: JWT (JSON Web Tokens), bcrypt
- Storage: Supabase Storage
- Environment Variables: dotenv
- Node.js installed
- MongoDB database setup
-
Clone the repository:
git clone https://github.com/savinduamalka/agni-e-commerce-backend.git cd agni-e-commerce-backend -
Install dependencies:
pnpm install
-
Create a
.envfile in the root directory and add the following:PORT=5000 MONGO_URI=your_mongodb_connection_string JWT_SECRET=your_secret_key
-
Start the server:
pnpm start
-
The backend will be running at:
http://localhost:5000
## API Endpoints
### Authentication
- `POST /api/auth/register` - Register a new user
- `POST /api/auth/login` - Login user
### Products
- `GET /api/products` - Get all products
- `POST /api/products` - Create a product (Admin only)
- `GET /api/products/:id` - Get product details
- `PUT /api/products/:id` - Update product (Admin only)
- `DELETE /api/products/:id` - Delete product (Admin only)
### Orders
- `POST /api/orders` - Create an order
- `GET /api/orders/user/:id` - Get user orders
- `GET /api/orders` - Get all orders (Admin only)
- `PUT /api/orders/:id/status` - Update order status (Admin only)
### Reviews
- `POST /api/reviews` - Add a review
- `GET /api/reviews` - Get all reviews
- `PUT /api/reviews/:id/hide` - Hide review (Admin only)
### User Management
- `GET /api/users` - Get all users (Admin only)
- `PUT /api/users/:id/block` - Block/unblock user (Admin only)
- `POST /api/admins` - Create new admin (Admin only)
### Address Management
- `POST /api/addresses` - Add a new address
- `GET /api/addresses/user/:id` - Get saved addresses
## License
This project is licensed under the MIT License.