Skip to content

waqar1978/nodejs-backend-jobsite

Repository files navigation

Jobs3 Backend

A comprehensive backend system for Jobs3, a modern job marketplace platform similar to Upwork. This Node.js/Express backend provides a full-featured API for connecting freelancers, employees, employers, and clients with intelligent job matching, real-time communication, and AI-powered search capabilities.

🚀 Features

Core Functionality

  • Multi-Role User System: Supports Freelancers, Employees, Employers, and Clients
  • Job/Gig Management: Create, browse, and manage job postings with multiple payment types (fixed-price and hourly)
  • Proposal System: Submit and manage proposals for jobs
  • Contract Management: Handle contracts between clients and freelancers/employees
  • Real-Time Messaging: Socket.io-based instant messaging between users
  • Reviews & Ratings: Comprehensive review system for completed projects
  • Portfolio Management: Freelancers and employees can showcase their work portfolios
  • Recent Views Tracking: Track recently viewed profiles and gigs
  • Visit Analytics: Track profile and portfolio visits

Advanced Features

  • AI-Powered Job Search: OpenAI GPT-4 integration for intelligent job matching and search
  • Vector Search with Pinecone: Semantic search capabilities using Pinecone vector database
  • Automated Job Syncing: Cron jobs for automatic job synchronization and updates
  • Email Notifications: Nodemailer integration for email communications
  • Telegram Bot Integration: Telegram bot support for notifications
  • File Storage: AWS S3 integration for scalable file storage
  • Image Processing: Sharp library for image optimization
  • Referral System: User referral tracking and management

🛠️ Tech Stack

Core Technologies

  • Node.js: Runtime environment
  • Express.js: Web application framework
  • MongoDB: NoSQL database with Mongoose ODM
  • Socket.io: Real-time bidirectional communication
  • JWT: JSON Web Tokens for authentication

AI & Search

  • OpenAI API: GPT-4 for AI-powered features
  • Pinecone: Vector database for semantic search
  • LangChain: AI application framework

Storage & Media

  • AWS S3: Cloud file storage
  • GridFS: MongoDB file storage system
  • Sharp: Image processing library
  • Multer: File upload handling

Utilities

  • bcryptjs: Password hashing
  • Nodemailer: Email service
  • node-cron: Task scheduling
  • moment-timezone: Date/time handling
  • Compression: Response compression
  • Morgan: HTTP request logger

📁 Project Structure

jobs3-backend/
├── app.js                 # Express app configuration
├── index.js               # Server entry point with Socket.io setup
├── package.json           # Dependencies and scripts
├── vercel.json            # Vercel deployment configuration
│
├── controllers/           # Business logic controllers
│   ├── applyGig.js
│   ├── clientGig.js
│   ├── contract.js
│   ├── employeeGig.js
│   ├── employerGig.js
│   ├── freelancerGig.js
│   ├── job.js
│   ├── message.js
│   ├── pinecone.js
│   ├── profile.js
│   ├── proposal.js
│   ├── reviews.js
│   └── user.js
│
├── models/                # Mongoose data models
│   ├── User.js
│   ├── Profile.js
│   ├── ClientsGig.js
│   ├── EmployerGig.js
│   ├── EmployeeGig.js
│   ├── freelancerGig.js
│   ├── Contract.js
│   ├── Proposal.js
│   ├── Reviews.js
│   └── ...
│
├── routes/                # API route definitions
│   ├── user.js
│   ├── job.js
│   ├── clientGig.js
│   ├── freelancerGig.js
│   ├── employerGig.js
│   ├── employeeGig.js
│   ├── proposal.js
│   ├── message.js
│   ├── contract.js
│   └── ...
│
├── middlewares/           # Custom middleware
│   ├── auth.js            # JWT authentication
│   ├── errorHandler.js    # Error handling
│   ├── asyncHandler.js    # Async error wrapper
│   └── socketAuth.js      # Socket.io authentication
│
├── database/              # Database configuration
│   └── databaseCon.js     # MongoDB connection
│
├── utils/                 # Utility functions
│   ├── openai.js          # OpenAI API integration
│   ├── pinecone-client.js # Pinecone client setup
│   ├── s3Client.js        # AWS S3 client
│   ├── mailer.js          # Email service
│   ├── socketServices.js  # Socket.io services
│   ├── uploadJobs.js      # Job synchronization
│   └── ...
│
└── public/                # Static files
    └── uploads/           # Uploaded files

