Skip to content

Latest commit

 

History

History
203 lines (179 loc) · 5.45 KB

File metadata and controls

203 lines (179 loc) · 5.45 KB

Backend PMS API Documentation

Authentication

All protected routes require API key in header:

X-API-Key: your_api_key_here

WebSocket Events

Connect to WebSocket:

const socket = io('wss://backendpms-wvoo.onrender.com', {
  path: '/socket.io',
  auth: { token: 'your_api_key' }
});

Events

// Server -> Client Events
socket.on('inventory_update', (data: { productId: string, stock: number }) => {})
socket.on('order_status', (data: { orderId: string, status: string }) => {})
socket.on('system_alert', (data: { type: string, message: string }) => {})

// Client -> Server Events
socket.emit('subscribe_inventory', productId: string)
socket.emit('subscribe_order', orderId: string)

REST Endpoints

Products API

// Create Product
POST /api/pms/products
Content-Type: application/json
{
  "name": string,
  "description": string,
  "price": number,
  "categoryId": string,
  "images": string[]
}

// Publish Product
PUT /api/pms/products/:id/publish
Content-Type: application/json
{
  "status": "published"
}

// Update Product
PATCH /api/pms/products/:id
Content-Type: application/json
{
  "name?": string,
  "price?": number
  // ...other fields
}

Inventory API

// Check Stock
GET /api/inventory/stock/:productId

// Adjust Stock
POST /api/inventory/adjust
Content-Type: application/json
{
  "productId": string,
  "quantity": number,
  "type": "increment" | "decrement"
}

// Get Low Stock Alerts
GET /api/inventory/alerts

Orders API

// Create Order
POST /api/pms/orders
Content-Type: application/json
{
  "items": Array<{
    "productId": string,
    "quantity": number
  }>,
  "customerId": string,
  "shippingAddress": string
}

// Update Order Status
PATCH /api/pms/orders/:id/status
Content-Type: application/json
{
  "status": "confirmed" | "processing" | "shipped" | "delivered"
}

Analytics API

// Get Sales Analytics
GET /api/analytics/sales
Query Params:
  startDate: YYYY-MM-DD
  endDate: YYYY-MM-DD
  groupBy: "day" | "week" | "month"

// Get Inventory Metrics
GET /api/analytics/inventory/metrics

Health Check API

// System Health
GET /health
Response:
{
  "status": "ok" | "degraded",
  "timestamp": string,
  "checks": {
    "database": { healthy: boolean, latency?: number },
    "memory": { healthy: boolean, usage: object },
    "websocket": { healthy: boolean, connections: number },
    "uptime": number
  }
}

Cache Integration

Redis configuration (via Upstash):

REDIS_URL=your_upstash_url
REDIS_TOKEN=your_upstash_token

Rate Limits

// Standard Limits
- 100 requests per minute for API endpoints
- 1000 WebSocket messages per minute
- 50 concurrent connections per client

API Documentation

API Flow Architecture

                      ┌─────────────────┐
                      │   API Request   │
                      └────────┬────────┘
                              │
                   ┌──────────┴──────────┐
                   │    Authentication   │
                   └──────────┬──────────┘
                              │
           ┌─────────────────┬┴────────────────┐
           │                 │                 │
   ┌───────▼──────┐  ┌──────▼─────┐  ┌───────▼──────┐
   │    /pms/*    │  │ /products/ │  │ /inventory/  │
   │  Endpoints   │  │ Endpoints  │  │  Endpoints   │
   └───────┬──────┘  └──────┬─────┘  └───────┬──────┘
           │                │                 │
   ┌───────▼──────┐  ┌──────▼─────┐  ┌───────▼──────┐
   │ PMS Service  │  │  Product   │  │  Inventory   │
   │    Layer     │  │  Service   │  │   Service    │
   └───────┬──────┘  └──────┬─────┘  └───────┬──────┘
           │                │                 │
           └────────┬──────┴─────────────────┘
                    │
            ┌───────▼───────┐
            │   Database    │
            │    Layer      │
            └───────┬───────┘
                    │
            ┌───────▼───────┐
            │    Cache      │
            │    Layer      │
            └───────┬───────┘
                    │
            ┌───────▼───────┐
            │   Response    │
            └───────────────┘

API Routes

PMS Integration

  • Base URL: /api/pms
  • Authentication: API Key required
  • Rate Limit: 100 requests/minute

Product Management

  • Base URL: /api/products
  • Caching: 5 minutes
  • Real-time updates via WebSocket

Inventory Control

  • Base URL: /api/inventory
  • Real-time sync enabled
  • Transaction support