A comprehensive REST API backend for a job searching platform built with Go, GORM, and PostgreSQL. Similar to HackerRank Jobs, this platform connects developers with companies and provides features for job posting, company reviews, ratings, and more.
- Features
- Tech Stack
- Prerequisites
- Installation
- Configuration
- Running the Application
- Testing the API
- API Documentation
- Project Structure
- Troubleshooting
- π JWT Authentication - Secure user registration and login
- π₯ Role-based Access Control - Developer, Company, and Admin roles
- π’ Company Profiles - Company information, ratings, and reviews
- πΌ Developer Profiles - Bio, experience, education, and certificates
- π Job Posting - Create, search, and filter job opportunities
- β Ratings & Reviews - Rate and review companies
- π¬ Comments & Reactions - Engage with job posts
- π Advanced Search - Filter by location, work mode, salary, experience
- π Pagination - Efficient data handling for large datasets
- Clean architecture with separation of concerns
- GORM for database operations with auto-migration
- Input validation using go-playground/validator
- Standardized API responses
- CORS support for frontend integration
- Comprehensive error handling
- Language: Go 1.22+
- Database: PostgreSQL
- ORM: GORM
- Authentication: JWT (golang-jwt/jwt)
- Router: Gin Web Framework
- Configuration: Viper
- Password Hashing: bcrypt
- Validation: go-playground/validator
Before you begin, ensure you have the following installed on your system:
- Version: 1.22 or higher
- Download: https://golang.org/dl/
- Verify installation:
You should see something like:
go version
go version go1.22.4 linux/amd64
- Version: 12 or higher
- Download: https://www.postgresql.org/download/
- Verify installation:
You should see something like:
psql --version
psql (PostgreSQL) 14.x
- Download: https://git-scm.com/downloads
- Verify installation:
git --version
# Using Git
git clone https://github.com/bishworup11/bdSeeker-backend.git
cd bdSeeker-backend
# OR download and extract the ZIP file, then navigate to the folder
cd bdSeeker-backend# Download all required packages
go mod download
# Verify dependencies are installed
go mod tidyThis will install:
- GORM and PostgreSQL driver
- JWT library
- Gin web framework
- Viper configuration management
- Validator
- Bcrypt for password hashing
- And other dependencies
-
Start PostgreSQL service (if not already running):
# On Linux sudo systemctl start postgresql # On macOS (with Homebrew) brew services start postgresql # On Windows # PostgreSQL should start automatically, or use Services app
-
Create the database:
# Connect to PostgreSQL psql -U postgres # You'll be prompted for password (default is often 'postgres') # Then run this SQL command: CREATE DATABASE bdseeker; # Exit psql \q
- Open pgAdmin
- Connect to your PostgreSQL server
- Right-click on "Databases" β "Create" β "Database"
- Enter database name:
bdseeker - Click "Save"
-
Copy the example environment file:
# The .env file should already exist, but if not: cp .env.example .env -
Edit the
.envfile with your settings:# Open with your favorite text editor nano .env # or vim .env # or use any text editor
-
Update the following values:
Option A: Using Environment Variables (Recommended with Viper)
# Set environment variables directly export DB_HOST=localhost export DB_PORT=5432 export DB_USER=postgres export DB_PASSWORD=your_password export DB_NAME=bdseeker export DB_SSLMODE=disable export JWT_SECRET=your-super-secret-jwt-key export JWT_EXPIRY=24h export JWT_REFRESH_EXPIRY=168h export SERVER_PORT=9000 export SERVER_HOST=0.0.0.0 export ENV=development
Option B: Using .env file (Backward Compatible)
# Database Configuration DB_HOST=localhost DB_PORT=5432 DB_USER=postgres # Your PostgreSQL username DB_PASSWORD=postgres # Your PostgreSQL password DB_NAME=bdseeker DB_SSLMODE=disable # JWT Configuration JWT_SECRET=your-super-secret-jwt-key-change-this-in-production JWT_EXPIRY=24h JWT_REFRESH_EXPIRY=168h # Server Configuration SERVER_PORT=9000 SERVER_HOST=0.0.0.0 # Environment ENV=development
Option C: Using config.yaml (New with Viper) Create a
config.yamlfile:dbhost: localhost dbport: "5432" dbuser: postgres dbpassword: postgres dbname: bdseeker dbsslmode: disable jwtsecret: your-super-secret-jwt-key jwtexpiry: 24h jwtrefreshexpiry: 168h serverport: "9000" serverhost: 0.0.0.0 environment: development
Important:
- Viper supports multiple configuration sources with priority: ENV vars > config file > defaults
- Environment variables take highest priority
- Replace
DB_USERandDB_PASSWORDwith your PostgreSQL credentials - Change
JWT_SECRETto a strong, random string in production
# Run directly without building
go run main.goYou should see:
β Database connection established successfully
β Database migrations completed successfully
π Server starting on 0.0.0.0:9000
π API Documentation: http://0.0.0.0:9000/api/v1/health
# Build the executable
go build -o bdseeker-api main.go
# Run the executable
./bdseeker-apiOpen your browser or use curl:
curl http://localhost:9000/api/v1/healthYou should see:
{"status":"ok"}We provide a comprehensive test script that tests all endpoints:
# Make the script executable (first time only)
chmod +x test_api.sh
# Run all tests
./test_api.shYou should see output like:
==========================================
bdSeeker REST API - Complete Test Suite
==========================================
Test 1: Health Check
β PASS
Test 2: Register Developer (new user)
β PASS
...
==========================================
TEST SUMMARY
==========================================
Total Tests: 26
Passed: 26
Failed: 0
β All tests passed!
curl -X POST http://localhost:9000/api/v1/auth/register \
-H "Content-Type: application/json" \
-d '{
"email": "john@example.com",
"password": "password123",
"full_name": "John Doe",
"role": "developer"
}'curl -X POST http://localhost:9000/api/v1/auth/login \
-H "Content-Type: application/json" \
-d '{
"email": "john@example.com",
"password": "password123"
}'Save the token from the response for authenticated requests.
curl -X GET http://localhost:9000/api/v1/auth/me \
-H "Authorization: Bearer YOUR_TOKEN_HERE"We provide a complete Postman collection!
-
Import the collection:
- Open Postman
- Click Import
- Select
bdSeeker-API.postman_collection.json - Select
bdSeeker-Local.postman_environment.json
-
Select environment: Choose "bdSeeker Local Environment" from the dropdown
-
Start testing: The collection includes 24 pre-configured requests with automatic token management!
For detailed Postman usage, see POSTMAN_GUIDE.md
- Base URL:
http://localhost:9000/api/v1 - Authentication: JWT Bearer token in
Authorizationheader - Content-Type:
application/json
| Method | Endpoint | Description | Auth Required |
|---|---|---|---|
| GET | /health |
Health check | No |
| POST | /auth/register |
Register new user | No |
| POST | /auth/login |
Login user | No |
| GET | /auth/me |
Get current user | Yes |
| GET | /companies |
List companies | No |
| POST | /companies |
Create company profile | Yes |
| GET | /developers |
List developers | No |
| POST | /developers |
Create developer profile | Yes |
| GET | /jobs |
List jobs | No |
| POST | /jobs |
Create job post | Yes (Company) |
| POST | /jobs/:id/reactions |
React to job | Yes |
| POST | /companies/:id/ratings |
Rate company | Yes |
For complete API documentation, see API_DOCUMENTATION.md
bdSeeker-backend/
βββ cmd/api/ # Application entry points (optional)
βββ internal/
β βββ config/ # Configuration management
β βββ database/ # Database connection & migrations
β βββ handlers/ # HTTP request handlers
β βββ middleware/ # Authentication, CORS, error handling
β βββ models/ # Database models (GORM)
β βββ repositories/ # Data access layer
β βββ services/ # Business logic
βββ pkg/utils/ # Utility functions (JWT, hashing, validation)
βββ .env # Environment variables (create from .env.example)
βββ main.go # Application entry point
βββ go.mod # Go module definition
βββ go.sum # Go dependencies checksums
βββ test_api.sh # Automated test script
βββ API_DOCUMENTATION.md # Complete API documentation
βββ README.md # This file
Error: failed to connect to database
Solutions:
- Verify PostgreSQL is running:
sudo systemctl status postgresql - Check database exists:
psql -U postgres -l | grep bdseeker - Verify credentials in
.envfile match your PostgreSQL setup - Try connecting manually:
psql -U postgres -d bdseeker
Error: bind: address already in use
Solutions:
# Find process using port 9000
lsof -i :9000
# Kill the process
kill -9 <PID>
# Or change the port in .env file
SERVER_PORT=8081Error: cannot find module
Solution:
# Clean and reinstall dependencies
go clean -modcache
go mod download
go mod tidyError: failed to run migrations
Solutions:
# Drop and recreate database
psql -U postgres -c "DROP DATABASE bdseeker;"
psql -U postgres -c "CREATE DATABASE bdseeker;"
# Restart the application (migrations run automatically)
./bdseeker-apiError: Invalid or expired token
Solution:
- Login again to get a new token
- Tokens expire after 24 hours by default (configurable in
.env)
If you encounter issues not listed here:
- Check the server logs for detailed error messages
- Verify all prerequisites are correctly installed
- Ensure
.envfile is properly configured - Review the API_DOCUMENTATION.md
- Open an issue on GitHub with:
- Error message
- Steps to reproduce
- Your environment (OS, Go version, PostgreSQL version)
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License.
Zubair Ahmed Rafi
- GitHub: @walleeva2018
Bishworup
- GitHub: @bishworup11
- Built following clean architecture principles
- Inspired by HackerRank Jobs platform
- Uses industry-standard Go libraries and best practices
Happy Coding! π
For questions or support, please open an issue on GitHub.