A robust Node.js/Express.js application for managing freelance contracts, jobs, and payments with role-based access control.
- Features
- Technology Stack
- Getting Started
- Database Schema
- API Documentation
- Security Features
- Error Handling
- 🔐 Authentication & Role-Based Access Control (Client/Contractor/Admin)
- 👤 Profile Management
- 📄 Contract Creation and Management
- 💼 Job Tracking and Payment Processing
- 💰 Balance Management with Deposit Limits
- 📊 Admin Analytics
- 🛡️ Input Sanitization and SQL Injection Protection
- Node.js & Express.js
- SQLite with Sequelize ORM
- JWT Authentication
- Pug Template Engine
- Helmet for Security Headers
- Body Parser & Sanitize for Input Protection
- Node.js (>=10.16.3)
- npm
- Clone the repository
- Install dependencies:
- Create
.envfile with:PORT=3000, SECRET=your_jwt_secret - Initialize database:
npm run seed- Start server:
npm start
## Database Schema
### Profile
- id (PK)
- firstName
- lastName
- profession
- balance
- type (client/contractor/admin)
- email (unique with type)
- password
### Contract
- id (PK)
- terms
- status (new/in_progress/terminated)
- ClientId (FK)
- ContractorId (FK)
### Job
- id (PK)
- description
- price
- paid (boolean)
- paymentDate
- ContractId (FK)
## API Documentation
### Authentication
All protected routes require Bearer token:
```bash
Authorization: Bearer <jwt_token>POST /profiles/login- Authenticate userPOST /profiles/register- Create new profileGET /profiles- Get authenticated user profile
GET /contracts/:id- Get contract by IDGET /contracts- List user's non-terminated contractsPOST /contracts- Create new contract (Client only)POST /contracts/:contractId- Start job (Contractor only)
GET /jobs/unpaid- Get unpaid jobsPOST /jobs/:job_id/pay- Process job payment (Client only)
POST /balance/deposit- Deposit money (Client only, max 25% of unpaid jobs)
GET /admin/best-profession- Get highest earning professionGET /admin/best-clients- Get top paying clients
-
Input Sanitization
- Request parameter sanitization
- SQL injection protection
- Input validation middleware
-
Authentication & Authorization
- JWT-based authentication
- Role-based access control
- Token expiration
-
Security Headers
- Helmet middleware
- Referrer Policy
- Hidden server information
The application implements centralized error handling with:
- Custom error middleware
- Standardized error responses
- Transaction rollbacks for database operations
- Detailed error logging in development
{
"success": true,
"error": false,
"message": "Operation successful",
"data": {}
}src/
├── controllers/ # Business logic
├── middleware/ # Auth & validation
├── models/ # Database models
├── routes/ # API routes
├── utils/ # Helper functions
├── views/ # Pug templates
├── app.js # Express configuration
└── server.js # Application entry- Fork repository
- Create feature branch
- Commit changes
- Push to branch
- Create Pull Request
GNU General Public License v3.0