A robust backend API for property listings with advanced search, user authentication, favorites management, and property recommendation features. Designed for real estate platforms to manage properties and user interactions efficiently.
- ๐ User Authentication: Secure JWT-based registration/login
- ๐ Property Management: Full CRUD operations with ownership validation
- ๐ Advanced Search: 10+ filter parameters for property discovery
- โก Performance Optimized: Redis caching for frequent operations
- โค๏ธ Favorites System: Save and manage favorite properties
- ๐ฌ Recommendation Engine: Share properties with other users
- Runtime: Node.js 18.x
- Framework: Express 4.x
- Database: MongoDB (with Mongoose ODM)
- Caching: Redis 7.x
- Authentication: JWT
- API Documentation: OpenAPI
Endpoint | Method | Description | Auth Required |
---|---|---|---|
/api/auth/register |
POST | Register new user | No |
/api/auth/login |
POST | User login | No |
/api/auth/me |
GET | Get current user | Yes |
/api/auth/logout |
POST | Logout user | Yes |
Endpoint | Method | Description | Auth Required |
---|---|---|---|
/api/properties |
POST | Create new property | Yes |
/api/properties |
GET | Search properties with filters | No |
/api/properties/:id |
GET | Get property by ID | No |
/api/properties/:id |
PATCH | Update property | Yes (Owner) |
/api/properties/:id |
DELETE | Delete property | Yes (Owner) |
Endpoint | Method | Description | Auth Required |
---|---|---|---|
/api/favorites |
GET | Get user's favorites | Yes |
/api/favorites/:propertyId |
POST | Add to favorites | Yes |
/api/favorites/:propertyId |
DELETE | Remove from favorites | Yes |
Endpoint | Method | Description | Auth Required |
---|---|---|---|
/api/recommendations/search-users |
GET | Search users by email | Yes |
/api/recommendations/send |
POST | Send property recommendation | Yes |
/api/recommendations/received |
GET | Get received recommendations | Yes |
/api/recommendations/sent |
GET | Get sent recommendations | Yes |
/api/recommendations/:id/read |
PATCH | Mark as read | Yes |
/api/recommendations/:id |
DELETE | Delete recommendation | Yes |
- Node.js 18.x
- MongoDB 7.0+
- Redis 7.x
- NPM 9.x+
- Clone the repository:
git clone https://github.com/your-username/backend-hypergro.git
cd backend-hypergro
- Install dependencies:
npm install
- Create
.env
file:
MONGODB_URI=mongodb://localhost:27017/property
REDIS_URL=redis://localhost:6379
JWT_SECRET=your_strong_secret_here
PORT=3000
- Run the
initializeCounter.js
file:
npm run initializeCounter.js
This needs to be done only once before running the main file server.js
, so that the _id
value for the properties gets initialized and then is automatically incremented/decremented when new properties are added/removed.
- Start the development server:
npm run dev
# Run unit tests
npm test
# Run tests with coverage
npm test -- --coverage
Search properties with any combination of these filters:
GET /api/properties?search=luxury&minPrice=100000&maxPrice=500000
&type=villa&minArea=2000&maxArea=5000&bedrooms=4&bathrooms=3
&furnished=true&state=California&city=Los Angeles&listingType=sale
&minRating=4&isVerified=true&tags=luxury|pool&availableFrom=2024-01-01
&sortBy=price&sortOrder=desc&page=1&limit=10
# Production build
npm run build
# Start production server
npm start
docker build -t backend-hypergro .
docker run -p 3000:3000 -d backend-hypergro
{
_id: String, // Format: PROP123
title: String,
description: String,
price: Number,
type: String, // ['apartment', 'house', 'villa', ...]
areaSqFt: Number,
bedrooms: Number,
bathrooms: Number,
furnished: Boolean,
state: String,
city: String,
listedBy: String, // Reference to User's listedBy field
listingType: String, // ['sale', 'rent']
rating: Number,
isVerified: Boolean,
tags: [String],
availableFrom: Date,
images: [String],
createdAt: Date,
updatedAt: Date
}
{
property: String, // Property ID
fromUser: ObjectId, // Sender user ID
toUser: ObjectId, // Recipient user ID
message: String,
isRead: Boolean, // Default: false
createdAt: Date,
updatedAt: Date
}
Redis is used to optimize these operations:
Operation | Cache Key Pattern | TTL |
---|---|---|
Property Search | properties:<query_hash> |
5 min |
Single Property | property:<id> |
5 min |
User Favorites | favorites:<userId> |
5 min |
Recommendations | recommendations:received:<userId> |
5 min |
Cache is automatically invalidated on:
- Property create/update/delete
- Favorite add/remove
- Recommendation send/mark read/delete
The API is protected with rate limiting:
- 100 requests per IP every 15 minutes
- Exceptions applied to authentication endpoints
- Fork the repository
- Create your feature branch (
git checkout -b feature/your-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin feature/your-feature
) - Open a pull request
This project is licensed under the MIT License - see the LICENSE file for details.