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
-
Clone the repository
git clone <repository-url> cd FreelancingBackend
-
Install dependencies
npm install
-
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
-
Set up Supabase Database
- Create a new Supabase project
- Run the database migrations (see Database Setup section)
- Configure RLS policies
-
Start the development server
npm run dev
🗄️ Database Setup
Required Tables
The application expects the following tables in your Supabase database:
- users - User accounts and profiles
- projects - Project listings and details
- estimates - Freelancer estimates for projects
- milestones - Project milestones and payments
- messages - Communication between users
- reviews - User reviews and ratings
- payments - Payment transactions
- tickets - Support tickets
- project_requests - Freelancer interest in projects
- 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=activeCreate 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/:idUpdate 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 testRun tests with coverage:
npm run test:coverage📦 Available Scripts
npm run dev- Start development server with hot reloadnpm run build- Build for productionnpm start- Start production servernpm test- Run testsnpm run test:watch- Run tests in watch modenpm run lint- Run ESLintnpm 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
- Create Repository - Add data access methods
- Create Service - Add business logic
- Create Controller - Add HTTP handlers
- Create Routes - Define API endpoints
- Add Types - Define TypeScript interfaces
- 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_secretBuild and Deploy
npm run build
npm start🤝 Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Run the test suite
- 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
On this page
Contributors
Created July 31, 2025
Updated July 31, 2025