انا طورت مشروع Freelancer Marketplace platform عن نسخة ماضية و اريد مراجعة دقيقة للمشروع هل هو مؤهل للحصول على وظيفة ام يحتاج تحسينات لم اقم بها وللعلم استغرق تطوير مشروع 3 اسابيع وفي هاد مشروع كل تفصيلة اشتغلت بها كانت مدروسة بدقة حتى يكون مشروع جاهز للانتاج يعني اضفت cache + realtime + jest testing + docker
<div align="center">#🚀FreelancePlatform—Backend API
**Production-ready REST API &Real-TimeBackend built withNestJS**[](https://nestjs.com/)[](https://www.typescriptlang.org/)[](https://www.mongodb.com/)[](https://redis.io/)[](https://socket.io/)[](https://jestjs.io/)[](https://www.docker.com/)> A full-featured freelance marketplace backend engineered at **SeniorBackendEngineer** level — clean architecture, real-time communication,Redis caching, role-based access control, and comprehensive test coverage.🌐**Production URL:**[`https://hirehub-freelance-platform.onrender.com`](https://hirehub-freelance-platform.onrender.com)</div>---##📋TableofContents-[Features](#-features)-[TechStack](#-tech-stack)-[ProjectStructure](#-project-structure)-[ArchitectureOverview](#-architecture-overview)-[Real-TimeSystem](#-real-time-system)-[RedisCacheLayer](#-redis-cache-layer)-[ErrorHandling](#-error-handling)-[TestingwithJest](#-testing-with-jest)-[EnvironmentVariables](#-environment-variables)-[RunLocallywithDockerDesktop](#-run-locally-with-docker-desktop)-[AvailableScripts](#-available-scripts)---##✨Features|Feature|Description||---|---||🔐**JWT Authentication**|Secure cookie-based auth with HTTP-only tokens, bcrypt password hashing ||👥**Role-BasedAccessControl**|Admin,Freelancer,Client, and Support roles with dedicated Guards||💬**Real-TimeChat**|WebSocket-powered messaging with typing indicators, seen receipts, and online presence ||🔔**Real-TimeNotifications**|Instant push notifications via Socket.IO with multi-socket user support ||⚡**RedisCache**|Full caching layer (get/set/del/lpush/lrange/getJSON)with TTL support via ioredis ||💳**PaymentSystem**|Escrow-style payments —Hold,Release,Refund,Cancelwith balance management ||📁**CloudinaryIntegration**|File/image upload using Cloudinary cloud storage ||📋**Proposal&ContractFlow**|Full lifecycle:Project→Proposal→Contract→Payment||🛡️**GlobalExceptionFilter**|Centralized error handling with structured JSON error responses ||🧪**31TestSuites**|Unit tests for all controllers, services, and guards using Jest+`@nestjs/testing`||📦**RepositoryPattern**|Decoupled data access layer using interfaces and dependency injection ||🐳**DockerReady**|One-command startup withDockerCompose(App+MongoDB+Redis)|---##🛠TechStack|Layer|Technology||---|---||Framework|NestJS11(Node.js 22)||Language|TypeScript5.7||Database|MongoDB6+Mongoose ODM ||Cache|Redis7 via ioredis ||Real-Time|Socket.IO 4+WebSocketGateways||Auth| JWT (jsonwebtoken)+ bcryptjs +CookieParser||Uploads|Cloudinary SDK +Multer||Validation|class-validator +class-transformer ||Testing|Jest30+ ts-jest +@nestjs/testing ||Containerization|Docker+DockerCompose|---##📁ProjectStructure```
backend/├── src/│├── controllers/# HTTP route handlers (REST endpoints)││├── auth.controller.ts
││├── user.controller.ts
││├── client.controller.ts
││├── freelancer.controller.ts
││├── project.controller.ts
││├── proposal.controller.ts
││├── contract.controller.ts
││├── payment.controller.ts
││├── message.controller.ts
││└── notification.controller.ts
│││├── services/#Business logic layer
││├── auth.service.ts
││├── payment.service.ts
││├── notification.service.ts
││└──...│││├── repository/#Data access layer (RepositoryPattern)││├── auth.repository.ts
││├── user.repository.ts
││└──...│││├── schemas/#Mongoose schemas (MongoDB models)││├── user.schema.ts
││├── project.schema.ts
││├── proposal.schema.ts
││├── contract.schema.ts
││├── payment.schema.ts
││├── message.schema.ts
││└── notification.schema.ts
│││├── gateways/#WebSocket gateways (Real-Time)││├── chat.gateway.ts #Messaging, typing, seen receipts
││└── notification.gateway.ts #Real-time push notifications
│││├── guards/#Route protection (RBAC)││├── auth.guard.ts
││├── admin.guard.ts
││├── client.guard.ts
││└── freelancer.guard.ts
│││├── modules/#NestJS feature modules (DI wiring)│││├── redis/#Redis cache layer
││├── redis.module.ts
││├── redis.service.ts # ioredis client init
││└── redis.helper.ts #get/set/del/lpush/getJSON helpers
│││├── dtos/#DataTransferObjects(validation schemas)│││├── interfaces/#TypeScript interfaces & repository contracts
│││├── enums/#Typed enums (roles, statuses, types)│││├── filters/││└── error.filter.ts #Global exception filter
│││├── libs/││├── helpers.ts #Shared utility functions
││├── messages.ts #Centralized response messages
││├── debug.logger.ts #CustomNestJS logger
││├── cloudinary.ts #Cloudinary upload helper
││└── proposal.helper.ts #Proposal business logic helpers
│││├── socket/││└── socket.adapter.ts # JWT-authenticated WebSocket adapter
│││├── token/││├── token.module.ts
││└── token.service.ts # JWT sign/verify service
│││├── specs/#All test files (Jest)││├── controllers/#13 controller test suites
││├── services/#14 service test suites
││└── guards/#4 guard test suites
│││├── response.interceptor.ts #Standardized API response wrapper
│├── validation.pipe.ts
│├── main.ts
│└── app.module.ts
│├──Dockerfile├── docker-compose.yml
├──.env.example
└── package.json
```---##🏗ArchitectureOverviewThis project follows a clean **layered architecture** separating concerns clearly:```
HTTP Request│▼Controller←Validates input via DTOs, routes to service
│▼Service←Business logic, orchestrates repositories
│▼Repository←Data access via Mongoose(implementsinterface)│▼MongoDB←Persistent storage
↕Redis←Cache layer used across services
↕Socket.IO ←Real-time events emitted from services
```**RepositoryPattern**—Every data entity has a typed interface(`IUserRepository`,`IProjectRepository`, etc.) injected via NestJS DI tokens.Services depend on abstractions, not implementations — making them fully testable with mocks.---##📡Real-TimeSystemTwoWebSocket gateways power the real-time layer, both protected by a custom **JWT-authenticated Socket adapter** that verifies the token on every connection before the socket is established.###ChatGateway(`chat.gateway.ts`)-Tracks online users per socket ID
-`send-message`→ delivers message instantly to recipient's socket
-`typing`→ forwards typing indicator to the receiver
-`message-seen`→ notifies sender when message is read
-`online-users`→ broadcasts updated online list on connect/disconnect
###NotificationGateway(`notification.gateway.ts`)-Multi-socket user support (same user on multiple tabs/devices)-`sendNotification()`→ called from services to push real-time alerts
-`mark-as-read`→ syncs read status in real time
-`receive-notification`→ emitted to client with type + payload
---##⚡RedisCacheLayerThe`RedisHelper` service wraps ioredis with a clean API used across the application for caching, rate limiting, and data structure operations:```typescript
// String cache with optional TTLawait redisHelper.set('key', value,300);// expires in 5 minawait redisHelper.get('key');await redisHelper.del('key');// JSON helpersawait redisHelper.getJSON<User>('user:123');// List operations (e.g. activity feeds, recent items)await redisHelper.lpush('feed:userId', item);await redisHelper.lrange('feed:userId',0,19);await redisHelper.ltrim('feed:userId',0,19);// Countersawait redisHelper.incr('views:projectId');await redisHelper.decr('slots:projectId');```Redis is initialized on module startup via `OnModuleInit` and accessed globally through the injected `RedisHelper`.---##🛡ErrorHandling
A **GlobalExceptionFilter**(`GlobalExceptionFilter`) catches every exception thrown anywhere in the application and returns a consistent, structured JSON error response:```json
{"success":false,"statusCode":404,"message":"Project not found","path":"/api/projects/abc123","timestamp":"2026-05-27T10:00:00.000Z"}```-Handles both `HttpException`(NestJS built-ins) and unknown runtime errors
-Logs method, path, status, message, and full stack trace to the server console
-Pairedwith a `ResponseInterceptor` that wraps all successful responses:```json
{"success":true,"message":"Project created successfully","data":{...}}```All error messages are managed in a centralized `messages.ts` file — no magic strings scattered across the codebase.---##🧪TestingwithJestThe project has **31 test suites** covering the full application layer —this is not token coverage,this is real behavioral testing.```
src/specs/├── controllers/ auth, user, client, freelancer, project, proposal,│ contract, contract-option, proposal-option,│ freelancer-project, message, notification, payment
├── services/ auth, user, client, freelancer, project, proposal,│ proposal-option, proposal-helper, contract,│ contract-option, freelancer-project, message,│ notification, payment
└── guards/ auth, admin, client, freelancer
```All tests use `@nestjs/testing``TestingModule`with fully mocked repositories and services — zero database dependency.```bash
#Run all tests
npm test
#Watch mode
npm run test:watch
#Coverage report
npm run test:cov
```Jest is configured with`ts-jest`forTypeScript support and path aliases (`src/*`) resolved correctly.
---
## 🔑 Environment Variables
Copy `.env.example` and fill in your values:
```env
# Server
PORT=4001
# Database
MONGO_URL=mongodb+srv://<username>:<password>@<cluster>/<db>?retryWrites=true&w=majority
# Auth
JWT_SECRET=your_jwt_secret_here
JWT_EXPIRES_IN=10d
# Redis
REDIS_URL=redis://:<password>@<host>:<port>
# Cloudinary
CLOUDINARY_CLOUD_NAME=your_cloud_name
CLOUDINARY_API_KEY=your_api_key
CLOUDINARY_API_SECRET=your_api_secret
# Frontend (CORS)
FRONTEND_URL=http://localhost:3000
```
---
## 🐳 Run Locally with Docker Desktop
Make sure **Docker Desktop** is installed and running, then:
**1. Clone the repository**
```bash
git clone https://github.com/ZenZN99/HireHub-Freelance-Platform
cd HireHub-Freelance-Platform
```
**2. Set up environment variables**
```bash
cp .env.example .env
# Edit .env — for local Docker you can leave MONGO_URL and REDIS_URL as-is
# they are already set in docker-compose.yml for the local services
```
**3. Start everything with one command**
```bash
docker compose up --build
```
This will spin up three containers:
| Container | Service | Port |
|---|---|---|
| `freelance_platform_app` | NestJS API | `4001` |
| `mongo_db` | MongoDB 6 | `27017` |
| `redis_db` | Redis 7 | `6379` |
**4. Verify the server is running**
```bash
curl http://localhost:4001
```
**Stop the stack**
```bash
docker compose down
```
**Stop and remove volumes (full reset)**
```bash
docker compose down -v
```
---
## 📜 Available Scripts
```bash
npm run start:dev # Development with hot-reload
npm run start:prod # Run compiled production build
npm run build # Compile TypeScript → dist/
npm test # Run Jest test suites
npm run test:cov # Jest with coverage report
npm run lint # ESLint auto-fix
npm run format # Prettier format
```
---
<div align="center">
Built with precision at **Senior Backend Engineer** level.
Clean architecture · Real-time ready · Redis optimized · Fully tested.
</div>
السؤال
Zen Eddin Allaham
انا طورت مشروع Freelancer Marketplace platform عن نسخة ماضية و اريد مراجعة دقيقة للمشروع هل هو مؤهل للحصول على وظيفة ام يحتاج تحسينات لم اقم بها وللعلم استغرق تطوير مشروع 3 اسابيع وفي هاد مشروع كل تفصيلة اشتغلت بها كانت مدروسة بدقة حتى يكون مشروع جاهز للانتاج يعني اضفت cache + realtime + jest testing + docker
2 أجوبة على هذا السؤال
Recommended Posts
انضم إلى النقاش
يمكنك أن تنشر الآن وتسجل لاحقًا. إذا كان لديك حساب، فسجل الدخول الآن لتنشر باسم حسابك.