# CMS Microservice - Network & Club Commission System [![Status](https://img.shields.io/badge/Status-Production%20Ready-success)]() [![Progress](https://img.shields.io/badge/Progress-85%25-blue)]() [![MVP](https://img.shields.io/badge/MVP-100%25%20Complete-brightgreen)]() ## πŸ“Š Project Status (2025-12-01) **Overall Progress**: 85% Complete (7/10 phases) **Production Readiness**: 95% **MVP Status**: βœ… 100% Complete ### βœ… Completed Phases (7) 1. βœ… Domain Layer (Entities, Enums, Value Objects) 2. βœ… Club Membership System 3. βœ… Binary Network Tree 4. βœ… **Commission Calculation & Background Worker** (MVP) 5. βœ… Protobuf gRPC Services 6. βœ… History & Configuration Management 7. βœ… Database Migration & Seed Data ### 🟑 Partially Complete (1) - Phase 10: Withdrawal & Settlement (40%) - βœ… Commands & Database - ❌ Payment Gateway Integration ### ❌ Not Started (1) - Phase 9: Club Shop & Product Integration (0%) ### ⏸️ Postponed (1) - Phase 7: Testing (Unit, Integration, Load tests) --- ## πŸš€ Recent Updates (2025-12-01) ### Email & SMS Notifications - COMPLETED βœ… - βœ… **MailKit 4.14.1** for Email (SMTP with HTML templates) - βœ… **Kavenegar 1.2.5** for SMS (Iranian SMS gateway) - βœ… User.Email field added with migration - βœ… 3 notification types: Commission, Club activation, Errors - βœ… Persian RTL templates with rich formatting - βœ… Production configuration guide created ### Hangfire Job Scheduling - COMPLETED βœ… - βœ… Dashboard UI at `/hangfire` - βœ… Cron schedule: Sunday 00:05 UTC - βœ… SQL Server persistence - βœ… Manual trigger API endpoints - βœ… Distributed execution support ### Infrastructure Enhancements - COMPLETED βœ… - βœ… Health Check endpoints (`/health`, `/health/ready`, `/health/live`) - βœ… AlertService (structured logging for Sentry/Slack) - βœ… Retry logic (Polly 8.5.0 with exponential backoff) - βœ… WorkerExecutionLog (database audit trail) - βœ… CurrentUserService (JWT authentication context) --- ## πŸ—οΈ Architecture **Clean Architecture** with 4 layers: ``` CMSMicroservice.Domain/ # Entities, Enums, Interfaces CMSMicroservice.Application/ # CQRS (Commands, Queries, MediatR) CMSMicroservice.Infrastructure/ # DbContext, Services, Background Jobs CMSMicroservice.WebApi/ # gRPC Services, Controllers CMSMicroservice.Protobuf/ # Protocol Buffers definitions ``` **Technology Stack**: - .NET 9.0 - Entity Framework Core 9.0.11 - gRPC + JSON Transcoding - Hangfire 1.8.22 (Job Scheduling) - MediatR 13.0.0 (CQRS) - Polly 8.5.0 (Resilience) - MailKit 4.14.1 (Email) - Kavenegar 1.2.5 (SMS) - SQL Server --- ## πŸ“– Documentation - **[Implementation Progress](docs/implementation-progress.md)** - Detailed phase-by-phase progress - **[Email/SMS Configuration Guide](docs/email-sms-configuration-guide.md)** - Production setup instructions - **[Balance Calculation Logic](docs/balance-calculation-carryover-logic.md)** - Commission algorithm details - **[Binary Tree Registration](docs/binary-tree-registration-guide.md)** - Network tree guide - **[Network Club Commission System](docs/network-club-commission-system-v1.1.md)** - Full system specification --- ## πŸš€ Quick Start ### Prerequisites - .NET 9.0 SDK - SQL Server (local or remote) - (Optional) Gmail account for Email - (Optional) Kavenegar account for SMS ### 1. Clone & Build ```bash cd /home/masoud/Apps/project/FourSat/CMS/src dotnet build ``` ### 2. Configure Database Update `appsettings.json` with your SQL Server connection: ```json "ConnectionStrings": { "DefaultConnection": "Server=YOUR_SERVER;Database=Foursat_CMS;..." } ``` ### 3. Apply Migrations ```bash cd CMSMicroservice.WebApi dotnet ef database update ``` ### 4. Configure Notifications (Optional) See [Email/SMS Configuration Guide](docs/email-sms-configuration-guide.md) ### 5. Run ```bash dotnet run --urls="http://localhost:5133" ``` ### 6. Access Endpoints - **Health**: http://localhost:5133/health - **Hangfire Dashboard**: http://localhost:5133/hangfire - **gRPC**: localhost:5133 (HTTP/2) --- ## πŸ”§ Configuration ### Email (SMTP) ```json "Email": { "Enabled": true, "SmtpHost": "smtp.gmail.com", "SmtpPort": 587, "SmtpUsername": "your-email@gmail.com", "SmtpPassword": "your-gmail-app-password", "FromEmail": "noreply@foursat.com", "FromName": "FourSat CMS", "EnableSsl": true } ``` ### SMS (Kavenegar) ```json "Sms": { "Enabled": true, "Provider": "Kavenegar", "KavenegarApiKey": "YOUR_API_KEY", "Sender": "10008663" } ``` ### Background Worker ```csharp // Cron: "5 0 * * 0" = Every Sunday at 00:05 UTC RecurringJob.AddOrUpdate( "weekly-commission-calculation", job => job.ExecuteAsync(CancellationToken.None), "5 0 * * 0"); ``` --- ## πŸ§ͺ Testing ### Manual Trigger (via API) ```bash # Trigger weekly calculation immediately curl -X POST http://localhost:5133/api/admin/trigger-weekly-calculation # Trigger recurring job now curl -X POST http://localhost:5133/api/admin/trigger-recurring-job-now # Get recurring jobs status curl http://localhost:5133/api/admin/recurring-jobs-status ``` ### Health Checks ```bash curl http://localhost:5133/health # Overall health curl http://localhost:5133/health/ready # Readiness probe (K8s) curl http://localhost:5133/health/live # Liveness probe (K8s) ``` --- ## πŸ“Š What's Remaining? ### High Priority 1. **Payment Gateway Integration** (Phase 10 - 1 week) - Daya or Bank Mellat API integration - IBAN transfer automation - Admin approval UI in BackOffice 2. **Production Configuration** (30 minutes) - Gmail App Password setup - Kavenegar API key registration - Update `appsettings.Production.json` ### Medium Priority 3. **Club Shop Integration** (Phase 9 - 2 weeks) - Product catalog for club memberships - Shopping cart integration - Auto-activation on purchase ### Low Priority 4. **Testing** (Phase 7 - Postponed) - Unit tests for business logic - Integration tests for API - Load testing for background worker ### Optional Enhancements - Redis distributed locks (multi-server deployment) - Sentry error tracking (API key needed) - Slack notifications (webhook needed) - FCM push notifications --- ## 🎯 MVP Features (100% Complete) βœ… Binary network tree with automatic placement βœ… Club membership (Member/Trial) with different commission rates βœ… Weekly commission calculation (Lesser Leg algorithm) βœ… Background worker with Hangfire (cron scheduling) βœ… Balance carryover logic (rollover unused volumes) βœ… MaxWeeklyBalances cap enforcement βœ… Health check endpoints (Kubernetes-ready) βœ… Manual trigger API (admin control) βœ… Email + SMS notifications (MailKit + Kavenegar) βœ… Retry logic with exponential backoff (Polly) βœ… Audit trail (WorkerExecutionLog, History tables) βœ… Structured logging (AlertService for Sentry/Slack) βœ… JWT authentication context (CurrentUserService) --- ## πŸ‘₯ Team **Development**: FourSat Team **Last Updated**: 2025-12-01 --- ## πŸ“ License Proprietary - FourSat Company # Multi-remote push enabled