/property-manegament-backend

This project is the backend part of the Property Management System. It provides a comprehensive API for managing property operations, such as room reservations, user management, and property details. Built with Express.js and PostgreSQL, this API serves as the backbone of the property management platform, ensuring efficient data handling, security,

Primary LanguageJavaScript

Property Management Website API

This project is the backend part of the Property Management System. It provides a comprehensive API for managing property operations, such as room reservations, user management, and property details. Built with Express.js and PostgreSQL, this API serves as the backbone of the property management platform, ensuring efficient data handling, security, and scalability.

Features

  • User Authentication & Authorization: Role-based access control using JWT.
  • Room Reservation System: Manage room availability and bookings.
  • Property Management: Support for managing multiple properties.
  • File Upload: Handle image uploads for rooms and users using Cloudinary and Multer.
  • Automated Scheduling: Task scheduling with node-schedule.
  • PDF Reporting: Generate PDFs for invoices, reports, etc., using jsPDF.
  • Email Notifications: Send notifications with EmailJS.
  • Logging: Centralized logging using Winston with daily log rotation.

Tech Stack

  • Express.js: Backend framework for building the API.
  • PostgreSQL: Relational database for storing data.
  • Sequelize: ORM for database interactions.
  • JWT: For user authentication and authorization.
  • Cloudinary: For image storage and management.
  • Multer: For handling file uploads.

Installation

To run the backend API locally:

  1. Clone the repository:

    git clone https://github.com/zmekonnen251/property-mangement-website-api.git
  2. Navigate to the project directory:

    cd property-mangement-website-api
  3. Install the dependencies:

     npm install
  4. Create a .env file in the root directory with the following:

    PORT=5000
    DATABASE_URL=your_postgres_database_url
    JWT_SECRET=your_jwt_secret
    CLOUDINARY_CLOUD_NAME=your_cloudinary_cloud_name
    CLOUDINARY_API_KEY=your_cloudinary_api_key
    CLOUDINARY_API_SECRET=your_cloudinary_api_secret
  5. Run database migrations and seed the database:

     npm run seedDb
  6. Start the server:

     npm run dev

The API will be running at http://localhost:5000.

Available Scripts

  • npm start: Start the production server.
  • npm run dev: Start the development server using nodemon.
  • npm run lint: Lint the code using ESLint.
  • npm run format: Format the code using Prettier.
  • npm run lint:fix: Fix linting errors automatically.
  • npm run seedDb: Seed the database with sample data.

Folder Structure

property-mangement-website-api/
├── config/             # Configuration files (e.g., database, cloudinary)
├── controllers/        # API route controllers
├── models/             # Sequelize models and database schema
├── routes/             # Express route definitions
├── middlewares/        # Express middlewares (auth, error handling)
├── services/           # Business logic and helper functions
├── utils/              # Utility functions (e.g., error handling, logging)
├── server.js           # Main server file
└── .env                # Environment variables

Key Dependencies

  • Express.js: ^4.18.2
  • Sequelize: ^6.32.1
  • pg (PostgreSQL): ^8.12.0
  • bcryptjs: For password hashing.
  • jsonwebtoken: For user authentication.
  • Cloudinary: For image upload and storage.
  • Winston: For logging with daily rotation.
  • Multer: For file uploads.

Database Setup

This project uses PostgreSQL as the database. Ensure that PostgreSQL is installed and running. Update the .env file with your database URL.

DATABASE_URL=your_postgres_database_url

Migrations are handled via sequelize-cli.

npx sequelize-cli db:migrate

Code Quality

  • ESLint: Linting with Airbnb's style guide.
  • Prettier: Code formatting for consistency.

To run the linter:

npm run lint

To format the code:

npm run format

License

This project is licensed under the ISC License.

Acknowledgements

Contact

Zelalem Mekonnen