A comprehensive backend API for a neighborhood management system built with Node.js, TypeScript, Express, and Supabase.
- 🔐 User Authentication - Multi-role authentication (Owner, Resident, Staff)
- 📝 Complaint Management - Create and track complaints with role-based access
- 🛠️ Service Management - Manage community services
- 📅 Booking System - Book and manage service appointments
- 📢 Notice Board - Community announcements and notices
- 🗳️ Polling System - Create and participate in community polls
- 📆 Event Management - Organize community events
- 🚨 Emergency Services - Emergency contact management
- 💬 AI Chatbot - Intelligent assistance using LangChain and Groq
- �️ Society Management - Multi-society support with unique codes
- Runtime: Node.js with TypeScript
- Framework: Express.js
- Database: Supabase (PostgreSQL)
- Authentication: Supabase Auth with JWT
- AI/ML: LangChain + Groq for chatbot functionality
- Validation: Custom middleware
- Security: CORS, cookie-parser, role-based access control
- Node.js (v16 or higher)
- npm or yarn
- Supabase account and project
- Clone the repository:
git clone <repository-url>
cd neighborly-backend- Install dependencies:
npm install- Set up environment variables:
# Create .env file with the following variables:
PORT=5000
SUPABASE_URL=your_supabase_url
SUPABASE_ANON_KEY=your_supabase_anon_key
SUPABASE_SERVICE_KEY=your_supabase_service_key
GROQ_API_KEY=your_groq_api_key
CORS_ORIGINS=http://localhost:3000
NODE_ENV=development- Build and run:
# Development
npm run dev
# Production
npm run build
npm startThe API uses Supabase authentication with role-based access control. Users can register as:
- Owner: Society owner with full administrative privileges
- Resident: Society member with limited access
- Staff: Staff member with specific permissions
Authentication is handled via HTTP-only cookies with JWT tokens.
Base URL: /api/auth
- POST
/register/owner - Description: Register a new society owner and create society
- Authentication: None required
- Request Body:
{
"email": "[email protected]",
"password": "securePassword123",
"fullName": "John Doe",
"phone_number": "+1234567890",
"societyName": "Green Valley Society",
"address": "123 Main Street",
"city": "Springfield",
"state": "Illinois",
"postal_code": "62701"
}- Response:
{
"message": "Owner and society created successfully",
"society": {
"id": "uuid",
"name": "Green Valley Society",
"society_code": "ABC-123",
"owner_id": "uuid"
}
}- POST
/register/resident - Description: Register a new resident to existing society
- Authentication: None required
- Request Body:
{
"email": "[email protected]",
"password": "securePassword123",
"fullName": "Jane Smith",
"phone_number": "+1234567891",
"society_code": "ABC-123",
"flat_number": "A-101"
}- POST
/register/staff - Description: Register new staff member
- Authentication: None required
- Request Body:
{
"email": "[email protected]",
"password": "securePassword123",
"fullName": "Mike Johnson",
"phone_number": "+1234567892",
"society_code": "ABC-123",
"department": "Maintenance"
}- POST
/login - Description: Authenticate user and receive session cookie
- Authentication: None required
- Request Body:
{
"email": "[email protected]",
"password": "securePassword123"
}- Response:
{
"message": "Logged in successfully",
"user": {
"id": "uuid",
"email": "[email protected]",
"role": "resident"
}
}- POST
/logout - Description: Clear authentication session
- Authentication: Required
- Response:
{
"message": "Logged out successfully"
}Base URL: /api/complaints
- POST
/ - Description: Create a new complaint
- Authentication: Required (Resident role)
- Request Body:
{
"title": "Water Leakage in A-Block",
"description": "There is a major water leakage in the A-Block corridor that needs immediate attention."
}- Response:
{
"id": "uuid",
"title": "Water Leakage in A-Block",
"description": "There is a major water leakage...",
"status": "open",
"user_id": "uuid",
"created_at": "2024-01-01T10:00:00Z"
}- GET
/my - Description: Get all complaints created by the authenticated resident
- Authentication: Required (Resident role)
- Response:
[
{
"id": "uuid",
"title": "Water Leakage in A-Block",
"status": "in_progress",
"created_at": "2024-01-01T10:00:00Z"
}
]- GET
/ - Description: Get all complaints with optional status filter
- Authentication: Required (Owner role)
- Query Parameters:
?status=open(optional) - Response:
[
{
"id": "uuid",
"title": "Water Leakage in A-Block",
"status": "open",
"user_id": "uuid",
"assigned_to": null,
"created_at": "2024-01-01T10:00:00Z"
}
]- GET
/assigned - Description: Get complaints assigned to the authenticated staff member
- Authentication: Required (Staff role)
- Response:
[
{
"id": "uuid",
"title": "Elevator Maintenance",
"status": "in_progress",
"assigned_to": "staff-uuid",
"created_at": "2024-01-01T10:00:00Z"
}
]- GET
/:id - Description: Get detailed information about a specific complaint
- Authentication: Required (authorization handled in controller)
- Response:
{
"id": "uuid",
"title": "Water Leakage in A-Block",
"description": "Detailed description...",
"status": "in_progress",
"user_id": "uuid",
"assigned_to": "staff-uuid",
"created_at": "2024-01-01T10:00:00Z",
"updated_at": "2024-01-02T15:30:00Z"
}- PATCH
/:id/assign - Description: Assign a complaint to a staff member
- Authentication: Required (Owner role)
- Request Body:
{
"staffId": "staff-uuid"
}- PATCH
/:id/status - Description: Update the status of a complaint
- Authentication: Required (Owner or Staff role)
- Request Body:
{
"status": "resolved"
}Base URL: /api/services
- POST
/createservice - Description: Create a new service
- Authentication: Required
- Request Body:
{
"name": "Plumbing Service",
"description": "Professional plumbing repairs and maintenance",
"price": 500,
"category": "Maintenance",
"available": true
}- PUT
/updateservice - Description: Update an existing service
- Authentication: Required
- Request Body:
{
"serviceId": "uuid",
"name": "Updated Service Name",
"price": 600,
"available": false
}- DELETE
/deleteservice - Description: Delete a service
- Authentication: Required
- Request Body:
{
"serviceId": "uuid"
}- GET
/fetchservices - Description: Retrieve all available services
- Authentication: Required
- Response:
[
{
"id": "uuid",
"name": "Plumbing Service",
"description": "Professional plumbing repairs",
"price": 500,
"category": "Maintenance",
"available": true,
"created_at": "2024-01-01T10:00:00Z"
}
]Base URL: /api/bookings
- POST
/book - Description: Book a service for a specific date
- Authentication: Required
- Request Body:
{
"serviceId": "uuid",
"bookingDate": "2024-01-15",
"details": "Need plumbing service for kitchen sink"
}- Response:
{
"message": "Service booked successfully",
"data": {
"id": "uuid",
"user_id": "uuid",
"service_id": "uuid",
"requested_date": "2024-01-15",
"status": "pending",
"created_at": "2024-01-01T10:00:00Z"
}
}- PUT
/editbooking - Description: Update booking date
- Authentication: Required
- Request Body:
{
"bookingId": "uuid",
"bookingDate": "2024-01-20"
}- DELETE
/cancelbooking - Description: Cancel an existing booking
- Authentication: Required
- Request Body:
{
"bookingId": "uuid"
}- GET
/fetchbooking - Description: Retrieve all bookings
- Authentication: Required
- Response:
[
{
"id": "uuid",
"user_id": "uuid",
"service_id": "uuid",
"requested_date": "2024-01-15",
"status": "confirmed",
"created_at": "2024-01-01T10:00:00Z"
}
]Base URL: /api/notice
- POST
/createnotice - Description: Create a new community notice
- Authentication: Required
- Request Body:
{
"title": "Maintenance Notice",
"content": "Water supply will be interrupted on Sunday from 10 AM to 2 PM for maintenance work.",
"priority": "high",
"expires_at": "2024-02-01T00:00:00Z"
}- PUT
/editnotice - Description: Update an existing notice
- Authentication: Required
- Request Body:
{
"noticeId": "uuid",
"title": "Updated Notice Title",
"content": "Updated notice content...",
"priority": "medium"
}- DELETE
/deletenotice - Description: Remove a notice
- Authentication: Required
- Request Body:
{
"noticeId": "uuid"
}- GET
/fetchnotices - Description: Retrieve all active notices
- Authentication: None required
- Response:
[
{
"id": "uuid",
"title": "Maintenance Notice",
"content": "Water supply will be interrupted...",
"priority": "high",
"created_at": "2024-01-01T10:00:00Z",
"expires_at": "2024-02-01T00:00:00Z"
}
]Base URL: /api/poll
- POST
/createpoll - Description: Create a new community poll
- Authentication: Required
- Request Body:
{
"question": "Should we install CCTV cameras in the lobby?",
"options": ["Yes", "No", "Need more information"],
"expires_at": "2024-02-15T23:59:59Z",
"description": "This poll is to gather community opinion on security improvements."
}- PUT
/editpoll - Description: Update an existing poll (only if no votes yet)
- Authentication: Required
- Request Body:
{
"pollId": "uuid",
"question": "Updated poll question?",
"options": ["Updated Option 1", "Updated Option 2"]
}- PUT
/closepoll - Description: Manually close an active poll
- Authentication: Required
- Request Body:
{
"pollId": "uuid"
}- GET
/getpolls - Description: Retrieve all polls (active and closed)
- Authentication: None required
- Response:
[
{
"id": "uuid",
"question": "Should we install CCTV cameras?",
"options": ["Yes", "No", "Need more info"],
"status": "active",
"votes_count": 45,
"created_at": "2024-01-01T10:00:00Z",
"expires_at": "2024-02-15T23:59:59Z"
}
]Base URL: /api/events
- POST
/addevent - Description: Create a new community event
- Authentication: Required
- Request Body:
{
"title": "Annual Society Meeting",
"description": "Mandatory meeting for all residents to discuss society matters.",
"date": "2024-02-20T18:00:00Z",
"location": "Community Hall",
"organizer": "Society Management",
"max_participants": 100
}- DELETE
/removeevent - Description: Remove an event
- Authentication: Required
- Request Body:
{
"eventId": "uuid"
}- GET
/fetchevents - Description: Retrieve all upcoming events
- Authentication: Required
- Response:
[
{
"id": "uuid",
"title": "Annual Society Meeting",
"description": "Mandatory meeting...",
"date": "2024-02-20T18:00:00Z",
"location": "Community Hall",
"organizer": "Society Management",
"max_participants": 100,
"current_participants": 23,
"created_at": "2024-01-01T10:00:00Z"
}
]Base URL: /api/availemergency
- GET
/fetchsemergencyervices - Description: Get all available emergency services
- Authentication: None required
- Response:
[
{
"id": "uuid",
"name": "Fire Department",
"phone": "101",
"description": "Emergency fire services",
"available_24_7": true
}
]- POST
/bookemergencyservice - Description: Request an emergency service
- Authentication: None required
- Request Body:
{
"serviceId": "uuid",
"emergency_type": "fire",
"location": "Building A, Floor 3",
"description": "Small fire in kitchen",
"contact_number": "+1234567890"
}- DELETE
/closeemergencyservice - Description: Mark emergency as resolved
- Authentication: None required
- Request Body:
{
"emergencyId": "uuid"
}Base URL: /api/emergencies
- POST
/addemergencyservice - Description: Add a new emergency service to the system
- Authentication: Required
- Request Body:
{
"name": "Ambulance Service",
"phone": "108",
"description": "Medical emergency services",
"available_24_7": true,
"response_time": "15 minutes"
}- DELETE
/deleteemergencyservice - Description: Remove an emergency service
- Authentication: Required
- Request Body:
{
"serviceId": "uuid"
}- GET
/getemergencyservices - Description: Get all emergency services in the system
- Authentication: Required
- Response:
[
{
"id": "uuid",
"name": "Fire Department",
"phone": "101",
"description": "Emergency fire services",
"available_24_7": true,
"response_time": "10 minutes",
"created_at": "2024-01-01T10:00:00Z"
}
]Base URL: /api/chatbot
- POST
/ - Description: Send a message to the AI chatbot for assistance
- Authentication: None required
- Request Body:
{
"message": "How do I register a complaint about noise?",
"context": "resident_help"
}- Response:
{
"response": "To register a noise complaint, you can use the complaint system by going to /api/complaints and creating a new complaint. Make sure to provide details about the noise issue, including time, location, and description of the problem.",
"timestamp": "2024-01-01T10:00:00Z"
}The API uses consistent error response format:
{
"message": "Error description",
"error": "Additional error details (in development mode)",
"statusCode": 400
}200- Success201- Created successfully400- Bad Request (validation errors)401- Unauthorized (authentication required)403- Forbidden (insufficient permissions)404- Not Found500- Internal Server Error
{
"message": "Authentication required",
"statusCode": 401
}{
"message": "Missing required fields: email, password",
"statusCode": 400
}{
"message": "Forbidden: Insufficient permissions for this action",
"statusCode": 403
}src/
├── config/ # Database and external service configurations
├── controllers/ # Request handlers and business logic
├── middleware/ # Authentication, validation, error handling
├── routes/ # API route definitions
├── services/ # Database operations and external API calls
├── types/ # TypeScript type definitions
└── index.ts # Application entry point
npm run dev # Start development server with hot reload
npm run build # Build TypeScript to JavaScript
npm start # Start production serverPORT=5000 # Server port
SUPABASE_URL= # Supabase project URL
SUPABASE_ANON_KEY= # Supabase anonymous key
SUPABASE_SERVICE_KEY= # Supabase service role key
GROQ_API_KEY= # Groq AI API key for chatbot
CORS_ORIGINS= # Allowed origins for CORS
NODE_ENV=development # Environment mode- Full access to all endpoints
- Can manage complaints, assign to staff
- Can create/manage services, events, polls, notices
- Society management permissions
- Can create and view own complaints
- Can book services
- Can participate in polls
- Read access to notices and events
- Can view assigned complaints
- Can update complaint status
- Limited service management
- Can view bookings and notices
The application uses the following main tables:
profiles- User profiles with role informationsocieties- Society/community informationcomplaints- Complaint managementservices- Available servicesbookings- Service bookingsnotices- Community noticespolls- Community pollsevents- Community eventsemergency_services- Emergency contact information
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
For support or questions about the API, please create an issue in the repository or contact the development team.
🔑 Role-Based Access
Residents (Users): Raise complaints, vote in polls, view notices, book services.
Committee (Owners/Admin): Manage complaints, budgets, polls, notices, and services.
Staff: Execute assigned tasks (resolve complaints, update booking status).
#📋 Complaint Management
Residents file complaints (e.g., “Lift not working”).
Complaints move through statuses → Pending → In Progress → Resolved.
Auto-escalation if unresolved after X days.
💰 Society Budget & Expenses
Transparent view of maintenance collections, allocations, and expenses.
Residents see charts of where funds are used.
📢 Digital Forum (Community Hub)
Notice Board: Committee posts updates.
Polls: Residents vote on society decisions (e.g., repaint building, install solar).
Events: Announcements for celebrations and gatherings.
#🚖 Services & Bookings
Book cabs, ambulances, halls, or society amenities.
Track bookings & status updates by staff/admin.
🛡️ Role-Based Functions (RBAC)
| Feature | User (Resident) | Staff (Worker) | Owner (Admin/Committee) |
|---|---|---|---|
| Complaints | Create, Track | Update status | Assign staff, Close issue |
| Polls | View, Vote | View,Vote | Create, Close poll |
| Notices | View | View | Create, Edit, Delete |
| Services/Bookings | Book, Track | Update assigned booking | Add service, Approve bookings |
⚡USP's
✅ Role-based login (Resident/Admin) ✅ Complaint filing + tracking ✅ Polls for community decisions ✅ Notice board ✅ Services (e.g., ambulance booking, hall booking, pool booking, etc.)
📌 Future Enhancements Visitor management (digital gate entry, delivery logs) for admins.
Community marketplace (food vendors, electricians).
Event RSVPs & interest-based groups.
Budget and fund tracking for societie's management group
Enhanced RBAC.