Skip to content

Repository files navigation

HireHub — RESTful API for Freelance Marketplace

HireHub is a RESTful API that connects clients and freelancers.
It supports project posting, offers, reviews, authentication, and role‑based access.


Tech Stack

  • Laravel 12
  • PHP 8.2
  • MySQL
  • REST API (JSON only)
  • Service‑based architecture

User Roles

  • Client
  • Freelancer
  • Admin

Features

  • Authentication (Register/Login)
  • Freelancer verification system
  • Projects (create, update, delete)
  • Offers system with auto‑rejection logic
  • Reviews & ratings
  • Filtering & sorting
  • Performance‑optimized queries
  • Clean architecture (Services, Form Requests, Models)

API Endpoints


Public Routes

POST /api/register
POST /api/login
POST /api/logout (auth:sanctum)


Protected Routes (auth:sanctum)

User & Profile

GET /api/user
GET /api/dashboard

GET /api/profile
PUT /api/profile


Freelancers (Public Listing)

GET /api/freelancers


Notifications

GET /api/notifications


Projects (Shared Read-Only)

GET /api/projects
GET /api/projects/{project}


Role-Based Routes

Admin (is_admin)

POST /api/admin/verify/{profile}


Client Routes (role.client)

Projects Management

POST /api/projects
PUT /api/projects/{project}
DELETE /api/projects/{project}

Offers (Client Actions)

GET /api/projects/{project}/offers
POST /api/projects/{project}/offers/{offer}/accept

Reviews

POST /api/projects/{project}/reviews


Freelancer Routes (role.freelancer + verified.freelancer)

Offers

POST /api/projects/{project}/offers
GET /api/my-offers
DELETE /api/offers/{offer}


Architecture

  • Controllers → HTTP layer
  • Services → Business logic
  • Models → Relationships
  • Form Requests → Validation
  • SOLID + Clean Code principles

Installation

git clone
cd hirehub
composer install
cp .env.example .env
php artisan key:generate
php artisan migrate --seed
php artisan serve


Performance Optimization

improves the performance of the GET /api/projects endpoint by fixing N+1 queries and enabling caching.

All screenshots are stored in:
docs/screenshotes/


N+1 Problem (Before Optimization)

The main branch executed many SQL queries for related models
(attachments, offers, tags, cities, countries, users).

This caused slow performance.

N+1 Problem


Eager Loading (N+1 Fixed)

Using eager loading:

->with(['user.city.country', 'tags', 'offers.user', 'attachments'])

reduced the number of queries significantly.

Eager Loading


Caching (task4)

Caching was added using:

Cache::remember($cacheKey, 300, function () { ... });

First request → cache miss + set

Cache Set

Second request → cache hit (0 queries)

Cache Hit


Redis Confirmation

Telescope → Redis shows:

GET laravel-cache-projects...

This confirms the response was served from cache, not the database.

Redis GET


Final Result Summary

Request Queries Cache
main 10–12 No
task4 (1st) 10–12 Miss
task4 (2nd) 0 Hit

Caching + eager loading improved performance and eliminated unnecessary database queries.


Postman Collection

A Postman collection is included:

HireHub.postman_collection.json

How to use:

  1. Open Postman
  2. Click Import
  3. Select the file
  4. Set the environment variable: {{base_url}} = http://localhost:8000/api {{client_token}} = {{freelancer_token}} = {{admin_token}}=

Conclusion

  • N+1 queries fully fixed
  • Caching reduced DB load by ~90%
  • Redis + Telescope confirm cached responses
  • Endpoint is now significantly faster and optimized

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages