Welcome to the KyuR backend! This document provides all the necessary details for frontend developers to connect to the backend, handle authentication, manage items, and integrate real-time messaging.
- Base URL (Local):
http://localhost:5000/api - Socket.io URL (Local):
http://localhost:5000 - Authentication: All protected routes expect a JWT token in the Authorization header:
Authorization: Bearer <token> - Response Format: All API responses follow a consistent envelope:
{ "success": true, // or false on error "data": { ... }, // Payload "message": "...", // Optional string (mostly on auth endpoints) "count": 10 // Optional (when returning arrays) }
POST /auth/register
- Body (JSON):
name,email(Must end in@iskolarngbayan.pup.edu.ph),password - Returns: User object with a
token. Note: The account starts asisVerified: false. A verification email is automatically sent.
POST /auth/login
- Body (JSON):
email,password - Returns: User object and
token.
GET /auth/profile
- Headers:
Authorization: Bearer <token> - Returns: The authenticated user's details (password stripped).
GET /auth/verify/:token
- Desc: Normally hit directly via a link in the user's email, but you can also hit it via AJAX.
- Returns: Success message.
POST /auth/forgotpassword
- Body (JSON):
email - Returns: Success message.
PUT /auth/resetpassword/:token
- Body (JSON):
password(min 6 characters) - Returns: The updated User object and a fresh
token.
Important
All item routes require authentication (Authorization: Bearer <token>).
POST /items/createItem
- Content-Type:
multipart/form-data(Do NOT send JSON) - Form Data Fields:
title(String)description(String)category(Enum:electronics,wallet,id,accessories,other)status(Enum:lost,found,claimed)locationId(String - maps to a QR code ID)image(File - Image up to 5MB)
- Returns: The created item, including the newly generated
imageUrlfrom AWS S3.
GET /items/getItems
- Query Params (Optional):
status(exact match)category(exact match)locationId(exact match)search(full-text search on title and description)page(number, default: 1)limit(number, default: 10)
- Returns:
{ "success": true, "data": { "items": [{...}, {...}], "page": 1, "pages": 5, "total": 45 } }
GET /items/:id
- Returns: Single item object, with
reportedByandclaimedBypopulated (includes their names and emails).
PUT /items/:id/status
- Body (JSON):
status(Enum:lost,found,claimed) - Returns: The updated item. If
statusis sent asclaimed, the backend automatically setsclaimedByto the current user's ID.
Important
Messaging heavily relies on Socket.io for real-time. REST endpoints are just used for fetching history and fallback read-receipts. All require auth.
GET /messages/:itemId
- Returns: Array of all messages for the specific item, sorted chronologically (oldest first).
senderandreceiverare populated withnameand_id.
PUT /messages/:id/read
- Desc: Only the intended receiver can mark a message as read.
- Returns: The updated message object (
isRead: true).
To connect to Socket.io, the frontend must pass the user's JWT token in the handshake auth object.
// Frontend Connection Example
import { io } from "socket.io-client";
const socket = io("http://localhost:5000", {
auth: {
token: "YOUR_JWT_TOKEN"
}
});join_room- Payload:
{ itemId: "60d5ecb8b392d..." } - Desc: Call this when a user opens a chat for a specific item.
- Payload:
send_message- Payload:
{ itemId: "...", receiverId: "...", content: "Hello!" } - Desc: Sends a message. The server validates, saves to MongoDB, and broadcasts it to the room.
- Payload:
typing&stop_typing- Payload:
{ itemId: "..." } - Desc: Broadcasts typing status to the other user in the room.
- Payload:
mark_read- Payload:
{ messageId: "...", itemId: "..." } - Desc: Updates MongoDB that a message is read and instantly notifies the sender's UI.
- Payload:
receive_message- Payload: A fully populated message object (matching the MongoDB schema, including populated sender/receiver).
- Action: Append to your chat UI array.
typing&stop_typing- Payload:
{ userId: "..." } - Action: Show/hide a "User is typing..." indicator.
- Payload:
message_read- Payload:
{ messageId: "..." } - Action: Add a "Read" checkmark next to the corresponding message in your UI.
- Payload:
error- Payload:
{ message: "Error description" } - Action: Show a toast/alert to the user if something failed (e.g. invalid token).
- Payload: