Skip to content

A scalable API for real estate management, enabling property listing, and searching for buyers.

Notifications You must be signed in to change notification settings

Hossam-H22/Real-Estate-API

Repository files navigation

Real Estate API


Overview

This is a RESTful API for a real estate application built using Node.js with TypeScript and PostgreSQL. The API allows users to manage properties, projects, areas, and cities.


Run Steps:

Note: you should have Docker installed

Step 1

  git clone https://github.com/Hossam-H22/Real-Estate-API.git
  cd Real-Estate-API

Step 2

  docker-compose up --build

Step 3 - (shutdown)

  docker-compose down 

Technologies Used

  • Node.js with TypeScript
  • PostgreSQL with TypeORM
  • Zod for validation
  • bcrypt for security
  • Cloudinary for image uploads
  • Express.js for routing and middleware

Features

  • Authentication & Authorization middleware for securing endpoints
  • Error Handling middleware for consistent API responses
  • Validation middleware using Zod
  • Pagination, Filtering, Sorting, and Selection using the ApiFeatures class
  • CRUD Operations for all entities

Folder Structure

src/
  database/
  middleware/
  modules/
    each module/
      moduleName.entity.ts
      moduleName.route.ts
      moduleName.controller.ts
      moduleName.service.ts
      moduleName.validation.ts
      moduleName.roles.ts
  utils/

Entities & Database Schema

Users

{
  "_id": "UUID",
  "name": "string",
  "email": "string",
  "password": "string",
  "phone": "string",
  "role": "enum('admin', 'buyer', 'agent')",
  "createdAt": "Date",
  "favorites": ["UUID (references properties)"],
}

Cities

{
  "_id": "UUID",
  "name": "string",
  "createdBy": "UUID (references users)",
  "createdAt": "Date"
}

Areas

{
  "_id": "UUID",
  "name": "string",
  "cityId": "UUID (references cities)",
  "createdBy": "UUID (references users)",
  "createdAt": "Date"
}

Projects

{
  "_id": "UUID",
  "name": "string",
  "description": "string",
  "areaId": "UUID (references areas)",
  "createdBy": "UUID (references users)",
  "createdAt": "Date"
}

Properties

{
  "_id": "UUID",
  "title": "string",
  "description": "string",
  "price": "number",
  "type": "enum('house', 'apartment', 'land', 'commercial')",
  "status": "enum('available', 'sold', 'rented')",
  "bedrooms": "number",
  "bathrooms": "number",
  "squareFeet": "number",
  "images": ["array of strings (URLs)"],
  "createdBy": "UUID (references users)",
  "projectId": "UUID (references projects)",
  "createdAt": "Date"
}

API Endpoints

Each module includes four endpoints:

Users

  • GET /user - Get all users
  • GET /user/:id - Get a specific user
  • POST /user - Create a new user
  • PUT /user/:id - Update a user

Cities

  • GET /city - Get all cities
  • GET /city/:id - Get a specific city
  • POST /city - Create a new city
  • PUT /city/:id - Update a city
  • Delete /city/:id - Delete a city

Areas

  • GET /area - Get all areas
  • GET /area/:id - Get a specific area
  • POST /area - Create a new area
  • PUT /area/:id - Update an area
  • Delete /area/:id - Delete an area

Projects

  • GET /project - Get all projects
  • GET /project/:id - Get a specific project
  • POST /project - Create a new project
  • PUT /project/:id - Update a project
  • Delete /project/:id - Delete a project

Properties

  • GET /property - Get all properties
  • GET /property/:id - Get a specific property
  • POST /property - Create a new property
  • PUT /property/:id - Update a property
  • Patch /property/:id/favorite - Toggle property on favorite list of User
  • Delete /property/:id - Delete a property

Query Parameters for Filtering & Pagination

  • Pagination: ?page=1&size=10
  • Sorting: ?sort=-createdAt (Descending), ?sort=price (Ascending)
  • Fields Selection: ?fields=name,description,price
  • Details Selection: ?details=createdBy,projectId
  • Filtering: ?price[gte]=50000&status=available
  • Search: ?search=apartment

Authentication & Authorization

  • User authentication is implemented using JWT.
  • Middleware ensures role-based access control.
  • Passwords are securely hashed using bcrypt.

Image Uploads

  • Cloudinary is used to store images.
  • The properties module allows uploading images via Cloudinary.

Error Handling

  • All errors are handled using a centralized middleware.
  • Standard response format for errors.

Postman - link


Conclusion

This API provides a comprehensive real estate management system with authentication, authorization, validation, and data management features.


About

A scalable API for real estate management, enabling property listing, and searching for buyers.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published