diff --git a/deployments/local/docker-compose.yml b/deployments/local/docker-compose.yml index c98e9d5a..ac5620af 100644 --- a/deployments/local/docker-compose.yml +++ b/deployments/local/docker-compose.yml @@ -420,6 +420,64 @@ services: - "traefik.http.services.social-service.loadbalancer.healthcheck.path=/health/live" - "traefik.http.services.social-service.loadbalancer.healthcheck.interval=10s" + # Mining Service .NET - Pi Network-style Point Mining + mining-service-net: + build: + context: ../../services/mining-service-net + dockerfile: Dockerfile + image: goodgo/mining-service-net:latest + container_name: mining-service-net-local + environment: + - ASPNETCORE_ENVIRONMENT=Development + - ASPNETCORE_URLS=http://+:8080 + # EN: Database - Neon PostgreSQL + # VI: Cơ sở dữ liệu - Neon PostgreSQL + - ConnectionStrings__DefaultConnection=Host=ep-holy-glitter-a4hongg7-pooler.us-east-1.aws.neon.tech;Port=5432;Database=mining_service;Username=neondb_owner;Password=npg_Ssfy6HKO0cXI;SSL Mode=Require + # EN: IAM Service Communication + # VI: Giao tiếp IAM Service + - IamService__BaseUrl=http://iam-service-net:8080 + - IamService__ServiceName=mining-service + # EN: JWT Configuration + # VI: Cấu hình JWT + - Jwt__Authority=http://iam-service-net:8080 + - Jwt__Audience=goodgo-api + - Jwt__RequireHttpsMetadata=false + # EN: Redis Cache + # VI: Cache Redis + - Redis__Host=167.114.174.113 + - Redis__Port=6379 + - Redis__Password=Velik@2026 + ports: + - "5006:8080" + depends_on: + iam-service-net: + condition: service_healthy + traefik: + condition: service_started + networks: + - microservices-network + restart: unless-stopped + healthcheck: + test: ["CMD", "curl", "-f", "http://localhost:8080/health/live"] + interval: 30s + timeout: 10s + retries: 3 + start_period: 40s + labels: + - "traefik.enable=true" + - "traefik.http.routers.mining-service.rule=PathPrefix(`/api/v1/mining`) || PathPrefix(`/api/v1/circles`) || PathPrefix(`/api/v1/referrals`)" + - "traefik.http.routers.mining-service.entrypoints=web" + - "traefik.http.services.mining-service.loadbalancer.server.port=8080" + - "traefik.http.services.mining-service.loadbalancer.healthcheck.path=/health/live" + - "traefik.http.services.mining-service.loadbalancer.healthcheck.interval=10s" + # EN: SignalR Hub route with sticky sessions + # VI: Route cho SignalR Hub với sticky sessions + - "traefik.http.routers.mining-hub.rule=PathPrefix(`/hubs/mining`)" + - "traefik.http.routers.mining-hub.entrypoints=web" + - "traefik.http.routers.mining-hub.service=mining-service" + - "traefik.http.services.mining-service.loadbalancer.sticky.cookie=true" + - "traefik.http.services.mining-service.loadbalancer.sticky.cookie.name=mining_session" + # Jaeger - Distributed Tracing # jaeger: diff --git a/services/mining-service-net/Dockerfile b/services/mining-service-net/Dockerfile index 28194630..f928911d 100644 --- a/services/mining-service-net/Dockerfile +++ b/services/mining-service-net/Dockerfile @@ -20,11 +20,11 @@ COPY src/ ./src/ # EN: Build the application # VI: Build ứng dụng WORKDIR "/src/src/MiningService.API" -RUN dotnet build "MiningService.API.csproj" -c Release -o /app/build --no-restore +RUN dotnet build "MiningService.API.csproj" -c Release -o /app/build # Publish stage / Giai đoạn publish FROM build AS publish -RUN dotnet publish "MiningService.API.csproj" -c Release -o /app/publish /p:UseAppHost=false --no-restore +RUN dotnet publish "MiningService.API.csproj" -c Release -o /app/publish /p:UseAppHost=false # Runtime stage / Giai đoạn runtime FROM mcr.microsoft.com/dotnet/aspnet:10.0 AS final diff --git a/services/mining-service-net/docker-compose.yml b/services/mining-service-net/docker-compose.yml deleted file mode 100644 index 101d65ce..00000000 --- a/services/mining-service-net/docker-compose.yml +++ /dev/null @@ -1,73 +0,0 @@ -version: '3.8' - -# EN: Docker Compose for Mining Service local development -# VI: Docker Compose cho phát triển Mining Service local - -services: - mining-api: - build: - context: . - dockerfile: Dockerfile - container_name: mining-service-api - ports: - - "5010:8080" - environment: - - ASPNETCORE_ENVIRONMENT=Development - - DATABASE_URL=Host=postgres;Port=5432;Database=mining_db;Username=postgres;Password=postgres - - REDIS_URL=redis:6379 - - RABBITMQ_URL=amqp://guest:guest@rabbitmq:5672 - depends_on: - postgres: - condition: service_healthy - redis: - condition: service_healthy - networks: - - mining-network - healthcheck: - test: ["CMD", "curl", "-f", "http://localhost:8080/health/live"] - interval: 30s - timeout: 10s - retries: 3 - start_period: 10s - - postgres: - image: postgres:16-alpine - container_name: mining-postgres - environment: - POSTGRES_USER: postgres - POSTGRES_PASSWORD: postgres - POSTGRES_DB: mining_db - ports: - - "5442:5432" - volumes: - - postgres_data:/var/lib/postgresql/data - networks: - - mining-network - healthcheck: - test: ["CMD-SHELL", "pg_isready -U postgres"] - interval: 10s - timeout: 5s - retries: 5 - - redis: - image: redis:7-alpine - container_name: mining-redis - ports: - - "6389:6379" - volumes: - - redis_data:/data - networks: - - mining-network - healthcheck: - test: ["CMD", "redis-cli", "ping"] - interval: 10s - timeout: 5s - retries: 5 - -volumes: - postgres_data: - redis_data: - -networks: - mining-network: - driver: bridge diff --git a/services/mining-service-net/src/MiningService.API/Properties/launchSettings.json b/services/mining-service-net/src/MiningService.API/Properties/launchSettings.json index 6355d40b..86c148b4 100644 --- a/services/mining-service-net/src/MiningService.API/Properties/launchSettings.json +++ b/services/mining-service-net/src/MiningService.API/Properties/launchSettings.json @@ -6,7 +6,7 @@ "dotnetRunMessages": true, "launchBrowser": true, "launchUrl": "swagger", - "applicationUrl": "http://localhost:5000", + "applicationUrl": "http://localhost:5006", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } diff --git a/services/mining-service-net/src/MiningService.API/appsettings.json b/services/mining-service-net/src/MiningService.API/appsettings.json index 523dc0fc..9753267a 100644 --- a/services/mining-service-net/src/MiningService.API/appsettings.json +++ b/services/mining-service-net/src/MiningService.API/appsettings.json @@ -30,7 +30,7 @@ ] }, "ConnectionStrings": { - "DefaultConnection": "Host=localhost;Port=5432;Database=myservice_db;Username=postgres;Password=postgres" + "DefaultConnection": "Host=ep-holy-glitter-a4hongg7-pooler.us-east-1.aws.neon.tech;Port=5432;Database=mining_service;Username=neondb_owner;Password=npg_Ssfy6HKO0cXI;SSL Mode=Require" }, "Redis": { "ConnectionString": "localhost:6379" diff --git a/services/mission-service-net/docs/en/README.md b/services/mission-service-net/docs/en/README.md new file mode 100644 index 00000000..8cf5fc1d --- /dev/null +++ b/services/mission-service-net/docs/en/README.md @@ -0,0 +1,432 @@ +# Mission Service .NET + +> **EN**: Mission & Task gamification service for GoodGo Platform. +> **VI**: Dịch vụ gamification Mission & Task cho GoodGo Platform. + +## Overview + +The **Mission Service** manages gamification missions and tasks, enabling users to earn rewards through various activities on the GoodGo platform. + +### Key Features + +| Feature | Description | +|---------|-------------| +| 🎬 **Watch Video** | Earn rewards by watching videos - Pay per view | +| 💰 **Pay Per Click** | Earn points by clicking ads/links | +| 📤 **Pay Per Upload** | Get rewarded for uploading UGC content | +| 👥 **Invite Friends** | Earn bonus when friends complete missions | +| 📅 **Daily Check-in** | Daily check-in with streak bonuses | +| ❤️ **Social Actions** | Like, Share, Subscribe to social channels | + +--- + +## Architecture Design + +### System Architecture + +```mermaid +%%{init: {'theme':'dark'}}%% +graph TD + subgraph Gateway["🌐 API Gateway"] + Traefik[Traefik] + end + + subgraph Mission["📋 Mission Service"] + API[API Layer] + Domain[Domain Layer] + Infra[Infrastructure] + end + + subgraph External["🔗 External Services"] + IAM[IAM Service] + Wallet[Wallet Service] + Mining[Mining Service] + Social[Social Service] + Storage[Storage Service] + end + + subgraph Data["💾 Data Layer"] + DB[(PostgreSQL)] + Redis[(Redis)] + RabbitMQ[RabbitMQ] + end + + Traefik --> API + API --> Domain + Domain --> Infra + Infra --> DB + Infra --> Redis + Infra --> RabbitMQ + + Mission <--> IAM + Mission --> Wallet + Mission <--> Mining + Mission <--> Social + Mission <--> Storage + + style Gateway fill:#3498DB,color:#ECF0F1,stroke:#2980B9,stroke-width:2px + style Mission fill:#8E44AD,color:#ECF0F1,stroke:#7D3C98,stroke-width:3px + style External fill:#27AE60,color:#ECF0F1,stroke:#229954,stroke-width:2px + style Data fill:#E67E22,color:#ECF0F1,stroke:#D35400,stroke-width:2px +``` + +### Clean Architecture Structure + +``` +mission-service-net/ +├── src/ +│ ├── MissionService.API/ # API Layer +│ │ ├── Controllers/ +│ │ │ ├── MissionsController.cs # Mission management +│ │ │ ├── TasksController.cs # Task execution +│ │ │ ├── CheckInController.cs # Daily check-in +│ │ │ └── RewardsController.cs # Reward claims +│ │ └── Application/ +│ │ ├── Commands/ # Write operations +│ │ ├── Queries/ # Read operations +│ │ └── IntegrationEvents/ # External events +│ │ +│ ├── MissionService.Domain/ # Domain Layer +│ │ ├── AggregatesModel/ +│ │ │ ├── MissionAggregate/ # Mission definitions +│ │ │ ├── TaskAggregate/ # Task executions +│ │ │ ├── CheckInAggregate/ # Daily check-in +│ │ │ └── RewardAggregate/ # Reward tracking +│ │ ├── Events/ # Domain events +│ │ └── Services/ # Domain services +│ │ +│ └── MissionService.Infrastructure/ # Infrastructure +│ ├── EntityConfigurations/ # EF Core mappings +│ ├── Repositories/ # Data access +│ └── ExternalServices/ # API clients +│ +├── tests/ +├── docs/ +└── Dockerfile +``` + +--- + +## Domain Model + +### Core Aggregates + +```mermaid +%%{init: {'theme':'dark'}}%% +classDiagram + class Mission { + +Guid Id + +string Code + +LocalizedString Title + +MissionType Type + +MissionReward Reward + +FrequencyType Frequency + +MissionStatus Status + +Activate() + +Pause() + +ValidateCompletion() + } + + class UserTask { + +Guid Id + +Guid UserId + +Guid MissionId + +TaskStatus Status + +TaskProgress Progress + +TaskEvidence Evidence + +Start() + +UpdateProgress() + +Complete() + +ClaimReward() + } + + class UserCheckIn { + +Guid Id + +Guid UserId + +int CurrentStreak + +int LongestStreak + +DateOnly LastCheckInDate + +CheckIn() + +GetStreakBonus() + } + + Mission "1" --> "*" UserTask : generates + UserTask --> UserCheckIn : may trigger +``` + +### Mission Types + +```mermaid +%%{init: {'theme':'dark'}}%% +flowchart LR + subgraph Types["📋 Mission Types"] + Video["🎬 Watch Video"] + Click["💰 Pay Per Click"] + Upload["📤 Pay Per Upload"] + Invite["👥 Invite Friends"] + CheckIn["📅 Daily Check-in"] + Social["❤️ Social Actions"] + end + + style Video fill:#E74C3C,color:#ECF0F1,stroke:#C0392B,stroke-width:2px + style Click fill:#3498DB,color:#ECF0F1,stroke:#2980B9,stroke-width:2px + style Upload fill:#9B59B6,color:#ECF0F1,stroke:#8E44AD,stroke-width:2px + style Invite fill:#2ECC71,color:#ECF0F1,stroke:#27AE60,stroke-width:2px + style CheckIn fill:#F39C12,color:#ECF0F1,stroke:#E67E22,stroke-width:2px + style Social fill:#E91E63,color:#ECF0F1,stroke:#C2185B,stroke-width:2px +``` + +--- + +## Daily Check-in System + +### 🔥 Streak Bonus + +```mermaid +%%{init: {'theme':'dark'}}%% +flowchart LR + subgraph Streak["📅 Streak Tiers"] + D1["Day 1-6
2 MP"] --> D7["Day 7
🎁 +20 MP"] + D7 --> D14["Day 14
🎁 +35 MP"] + D14 --> D21["Day 21
🎁 +50 MP"] + D21 --> D30["Day 30
👑 +100 MP"] + end + + style D1 fill:#7F8C8D,color:#ECF0F1,stroke:#5D6D7E,stroke-width:2px + style D7 fill:#3498DB,color:#ECF0F1,stroke:#2980B9,stroke-width:2px + style D14 fill:#8E44AD,color:#ECF0F1,stroke:#7D3C98,stroke-width:2px + style D21 fill:#E67E22,color:#ECF0F1,stroke:#D35400,stroke-width:2px + style D30 fill:#C0392B,color:#ECF0F1,stroke:#A93226,stroke-width:3px +``` + +| Streak | Daily Points | Milestone Bonus | +|--------|--------------|-----------------| +| Day 1-6 | 2 MP | - | +| Day 7 | 3 MP | 🎁 20 MP bonus | +| Day 8-13 | 3 MP | - | +| Day 14 | 4 MP | 🎁 35 MP bonus | +| Day 15-20 | 4 MP | - | +| Day 21 | 5 MP | 🎁 50 MP bonus | +| Day 22-29 | 5 MP | - | +| Day 30 | 10 MP | 👑 100 MP + Badge | + +--- + +## API Endpoints + +### Mission APIs + +| Method | Endpoint | Description | +|--------|----------|-------------| +| `GET` | `/api/v1/missions` | List available missions | +| `GET` | `/api/v1/missions/{id}` | Get mission details | +| `GET` | `/api/v1/missions/featured` | Featured missions | + +### Task APIs + +| Method | Endpoint | Description | +|--------|----------|-------------| +| `POST` | `/api/v1/tasks/start` | Start a mission task | +| `GET` | `/api/v1/tasks/me` | Get my active tasks | +| `POST` | `/api/v1/tasks/{id}/progress` | Update task progress | +| `POST` | `/api/v1/tasks/{id}/complete` | Mark task complete | +| `POST` | `/api/v1/tasks/{id}/claim` | Claim reward | +| `GET` | `/api/v1/tasks/history` | Task history | + +### Check-in APIs + +| Method | Endpoint | Description | +|--------|----------|-------------| +| `POST` | `/api/v1/checkin` | Daily check-in | +| `GET` | `/api/v1/checkin/status` | Check-in status | +| `GET` | `/api/v1/checkin/calendar` | Monthly calendar | + +### Admin Backoffice APIs + +#### 🔧 Configuration Management + +| Method | Endpoint | Description | +|--------|----------|-------------| +| `GET` | `/api/v1/admin/config` | Get system configuration | +| `PUT` | `/api/v1/admin/config` | Update configuration | +| `GET` | `/api/v1/admin/config/missions` | Get mission type configs | +| `PUT` | `/api/v1/admin/config/missions` | Update mission configs | +| `GET` | `/api/v1/admin/config/checkin` | Get check-in & streak config | +| `PUT` | `/api/v1/admin/config/checkin` | Update streak bonuses | +| `GET` | `/api/v1/admin/config/rewards` | Get reward configuration | +| `PUT` | `/api/v1/admin/config/rewards` | Update reward rates | + +#### 📋 Mission Management + +| Method | Endpoint | Description | +|--------|----------|-------------| +| `GET` | `/api/v1/admin/missions` | List missions (paginated) | +| `POST` | `/api/v1/admin/missions` | Create new mission | +| `GET` | `/api/v1/admin/missions/{id}` | Get mission details | +| `PUT` | `/api/v1/admin/missions/{id}` | Update mission | +| `DELETE` | `/api/v1/admin/missions/{id}` | Delete mission | +| `PUT` | `/api/v1/admin/missions/{id}/activate` | Activate mission | +| `PUT` | `/api/v1/admin/missions/{id}/pause` | Pause mission | +| `POST` | `/api/v1/admin/missions/{id}/duplicate` | Duplicate mission | + +#### 👥 User & Task Management + +| Method | Endpoint | Description | +|--------|----------|-------------| +| `GET` | `/api/v1/admin/users` | List users (paginated) | +| `GET` | `/api/v1/admin/users/{id}` | Get user details | +| `GET` | `/api/v1/admin/users/{id}/tasks` | Get user's tasks | +| `GET` | `/api/v1/admin/users/{id}/checkin` | Get user's check-in history | +| `PUT` | `/api/v1/admin/users/{id}/reset-streak` | Reset user streak | +| `PUT` | `/api/v1/admin/users/{id}/adjust-points` | Adjust user points | +| `GET` | `/api/v1/admin/tasks` | List tasks (paginated) | +| `GET` | `/api/v1/admin/tasks/{id}` | Get task details | +| `PUT` | `/api/v1/admin/tasks/{id}/verify` | Manually verify task | +| `PUT` | `/api/v1/admin/tasks/{id}/reject` | Reject task | +| `PUT` | `/api/v1/admin/tasks/{id}/approve` | Approve task | + +#### 📊 Analytics & Reports + +| Method | Endpoint | Description | +|--------|----------|-------------| +| `GET` | `/api/v1/admin/analytics/overview` | Dashboard overview | +| `GET` | `/api/v1/admin/analytics/missions` | Mission statistics | +| `GET` | `/api/v1/admin/analytics/checkin` | Check-in statistics | +| `GET` | `/api/v1/admin/analytics/rewards` | Reward statistics | +| `GET` | `/api/v1/admin/analytics/users` | User statistics | +| `GET` | `/api/v1/admin/audit-logs` | Configuration change logs | + +--- + +## Integration Points + +### Service Dependencies + +```mermaid +%%{init: {'theme':'dark'}}%% +flowchart LR + subgraph Mission["📋 Mission Service"] + M[Mission Service] + end + + subgraph Auth["🔐 Auth"] + IAM[IAM Service] + end + + subgraph Rewards["💰 Rewards"] + Wallet[Wallet Service] + Mining[Mining Service] + end + + subgraph Social["👥 Social"] + SocialSvc[Social Service] + Storage[Storage Service] + end + + IAM -->|JWT Auth| M + M -->|Grant Points| Wallet + M <-->|Referral Sync| Mining + M <-->|Friend Check| SocialSvc + M <-->|Media| Storage + + style Mission fill:#8E44AD,color:#ECF0F1,stroke:#7D3C98,stroke-width:3px + style Auth fill:#C0392B,color:#ECF0F1,stroke:#A93226,stroke-width:2px + style Rewards fill:#27AE60,color:#ECF0F1,stroke:#229954,stroke-width:2px + style Social fill:#3498DB,color:#ECF0F1,stroke:#2980B9,stroke-width:2px +``` + +### Integration Events + +| Event | Publisher | Consumer | Description | +|-------|-----------|----------|-------------| +| `MissionCompletedEvent` | Mission | Wallet | User completed mission | +| `CheckInCompletedEvent` | Mission | Wallet | Daily check-in done | +| `UserRegisteredEvent` | IAM | Mission | Create user profile | +| `ReferralActivatedEvent` | Mining | Mission | Sync invite status | + +--- + +## Tech Stack + +| Component | Technology | Purpose | +|-----------|------------|---------| +| **Framework** | .NET 10 | Latest LTS framework | +| **API Layer** | Controllers + MediatR | CQRS pattern | +| **Database** | PostgreSQL + EF Core 10 | Persistent storage | +| **Caching** | Redis + HybridCache | L1+L2 caching | +| **Message Queue** | RabbitMQ (MassTransit) | Integration events | +| **Scheduler** | Hangfire | Background jobs | +| **Validation** | FluentValidation | Request validation | +| **API Docs** | Swagger/OpenAPI | Documentation | + +--- + +## Configuration + +### Environment Variables + +| Variable | Description | Required | +|----------|-------------|----------| +| `DATABASE_URL` | PostgreSQL connection | Yes | +| `REDIS_URL` | Redis connection | Yes | +| `RABBITMQ_URL` | RabbitMQ connection | Yes | +| `JWT_AUTHORITY` | JWT issuer URL | Yes | +| `MAX_DAILY_TASKS` | Max tasks per day | No | + +--- + +## Security & Anti-Fraud + +### Fraud Prevention + +```mermaid +%%{init: {'theme':'dark'}}%% +flowchart TD + Request([🚀 Request]) --> Rate{⏱️ Rate Limit} + Rate -->|Exceeded| Block[❌ Block] + Rate -->|OK| Device{🔍 Device Check} + Device -->|Suspicious| Flag[⚠️ Flag] + Device -->|OK| Verify{✅ Verify Evidence} + Verify -->|Invalid| Reject[❌ Reject] + Verify -->|Valid| Reward[🎁 Grant Reward] + + style Block fill:#C0392B,color:#ECF0F1,stroke:#A93226,stroke-width:2px + style Reject fill:#E74C3C,color:#ECF0F1,stroke:#C0392B,stroke-width:2px + style Reward fill:#27AE60,color:#ECF0F1,stroke:#229954,stroke-width:2px +``` + +| Measure | Description | +|---------|-------------| +| **Rate Limiting** | Max tasks per user per day | +| **Cooldown** | Min time between completions | +| **Device Fingerprint** | Track multi-account | +| **Evidence Validation** | AI + Manual review for UGC | + +--- + +## Roadmap + +### Phase 1: Core (Week 1-2) +- [ ] Project setup +- [ ] Domain model +- [ ] Database schema + +### Phase 2: Daily Check-in (Week 3) +- [ ] Check-in aggregate +- [ ] Streak calculation +- [ ] Milestone rewards + +### Phase 3: Watch Video (Week 4-5) +- [ ] Video mission type +- [ ] Progress tracking +- [ ] Duration verification + +### Phase 4: Social Actions (Week 6-7) +- [ ] Social platform configs +- [ ] Verification methods +- [ ] OAuth integration + +### Phase 5: Advanced (Week 8+) +- [ ] Pay per click/upload +- [ ] Invite friends +- [ ] Admin analytics diff --git a/services/mission-service-net/docs/vi/README.md b/services/mission-service-net/docs/vi/README.md new file mode 100644 index 00000000..18cda367 --- /dev/null +++ b/services/mission-service-net/docs/vi/README.md @@ -0,0 +1,432 @@ +# Mission Service .NET + +> **EN**: Mission & Task gamification service for GoodGo Platform. +> **VI**: Dịch vụ gamification Mission & Task cho GoodGo Platform. + +## Tổng Quan + +**Mission Service** quản lý các nhiệm vụ (missions) và tác vụ (tasks) gamification, cho phép người dùng kiếm phần thưởng thông qua các hoạt động trên nền tảng GoodGo. + +### Tính Năng Chính + +| Tính Năng | Mô Tả | +|-----------|-------| +| 🎬 **Xem Video** | Kiếm thưởng bằng cách xem video - Pay per view | +| 💰 **Pay Per Click** | Kiếm điểm bằng cách nhấn quảng cáo/liên kết | +| 📤 **Pay Per Upload** | Được thưởng khi tải lên nội dung UGC | +| 👥 **Mời Bạn Bè** | Kiếm bonus khi bạn hoàn thành nhiệm vụ | +| 📅 **Điểm Danh Hàng Ngày** | Điểm danh với thưởng streak | +| ❤️ **Tương Tác Xã Hội** | Like, Share, Subscribe kênh mạng xã hội | + +--- + +## Thiết Kế Kiến Trúc + +### Kiến Trúc Hệ Thống + +```mermaid +%%{init: {'theme':'dark'}}%% +graph TD + subgraph Gateway["🌐 API Gateway"] + Traefik[Traefik] + end + + subgraph Mission["📋 Mission Service"] + API[Tầng API] + Domain[Tầng Domain] + Infra[Tầng Infrastructure] + end + + subgraph External["🔗 Dịch Vụ Liên Quan"] + IAM[IAM Service] + Wallet[Wallet Service] + Mining[Mining Service] + Social[Social Service] + Storage[Storage Service] + end + + subgraph Data["💾 Tầng Dữ Liệu"] + DB[(PostgreSQL)] + Redis[(Redis)] + RabbitMQ[RabbitMQ] + end + + Traefik --> API + API --> Domain + Domain --> Infra + Infra --> DB + Infra --> Redis + Infra --> RabbitMQ + + Mission <--> IAM + Mission --> Wallet + Mission <--> Mining + Mission <--> Social + Mission <--> Storage + + style Gateway fill:#3498DB,color:#ECF0F1,stroke:#2980B9,stroke-width:2px + style Mission fill:#8E44AD,color:#ECF0F1,stroke:#7D3C98,stroke-width:3px + style External fill:#27AE60,color:#ECF0F1,stroke:#229954,stroke-width:2px + style Data fill:#E67E22,color:#ECF0F1,stroke:#D35400,stroke-width:2px +``` + +### Cấu Trúc Clean Architecture + +``` +mission-service-net/ +├── src/ +│ ├── MissionService.API/ # Tầng API +│ │ ├── Controllers/ +│ │ │ ├── MissionsController.cs # Quản lý mission +│ │ │ ├── TasksController.cs # Thực thi task +│ │ │ ├── CheckInController.cs # Điểm danh +│ │ │ └── RewardsController.cs # Nhận thưởng +│ │ └── Application/ +│ │ ├── Commands/ # Thao tác ghi +│ │ ├── Queries/ # Thao tác đọc +│ │ └── IntegrationEvents/ # Sự kiện tích hợp +│ │ +│ ├── MissionService.Domain/ # Tầng Domain +│ │ ├── AggregatesModel/ +│ │ │ ├── MissionAggregate/ # Định nghĩa mission +│ │ │ ├── TaskAggregate/ # Thực thi task +│ │ │ ├── CheckInAggregate/ # Điểm danh +│ │ │ └── RewardAggregate/ # Theo dõi thưởng +│ │ ├── Events/ # Domain events +│ │ └── Services/ # Domain services +│ │ +│ └── MissionService.Infrastructure/ # Tầng Infrastructure +│ ├── EntityConfigurations/ # EF Core mappings +│ ├── Repositories/ # Truy cập dữ liệu +│ └── ExternalServices/ # API clients +│ +├── tests/ +├── docs/ +└── Dockerfile +``` + +--- + +## Domain Model + +### Các Aggregate Chính + +```mermaid +%%{init: {'theme':'dark'}}%% +classDiagram + class Mission { + +Guid Id + +string Code + +LocalizedString Title + +MissionType Type + +MissionReward Reward + +FrequencyType Frequency + +MissionStatus Status + +Activate() + +Pause() + +ValidateCompletion() + } + + class UserTask { + +Guid Id + +Guid UserId + +Guid MissionId + +TaskStatus Status + +TaskProgress Progress + +TaskEvidence Evidence + +Start() + +UpdateProgress() + +Complete() + +ClaimReward() + } + + class UserCheckIn { + +Guid Id + +Guid UserId + +int CurrentStreak + +int LongestStreak + +DateOnly LastCheckInDate + +CheckIn() + +GetStreakBonus() + } + + Mission "1" --> "*" UserTask : tạo ra + UserTask --> UserCheckIn : có thể kích hoạt +``` + +### Các Loại Mission + +```mermaid +%%{init: {'theme':'dark'}}%% +flowchart LR + subgraph Types["📋 Loại Mission"] + Video["🎬 Xem Video"] + Click["💰 Pay Per Click"] + Upload["📤 Pay Per Upload"] + Invite["👥 Mời Bạn Bè"] + CheckIn["📅 Điểm Danh"] + Social["❤️ Tương Tác XH"] + end + + style Video fill:#E74C3C,color:#ECF0F1,stroke:#C0392B,stroke-width:2px + style Click fill:#3498DB,color:#ECF0F1,stroke:#2980B9,stroke-width:2px + style Upload fill:#9B59B6,color:#ECF0F1,stroke:#8E44AD,stroke-width:2px + style Invite fill:#2ECC71,color:#ECF0F1,stroke:#27AE60,stroke-width:2px + style CheckIn fill:#F39C12,color:#ECF0F1,stroke:#E67E22,stroke-width:2px + style Social fill:#E91E63,color:#ECF0F1,stroke:#C2185B,stroke-width:2px +``` + +--- + +## Hệ Thống Điểm Danh Hàng Ngày + +### 🔥 Thưởng Streak + +```mermaid +%%{init: {'theme':'dark'}}%% +flowchart LR + subgraph Streak["📅 Các Cấp Streak"] + D1["Ngày 1-6
2 MP"] --> D7["Ngày 7
🎁 +20 MP"] + D7 --> D14["Ngày 14
🎁 +35 MP"] + D14 --> D21["Ngày 21
🎁 +50 MP"] + D21 --> D30["Ngày 30
👑 +100 MP"] + end + + style D1 fill:#7F8C8D,color:#ECF0F1,stroke:#5D6D7E,stroke-width:2px + style D7 fill:#3498DB,color:#ECF0F1,stroke:#2980B9,stroke-width:2px + style D14 fill:#8E44AD,color:#ECF0F1,stroke:#7D3C98,stroke-width:2px + style D21 fill:#E67E22,color:#ECF0F1,stroke:#D35400,stroke-width:2px + style D30 fill:#C0392B,color:#ECF0F1,stroke:#A93226,stroke-width:3px +``` + +| Streak | Điểm Hàng Ngày | Thưởng Mốc | +|--------|----------------|------------| +| Ngày 1-6 | 2 MP | - | +| Ngày 7 | 3 MP | 🎁 20 MP bonus | +| Ngày 8-13 | 3 MP | - | +| Ngày 14 | 4 MP | 🎁 35 MP bonus | +| Ngày 15-20 | 4 MP | - | +| Ngày 21 | 5 MP | 🎁 50 MP bonus | +| Ngày 22-29 | 5 MP | - | +| Ngày 30 | 10 MP | 👑 100 MP + Badge | + +--- + +## API Endpoints + +### APIs Mission + +| Phương Thức | Endpoint | Mô Tả | +|-------------|----------|-------| +| `GET` | `/api/v1/missions` | Danh sách mission | +| `GET` | `/api/v1/missions/{id}` | Chi tiết mission | +| `GET` | `/api/v1/missions/featured` | Mission nổi bật | + +### APIs Task + +| Phương Thức | Endpoint | Mô Tả | +|-------------|----------|-------| +| `POST` | `/api/v1/tasks/start` | Bắt đầu task | +| `GET` | `/api/v1/tasks/me` | Task đang làm | +| `POST` | `/api/v1/tasks/{id}/progress` | Cập nhật tiến độ | +| `POST` | `/api/v1/tasks/{id}/complete` | Hoàn thành task | +| `POST` | `/api/v1/tasks/{id}/claim` | Nhận thưởng | +| `GET` | `/api/v1/tasks/history` | Lịch sử task | + +### APIs Điểm Danh + +| Phương Thức | Endpoint | Mô Tả | +|-------------|----------|-------| +| `POST` | `/api/v1/checkin` | Điểm danh | +| `GET` | `/api/v1/checkin/status` | Trạng thái điểm danh | +| `GET` | `/api/v1/checkin/calendar` | Lịch tháng | + +### APIs Admin Backoffice + +#### 🔧 Quản Lý Cấu Hình + +| Phương Thức | Endpoint | Mô Tả | +|-------------|----------|-------| +| `GET` | `/api/v1/admin/config` | Lấy cấu hình hệ thống | +| `PUT` | `/api/v1/admin/config` | Cập nhật cấu hình | +| `GET` | `/api/v1/admin/config/missions` | Cấu hình mission types | +| `PUT` | `/api/v1/admin/config/missions` | Cập nhật cấu hình mission | +| `GET` | `/api/v1/admin/config/checkin` | Cấu hình check-in & streak | +| `PUT` | `/api/v1/admin/config/checkin` | Cập nhật thưởng streak | +| `GET` | `/api/v1/admin/config/rewards` | Cấu hình phần thưởng | +| `PUT` | `/api/v1/admin/config/rewards` | Cập nhật reward rates | + +#### 📋 Quản Lý Mission + +| Phương Thức | Endpoint | Mô Tả | +|-------------|----------|-------| +| `GET` | `/api/v1/admin/missions` | Danh sách missions (phân trang) | +| `POST` | `/api/v1/admin/missions` | Tạo mission mới | +| `GET` | `/api/v1/admin/missions/{id}` | Chi tiết mission | +| `PUT` | `/api/v1/admin/missions/{id}` | Cập nhật mission | +| `DELETE` | `/api/v1/admin/missions/{id}` | Xóa mission | +| `PUT` | `/api/v1/admin/missions/{id}/activate` | Kích hoạt mission | +| `PUT` | `/api/v1/admin/missions/{id}/pause` | Tạm dừng mission | +| `POST` | `/api/v1/admin/missions/{id}/duplicate` | Nhân bản mission | + +#### 👥 Quản Lý User & Task + +| Phương Thức | Endpoint | Mô Tả | +|-------------|----------|-------| +| `GET` | `/api/v1/admin/users` | Danh sách users (phân trang) | +| `GET` | `/api/v1/admin/users/{id}` | Chi tiết user | +| `GET` | `/api/v1/admin/users/{id}/tasks` | Tasks của user | +| `GET` | `/api/v1/admin/users/{id}/checkin` | Check-in history của user | +| `PUT` | `/api/v1/admin/users/{id}/reset-streak` | Reset streak user | +| `PUT` | `/api/v1/admin/users/{id}/adjust-points` | Điều chỉnh điểm user | +| `GET` | `/api/v1/admin/tasks` | Danh sách tasks (phân trang) | +| `GET` | `/api/v1/admin/tasks/{id}` | Chi tiết task | +| `PUT` | `/api/v1/admin/tasks/{id}/verify` | Xác thực task thủ công | +| `PUT` | `/api/v1/admin/tasks/{id}/reject` | Từ chối task | +| `PUT` | `/api/v1/admin/tasks/{id}/approve` | Duyệt task | + +#### 📊 Phân Tích & Báo Cáo + +| Phương Thức | Endpoint | Mô Tả | +|-------------|----------|-------| +| `GET` | `/api/v1/admin/analytics/overview` | Tổng quan dashboard | +| `GET` | `/api/v1/admin/analytics/missions` | Thống kê mission | +| `GET` | `/api/v1/admin/analytics/checkin` | Thống kê check-in | +| `GET` | `/api/v1/admin/analytics/rewards` | Thống kê phần thưởng | +| `GET` | `/api/v1/admin/analytics/users` | Thống kê người dùng | +| `GET` | `/api/v1/admin/audit-logs` | Nhật ký thay đổi cấu hình | + +--- + +## Điểm Tích Hợp + +### Phụ Thuộc Dịch Vụ + +```mermaid +%%{init: {'theme':'dark'}}%% +flowchart LR + subgraph Mission["📋 Mission Service"] + M[Mission Service] + end + + subgraph Auth["🔐 Xác Thực"] + IAM[IAM Service] + end + + subgraph Rewards["💰 Phần Thưởng"] + Wallet[Wallet Service] + Mining[Mining Service] + end + + subgraph Social["👥 Mạng Xã Hội"] + SocialSvc[Social Service] + Storage[Storage Service] + end + + IAM -->|JWT Auth| M + M -->|Cấp Điểm| Wallet + M <-->|Đồng Bộ Referral| Mining + M <-->|Kiểm Tra Bạn Bè| SocialSvc + M <-->|Media| Storage + + style Mission fill:#8E44AD,color:#ECF0F1,stroke:#7D3C98,stroke-width:3px + style Auth fill:#C0392B,color:#ECF0F1,stroke:#A93226,stroke-width:2px + style Rewards fill:#27AE60,color:#ECF0F1,stroke:#229954,stroke-width:2px + style Social fill:#3498DB,color:#ECF0F1,stroke:#2980B9,stroke-width:2px +``` + +### Integration Events + +| Sự Kiện | Nhà Xuất Bản | Người Tiêu Thụ | Mô Tả | +|---------|--------------|----------------|-------| +| `MissionCompletedEvent` | Mission | Wallet | Hoàn thành mission | +| `CheckInCompletedEvent` | Mission | Wallet | Điểm danh xong | +| `UserRegisteredEvent` | IAM | Mission | Tạo hồ sơ user | +| `ReferralActivatedEvent` | Mining | Mission | Đồng bộ mời bạn | + +--- + +## Tech Stack + +| Thành Phần | Công Nghệ | Mục Đích | +|------------|-----------|----------| +| **Framework** | .NET 10 | Framework LTS mới nhất | +| **API Layer** | Controllers + MediatR | CQRS pattern | +| **Database** | PostgreSQL + EF Core 10 | Lưu trữ dữ liệu | +| **Caching** | Redis + HybridCache | L1+L2 caching | +| **Message Queue** | RabbitMQ (MassTransit) | Integration events | +| **Scheduler** | Hangfire | Background jobs | +| **Validation** | FluentValidation | Validation request | +| **API Docs** | Swagger/OpenAPI | Tài liệu API | + +--- + +## Cấu Hình + +### Biến Môi Trường + +| Biến | Mô Tả | Bắt Buộc | +|------|-------|----------| +| `DATABASE_URL` | Kết nối PostgreSQL | Có | +| `REDIS_URL` | Kết nối Redis | Có | +| `RABBITMQ_URL` | Kết nối RabbitMQ | Có | +| `JWT_AUTHORITY` | URL phát hành JWT | Có | +| `MAX_DAILY_TASKS` | Số task tối đa/ngày | Không | + +--- + +## Bảo Mật & Chống Gian Lận + +### Phòng Chống Gian Lận + +```mermaid +%%{init: {'theme':'dark'}}%% +flowchart TD + Request([🚀 Yêu Cầu]) --> Rate{⏱️ Rate Limit} + Rate -->|Vượt Quá| Block[❌ Chặn] + Rate -->|OK| Device{🔍 Kiểm Tra Thiết Bị} + Device -->|Đáng Ngờ| Flag[⚠️ Đánh Dấu] + Device -->|OK| Verify{✅ Xác Thực Bằng Chứng} + Verify -->|Không Hợp Lệ| Reject[❌ Từ Chối] + Verify -->|Hợp Lệ| Reward[🎁 Cấp Thưởng] + + style Block fill:#C0392B,color:#ECF0F1,stroke:#A93226,stroke-width:2px + style Reject fill:#E74C3C,color:#ECF0F1,stroke:#C0392B,stroke-width:2px + style Reward fill:#27AE60,color:#ECF0F1,stroke:#229954,stroke-width:2px +``` + +| Biện Pháp | Mô Tả | +|-----------|-------| +| **Rate Limiting** | Số task tối đa mỗi ngày | +| **Cooldown** | Thời gian chờ giữa các lần hoàn thành | +| **Device Fingerprint** | Theo dõi đa tài khoản | +| **Evidence Validation** | AI + Manual review cho UGC | + +--- + +## Lộ Trình + +### Giai Đoạn 1: Core (Tuần 1-2) +- [ ] Thiết lập project +- [ ] Domain model +- [ ] Database schema + +### Giai Đoạn 2: Điểm Danh (Tuần 3) +- [ ] Check-in aggregate +- [ ] Tính toán streak +- [ ] Phần thưởng mốc + +### Giai Đoạn 3: Xem Video (Tuần 4-5) +- [ ] Loại mission video +- [ ] Theo dõi tiến độ +- [ ] Xác thực thời lượng + +### Giai Đoạn 4: Tương Tác XH (Tuần 6-7) +- [ ] Cấu hình nền tảng xã hội +- [ ] Phương thức xác thực +- [ ] Tích hợp OAuth + +### Giai Đoạn 5: Nâng Cao (Tuần 8+) +- [ ] Pay per click/upload +- [ ] Mời bạn bè +- [ ] Admin analytics