📋 Prerequisites

Before you begin, ensure you have the following installed:

  • Node.js (v14 or higher)
  • npm or yarn
  • MongoDB (local or cloud instance like MongoDB Atlas)
  • AWS Account (for S3 storage)
  • OpenAI API Key
  • Pinecone Account (for vector search)

🔧 Installation

  1. Clone the repository

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

    npm install
    # or
    yarn install
  3. Set up environment variables Create a .env file in the root directory:

    # Server Configuration
    PORT=5846
    NODE_ENV=development
    
    # Database
    MONGODB_URL=mongodb://localhost:27017/jobs3
    # or for MongoDB Atlas:
    # MONGODB_URL=mongodb+srv://username:[email protected]/jobs3
    
    # JWT Configuration
    JWT_SECRETKEY=your-secret-key-here
    JWT_EXPIRE=1d
    
    # AWS S3 Configuration
    AWS_ACCESS_KEY_ID=your-aws-access-key
    AWS_SECRET_ACCESS_KEY=your-aws-secret-key
    AWS_REGION=us-east-1
    AWS_BUCKET_NAME=your-bucket-name
    
    # OpenAI Configuration
    OPENAI_API_KEY=your-openai-api-key
    
    # Pinecone Configuration
    PINECONE_API_KEY=your-pinecone-api-key
    PINECONE_ENVIRONMENT=your-pinecone-environment
    PINECONE_INDEX_NAME=your-index-name
    
    # Email Configuration (Nodemailer)
    EMAIL_HOST=smtp.gmail.com
    EMAIL_PORT=587
    EMAIL_USER=[email protected]
    EMAIL_PASS=your-email-password
    
    # Telegram Bot (Optional)
    TELEGRAM_BOT_TOKEN=your-telegram-bot-token
  4. Start the development server

    npm start
    # or
    yarn start

    The server will start on http://localhost:5846 (or the port specified in your .env file).

🌐 API Endpoints

Base URL

http://localhost:5846/api/v1

Main Endpoints

User Management

  • POST /user/register - Register a new user
  • POST /user/login - User login
  • GET /user/profile - Get user profile (protected)
  • PUT /user/profile - Update user profile (protected)

Jobs & Gigs

  • GET /jobs/ai-search/:searchKey - AI-powered job search
  • GET /client_gig - Get client gigs
  • POST /client_gig - Create client gig (protected)
  • GET /freelancer_gig - Get freelancer gigs
  • POST /freelancer_gig - Create freelancer gig (protected)
  • GET /employer_gig - Get employer gigs
  • POST /employer_gig - Create employer gig (protected)
  • GET /employee_gig - Get employee gigs
  • POST /employee_gig - Create employee gig (protected)

Proposals

  • POST /proposal - Submit a proposal (protected)
  • GET /proposal - Get proposals (protected)
  • PUT /proposal/:id - Update proposal (protected)

Contracts

  • POST /contract - Create a contract (protected)
  • GET /contract - Get contracts (protected)
  • PUT /contract/:id - Update contract (protected)
  • POST /extend_request - Request contract extension (protected)

Messaging

  • Real-time messaging via Socket.io
  • GET /message - Get message history (protected)
  • POST /message - Send message (protected)

Reviews

  • POST /review - Submit a review (protected)
  • GET /review - Get reviews (protected)

Portfolio

  • GET /freelancer_portfolio - Get freelancer portfolios
  • POST /freelancer_portfolio - Create/update portfolio (protected)
  • GET /employee_portfolio - Get employee portfolios
  • POST /employee_portfolio - Create/update portfolio (protected)

