GitHunt
AB

AbhishekChd/FreelancingBackend

Freelancing Platform Backend

A robust, scalable backend for a freelancing platform built with Node.js, TypeScript, Express, and Supabase.

🏗️ Architecture

This backend follows Clean Architecture principles with proper separation of concerns:

  • Controllers: Handle HTTP requests and responses
  • Services: Contain business logic and orchestrate operations
  • Repositories: Handle data access and database operations
  • Middleware: Authentication, validation, and request processing
  • Types: TypeScript interfaces and type definitions

🚀 Features

Core Modules

  • User Management: Registration, authentication, profile management
  • Project Management: Create, update, publish, and manage projects
  • Role-based Access Control: Client, Freelancer, and Admin roles
  • Authentication & Authorization: JWT-based authentication with role-based permissions

Security Features

  • JWT token-based authentication
  • Password hashing with bcrypt
  • Role-based authorization
  • Input validation and sanitization
  • CORS protection
  • Helmet security headers

Database Features

  • Supabase PostgreSQL integration
  • Row Level Security (RLS) policies
  • Type-safe database operations
  • Efficient querying with pagination

📋 Prerequisites

  • Node.js (v16 or higher)
  • npm or yarn
  • Supabase account and project

🛠️ Installation

  1. Clone the repository

    git clone <repository-url>
    cd FreelancingBackend
  2. Install dependencies

    npm install
  3. Set up environment variables

    cp env.example .env

    Fill in your environment variables:

    # Server Configuration
    PORT=3000
    NODE_ENV=development
    
    # Supabase Configuration
    SUPABASE_URL=your_supabase_project_url
    SUPABASE_ANON_KEY=your_supabase_anon_key
    SUPABASE_SERVICE_ROLE_KEY=your_supabase_service_role_key
    
    # JWT Configuration
    JWT_SECRET=your_jwt_secret_key_here
    JWT_EXPIRES_IN=7d
  4. Set up Supabase Database

    • Create a new Supabase project
    • Run the database migrations (see Database Setup section)
    • Configure RLS policies
  5. Start the development server

    npm run dev

🗄️ Database Setup

Required Tables

The application expects the following tables in your Supabase database:

  1. users - User accounts and profiles
  2. projects - Project listings and details
  3. estimates - Freelancer estimates for projects
  4. milestones - Project milestones and payments
  5. messages - Communication between users
  6. reviews - User reviews and ratings
  7. payments - Payment transactions
  8. tickets - Support tickets
  9. project_requests - Freelancer interest in projects
  10. notifications - User notifications

RLS Policies

Enable Row Level Security on all tables and configure appropriate policies for:

  • Users can only access their own data
  • Clients can only manage their own projects
  • Freelancers can view active projects
  • Admins have full access

📚 API Documentation

Base URL

http://localhost:3000/api/v1

Authentication

All protected endpoints require a Bearer token in the Authorization header:

Authorization: Bearer <your-jwt-token>

User Endpoints

Register User

POST /users/register
Content-Type: application/json

{
  "email": "user@example.com",
  "password": "password123",
  "name": "John Doe",
  "role": "client",
  "bio": "Optional bio"
}

Login

POST /users/login
Content-Type: application/json

{
  "email": "user@example.com",
  "password": "password123"
}

Get Profile

GET /users/profile
Authorization: Bearer <token>

Update Profile

PUT /users/profile
Authorization: Bearer <token>
Content-Type: application/json

{
  "name": "Updated Name",
  "bio": "Updated bio"
}

Project Endpoints

Get Projects

GET /projects?page=1&limit=10&status=active

Create Project

POST /projects
Authorization: Bearer <token>
Content-Type: application/json

{
  "title": "Website Development",
  "description": "Need a modern website built",
  "budget_min": 1000,
  "budget_max": 5000,
  "timeline_days": 30,
  "skills_required": ["React", "Node.js"],
  "tags": ["web-development", "frontend"]
}

Get Project by ID

GET /projects/:id

Update Project

PUT /projects/:id
Authorization: Bearer <token>
Content-Type: application/json

{
  "title": "Updated Title",
  "description": "Updated description"
}

Publish Project

PUT /projects/:id/publish
Authorization: Bearer <token>

🧪 Testing

Run tests:

npm test

Run tests with coverage:

npm run test:coverage

📦 Available Scripts

  • npm run dev - Start development server with hot reload
  • npm run build - Build for production
  • npm start - Start production server
  • npm test - Run tests
  • npm run test:watch - Run tests in watch mode
  • npm run lint - Run ESLint
  • npm run lint:fix - Fix ESLint issues

🔧 Development

Project Structure

src/
├── config/          # Configuration files
├── controllers/     # HTTP request handlers
├── middleware/      # Express middleware
├── repositories/    # Data access layer
├── routes/          # API route definitions
├── services/        # Business logic
├── types/           # TypeScript type definitions
├── utils/           # Utility functions
├── app.ts           # Express app setup
└── index.ts         # Application entry point

Adding New Features

  1. Create Repository - Add data access methods
  2. Create Service - Add business logic
  3. Create Controller - Add HTTP handlers
  4. Create Routes - Define API endpoints
  5. Add Types - Define TypeScript interfaces
  6. Add Tests - Write unit and integration tests

🚀 Deployment

Environment Variables for Production

NODE_ENV=production
PORT=3000
SUPABASE_URL=your_production_supabase_url
SUPABASE_ANON_KEY=your_production_anon_key
SUPABASE_SERVICE_ROLE_KEY=your_production_service_role_key
JWT_SECRET=your_secure_jwt_secret

Build and Deploy

npm run build
npm start

🤝 Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests for new functionality
  5. Run the test suite
  6. Submit a pull request

📄 License

This project is licensed under the MIT License.

🆘 Support

For support and questions:

  • Create an issue in the repository
  • Check the API documentation
  • Review the code examples

🔮 Roadmap

  • Estimate and milestone management
  • Messaging system
  • Payment integration (Stripe/Razorpay)
  • File upload functionality
  • Real-time notifications
  • Admin dashboard
  • Review and rating system
  • Search and filtering
  • Email notifications
  • WebSocket support for real-time features