Skip to content

Athang69/StationaryX-BD

Repository files navigation

🖊️ StationeryX — Backend

A modular RESTful backend for stationery inventory management — covering products, stock, and order processing.

Node.js Express MongoDB JavaScript


📌 About

StationeryX is a backend service for managing a stationery store's operations — product catalog, stock levels, and order processing. Built with a clean modular architecture separating routes, controllers, and services for scalability and testability.


✨ Features

  • 📦 Product Management — Create, read, update, and delete stationery products
  • 📊 Inventory Tracking — Real-time stock level monitoring and updates
  • 🛒 Order Processing — Place and manage customer orders
  • 🔍 Optimized Queries — MongoDB indexing for fast product catalog lookups
  • 🧱 Modular Architecture — Separated routes, controllers, and services layer
  • Input Validation — Request validation and centralized error handling

🛠️ Tech Stack

Layer Technology
Runtime Node.js
Framework Express.js
Database MongoDB (Mongoose ODM)
Architecture RESTful API, MVC pattern

🏗️ Project Structure

StationaryX-BD/
├── src/
│   ├── controllers/       # Request handlers for each resource
│   │   ├── productController.js
│   │   ├── orderController.js
│   │   └── inventoryController.js
│   ├── models/            # Mongoose schemas
│   │   ├── Product.js
│   │   └── Order.js
│   ├── routes/            # Express route definitions
│   │   ├── productRoutes.js
│   │   ├── orderRoutes.js
│   │   └── inventoryRoutes.js
│   ├── middleware/         # Error handling, validation
│   └── app.js             # Express app setup
└── server.js              # Entry point

🚀 Getting Started

Prerequisites

1. Clone the repo

git clone https://github.com/Athang69/StationaryX-BD.git
cd StationaryX-BD

2. Install dependencies

npm install

3. Configure environment

Create a .env file:

PORT=5000
MONGO_URI=your_mongodb_connection_string

4. Run the server

# Development
npm run dev

# Production
npm start

Server runs at http://localhost:5000


🔌 API Reference

Products

Method Endpoint Description
GET /api/products Get all products
GET /api/products/:id Get product by ID
POST /api/products Create new product
PUT /api/products/:id Update product details
DELETE /api/products/:id Delete product

Sample Request — Create Product:

POST /api/products
{
  "name": "Pilot G2 Pen",
  "category": "Pens",
  "price": 45,
  "stock": 200,
  "sku": "PEN-G2-BLK"
}

Sample Response:

{
  "success": true,
  "data": {
    "_id": "64abc123...",
    "name": "Pilot G2 Pen",
    "category": "Pens",
    "price": 45,
    "stock": 200,
    "sku": "PEN-G2-BLK",
    "createdAt": "2024-09-01T10:00:00Z"
  }
}

Inventory

Method Endpoint Description
GET /api/inventory Get all stock levels
PATCH /api/inventory/:id Update stock for a product

Sample Request — Update Stock:

PATCH /api/inventory/64abc123
{
  "stock": 150
}

Orders

Method Endpoint Description
GET /api/orders Get all orders
POST /api/orders Place a new order
GET /api/orders/:id Get order by ID
PATCH /api/orders/:id Update order status

Sample Request — Place Order:

POST /api/orders
{
  "items": [
    { "productId": "64abc123", "quantity": 3 }
  ],
  "customerName": "John Doe"
}

📄 .env.example

PORT=5000
MONGO_URI=mongodb+srv://<username>:<password>@cluster.mongodb.net/stationeryx

💡 Design Decisions

  • Modular MVC structure — Routes, controllers, and models are fully separated so each layer can be tested and extended independently
  • MongoDB with indexing — Product SKU and category fields are indexed for fast catalog queries under load
  • Centralized error handling — A single error middleware catches and formats all errors consistently across the API

👨‍💻 Author

Athang KaliGitHub · LinkedIn · Portfolio

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors