A production-ready, enterprise-grade REST API for freelancers to manage clients, projects, time logs, invoices, payments, and expenses.
- β Authentication & Authorization - JWT-based auth with Role-Based Access Control and Firebase Social Auth (Google/GitHub) support.
- β Client Management - Full CRUD operations for client data
- β Project Tracking - Hourly and fixed-price billing support
- β Time Logging - Track billable and non-billable hours
- β Invoice Generation - Professional PDF invoices with automatic calculations
- β Payment Tracking - Record and monitor payments
- β Expense Management - Track business expenses
- β Reporting & Analytics - Financial reports and insights
- β Notifications - Real-time notification system
- β Admin Dashboard - Administrative controls and metrics
- π Input Sanitization - Protection against NoSQL injection and XSS
- π Rate Limiting - Configurable rate limits per endpoint type
- π Helmet.js - Security headers and CSP
- π CORS - Whitelist-based origin control
- π JWT Authentication - Secure token-based authentication
- π Password Hashing - Bcrypt with configurable rounds
- π HPP Protection - HTTP Parameter Pollution prevention
- π Comprehensive Logging - Winston with log rotation
- π Error Tracking - Structured error handling
- π API Documentation - Swagger/OpenAPI 3.0
- π Health Checks - Monitoring endpoints
- π Graceful Shutdown - Proper cleanup on termination
- π Environment Validation - Required config checks on startup
- β Unit Tests - Comprehensive test coverage
- β Integration Tests - API endpoint testing
- β CI/CD Pipeline - GitHub Actions automation
- β Code Coverage - 70%+ coverage requirement
- β Security Audits - Automated vulnerability scanning
- Node.js >= 18.x
- MongoDB >= 6.0
- npm >= 9.x
```bash git clone https://github.com/Rajkoli145/FreelancerFlow.git cd FreelancerFlow/backend ```
```bash npm install ```
Create a `.env` file in the backend directory:
```bash cp .env.example .env ```
Required Environment Variables:
```env
NODE_ENV=development PORT=5000
MONGO_URI=mongodb://localhost:27017/freelancerflow
JWT_SECRET=your_super_secret_jwt_key_min_32_chars_CHANGE_THIS JWT_EXPIRE=7d
FRONTEND_URL=http://localhost:5173
BCRYPT_ROUNDS=10
ENABLE_SWAGGER=true ```
Generate a secure JWT secret:
```bash node -e "console.log(require('crypto').randomBytes(64).toString('hex'))" ```
```bash
docker run -d -p 27017:27017 --name mongodb mongo:6.0
mongod ```
```bash
npm run dev
npm start ```
The server will start on http://localhost:5000
Once the server is running, access the interactive API documentation:
Swagger UI: http://localhost:5000/api-docs
OpenAPI JSON: http://localhost:5000/api-docs.json
```bash
npm test
npm run test:watch
npm run test:unit
npm run test:integration
npm run test:ci ```
```bash
npm run lint
npm run lint:fix ```
``` backend/ βββ src/ β βββ config/ # Configuration files β β βββ config.js # Environment config with validation β β βββ db.js # Database connection β β βββ swagger.js # API documentation setup β βββ controllers/ # Request handlers β β βββ authController.js β β βββ clientController.js β β βββ projectController.js β β βββ ... β βββ middleware/ # Custom middleware β β βββ authMiddleware.js # JWT authentication β β βββ errorMiddleware.js # Error handling β β βββ validateMiddleware.js # Input validation β βββ models/ # Mongoose schemas β β βββ user.js β β βββ Client.js β β βββ Project.js β β βββ ... β βββ routes/ # API routes β β βββ authRoutes.js β β βββ clientRoutes.js β β βββ ... β βββ utils/ # Utility functions β β βββ logger.js # Winston logger β β βββ errors.js # Custom error classes β β βββ pdfGenerator.js # Invoice PDF generation β βββ tests/ # Test files β β βββ setup/ β β βββ *.test.js β βββ index.js # Application entry point βββ logs/ # Application logs (auto-generated) βββ coverage/ # Test coverage reports βββ .env.example # Environment variables template βββ jest.config.json # Jest configuration βββ package.json ```
- No Hardcoded Secrets - All sensitive data in environment variables
- Input Validation - Joi schemas for all API inputs
- SQL/NoSQL Injection Protection - express-mongo-sanitize
- XSS Protection - xss-clean middleware
- Rate Limiting - Configurable per endpoint type
- CORS - Whitelist-based origin control
- Security Headers - Helmet.js with CSP
- Error Sanitization - No sensitive data in error responses
- Logging - Structured logging without sensitive data
- Dependency Audits - Regular npm audit checks
- Generate strong JWT secret (64+ characters)
- Set
NODE_ENV=production - Use HTTPS only
- Configure proper CORS origins
- Set up firewall rules
- Enable MongoDB authentication
- Use environment-specific rate limits
- Set up monitoring and alerting
- Regular security audits
- Keep dependencies updated
```env NODE_ENV=production PORT=5000 MONGO_URI=mongodb+srv://user:pass@cluster.mongodb.net/freelancerflow JWT_SECRET=<64-character-random-string> FRONTEND_URL=https://your-frontend-domain.com RATE_LIMIT_MAX_REQUESTS=50 ENABLE_SWAGGER=false ```
```bash heroku create your-app-name heroku config:set NODE_ENV=production heroku config:set MONGO_URI=your_mongodb_uri heroku config:set JWT_SECRET=your_jwt_secret git push heroku main ```
```bash railway login railway init railway up ```
- Set up Node.js environment
- Install PM2:
npm install -g pm2 - Start application:
pm2 start src/index.js --name freelancerflow - Configure nginx as reverse proxy
- Set up SSL with Let's Encrypt
- Basic Health:
GET /health - API Health:
GET /api/health
Logs are stored in logs/ directory:
combined-YYYY-MM-DD.log- All logserror-YYYY-MM-DD.log- Error logs onlyexceptions-YYYY-MM-DD.log- Uncaught exceptionsrejections-YYYY-MM-DD.log- Unhandled promise rejections
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
- Write tests for new features
- Maintain 70%+ code coverage
- Follow existing code style
- Update documentation
- Add JSDoc comments for functions
POST /api/auth/signup- Register new userPOST /api/auth/login- Login userGET /api/auth/me- Get current userPUT /api/auth/profile- Update profilePUT /api/auth/password- Change passwordPOST /api/auth/firebase- Login/Signup with Firebase OAuth (Google/GitHub)
GET /api/client- List all clientsPOST /api/client- Create clientGET /api/client/:id- Get client detailsPUT /api/client/:id- Update clientDELETE /api/client/:id- Delete client
GET /api/project- List all projectsPOST /api/project- Create projectGET /api/project/:id- Get project detailsPUT /api/project/:id- Update projectDELETE /api/project/:id- Delete project
See Swagger documentation for complete API reference
This project is licensed under the MIT License - see the LICENSE file for details.
Raj Koli
- GitHub: @Rajkoli145
- Email: your.email@example.com
- Express.js team for the excellent framework
- MongoDB team for the database
- All open-source contributors
For support, email support@freelancerflow.com or open an issue on GitHub.
Made with β€οΈ for freelancers worldwide