A comprehensive data collection and task management platform built with NestJS, designed for managing crowdsourced data collection projects with multi-language support and role-based access control.
Leyu API is a robust backend system that facilitates collaborative data collection projects. It enables organizations to create projects, define tasks, and manage contributors, reviewers, and facilitators in a structured workflow. The platform supports multiple languages and dialects, making it ideal for linguistic data collection and annotation projects.
- Project Creation: Create and manage data collection projects with detailed metadata
- Task Distribution: Automated task assignment to contributors based on skills and availability
- Micro-task System: Break down large tasks into manageable micro-tasks for efficient processing
- Progress Tracking: Real-time monitoring of project completion status
- Multi-role Support: Contributors, Reviewers, Facilitators, and Project Managers
- User Scoring System: Performance-based scoring and reputation management
- Geographic Organization: Users organized by regions, zones, and administrative areas
- Skill-based Assignment: Task distribution based on user expertise and language proficiency
- Language Management: Support for multiple languages and dialects
- Localized Content: Language-specific task instructions and content
- Regional Customization: Adapt content based on geographic regions
- Dataset Management: Structured data collection with validation and quality checks
- Review Workflow: Multi-stage review process with approval/rejection mechanisms
- Flag System: Quality control through flagging and review processes
- Audio Support: Handle audio data with duration tracking and file management
- Payment System: Integrated wallet and transaction management
- Contributor Compensation: Automated payment processing for completed tasks
- Financial Tracking: Comprehensive transaction history and reporting
- SMS Integration: Multi-provider SMS support (Geez SMS, Afro Message)
- Email Notifications: Automated email communications
- Activity Logging: Comprehensive audit trail of user activities
- Auth Module: JWT-based authentication, user management, and role-based access control
- Project Module: Project lifecycle management and task orchestration
- Data Set Module: Data collection, validation, and quality assurance
- Task Distribution Module: Intelligent task assignment and workload balancing
- Finance Module: Payment processing, wallet management, and transaction tracking
- Communication Module: Multi-channel messaging and notification system
- Base Data Module: Master data management for languages, dialects, and geographic regions
- Statistics Module: Analytics and reporting capabilities
- Cache Module: Redis-based caching and background job processing
- Framework: NestJS (Node.js)
- Database: PostgreSQL with TypeORM
- Cache & Queue: Redis with BullMQ
- Authentication: JWT with Passport
- File Storage: MinIO (S3-compatible)
- Email: Nodemailer with Gmail integration
- SMS: Multiple providers (Geez SMS, Afro Message)
- Push Notifications: Firebase Admin SDK
- Payment: Santim Pay integration
- API Documentation: Swagger/OpenAPI
- Validation: Zod schemas with class-validator
- Node.js (v20 or higher)
- PostgreSQL (v12 or higher)
- Redis (v7 or higher)
- MinIO or S3-compatible storage
-
Clone the repository
git clone <repository-url> cd leyu-backend
-
Install dependencies
npm install
-
Environment Configuration
cp .env.example .env
Configure the following environment variables:
# Database DATABASE_URL="postgresql://username:password@localhost:5432/leyu_db" DATABASE_SCHEMA="public" # JWT Configuration JWT_SECRET="your-secret-key" JWT_EXPIRES_IN="24h" JWT_REFRESH_EXPIRES_IN="10d" # Redis REDIS_URL="redis://localhost:6379" # MinIO/S3 Storage MINIO_ENDPOINT="localhost:9000" MINIO_ACCESS_KEY="your-access-key" MINIO_SECRET_KEY="your-secret-key" MINIO_BUCKET="leyu-bucket" # Email Configuration EMAIL_USER="your-email@gmail.com" EMAIL_PASS="your-app-password" # SMS Providers AFRO_SMS_BASE_URL="https://api.afromessage.com/api" AFRO_TOKEN="your-afro-token" # Payment Gateway SANTIM_PAY_MERCHANT_ID="your-merchant-id" SANTIM_PAY_PRIVATE_KEY_IN_PEM="your-private-key"
-
Database Setup
# Run migrations npm run migration:run # Seed initial data npm run seed
# Development mode with hot reload
npm run start:dev
# Production mode
npm run start:prod
# Debug mode
npm run start:debugThe API will be available at http://localhost:3000/api
Access the interactive API documentation at:
- Swagger UI:
http://localhost:3000/doc
# Generate new migration
npm run migration:generate
# Run migrations
npm run migration:run
# Revert last migration
npm run migration:revert
# Create new seed
npm run seed:create
# Run seeds
npm run seed:run# Unit tests
npm run test
# End-to-end tests
npm run test:e2e
# Test coverage
npm run test:cov
# Watch mode
npm run test:watch# Lint code
npm run lint
# Format code
npm run format# Build and start services
docker-compose up -d
# View logs
docker-compose logs -f
# Stop services
docker-compose downCreate a .env file with Docker-specific configurations:
DC_BACK_IMAGE_NAME=leyu-api
DC_BACK_IMAGE_TAG=latest
DC_BACK_APP_PORT=3000POST /api/auth/login- User loginPOST /api/auth/register- User registrationPOST /api/auth/refresh- Refresh JWT tokenPOST /api/auth/logout- User logout
GET /api/projects- List projectsPOST /api/projects- Create projectGET /api/projects/:id- Get project detailsPUT /api/projects/:id- Update projectDELETE /api/projects/:id- Delete project
GET /api/tasks- List tasksPOST /api/tasks- Create taskGET /api/tasks/:id- Get task detailsPUT /api/tasks/:id- Update taskPOST /api/tasks/:id/assign- Assign task to user
GET /api/data-sets- List data setsPOST /api/data-sets- Submit data setGET /api/data-sets/:id- Get data set detailsPUT /api/data-sets/:id/review- Review data setPOST /api/data-sets/:id/flag- Flag data set
GET /api/users- List usersGET /api/users/:id- Get user profilePUT /api/users/:id- Update user profileGET /api/users/:id/statistics- Get user statistics
- JWT Authentication: Secure token-based authentication
- Role-based Access Control: Fine-grained permissions system
- Input Validation: Comprehensive request validation using Zod
- Rate Limiting: API rate limiting to prevent abuse
- CORS Configuration: Configurable cross-origin resource sharing
- SQL Injection Protection: TypeORM query builder protection
- Password Hashing: Bcrypt password encryption
- Redis Caching: Intelligent caching strategy for frequently accessed data
- Database Indexing: Optimized database queries with proper indexing
- Background Jobs: Asynchronous processing using BullMQ
- Connection Pooling: Efficient database connection management
- Response Compression: Gzip compression for API responses
- Health Endpoint:
/api/health- Application health status - Database Health: Database connectivity monitoring
- Redis Health: Cache service monitoring
- Custom Metrics: Application-specific performance metrics
- 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
- Follow TypeScript best practices
- Write comprehensive tests for new features
- Update documentation for API changes
- Follow the existing code style and conventions
- Ensure all tests pass before submitting PR
-
Database Connection Issues
- Verify PostgreSQL is running
- Check database credentials in
.env - Ensure database exists and is accessible
-
Redis Connection Issues
- Verify Redis server is running
- Check Redis URL configuration
- Ensure Redis is accessible from the application
-
File Upload Issues
- Verify MinIO/S3 configuration
- Check bucket permissions
- Ensure storage service is accessible
-
SMS/Email Issues
- Verify provider credentials
- Check API endpoints and tokens
- Review rate limits and quotas
This project is licensed under the UNLICENSED License - see the package.json file for details.
For support and questions, please contact the development team or create an issue in the repository.
