A robust RESTful API backend for a task marketplace platform where users can post tasks for others to complete and earn rewards. Built with Go, PostgreSQL, and modern web technologies.
- Overview
- Key Features
- Tech Stack
- Architecture
- Getting Started
- API Documentation
- Testing
- Deployment
- License
SocioTask is a task marketplace backend system that enables users to create, manage, and complete tasks in exchange for rewards. The platform supports multiple authentication methods including traditional email/password, Google OAuth, and Twitter OAuth, making it accessible to a wide range of users.
The system handles:
- Task Management: Users can create tasks with descriptions, deadlines, participant limits, and reward amounts
- Reward System: Automated reward tracking and distribution for completed tasks
- User Authentication: Multiple OAuth providers and JWT-based authentication
- Task Actions: Categorized task types (type_1, type_2, type_3) for different task categories
- User Profiles: User management with profiles, wallet addresses, and task history
- ✅ User registration and authentication
- ✅ Google OAuth 2.0 integration
- ✅ Twitter OAuth integration
- ✅ JWT-based session management
- ✅ User profiles with bio and wallet addresses
- ✅ Android-specific Google login support
- ✅ Create tasks with detailed specifications
- ✅ Set task rewards (USDT-based)
- ✅ Define participant limits
- ✅ Set deadlines for task completion
- ✅ Task categorization through action types
- ✅ Task status tracking
- ✅ Update and delete tasks
- ✅ Filter tasks by various criteria
- ✅ Automated reward tracking
- ✅ Task completion verification
- ✅ Reward distribution management
- ✅ User reward history
- ✅ Password hashing using bcrypt
- ✅ JWT token authentication
- ✅ Protected API endpoints
- ✅ CORS configuration
- ✅ Request validation and sanitization
- Language: Go 1.25.0
- Router: Chi v5 - Lightweight and fast HTTP router
- Authentication: JWT (golang-jwt/jwt v5)
- Password Hashing: bcrypt (golang.org/x/crypto)
- Database: PostgreSQL 12.4
- Driver: pgx/v5 - High-performance PostgreSQL driver
- Migration: Goose v3 - Database migration tool
- Google OAuth: Google API Client
- Twitter OAuth: OAuth2 implementation
- Framework: Testify - Testing toolkit with assertions
- Strategy: Unit tests for store layer
- Database: Docker-based PostgreSQL for testing
- Containerization: Docker & Docker Compose
- Server: Custom HTTP server with timeouts
be-sociotask/
├── internal/
│ ├── api/ # HTTP handlers
│ │ ├── task_handler.go
│ │ ├── user_handler.go
│ │ ├── auth_handler.go
│ │ ├── action_handler.go
│ │ ├── reward_handler.go
│ │ └── rewards_handler.go
│ ├── app/ # Application initialization
│ │ └── app.go
│ ├── auth/ # Authentication logic
│ │ ├── jwt.go
│ │ └── google/
│ ├── middleware/ # HTTP middleware
│ │ └── middleware.go
│ ├── pages/ # HTML pages
│ │ └── html.go
│ ├── routes/ # Route definitions
│ │ └── routes.go
│ ├── store/ # Data access layer
│ │ ├── database.go
│ │ ├── task_store.go
│ │ ├── user_store.go
│ │ ├── rewards_store.go
│ │ ├── task_action_store.go
│ │ └── *_test.go
│ └── utils/ # Utility functions
│ └── utils.go
├── migrations/ # Database migrations
│ ├── 00001_users.sql
│ ├── 00002_tasks.sql
│ ├── 00003_*.sql
│ └── ...
├── docs/ # API documentation
│ ├── task-api.md
│ ├── user-current.md
│ ├── rewards-api.md
│ ├── task-action-api.md
│ ├── task-reward-api.md
│ ├── login-api.md
│ ├── register-api.md
│ ├── oauth-google-api.md
│ └── oauth-twitter-api.md
├── main.go # Application entry point
├── go.mod # Go module dependencies
├── go.sum # Dependency checksums
└── docker-compose.yml # Docker configuration
Users Table
- User credentials and profile information
- OAuth identities (X/Twitter ID)
- Wallet addresses for rewards
- Full name and bio
Tasks Table
- Task details (title, description)
- Creator reference (user_id)
- Reward information (USDT amount)
- Deadline and participant limits
- Task status tracking
- Associated action type
Task Actions Table
- Action type classification (type_1, type_2, type_3)
- Action name and description
- Used to categorize tasks
Task Rewards Table
- Reward definitions
- Reference data for task rewards
Rewards Table
- Records of task completions
- Links users to completed tasks
- Timestamp tracking
The project follows a clean architecture pattern:
- Handlers (
internal/api/) - HTTP request/response handling - Store (
internal/store/) - Database operations and business logic - Middleware (
internal/middleware/) - Authentication and authorization - Routes (
internal/routes/) - API route definitions
- Go: Version 1.25.0 or higher
- PostgreSQL: Version 12.4 or higher (or use Docker)
- Docker & Docker Compose: (Optional, for containerized database)
- Git: For cloning the repository
-
Clone the repository
git clone https://github.com/BlankOnDev/be-sociotask.git cd be-sociotask -
Install Go dependencies
go mod download
-
Set up PostgreSQL
Using Docker (recommended for development):
docker-compose up -d
This will start a PostgreSQL instance on port 5433.
Or install PostgreSQL manually and create a database:
CREATE DATABASE socialtask;
-
Create environment file
cp .env.example .env
-
Configure environment variables
Edit
.envwith your settings:# Database Configuration DB_HOST=localhost DB_USER=postgres DB_PASSWORD=your_password DB_NAME=socialtask DB_PORT=5432 # JWT Secret JWT_SECRET=your_super_secret_jwt_key # Twitter OAuth TWITTER_CLIENT_ID=your_twitter_client_id TWITTER_CLIENT_SECRET=your_twitter_client_secret TWITTER_REDIRECT_URL=http://localhost:8080/login/twitter/callback # Google OAuth Google_Client_ID_Web=your_google_client_id Google_Client_Secret_Web=your_google_client_secret Google_Redirect_URL=http://localhost:8080/login/google/callback
-
Load environment variables (Linux/Mac)
set -a source .env set +a
Or for Windows PowerShell:
Get-Content .env | ForEach-Object { if ($_ -match '^([^=]+)=(.*)$') { [System.Environment]::SetEnvironmentVariable($matches[1], $matches[2]) } }
-
Run migrations
The application uses Goose for database migrations. Migrations are automatically applied when the application starts.
To run migrations manually:
go install github.com/pressly/goose/v3/cmd/goose@latest goose -dir migrations postgres "host=localhost user=postgres password=postgres dbname=socialtask port=5432 sslmode=disable" up -
Verify migrations
goose -dir migrations postgres "host=localhost user=postgres password=postgres dbname=socialtask port=5432 sslmode=disable" status
-
Start the server
go run main.go
Or specify a custom port:
go run main.go -port=3000
-
Verify the server is running
curl http://localhost:8080/health
You should receive a health check response.
-
Access the application
- API Base URL:
http://localhost:8080 - Home Page:
http://localhost:8080/ - Health Check:
http://localhost:8080/health
- API Base URL:
The API provides comprehensive endpoints for managing tasks, users, rewards, and authentication.
http://localhost:8080
Most endpoints require JWT authentication. Include the token in the Authorization header:
Authorization: Bearer <your_jwt_token>
POST /register- Register a new userPOST /login- Login with email/passwordGET /login/google- Initiate Google OAuthGET /login/google/callback- Google OAuth callbackPOST /login/google/android- Android Google loginGET /login/twitter- Initiate Twitter OAuthGET /login/twitter/callback- Twitter OAuth callback
GET /users/current- Get current authenticated user (Protected)GET /users/{id}/tasks- Get tasks created by a specific user
GET /tasks- Get all tasksGET /tasks/{id}- Get task by IDPOST /tasks- Create a new task (Protected)PUT /tasks/{id}- Update a task (Protected)DELETE /tasks/{id}- Delete a task (Protected)
GET /actions- Get all task actionsGET /actions/{id}- Get task action by ID
GET /reward- Get all rewardsGET /reward/{id}- Get reward by ID
POST /rewards- Record task completion (Protected)
For detailed request/response examples, validation rules, and error codes, see:
- Task API Documentation
- User API Documentation
- Rewards API Documentation
- Task Actions API Documentation
- Task Rewards API Documentation
- Login API Documentation
- Register API Documentation
- Google OAuth Documentation
- Twitter OAuth Documentation
The project includes comprehensive unit tests for the store layer.
-
Start the test database
docker-compose up -d
-
Run all tests
go test ./... -
Run tests with coverage
go test -cover ./... -
Run tests with verbose output
go test -v ./... -
Run specific test
go test -v ./internal/store -run TestCreateTask
Tests are located in internal/store/*_test.go files:
task_store_test.go- Task CRUD operationsuser_store_test.go- User management operationsrewards_store_test.go- Reward tracking operationstask_reward_store_test.go- Task reward operations
Each test:
- Sets up a clean test database
- Runs migrations
- Executes test cases
- Cleans up after completion
-
Environment Variables
- Use secure, randomly generated JWT secrets
- Configure production database credentials
- Set up production OAuth redirect URLs
-
Database
- Use a managed PostgreSQL service (AWS RDS, Google Cloud SQL, etc.)
- Enable SSL connections (
sslmode=require) - Set up automated backups
- Configure connection pooling
-
Server Configuration
- Use a reverse proxy (Nginx, Caddy)
- Enable HTTPS/TLS
- Configure rate limiting
- Set up logging and monitoring
-
Build for Production
go build -o sociotask-server main.go
-
Run in Production
./sociotask-server -port=8080
Create a Dockerfile:
FROM golang:1.25-alpine AS builder
WORKDIR /app
COPY go.mod go.sum ./
RUN go mod download
COPY . .
RUN go build -o server main.go
FROM alpine:latest
RUN apk --no-cache add ca-certificates
WORKDIR /root/
COPY --from=builder /app/server .
COPY --from=builder /app/migrations ./migrations
EXPOSE 8080
CMD ["./server"]Build and run:
docker build -t sociotask-backend .
docker run -p 8080:8080 --env-file .env sociotask-backendThis project is licensed under the MIT License - see the LICENSE file for details.
Harun Darat
- GitHub: @BlankOnDev