Introduction
The SmartShelf API is a RESTful API built with Express.js that provides comprehensive inventory management capabilities. It follows REST principles and returns JSON-formatted responses for all endpoints.Base URL
/api. The default port is 5000 but can be configured via environment variables.
API Architecture
SmartShelf API is built using:- Express.js - Web framework
- MongoDB - Database with Mongoose ODM
- JWT - Token-based authentication
- Helmet - Security headers
- CORS - Cross-origin resource sharing
- express-rate-limit - Request throttling
RESTful Design Principles
The API follows REST conventions:- Resources are represented as nouns (e.g.,
/inventory,/tasks,/users) - HTTP methods indicate actions:
GET- Retrieve resourcesPOST- Create new resourcesPUT- Update existing resourcesDELETE- Remove resources
- Stateless requests with authentication via JWT tokens
- Consistent URL structure and naming conventions
Response Format Standards
Success Response
All successful responses follow this structure:Error Response
All error responses follow this structure:HTTP Status Codes
The API uses standard HTTP status codes:Request succeeded
Resource successfully created
Invalid request parameters or validation failed
Authentication required or invalid credentials
Authenticated but not authorized for this action
Requested resource does not exist
Server error occurred
Rate Limiting
To prevent abuse, the API implements rate limiting:- Window: 15 minutes
- Limit: 100 requests per IP address
- Headers: Standard rate limit headers included in responses
RateLimit-Limit- Total requests allowedRateLimit-Remaining- Requests remainingRateLimit-Reset- Time when limit resets
API Versioning
Currently, the API is at version 1.0.0. The base path/api serves the current version. Future versions may introduce versioned paths like /api/v2 to maintain backward compatibility.
Quick Start Example
Here’s a simple example to get started with the SmartShelf API:1. Check API Health
2. Register a New User
3. Make Authenticated Request
Endpoint Documentation
Explore detailed documentation for each API module:Authentication
User registration, login, and JWT token management
Inventory
Product and stock management endpoints
Users
User management and role-based access control
Tasks
Task assignment and tracking
Alerts
Low stock and system alerts
Analytics
Business intelligence, reporting, and demand forecasting
Security
The API implements multiple security measures:- Helmet.js - Sets security HTTP headers
- CORS - Configured for trusted origins only
- JWT - Secure token-based authentication
- bcryptjs - Password hashing with salt
- Rate limiting - Protection against DoS attacks
- Input validation - Using express-validator
- HttpOnly cookies - Secure token storage option
Support
For issues or questions:- Check the Authentication Guide for auth-related questions
- Review endpoint-specific documentation for detailed parameters
- Ensure your requests include proper headers and authentication tokens