From f968a6c005cb00869cb46801d16bdd838513598e Mon Sep 17 00:00:00 2001 From: masoodafar-web Date: Wed, 18 Feb 2026 21:44:39 +0330 Subject: [PATCH] docs: move README to totalDoc, replace with placeholder --- README.md | 446 +----------------- .../appsettings.Development.json | 84 ---- 2 files changed, 2 insertions(+), 528 deletions(-) delete mode 100644 src/CMSMicroservice.WebApi/appsettings.Development.json diff --git a/README.md b/README.md index 829ad70..f542b5b 100644 --- a/README.md +++ b/README.md @@ -1,445 +1,3 @@ -# CMS Microservice - Network & Club Commission + Inventory Management System +# CMS Microservice -[![Status](https://img.shields.io/badge/Status-Active%20Development-success)]() -[![Progress](https://img.shields.io/badge/Inventory%20System-Phase%202%20Complete-blue)]() -[![Phase](https://img.shields.io/badge/Next-Business%20Services-orange)]() - -## ๐Ÿ“Š Project Status (January 2026) - -### ๐Ÿช Inventory Management System - NEW! -**Progress**: Phase 2 Complete (50%) -**Architecture**: Clean Architecture + CQRS + Repository Pattern - -#### โœ… Completed Phases -1. โœ… **Phase 1: Infrastructure & Domain Layer** - - Domain Entities: `InventoryItem`, `StockMovement`, `Warehouse` - - Domain Enums: `StockMovementType` - - EF Core Configurations with proper indexing - - Database migration applied - -2. โœ… **Phase 2: Repository Pattern & CQRS** - - Repository Interfaces & Implementations - - CQRS Commands (17 commands) - - CQRS Queries (35 queries) - - MediatR Handlers (52 handlers) - -#### ๐Ÿ”„ In Progress -3. ๐Ÿ”„ **Phase 3: Business Services Layer** -4. โณ **Phase 4: DTOs & AutoMapper** -5. โณ **Phase 5: API Controllers** - ---- - -### ๐Ÿ’ผ Commission System - Production Ready -**Progress**: 85% Complete -**MVP Status**: โœ… 100% Complete - -#### โœ… Completed Features -- โœ… Binary network tree with automatic placement -- โœ… Club membership (Member/Trial) with commission rates -- โœ… Weekly commission calculation (Lesser Leg algorithm) -- โœ… Background worker with Hangfire -- โœ… Email + SMS notifications (MailKit + Kavenegar) -- โœ… Health check endpoints (Kubernetes-ready) - -### ๐ŸŸก Partially Complete -- Phase 10: Withdrawal & Settlement (40%) - - โœ… Commands & Database - - โŒ Payment Gateway Integration - -### โŒ Not Started -- Phase 9: Club Shop & Product Integration (0%) - ---- - -## ๐Ÿš€ Recent Updates (January 2026) - -### ๐Ÿช Inventory Management System - NEW! โœ… -**Complete CQRS-based inventory management with:** - -#### Domain Layer: -- โœ… `InventoryItem` - Multi-warehouse product tracking with min/max thresholds -- โœ… `StockMovement` - Complete audit trail with 8 movement types -- โœ… `Warehouse` - Multi-location support with default warehouse - -#### Repository Pattern: -- โœ… `IInventoryItemRepository` - 25+ methods for inventory operations -- โœ… `IStockMovementRepository` - Movement tracking & analytics -- โœ… `IWarehouseRepository` - Warehouse management & statistics - -#### CQRS Commands (17 total): -- **Inventory:** Create, Update, Delete, Reserve, Release, Reduce, Increase -- **Movement:** Create, BulkCreate, Delete -- **Warehouse:** Create, Update, Delete, SetDefault, Activate, BulkCreate - -#### CQRS Queries (35 total): -- **Inventory:** GetById, Search, LowStock, OutOfStock, CheckAvailability -- **Movement:** GetHistory, GetByOrder, Search, Analytics, DailyVolume, TopMoving -- **Warehouse:** GetById, Search, GetStats, GetLowStock, GetAllStats - -#### Business Features: -- โœ… Multi-warehouse inventory management -- โœ… Stock reservation system for orders -- โœ… Automatic movement tracking -- โœ… Low stock & out-of-stock alerts -- โœ… Advanced analytics & reporting -- โœ… Bulk operations support -- โœ… Transaction-safe operations - ---- - -### 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 -โ”œโ”€โ”€ Entities/ -โ”‚ โ”œโ”€โ”€ InventoryItem.cs # NEW: Inventory tracking -โ”‚ โ”œโ”€โ”€ StockMovement.cs # NEW: Movement audit -โ”‚ โ””โ”€โ”€ Warehouse.cs # NEW: Multi-warehouse -โ”œโ”€โ”€ Enums/ -โ”‚ โ””โ”€โ”€ StockMovementType.cs # NEW: Movement types - -CMSMicroservice.Application/ # CQRS (Commands, Queries, MediatR) -โ”œโ”€โ”€ Features/ -โ”‚ โ”œโ”€โ”€ InventoryItems/ # NEW: Inventory CQRS -โ”‚ โ”‚ โ”œโ”€โ”€ Commands/ -โ”‚ โ”‚ โ”œโ”€โ”€ Queries/ -โ”‚ โ”‚ โ””โ”€โ”€ Handlers/ -โ”‚ โ”œโ”€โ”€ StockMovements/ # NEW: Movement CQRS -โ”‚ โ”‚ โ”œโ”€โ”€ Commands/ -โ”‚ โ”‚ โ”œโ”€โ”€ Queries/ -โ”‚ โ”‚ โ””โ”€โ”€ Handlers/ -โ”‚ โ””โ”€โ”€ Warehouses/ # NEW: Warehouse CQRS -โ”‚ โ”œโ”€โ”€ Commands/ -โ”‚ โ”œโ”€โ”€ Queries/ -โ”‚ โ””โ”€โ”€ Handlers/ -โ””โ”€โ”€ Common/Interfaces/ - โ””โ”€โ”€ Repositories/ # NEW: Repository interfaces - -CMSMicroservice.Infrastructure/ # DbContext, Services, Background Jobs -โ”œโ”€โ”€ Persistence/ -โ”‚ โ”œโ”€โ”€ Context/ -โ”‚ โ”œโ”€โ”€ Configurations/ # NEW: EF Core configs -โ”‚ โ”œโ”€โ”€ Repositories/ # NEW: Repository implementations -โ”‚ โ””โ”€โ”€ Migrations/ -โ””โ”€โ”€ DependencyInjection.cs # NEW: DI setup - -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 - -- **[Development Plan](docs/development-plan.md)** - NEW: Inventory system roadmap -- **[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 - ---- - -## ๐Ÿช Inventory System Usage - -### Create Warehouse -```csharp -await mediator.Send(new CreateWarehouseCommand -{ - Name = "Main Warehouse", - Code = "WH-001", - IsDefault = true, - IsActive = true -}); -``` - -### Create Inventory Item -```csharp -await mediator.Send(new CreateInventoryItemCommand -{ - ProductId = 1, - WarehouseId = 1, - Quantity = 100, - MinQuantity = 10, - MaxQuantity = 1000 -}); -``` - -### Reserve Stock for Order -```csharp -await mediator.Send(new ReserveInventoryCommand -{ - Id = inventoryId, - Quantity = 5, - OrderId = 12345 -}); -``` - -### Check Availability -```csharp -bool available = await mediator.Send( - new CheckInventoryAvailabilityQuery(inventoryId, 10)); -``` - -### Get Low Stock Alerts -```csharp -var lowStock = await mediator.Send(new GetLowStockItemsQuery -{ - WarehouseId = 1, - Count = 50 -}); -``` - -### Get Movement Analytics -```csharp -var summary = await mediator.Send(new GetMovementSummaryQuery -{ - FromDate = DateTime.Now.AddDays(-7), - ToDate = DateTime.Now -}); - -var topProducts = await mediator.Send(new GetTopMovingProductsQuery -{ - FromDate = DateTime.Now.AddDays(-30), - ToDate = DateTime.Now, - Count = 10 -}); -``` - ---- - -## ๐Ÿš€ 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? - -### ๐Ÿช Inventory System (Current Focus) -1. **Phase 3: Business Services** (In Progress) - - `IInventoryManagementService` - High-level operations - - `IStockMovementService` - Movement orchestration - - `IWarehouseService` - Warehouse business logic - - `IInventoryReportingService` - Advanced reporting - -2. **Phase 4: DTOs & AutoMapper** (Next) - - Request/Response DTOs - - AutoMapper profiles - - Validation rules - -3. **Phase 5: API Controllers** (Planned) - - `InventoryController` - REST API - - `WarehouseController` - Warehouse management - - `StockMovementController` - Movement tracking - - Swagger documentation - -### ๐Ÿ’ผ Commission System -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) - -### ๐Ÿ’ผ Commission System: -โœ… 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) - -### ๐Ÿช Inventory System (Phase 2 Complete): -โœ… Domain entities (InventoryItem, StockMovement, Warehouse) -โœ… Multi-warehouse inventory management -โœ… Stock reservation system for orders -โœ… 8 movement types with complete audit trail -โœ… Repository pattern with 25+ methods per repository -โœ… CQRS with 17 commands and 35 queries -โœ… 52 MediatR handlers with business logic -โœ… Low stock and out-of-stock alerts -โœ… Advanced analytics (top products, daily volume) -โœ… Bulk operations support -โœ… Transaction-safe operations with rollback -โœ… DI container configuration - ---- - -## ๐Ÿ‘ฅ Team - -**Development**: FourSat Team -**Last Updated**: January 2026 - ---- - -## ๐Ÿ“ License - -Proprietary - FourSat Company -# Multi-remote push enabled +Documentation moved to [totalDoc/INDEX.md](../totalDoc/INDEX.md). diff --git a/src/CMSMicroservice.WebApi/appsettings.Development.json b/src/CMSMicroservice.WebApi/appsettings.Development.json deleted file mode 100644 index 5e17cea..0000000 --- a/src/CMSMicroservice.WebApi/appsettings.Development.json +++ /dev/null @@ -1,84 +0,0 @@ -{ - "PaymentProvider": "zarinpal", - "ZarinPal": { - "MerchantId": "00000000-0000-0000-0000-000000000000", - "UseSandbox": true - }, - "CmsBaseUrl": "http://localhost:32847", - "FrontOfficeBaseUrl": "http://localhost:5268", - "JwtSecurityKey": "TvlZVx5TJaHs8e9HgUdGzhGP2CIidoI444nAj+8+g7c=", - "JwtIssuer": "https://localhost", - "JwtAudience": "https://localhost", - "JwtExpiryInDays": 5, - "ConnectionStrings": { - "DefaultConnection": "Data Source=194.5.195.53,31433; Initial Catalog=Foursat;User ID=sa;Password=87zH26nbqT;Connection Timeout=300000;MultipleActiveResultSets=True;Encrypt=False", - "providerName": "System.Data.SqlClient" - }, - "Otp": { - "Secret": "K2w8k1h1mH2Qz1kqWk0c8kQ2Pq8q9H1eE2nqN1qQ8x7M=" - }, - "Monitoring": { - "SentryEnabled": false, - "SentryDsn": "", - "SlackEnabled": false, - "SlackWebhookUrl": "", - "EmailAlertsEnabled": false, - "AdminEmails": [ - "admin@example.com" - ], - "SmsNotificationsEnabled": false, - "SmsApiKey": "", - "SmsGatewayUrl": "" - }, - "Email": { - "Enabled": true, - "SmtpHost": "smtp.gmail.com", - "SmtpPort": 587, - "SmtpUsername": "your-email@gmail.com", - "SmtpPassword": "your-app-password", - "FromEmail": "noreply@foursat.com", - "FromName": "FourSat CMS", - "EnableSsl": true - }, - "Sms": { - "Enabled": true, - "Provider": "Kavenegar", - "KavenegarApiKey": "497263626F32626A48685A6137524C4F78575A766E4C74694A556B79317648424964655030682B554545413D", - "Sender": "1000001110100" - }, - "DayaPayment": { - "BaseUrl": "https://api.daya.ir", - "ApiKey": "YOUR_DAYA_API_KEY" - }, - "DayaApi": { - "UseMock": false, - "BaseAddress": "https://Dayadiamond.ir", - "MerchantPermissionKey": "56146364$04sXjethI5WxhItR1Q9xnmFdJzl2BB8Bclsq8dAy7YVSZp3vtt-wP7ivrcCvmKLq", - "CacheDurationMinutes": 20 - }, - "Chatika": { - "Enabled": true, - "BaseUrl": "https://api.chatika.ir", - "ApiKey": "tIukvL8dnV4cB3yVWcCD9Xyfbj8rBxm5wPt2mLyJCgTsBBoMTWjt6mFEqQwpw-er" - }, - "BackgroundJobs": { - "WeeklyCommissionCalculation": { - "Enabled": true, - "CronExpression": "5 0 * * 0" - } - }, - "AllowedHosts": "*", - "Kestrel": { - "EndpointDefaults": { - "Protocols": "Http2" - } - }, - "Authentication": { - "Authority": "https://ids.domain.com/", - "Audience": "domain_api" - }, - "Seq": { - "ServerUrl": "https://seq.afrino.co", - "ApiKey": "oxpvpUzU1pZxMS4s3Fqq" - } -}