Atoms is an e-commerce backend built with TypeScript and Express.js. It provides a set of RESTful APIs for managing products, user authentication, and shopping cart functionality.
- User authentication (signup, signin, superuser creation)
- Product management (CRUD operations)
- Shopping cart functionality
- Category-based product browsing
- Role-based access control
- Node.js (v18 or later recommended)
- npm
- TypeScript
- MongoDB (or your preferred database)
-
Clone the repository:
git clone https://github.com/Ojochogwu866/atoms.git cd atoms
-
Install dependencies:
npm install
-
Set up your environment variables in a
.env
file:PORT=3000 MONGODB_URI=your_mongodb_connection_string JWT_SECRET=your_jwt_secret
-
Compile TypeScript:
npm run build
-
Start the server:
npm start
src/
├── config/
│ ├── auth.ts
│ ├── database.ts
├── controllers/
│ ├── authControllers.ts
│ ├── cartControllers.ts
│ └── productControllers.ts
├── middlewares/
│ └── auth.ts
│ └── errorHandler.ts
│ └── rateLimiter.ts
│ └── validator.ts
├── routes/
│ ├── authRoutes.ts
│ ├── cartRoutes.ts
│ └── index.ts
│ └── productRoutes.ts
├── models/
│ ├── User.ts
│ ├── Product.ts
│ ├── Cart.ts
├── services/
│ ├── authService.ts
│ ├── productService.ts
│ ├── cartService.ts
├── utils/
│ ├── logger.ts
└── app.ts
GET /products
: Get all productsGET /products/:id
: Get a specific productGET /products/categories
: Get all categoriesGET /products/category/:category
: Get products by categoryPOST /products
: Create a new product (Admin/Superuser only)PATCH /products/:id
: Update a product (Admin/Superuser only)DELETE /products/:id
: Delete a product (Admin/Superuser only)
GET /cart
: Get the user's cartPOST /cart/add
: Add a product to the cartDELETE /cart/remove/:productId
: Remove a product from the cartDELETE /cart/clear
: Clear the entire cart
POST /auth/signup
: User registrationPOST /auth/signin
: User loginPOST /auth/superuser
: Create a superuser
authMiddleware
: Ensures that the user is authenticatedrestrictTo
: Restricts access to specific user roles
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License.