Profile

  • GET /profile - Get profiles
  • PUT /profile - Update profile (protected)
  • GET /visit_freelancer - Track freelancer visits
  • GET /visit_portfolio - Track portfolio visits

Recent Views

  • GET /recentView - Get recently viewed items (protected)
  • POST /recentView - Add to recent views (protected)

🔐 Authentication

The API uses JWT (JSON Web Tokens) for authentication. Include the token in the Authorization header:

Authorization: Bearer <your-jwt-token>

Protected routes require a valid JWT token. The token is generated upon login and expires after the time specified in JWT_EXPIRE.

💬 Real-Time Features

Socket.io Events

The backend uses Socket.io for real-time communication. Key events include:

  • Connection: Connect to the server
  • Message Events: Send and receive messages in real-time
  • User Status: Track online/offline status
  • Notifications: Real-time notifications for various events

Socket Authentication

Socket connections are authenticated using the socketAuth middleware. Include the JWT token when connecting:

const socket = io('http://localhost:5846', {
  auth: {
    token: 'your-jwt-token'
  }
});

🤖 AI Features

AI-Powered Job Search

The platform uses OpenAI GPT-4 and Pinecone vector database for intelligent job matching:

  • Semantic Search: Find jobs based on meaning, not just keywords
  • Job Recommendations: AI-powered job recommendations for users
  • Profile Matching: Match freelancers/employees with relevant jobs

Job Synchronization

Automated cron jobs sync and update job listings, ensuring the vector database stays current with the latest job postings.

📦 Deployment

Vercel Deployment

The project includes vercel.json for easy deployment on Vercel:

  1. Install Vercel CLI:

    npm i -g vercel
  2. Deploy:

    vercel
  3. Set environment variables in Vercel dashboard

Environment Variables for Production

Ensure all environment variables are set in your production environment:

  • MongoDB connection string
  • AWS credentials
  • OpenAI API key
  • Pinecone credentials
  • JWT secret
  • Email service credentials

🔄 Cron Jobs

The system includes automated cron jobs for:

  • Job synchronization with Pinecone
  • Sending email recommendations
  • Updating job statuses
  • Cleaning up expired data

📝 User Roles

The platform supports four main user roles:

  1. Freelancer: Independent contractors offering services
  2. Employee: Full-time or part-time employees
  3. Employer: Companies posting job opportunities
  4. Client: Clients posting project requirements

Users can have multiple roles simultaneously.

🗄️ Database Models

Key database models include:

  • User: User accounts and authentication
  • Profile: Extended user profiles with skills, experience, etc.
  • ClientsGig: Job postings by clients
  • EmployerGig: Job postings by employers
  • FreelancerGig: Service offerings by freelancers
  • EmployeeGig: Job applications by employees
  • Contract: Contracts between parties
  • Proposal: Job proposals
  • Reviews: Reviews and ratings
  • Message: Chat messages
  • Notification: System notifications

🛡️ Security Features

  • Password hashing with bcryptjs
  • JWT-based authentication
  • CORS configuration
  • Input validation
  • Error handling middleware
  • File upload security

📧 Email Service

The platform uses Nodemailer for:

  • User registration confirmations
  • Password reset emails
  • Job recommendations
  • Contract notifications
  • Proposal updates

🧪 Testing

Currently, no test suite is configured. To add testing:

npm install --save-dev jest supertest

🤝 Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

📄 License

ISC License

👥 Support

For support and questions, please contact the development team or open an issue in the repository.

🔮 Future Enhancements

  • Enhanced AI matching algorithms
  • Advanced analytics dashboard
  • Payment gateway integration
  • Mobile app API support
  • Enhanced security features
  • Comprehensive test coverage
  • API documentation with Swagger/OpenAPI

Built with ❤️ for the Jobs3 marketplace platform

About

A comprehensive backend system for a modern job marketplace platform similar to Upwork. This Node.js/Express backend provides a full-featured API for connecting freelancers, employees, employers, and clients with intelligent job matching, real-time communication, and AI-powered search capabilities.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors