Refactor code structure for improved readability and maintainability
This commit is contained in:
@@ -0,0 +1,268 @@
|
||||
# BackOffice BFF to CMS Migration Plan
|
||||
|
||||
**هدف**: حذف BackOffice.BFF و ارتباط مستقیم BackOffice (UI) با CMS
|
||||
|
||||
**تاریخ شروع**: 2025-02-07
|
||||
**تاریخ تکمیل Build Migration**: 2025-02-08
|
||||
**وضعیت**: ✅ **Build Migration Complete** (0 errors)
|
||||
|
||||
---
|
||||
|
||||
## ✅ خلاصه اجرا
|
||||
|
||||
### استراتژی انتخابشده: Strategy C (استفاده مستقیم از Proto های CMS)
|
||||
به جای حفظ DLL های BFF، مستقیماً `CMSMicroservice.Protobuf` را به عنوان `ProjectReference` اضافه کردیم و تمام `using` ها را تغییر دادیم.
|
||||
|
||||
### نتایج:
|
||||
- ✅ تمام 208 reference از `BackOffice.BFF.*` به `CMSMicroservice.Protobuf.Protos.*` تغییر یافت
|
||||
- ✅ 24 DLL reference حذف و یک `ProjectReference` جایگزین شد
|
||||
- ✅ `appsettings.json` از BFF URL به CMS URL تغییر کرد
|
||||
- ✅ ~65 build error رفع شد
|
||||
- ✅ **Build Succeeded با 0 خطا**
|
||||
|
||||
---
|
||||
|
||||
## مراحل مهاجرت
|
||||
|
||||
### مرحله 1: مستندسازی سرویسهای BackOffice UI ✅
|
||||
- لیست تمام سرویسهای استفاده شده در UI
|
||||
- شناسایی dependency ها
|
||||
- مستندسازی هر صفحه و کامپوننت
|
||||
|
||||
### مرحله 2: مستندسازی سرویسهای BackOffice.BFF ✅
|
||||
- لیست تمام gRPC services در BFF
|
||||
- شناسایی endpoints و methods
|
||||
|
||||
### مرحله 3: تحلیل و انتخاب استراتژی ✅
|
||||
- تحلیل سه استراتژی ممکن (A, B, C)
|
||||
- انتخاب Strategy C: مستقیم از CMS protos
|
||||
|
||||
### مرحله 4: مهاجرت کد ✅
|
||||
- تغییر namespace ها (208 مورد)
|
||||
- رفع خطاهای Build (~65 خطا)
|
||||
- اصلاح proto های CMS (اضافه کردن فیلدهای مورد نیاز)
|
||||
- آپدیت مستندات
|
||||
|
||||
---
|
||||
|
||||
## 1. سرویسهای استفاده شده در BackOffice UI
|
||||
|
||||
### 1.1 Services مستقیماً از CMS (gRPC Clients)
|
||||
|
||||
| Service | Usage Count | Pages/Components |
|
||||
|---------|-------------|------------------|
|
||||
| `CategoryContract.CategoryContractClient` | 4 | CategoryMultiSelectAutoComplete, CategoryMultiSelectCombo, CategoryAutoComplete |
|
||||
| `RoleContract.RoleContractClient` | 3 | RoleAutoComplete, RoleTitleColumn, UserRoleDialog |
|
||||
| `ProductsContract.ProductsContractClient` | 1 | ProductsAutoComplete |
|
||||
| `UserRoleContract.UserRoleContractClient` | 1 | UserRoleDialog |
|
||||
|
||||
### 1.2 Services از طریق BFF (Interface-based)
|
||||
|
||||
| Service Interface | Implementation | Purpose |
|
||||
|-------------------|----------------|---------|
|
||||
| `ITagService` | BFF → CMS | مدیریت تگها |
|
||||
| `IDiscountCategoryService` | BFF → CMS | دستهبندیهای تخفیف |
|
||||
| `IPersianDateTimeService` | BFF Local | تبدیل تاریخ شمسی |
|
||||
|
||||
### 1.3 صفحات اصلی BackOffice
|
||||
|
||||
```
|
||||
BackOffice/Pages/
|
||||
├── Dashboard/ - داشبورد اصلی
|
||||
├── User/ - مدیریت کاربران
|
||||
├── UserRole/ - نقشهای کاربری
|
||||
├── Role/ - مدیریت نقشها
|
||||
├── Category/ - دستهبندی محصولات
|
||||
├── Products/ - محصولات
|
||||
├── Package/ - پکیجها
|
||||
├── Tag/ - تگها
|
||||
├── UserOrder/ - سفارشات
|
||||
├── UserAddress/ - آدرسها
|
||||
├── Inventory/ - انبار
|
||||
├── Payment/ - پرداختها
|
||||
├── DiscountShop/ - فروشگاه تخفیف
|
||||
├── Commission/ - کمیسیون
|
||||
├── Network/ - شبکه
|
||||
├── Club/ - باشگاه مشتریان
|
||||
├── PublicMessages/ - پیامهای عمومی
|
||||
├── Settings/ - تنظیمات
|
||||
└── SystemManagement/ - مدیریت سیستم
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 2. سرویسهای BackOffice.BFF
|
||||
|
||||
### 2.1 لیست کامل gRPC Services در BFF
|
||||
|
||||
| # | Service | Proto File | Status | CMS Equivalent |
|
||||
|---|---------|------------|--------|----------------|
|
||||
| 1 | CategoryService | category.proto | ✅ Migrated | CMSMicroservice.Protobuf.Protos.Category |
|
||||
| 2 | ProductsService | products.proto | ✅ Migrated | CMSMicroservice.Protobuf.Protos.Products |
|
||||
| 3 | TagService | tag.proto | ✅ Migrated | CMSMicroservice.Protobuf.Protos.Tag |
|
||||
| 4 | ProductTagService | producttag.proto | ✅ Migrated | CMSMicroservice.Protobuf.Protos.ProductTag |
|
||||
| 5 | UserService | user.proto | ✅ Migrated | CMSMicroservice.Protobuf.Protos.User |
|
||||
| 6 | RoleService | role.proto | ✅ Migrated | CMSMicroservice.Protobuf.Protos.Role |
|
||||
| 7 | UserRoleService | userrole.proto | ✅ Migrated | CMSMicroservice.Protobuf.Protos.UserRole |
|
||||
| 8 | UserAddressService | useraddress.proto | ✅ Migrated | CMSMicroservice.Protobuf.Protos.UserAddress |
|
||||
| 9 | UserOrderService | userorder.proto | ✅ Migrated | CMSMicroservice.Protobuf.Protos.UserOrder |
|
||||
| 10 | InventoryService | inventory.proto | ✅ Migrated | CMSMicroservice.Protobuf.Protos.Inventory |
|
||||
| 11 | DiscountProductService | discountproduct.proto | ✅ Migrated | CMSMicroservice.Protobuf.Protos.DiscountProduct |
|
||||
| 12 | DiscountOrderService | discountorder.proto | ✅ Migrated | CMSMicroservice.Protobuf.Protos.DiscountOrder |
|
||||
| 13 | DiscountShoppingCartService | discountshoppingcart.proto | ✅ Migrated | CMSMicroservice.Protobuf.Protos.DiscountCategory |
|
||||
| 14 | CommissionService | commission.proto | ✅ Migrated | CMSMicroservice.Protobuf.Protos.Commission |
|
||||
| 15 | NetworkMembershipService | networkmembership.proto | ✅ Migrated | CMSMicroservice.Protobuf.Protos.NetworkMembership |
|
||||
| 16 | ClubMembershipService | clubmembership.proto | ✅ Migrated | CMSMicroservice.Protobuf.Protos.ClubMembership |
|
||||
| 17 | PublicMessageService | publicmessage.proto | ✅ Migrated | CMSMicroservice.Protobuf.Protos (PublicMessage) |
|
||||
| 18 | ConfigurationService | configuration.proto | ✅ Migrated | CMSMicroservice.Protobuf.Protos.Configuration |
|
||||
| 19 | OtpService | otp.proto | ✅ Migrated | CMSMicroservice.Protobuf.Protos.OtpToken |
|
||||
| 20 | HealthService | health.proto | ✅ Migrated | CMSMicroservice.Protobuf.Protos.Health |
|
||||
|
||||
**Status Legend:**
|
||||
- ✅ Migrated to CMS (Build compiles successfully)
|
||||
|
||||
---
|
||||
|
||||
## 3. منطق و Business Logic سرویسها
|
||||
|
||||
### 3.1 CategoryService
|
||||
|
||||
**Path**: `BackOffice.BFF/src/BackOffice.BFF.WebApi/Services/CategoryService.cs`
|
||||
|
||||
#### Methods:
|
||||
- `GetAllCategories()` - دریافت تمام دستهبندیها
|
||||
- `GetCategory(id)` - دریافت یک دستهبندی
|
||||
- `CreateCategory()` - ایجاد دستهبندی جدید
|
||||
- `UpdateCategory()` - ویرایش دستهبندی
|
||||
- `DeleteCategory()` - حذف دستهبندی
|
||||
|
||||
#### Business Logic:
|
||||
```
|
||||
[در انتظار تحلیل دقیق]
|
||||
```
|
||||
|
||||
#### Dependencies:
|
||||
- CMS CategoryContract
|
||||
|
||||
---
|
||||
|
||||
### 3.2 TagService
|
||||
|
||||
**Path**: `BackOffice.BFF/src/BackOffice.BFF.WebApi/Services/TagService.cs`
|
||||
|
||||
#### Methods:
|
||||
[در انتظار تحلیل]
|
||||
|
||||
#### Business Logic:
|
||||
[در انتظار تحلیل]
|
||||
|
||||
---
|
||||
|
||||
## 4. پیشرفت مهاجرت
|
||||
|
||||
### Services Migration Progress: 20/20 (100%) ✅
|
||||
|
||||
| Service | Analysis | Implementation | Testing | Docs Updated | Completed |
|
||||
|---------|----------|----------------|---------|--------------|-----------|
|
||||
| CategoryService | ✅ | ✅ | ⬜ | ✅ | ✅ |
|
||||
| ProductsService | ✅ | ✅ | ⬜ | ✅ | ✅ |
|
||||
| TagService | ✅ | ✅ | ⬜ | ✅ | ✅ |
|
||||
| ProductTagService | ✅ | ✅ | ⬜ | ✅ | ✅ |
|
||||
| UserService | ✅ | ✅ | ⬜ | ✅ | ✅ |
|
||||
| RoleService | ✅ | ✅ | ⬜ | ✅ | ✅ |
|
||||
| UserRoleService | ✅ | ✅ | ⬜ | ✅ | ✅ |
|
||||
| UserAddressService | ✅ | ✅ | ⬜ | ✅ | ✅ |
|
||||
| UserOrderService | ✅ | ✅ | ⬜ | ✅ | ✅ |
|
||||
| InventoryService | ✅ | ✅ | ⬜ | ✅ | ✅ |
|
||||
| DiscountProductService | ✅ | ✅ | ⬜ | ✅ | ✅ |
|
||||
| DiscountOrderService | ✅ | ✅ | ⬜ | ✅ | ✅ |
|
||||
| CommissionService | ✅ | ✅ | ⬜ | ✅ | ✅ |
|
||||
| NetworkMembershipService | ✅ | ✅ | ⬜ | ✅ | ✅ |
|
||||
| ClubMembershipService | ✅ | ✅ | ⬜ | ✅ | ✅ |
|
||||
| PublicMessageService | ✅ | ✅ | ⬜ | ✅ | ✅ |
|
||||
| ConfigurationService | ✅ | ✅ | ⬜ | ✅ | ✅ |
|
||||
| OtpService | ✅ | ✅ | ⬜ | ✅ | ✅ |
|
||||
| HealthService | ✅ | ✅ | ⬜ | ✅ | ✅ |
|
||||
| AppVersionService | ✅ | ✅ | ⬜ | ✅ | ✅ |
|
||||
|
||||
> ⚠️ **توجه**: ستون Testing هنوز انجام نشده - تست Runtime باید انجام شود.
|
||||
|
||||
---
|
||||
|
||||
## 5. تغییرات اعمالشده
|
||||
|
||||
### 5.1 تغییرات اصلی
|
||||
- **csproj**: حذف 24 رفرنس DLL و اضافه کردن یک `ProjectReference` به `CMSMicroservice.Protobuf.csproj`
|
||||
- **appsettings.json**: تغییر `GwUrl` از `https://backoffice-bff.se.kbs1.ir` به `https://cms.se.kbs1.ir`
|
||||
- **ConfigureService.cs**: تغییر تمام 24 `using` و اصلاح نام contract ها (`OtpContract` → `OtpTokenContract`, `InventoryBFFContract` → `InventoryContract`)
|
||||
- **208 فایل**: تغییر namespace از `BackOffice.BFF.*` به `CMSMicroservice.Protobuf.Protos.*`
|
||||
|
||||
### 5.2 تغییرات Proto های CMS
|
||||
فیلدهای زیر به proto های CMS اضافه شدند (چون BackOffice UI به آنها نیاز داشت):
|
||||
|
||||
| Proto File | Field Added | Message |
|
||||
|-----------|------------|---------|
|
||||
| `products.proto` | `ImageFileModel image_file`, `ImageFileModel thumbnail_file` | CreateNewProductsRequest, UpdateProductsRequest |
|
||||
| `inventory.proto` | `bool is_low_stock = 18` | InventoryItemDto |
|
||||
| `discountproduct.proto` | `ImageFileModel` message + fields | CreateDiscountProductRequest, UpdateDiscountProductRequest |
|
||||
| `package.proto` | `BoostCardFileModel` message + fields | CreateNewPackageRequest, UpdatePackageRequest |
|
||||
| `manualpayment.proto` | `FileUploadModel` message + fields | CreateManualPaymentRequest |
|
||||
|
||||
### 5.3 تغییرات خاص فیلد/منطق
|
||||
|
||||
| فایل | تغییر |
|
||||
|------|------|
|
||||
| LoginPage.razor.cs | `SendOtpRequest` → `CreateNewOtpTokenRequest` + `Purpose = "login"` |
|
||||
| VerifyCodePage.razor.cs | `VerifyOtpCodeRequest` → `VerifyOtpTokenRequest` + verify via `UserClient` |
|
||||
| PublicMessageService.cs | بازنویسی کامل: `MessageId`→`Id`, `MessageType`→`Type`, `Status`→`IsActive`, `TotalCount`→`MetaData.TotalCount` |
|
||||
| UserPayouts.razor.cs | تغییر از nested `PaginationState`/`GetUserPayoutsFilter` به فیلدهای flat |
|
||||
| Configuration.razor | تغییر از `PageIndex`/`PageSize` به nested `PaginationState` |
|
||||
| HealthDashboard.razor | `GetSystemHealthRequest` → `google.protobuf.Empty` + `HealthStatus` enum handling |
|
||||
| NetworkTreeViewer.razor | `ActivationWeekDefinitionId` از `long?` به `string` (StringValue) |
|
||||
| PayoutDetailsDialog.razor | `Payout.LastModified` → `Payout.Created` (CMS فیلد LastModified ندارد) |
|
||||
| UserOrderDetailsDialog.razor | VAT فیلدها از flat به nested `VatInfo.*` |
|
||||
| AppVersionService.cs | حذف wrapper `Item` و تغییر فیلدهای response |
|
||||
| ManualPayments.razor | `GetManualPaymentsRequest` → `GetAllManualPaymentsRequest` + enum casts |
|
||||
| UserOrderMainPage.razor.cs | `PaymentStatus`/`DeliveryStatus`/`PaymentMethod` enum casts + `Clear*Item()` |
|
||||
|
||||
### 5.4 نکات فنی
|
||||
- BackOffice UI از gRPC Web استفاده میکند
|
||||
- Proto codegen rule: مقادیر enum با prefix، prefix آنها در C# حذف میشود (مثلاً `DeliveryStatus_Pending` → `DeliveryStatus.Pending`)
|
||||
- الگوی `oneof` در CMS: `oneof PaymentStatus_item { ... }` → property accessor مستقیم `PaymentStatus`
|
||||
|
||||
### 5.5 چالشها و حلشدهها
|
||||
- ✅ Authentication/Authorization: CMS از IdentityServer استفاده میکند
|
||||
- ✅ Proto incompatibility: فیلدهای جدید به CMS protos اضافه شدند
|
||||
- ✅ Nested vs Flat field pattern: هر سرویس به الگوی CMS proto خودش تبدیل شد
|
||||
- ✅ Enum handling: Cast های صریح اضافه شدند
|
||||
|
||||
### 5.6 مزایای حاصلشده
|
||||
- کاهش latency (حذف یک لایه میانی BFF)
|
||||
- سادهتر شدن معماری
|
||||
- کاهش هزینه deployment (یک سرویس کمتر)
|
||||
- بهبود performance
|
||||
|
||||
---
|
||||
|
||||
## 6. مراحل بعدی
|
||||
|
||||
### Immediate Next Steps:
|
||||
1. ✅ ایجاد این مستند
|
||||
2. ✅ تحلیل دقیق هر service در BFF
|
||||
3. ✅ مهاجرت namespace ها (208 مورد)
|
||||
4. ✅ رفع خطاهای Build (~65 خطا)
|
||||
5. ✅ Build Succeeded با 0 خطا
|
||||
6. ⏳ **تست Runtime** - deploy و تست عملکرد واقعی هر صفحه
|
||||
7. ⏳ **بررسی CMS backend** - فیلدهای جدید اضافهشده به proto ها نیاز به handler در CMS دارند
|
||||
8. ⏳ **حذف BackOffice.BFF** - بعد از تست موفق، سرویس BFF از deployment حذف شود
|
||||
|
||||
### ⚠️ نکات مهم برای Runtime:
|
||||
- فیلدهایی مثل `is_low_stock` در Inventory و `image_file`/`thumbnail_file` در Products فقط در proto اضافه شدهاند
|
||||
- CMS backend باید handler آنها را برای populate کردن داده پیادهسازی کند
|
||||
- فیلدهای PublicMessage (`IsDismissible`, `TargetAudience`, `Tags`) در CMS وجود ندارند و به مقادیر default تنظیم شدهاند
|
||||
|
||||
---
|
||||
|
||||
**Last Updated**: 2025-02-08
|
||||
**Document Version**: 2.0
|
||||
**Status**: ✅ Build Migration Complete - Runtime Testing Pending
|
||||
@@ -0,0 +1,483 @@
|
||||
# 📋 لیست کامل جداول و Mapping ها
|
||||
|
||||
## تعداد کل: 33 جدول
|
||||
|
||||
### جداول با تغییر نام (10 جدول)
|
||||
|
||||
این جداول در دیتابیس قدیمی نامگذاری اشتباه دارند و در دیتابیس جدید اصلاح میشوند:
|
||||
|
||||
| # | نام قدیمی (Source) | نام جدید (Target) | دلیل تغییر |
|
||||
|---|-------------------|-------------------|-----------|
|
||||
| 1 | `Categorys` | `Categories` | جمع صحیح Category |
|
||||
| 2 | `FactorDetailss` | `FactorDetails` | Detail تکی نیست، s اضافی |
|
||||
| 3 | `ProductGalleryss` | `ProductGalleries` | Gallery → Galleries، s اضافی |
|
||||
| 4 | `ProductImagess` | `ProductImages` | Image → Images، s اضافی |
|
||||
| 5 | `Productss` | `Products` | s اضافی |
|
||||
| 6 | `PruductCategorys` | `ProductCategories` | Pruduct → Product + جمع صحیح |
|
||||
| 7 | `PruductTags` | `ProductTags` | Pruduct → Product |
|
||||
| 8 | `Transactionss` | `Transactions` | s اضافی |
|
||||
| 9 | `UserAddresss` | `UserAddresses` | Address → Addresses، s اضافی |
|
||||
| 10 | `UserCartss` | `UserCarts` | s اضافی |
|
||||
|
||||
---
|
||||
|
||||
### جداول بدون تغییر نام (23 جدول)
|
||||
|
||||
این جداول نامگذاری صحیحی دارند:
|
||||
|
||||
| # | نام جدول |
|
||||
|---|----------|
|
||||
| 1 | `ClubFeatures` |
|
||||
| 2 | `ClubMembershipHistories` |
|
||||
| 3 | `ClubMemberships` |
|
||||
| 4 | `CommissionPayoutHistories` |
|
||||
| 5 | `Contracts` |
|
||||
| 6 | `NetworkMembershipHistories` |
|
||||
| 7 | `NetworkWeeklyBalances` |
|
||||
| 8 | `OtpTokens` |
|
||||
| 9 | `Packages` |
|
||||
| 10 | `Roles` |
|
||||
| 11 | `SystemConfigurationHistories` |
|
||||
| 12 | `SystemConfigurations` |
|
||||
| 13 | `Tags` |
|
||||
| 14 | `UserClubFeatures` |
|
||||
| 15 | `UserCommissionPayouts` |
|
||||
| 16 | `UserContracts` |
|
||||
| 17 | `UserOrders` |
|
||||
| 18 | `UserRoles` |
|
||||
| 19 | `Users` |
|
||||
| 20 | `UserWalletChangeLogs` |
|
||||
| 21 | `UserWallets` |
|
||||
| 22 | `WeeklyCommissionPools` |
|
||||
| 23 | `WorkerExecutionLogs` |
|
||||
|
||||
---
|
||||
|
||||
## ترتیب پیشنهادی برای Migration
|
||||
|
||||
### مرحله 1: جداول پایه (Independent Tables)
|
||||
بدون FK، میتوانند اول migrate شوند:
|
||||
|
||||
1. `Roles`
|
||||
2. `Tags`
|
||||
3. `SystemConfigurations`
|
||||
4. `ClubFeatures`
|
||||
5. `Packages`
|
||||
|
||||
### مرحله 2: جداول کاربری
|
||||
FK به Users:
|
||||
|
||||
6. `Users` ⚠️ **مهم**: پس از migration → Post-Migration Transformation
|
||||
7. `OtpTokens`
|
||||
8. `UserRoles`
|
||||
9. `UserWallets`
|
||||
10. `UserWalletChangeLogs`
|
||||
11. `UserAddresses`
|
||||
12. `UserCarts`
|
||||
|
||||
### مرحله 3: جداول محصولات
|
||||
FK به Categories و Products:
|
||||
|
||||
13. `Categories`
|
||||
14. `Products`
|
||||
15. `ProductImages`
|
||||
16. `ProductGalleries`
|
||||
17. `ProductCategories`
|
||||
18. `ProductTags`
|
||||
|
||||
### مرحله 4: جداول عضویت و کمیسیون
|
||||
|
||||
19. `ClubMemberships`
|
||||
20. `ClubMembershipHistories`
|
||||
21. `NetworkWeeklyBalances`
|
||||
22. `NetworkMembershipHistories`
|
||||
23. `CommissionPayoutHistories`
|
||||
24. `UserCommissionPayouts`
|
||||
25. `WeeklyCommissionPools`
|
||||
|
||||
### مرحله 5: جداول قراردادها و تراکنشها
|
||||
|
||||
26. `Contracts`
|
||||
27. `UserContracts`
|
||||
28. `Transactions`
|
||||
29. `FactorDetails`
|
||||
|
||||
### مرحله 6: جداول کاربری پیشرفته
|
||||
|
||||
30. `UserOrders`
|
||||
31. `UserClubFeatures`
|
||||
|
||||
### مرحله 7: جداول سیستمی
|
||||
|
||||
32. `SystemConfigurationHistories`
|
||||
33. `WorkerExecutionLogs`
|
||||
|
||||
---
|
||||
|
||||
## تغییرات ساختاری مهم
|
||||
|
||||
### 1. Users Table
|
||||
**تبدیل Binary Tree:**
|
||||
- **قدیمی**: `ParentId` (یک Parent ساده)
|
||||
- **جدید**: `NetworkParentId` + `LegPosition` (Binary Tree)
|
||||
|
||||
**Post-Migration Script:**
|
||||
```sql
|
||||
-- Script: Scripts/PostMigration_DataTransformation.sql
|
||||
-- اجرا: خودکار بعد از migration (اگر RunPostMigrationTransformation=true)
|
||||
```
|
||||
|
||||
**چه کاری انجام میدهد:**
|
||||
1. ✅ بررسی: آیا Parent ها بیشتر از 2 فرزند دارند؟ (ROLLBACK اگر دارند)
|
||||
2. ✅ کپی: `ParentId` → `NetworkParentId`
|
||||
3. ✅ تخصیص: `LegPosition` (فرزند اول=Left, فرزند دوم=Right)
|
||||
4. ✅ حل Orphan ها: Parent نداشته → `NetworkParentId=NULL`
|
||||
5. ✅ Validation نهایی: Binary Tree درست است؟
|
||||
6. ✅ آمار: تعداد کل، Left/Right distribution
|
||||
|
||||
---
|
||||
|
||||
## Configuration در appsettings.json
|
||||
|
||||
```json
|
||||
{
|
||||
"TableMappings": {
|
||||
"Categorys": "Categories",
|
||||
"ClubFeatures": "ClubFeatures",
|
||||
"ClubMembershipHistories": "ClubMembershipHistories",
|
||||
"ClubMemberships": "ClubMemberships",
|
||||
"CommissionPayoutHistories": "CommissionPayoutHistories",
|
||||
"Contracts": "Contracts",
|
||||
"FactorDetailss": "FactorDetails",
|
||||
"NetworkMembershipHistories": "NetworkMembershipHistories",
|
||||
"NetworkWeeklyBalances": "NetworkWeeklyBalances",
|
||||
"OtpTokens": "OtpTokens",
|
||||
"Packages": "Packages",
|
||||
"ProductGalleryss": "ProductGalleries",
|
||||
"ProductImagess": "ProductImages",
|
||||
"Productss": "Products",
|
||||
"PruductCategorys": "ProductCategories",
|
||||
"PruductTags": "ProductTags",
|
||||
"Roles": "Roles",
|
||||
"SystemConfigurationHistories": "SystemConfigurationHistories",
|
||||
"SystemConfigurations": "SystemConfigurations",
|
||||
"Tags": "Tags",
|
||||
"Transactionss": "Transactions",
|
||||
"UserAddresss": "UserAddresses",
|
||||
"UserCartss": "UserCarts",
|
||||
"UserClubFeatures": "UserClubFeatures",
|
||||
"UserCommissionPayouts": "UserCommissionPayouts",
|
||||
"UserContracts": "UserContracts",
|
||||
"UserOrders": "UserOrders",
|
||||
"UserRoles": "UserRoles",
|
||||
"Users": "Users",
|
||||
"UserWalletChangeLogs": "UserWalletChangeLogs",
|
||||
"UserWallets": "UserWallets",
|
||||
"WeeklyCommissionPools": "WeeklyCommissionPools",
|
||||
"WorkerExecutionLogs": "WorkerExecutionLogs"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## چکلیست قبل از Migration
|
||||
|
||||
### 1. ساختار Target Database
|
||||
- [ ] همه 33 جدول در Target ایجاد شدهاند
|
||||
- [ ] Schema صحیح است: `[CMS].[TableName]`
|
||||
- [ ] Column ها مطابقت دارند
|
||||
- [ ] `Users` دارای `NetworkParentId` و `LegPosition` است
|
||||
|
||||
### 2. Connection Strings
|
||||
- [ ] `SourceDatabase`: IP, Port, Username, Password صحیح
|
||||
- [ ] `TargetDatabase`: IP, Port, Username, Password صحیح
|
||||
- [ ] Firewall: IP شما مجاز است
|
||||
- [ ] SQL User دسترسی `db_datareader` (Source) دارد
|
||||
- [ ] SQL User دسترسی `db_datawriter` (Target) دارد
|
||||
|
||||
### 3. تنظیمات Migration
|
||||
- [ ] `BatchSize`: مناسب با Network شما
|
||||
- [ ] `MaxConcurrentTables`: 3 (پیشنهادی)
|
||||
- [ ] `RunPostMigrationTransformation`: true
|
||||
- [ ] `TableMappings`: همه 33 جدول لیست شده
|
||||
|
||||
### 4. Backup
|
||||
- [ ] ⚠️ **حتماً** Target Database را Backup بگیرید
|
||||
- [ ] فضای کافی روی Disk دارید
|
||||
|
||||
---
|
||||
|
||||
## آمار تخمینی
|
||||
|
||||
بر اساس backup file (`dbbkup/CMS.sql`):
|
||||
|
||||
| دسته | تعداد جداول | تخمین رکوردها |
|
||||
|------|------------|---------------|
|
||||
| **Core** (Users, Roles, etc.) | 5 | ~2,000 |
|
||||
| **Products** (Categories, Products, etc.) | 8 | ~5,000 |
|
||||
| **Club & Network** | 7 | ~10,000 |
|
||||
| **Transactions & Orders** | 6 | ~20,000 |
|
||||
| **System & Logs** | 7 | ~15,000 |
|
||||
| **جمع کل** | **33** | **~50,000+** |
|
||||
|
||||
**زمان تخمینی:** 5-10 دقیقه (بسته به Network)
|
||||
|
||||
---
|
||||
|
||||
**نسخه:** 1.0
|
||||
**تاریخ:** December 6, 2025
|
||||
**وضعیت:** ✅ آماده برای Production
|
||||
|
||||
---
|
||||
|
||||
## Post-Migration Binary Tree Transformation
|
||||
|
||||
> Merged from `DataMigration/POST-MIGRATION-TRANSFORMATION.md`
|
||||
|
||||
## تغییرات اعمال شده
|
||||
|
||||
### 1. اضافه شدن SQL Script
|
||||
|
||||
**فایل**: `Scripts/PostMigration_DataTransformation.sql`
|
||||
|
||||
این اسکریپت **بعد از migration دادهها** اجرا میشود و تبدیلات زیر را انجام میدهد:
|
||||
|
||||
#### تبدیل Users Table: `ParentId` → `NetworkParentId + LegPosition`
|
||||
|
||||
**مراحل:**
|
||||
|
||||
1. **Validation**: بررسی کاربرانی که بیشتر از 2 فرزند دارند (❌ برای binary tree نامعتبر)
|
||||
2. **Copy**: کپی `ParentId` به `NetworkParentId`
|
||||
3. **Assign LegPosition**:
|
||||
- فرزند اول → Left (0)
|
||||
- فرزند دوم → Right (1)
|
||||
4. **Orphan Detection**: پیدا کردن کاربرانی که Parent آنها وجود ندارد
|
||||
5. **Final Validation**: تایید یکپارچگی binary tree (هر Parent حداکثر 2 فرزند)
|
||||
6. **Statistics**: آمار نهایی
|
||||
|
||||
---
|
||||
|
||||
## جریان کار Migration (بروزرسانی شده)
|
||||
|
||||
```
|
||||
1. خواندن تنظیمات
|
||||
↓
|
||||
2. اتصال به Source و Target databases
|
||||
↓
|
||||
3. کشف و نگاشت جداول (Table Mappings)
|
||||
↓
|
||||
4. Migration دادهها (Batch Processing + Retry)
|
||||
↓
|
||||
5. گزارش نتایج Migration
|
||||
↓
|
||||
6. ✨ Post-Migration Transformation (جدید!)
|
||||
├─ اجرای Scripts/PostMigration_DataTransformation.sql
|
||||
├─ تبدیل ParentId → NetworkParentId
|
||||
├─ تخصیص LegPosition
|
||||
├─ Validation
|
||||
└─ Log نتایج
|
||||
↓
|
||||
7. پایان
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## تنظیمات جدید
|
||||
|
||||
### `appsettings.json`
|
||||
|
||||
```json
|
||||
{
|
||||
"MigrationSettings": {
|
||||
...
|
||||
"RunPostMigrationTransformation": true // ✨ جدید
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**گزینهها:**
|
||||
- `true` (پیشفرض): اسکریپت تبدیل بعد از migration اجرا میشود
|
||||
- `false`: فقط migration دادهها انجام میشود (تبدیل دستی)
|
||||
|
||||
---
|
||||
|
||||
## خروجی Migration
|
||||
|
||||
### قبل:
|
||||
```
|
||||
[12:35:42 INF] === Migration Complete ===
|
||||
[12:35:42 INF] Success: 33 tables, 50,000+ records
|
||||
[12:35:42 INF] Failed: 0 tables
|
||||
[12:35:42 INF] Duration: 00:05:27
|
||||
```
|
||||
|
||||
### بعد (با Transformation):
|
||||
```
|
||||
[12:35:42 INF] === Migration Complete ===
|
||||
[12:35:42 INF] Success: 33 tables, 50,000+ records
|
||||
[12:35:42 INF] Failed: 0 tables
|
||||
[12:35:42 INF] Duration: 00:05:27
|
||||
|
||||
[12:35:42 INF] === Starting Post-Migration Data Transformation ===
|
||||
[12:35:43 INF] Executing post-migration transformation script...
|
||||
[12:35:43 INF] SQL: === Starting Post-Migration Data Transformation ===
|
||||
[12:35:43 INF] SQL: Step 1: Validating Users for binary tree conversion...
|
||||
[12:35:44 INF] SQL: Step 2: Copying ParentId → NetworkParentId...
|
||||
[12:35:44 INF] SQL: - Updated: 1,250 users
|
||||
[12:35:44 INF] SQL: Step 3: Assigning LegPosition (Left/Right)...
|
||||
[12:35:45 INF] SQL: - Updated: 1,250 users
|
||||
[12:35:45 INF] SQL: Step 4: Checking for orphaned nodes...
|
||||
[12:35:45 INF] SQL: - No orphaned nodes found
|
||||
[12:35:45 INF] SQL: Step 5: Verifying binary tree integrity...
|
||||
[12:35:45 INF] SQL: - Binary tree integrity: OK
|
||||
[12:35:45 INF] SQL: Step 6: Migration Statistics:
|
||||
[12:35:46 INF] SQL: === Post-Migration Data Transformation Complete ===
|
||||
[12:35:46 INF] Post-migration transformation completed successfully
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Validation Checks
|
||||
|
||||
### 1. Binary Tree Violation Check
|
||||
|
||||
اگر کاربری بیشتر از 2 فرزند داشته باشد:
|
||||
|
||||
```
|
||||
ERROR: Cannot proceed with binary tree migration. Please resolve manually.
|
||||
|
||||
ParentId ChildCount ChildIds
|
||||
-------- ---------- ----------
|
||||
12345 3 67890, 67891, 67892
|
||||
```
|
||||
|
||||
**راه حل دستی:**
|
||||
1. تصمیم بگیرید کدام 2 فرزند در binary tree بمانند
|
||||
2. فرزند سوم را به Parent دیگری منتقل کنید
|
||||
3. Migration را دوباره اجرا کنید
|
||||
|
||||
### 2. Orphaned Nodes Detection
|
||||
|
||||
اگر Parent کاربر وجود نداشته باشد:
|
||||
|
||||
```
|
||||
WARNING: Found orphaned nodes (parent does not exist)!
|
||||
|
||||
Id NetworkParentId Issue
|
||||
----- --------------- -----------------------------
|
||||
99999 88888 Orphaned: Parent does not exist
|
||||
```
|
||||
|
||||
**راه حل خودکار:**
|
||||
- اسکریپت این کاربران را به `NetworkParentId = NULL` تبدیل میکند (root level)
|
||||
|
||||
---
|
||||
|
||||
## خطاها و عیبیابی
|
||||
|
||||
### خطا: "Post-migration script not found"
|
||||
|
||||
```
|
||||
[12:35:46 WRN] Post-migration script not found: /path/to/Scripts/PostMigration_DataTransformation.sql
|
||||
[12:35:46 INF] Skipping data transformation. Users table will need manual ParentId→NetworkParentId migration.
|
||||
```
|
||||
|
||||
**راه حل:**
|
||||
- Script را manually اجرا کنید از SQL Server Management Studio
|
||||
- یا فایل را در مسیر `Scripts/` قرار دهید و دوباره اجرا کنید
|
||||
|
||||
### خطا: "Binary tree integrity violation"
|
||||
|
||||
```
|
||||
ERROR: Binary tree integrity violation! Some parents have more than 2 children.
|
||||
```
|
||||
|
||||
**راه حل:**
|
||||
1. Query زیر را اجرا کنید تا والدین مشکلدار را ببینید:
|
||||
```sql
|
||||
SELECT
|
||||
ParentId,
|
||||
COUNT(*) as ChildCount,
|
||||
STRING_AGG(CAST(Id AS VARCHAR), ', ') as ChildIds
|
||||
FROM [CMS].[Users]
|
||||
WHERE ParentId IS NOT NULL
|
||||
GROUP BY ParentId
|
||||
HAVING COUNT(*) > 2;
|
||||
```
|
||||
|
||||
2. فرزندان اضافی را دستی حل کنید
|
||||
3. Migration را دوباره اجرا کنید
|
||||
|
||||
---
|
||||
|
||||
## غیرفعال کردن Transformation
|
||||
|
||||
اگر میخواهید فقط دادهها migrate شوند بدون تبدیل:
|
||||
|
||||
```json
|
||||
{
|
||||
"MigrationSettings": {
|
||||
"RunPostMigrationTransformation": false
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
سپس میتوانید اسکریپت را **دستی** از SSMS اجرا کنید:
|
||||
|
||||
```sql
|
||||
-- فایل: Scripts/PostMigration_DataTransformation.sql
|
||||
-- اجرا در: Target Database
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## آمار نهایی
|
||||
|
||||
بعد از transformation، این آمار نمایش داده میشود:
|
||||
|
||||
| Metric | Count |
|
||||
|--------|-------|
|
||||
| Total Users | 2,500 |
|
||||
| Users with NetworkParentId | 1,250 |
|
||||
| Users with LegPosition Left | 625 |
|
||||
| Users with LegPosition Right | 625 |
|
||||
| Root users (no parent) | 1,250 |
|
||||
|
||||
---
|
||||
|
||||
## تغییرات کد
|
||||
|
||||
### `MigrationService.cs`
|
||||
|
||||
**متد جدید:**
|
||||
```csharp
|
||||
private async Task RunPostMigrationTransformationAsync(string targetConn, CancellationToken cancellationToken)
|
||||
{
|
||||
// 1. خواندن SQL script
|
||||
// 2. اتصال به Target database
|
||||
// 3. اجرای script با handling PRINT messages
|
||||
// 4. Log کردن نتایج
|
||||
}
|
||||
```
|
||||
|
||||
**Integration:**
|
||||
- بعد از اتمام موفق migration، اگر `RunPostMigrationTransformation = true` باشد، این متد اجرا میشود
|
||||
- اگر script یافت نشود، فقط یک warning نمایش داده میشود (Migration fail نمیشود)
|
||||
- اگر transformation fail شود، Migration موفق تلقی میشود ولی warning نمایش داده میشود
|
||||
|
||||
---
|
||||
|
||||
## مزایا
|
||||
|
||||
✅ **خودکار**: نیازی به اجرای دستی script نیست
|
||||
✅ **Safe**: اگر fail شود، Migration rollback نمیشود
|
||||
✅ **Logged**: تمام مراحل در console و file log میشود
|
||||
✅ **Configurable**: میتوان غیرفعال کرد
|
||||
✅ **Validated**: قبل از commit، تمام validationها انجام میشود
|
||||
|
||||
---
|
||||
|
||||
**نسخه:** 1.1
|
||||
**تاریخ:** December 6, 2025
|
||||
**وضعیت:** ✅ Build موفق
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,350 @@
|
||||
# 🚀 نقشهراه حذف Gateway ها و انتقال به CMS
|
||||
|
||||
> تاریخ: ۳۰ ژانویه ۲۰۲۶
|
||||
|
||||
## 🎯 هدف کلی
|
||||
|
||||
حذف پیچیدگی معماری با انتقال همه سرویسهای Gateway به CMS microservice. این کار مزایای زیر داره:
|
||||
|
||||
- **Performance بهتر**: حذف network hop اضافی
|
||||
- **Simplicity**: کمتر dependency، آسانتر maintenance
|
||||
- **Cost**: کمتر resource و deployment complexity
|
||||
- **Modularity**: ساختار ماژولار در CMS که بعداً قابل جداسازی باشه
|
||||
|
||||
---
|
||||
|
||||
## 📊 وضعیت موجود
|
||||
|
||||
### BackOffice.BFF - Services List ✅
|
||||
|
||||
| Service | Proto | وضعیت در CMS | Type |
|
||||
|---------|-------|-------------|------|
|
||||
| AppVersionService | ✅ | ✅ موجود | Direct |
|
||||
| CategoryService | ✅ | ✅ موجود | Direct |
|
||||
| ClubMembershipService | ✅ | ✅ موجود | Direct |
|
||||
| CommissionService | ✅ | ✅ موجود | Direct |
|
||||
| ConfigurationService | ✅ | ✅ موجود | Direct |
|
||||
| DiscountCategoryService | ✅ | ✅ موجود | Direct |
|
||||
| DiscountOrderService | ✅ | ✅ موجود | Direct |
|
||||
| DiscountProductService | ✅ | ✅ موجود | Direct |
|
||||
| DiscountShoppingCartService | ✅ | ✅ موجود | Direct |
|
||||
| HealthService | ✅ | ❌ ندارد | **New** |
|
||||
| InventoryService | ✅ | ✅ موجود | Direct |
|
||||
| ManualPaymentService | ✅ | ✅ موجود | Direct |
|
||||
| NetworkMembershipService | ✅ | ❌ ندارد | **New** |
|
||||
| OtpService | ✅ | ✅ موجود (OtpTokenService) | Direct |
|
||||
| PackageService | ✅ | ✅ موجود | Direct |
|
||||
| ProductTagService | ✅ | ✅ موجود | Direct |
|
||||
| ProductsService | ✅ | ✅ موجود | Direct |
|
||||
| PublicMessageService | ✅ | ✅ موجود | Direct |
|
||||
| RoleService | ✅ | ✅ موجود | Direct |
|
||||
| TagService | ✅ | ✅ موجود | Direct |
|
||||
| UserAddressService | ✅ | ✅ موجود | Direct |
|
||||
| UserOrderService | ✅ | ✅ موجود | Direct |
|
||||
| UserRoleService | ✅ | ✅ موجود | Direct |
|
||||
| UserService | ✅ | ✅ موجود | Direct |
|
||||
|
||||
**خلاصه BackOffice.BFF**: 24 سرویس - 22 موجود در CMS، 2 نیاز به ایجاد
|
||||
|
||||
---
|
||||
|
||||
### FrontOffice.BFF - Services List 🔄
|
||||
|
||||
| Service | Proto | وضعیت در CMS | Type | توضیحات |
|
||||
|---------|-------|-------------|------|---------|
|
||||
| AppVersionGrpcService | ✅ | ✅ موجود | Direct | |
|
||||
| CategoriesService | ✅ | ✅ موجود | Direct | |
|
||||
| CityService | ✅ | ✅ موجود | Direct | |
|
||||
| ClubMembershipService | ✅ | ✅ موجود | Direct | |
|
||||
| ClubMembershipGrpcService | ✅ | ✅ موجود | Direct | |
|
||||
| CommissionService | ✅ | ✅ موجود | Direct | |
|
||||
| ConfigurationGrpcService | ✅ | ✅ موجود | Direct | |
|
||||
| DiscountShopService | ✅ | ✅ موجود (partial) | **Extend** | نیاز ترکیب با DiscountProduct/Category/Cart |
|
||||
| NetworkMembershipService | ✅ | ❌ ندارد | **New** | |
|
||||
| PackageService | ✅ | ✅ موجود | Direct | |
|
||||
| ProductsService | ✅ | ✅ موجود | Direct | |
|
||||
| ShopingCartService | ✅ | ✅ موجود (UserCartsService) | Direct | |
|
||||
| TransactionService | ✅ | ✅ موجود (TransactionsService) | Direct | |
|
||||
| UserAddressService | ✅ | ✅ موجود | Direct | |
|
||||
| UserOrderService | ✅ | ✅ موجود | Direct | |
|
||||
| UserService | ✅ | ✅ موجود | **Customer** | نیاز Customer-specific logic |
|
||||
| UserWalletService | ✅ | ✅ موجود | Direct | |
|
||||
|
||||
**خلاصه FrontOffice.BFF**: 17 سرویس - 15 موجود، 1 نیاز ایجاد، 1 نیاز extend
|
||||
|
||||
---
|
||||
|
||||
## 🛠️ Migration Strategy
|
||||
|
||||
### Phase 1: سرویسهای جدید در CMS
|
||||
|
||||
#### 1.1 HealthService (BackOffice.BFF → CMS)
|
||||
|
||||
**مسیر**: `CMS/src/CMSMicroservice.WebApi/Services/HealthService.cs`
|
||||
|
||||
```csharp
|
||||
// الگوی پیادهسازی
|
||||
public class HealthService : HealthContract.HealthContractBase
|
||||
{
|
||||
public override async Task<HealthCheckResponse> CheckHealth(Empty request, ServerCallContext context)
|
||||
{
|
||||
// Logic: Database connectivity, external services, etc.
|
||||
return new HealthCheckResponse { ... };
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**Dependencies**:
|
||||
- Proto: `CMS/src/CMSMicroservice.Protobuf/Protos/Health.proto`
|
||||
- Application Layer: `CMS/src/CMSMicroservice.Application/HealthCQ/`
|
||||
|
||||
#### 1.2 NetworkMembershipService (Both → CMS)
|
||||
|
||||
**مسیر**: `CMS/src/CMSMicroservice.WebApi/Services/NetworkMembershipService.cs`
|
||||
|
||||
```csharp
|
||||
public class NetworkMembershipService : NetworkMembershipContract.NetworkMembershipContractBase
|
||||
{
|
||||
// Binary Tree Management
|
||||
// User Placement Logic
|
||||
// Network Statistics
|
||||
}
|
||||
```
|
||||
|
||||
**Dependencies**:
|
||||
- Proto: `CMS/src/CMSMicroservice.Protobuf/Protos/NetworkMembership.proto`
|
||||
- Application: `CMS/src/CMSMicroservice.Application/NetworkMembershipCQ/`
|
||||
- Domain: احتمالاً موجوده، نیاز بررسی
|
||||
|
||||
---
|
||||
|
||||
### Phase 2: ماژولار کردن در CMS
|
||||
|
||||
#### ساختار پیشنهادی:
|
||||
|
||||
```
|
||||
CMS/src/CMSMicroservice.WebApi/Services/
|
||||
├── Core/ # سرویسهای پایه
|
||||
│ ├── HealthService.cs
|
||||
│ ├── ConfigurationService.cs
|
||||
│ └── AppVersionService.cs
|
||||
├── UserManagement/ # مدیریت کاربران
|
||||
│ ├── UserService.cs
|
||||
│ ├── UserRoleService.cs
|
||||
│ ├── UserAddressService.cs
|
||||
│ ├── UserOrderService.cs
|
||||
│ ├── UserWalletService.cs
|
||||
│ ├── UserCartsService.cs
|
||||
│ └── OtpTokenService.cs
|
||||
├── ProductCatalog/ # کاتالوگ محصولات
|
||||
│ ├── ProductsService.cs
|
||||
│ ├── CategoryService.cs
|
||||
│ ├── ProductTagService.cs
|
||||
│ ├── TagService.cs
|
||||
│ ├── ProductGalleriesService.cs
|
||||
│ └── ProductImagesService.cs
|
||||
├── DiscountShop/ # فروشگاه تخفیف
|
||||
│ ├── DiscountProductService.cs
|
||||
│ ├── DiscountCategoryService.cs
|
||||
│ ├── DiscountOrderService.cs
|
||||
│ └── DiscountShoppingCartService.cs
|
||||
├── Commission/ # کمیسیون و شبکه
|
||||
│ ├── CommissionService.cs
|
||||
│ ├── NetworkMembershipService.cs # جدید
|
||||
│ └── ClubMembershipService.cs
|
||||
├── Inventory/ # انبارداری
|
||||
│ └── InventoryService.cs
|
||||
├── Payment/ # پرداخت
|
||||
│ ├── ManualPaymentService.cs
|
||||
│ ├── TransactionsService.cs
|
||||
│ └── UserWalletChangeLogService.cs
|
||||
└── Content/ # محتوا
|
||||
├── PublicMessageService.cs
|
||||
├── CityService.cs
|
||||
└── PackageService.cs
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Phase 3: Proto Files Management
|
||||
|
||||
#### موجود در CMS که نیاز تغییر نداره:
|
||||
- `Category.proto` ✅
|
||||
- `Commission.proto` ✅
|
||||
- `Products.proto` ✅
|
||||
- `User.proto` ✅
|
||||
- `Configuration.proto` ✅
|
||||
- ... (بیشتر protos موجودن)
|
||||
|
||||
#### نیاز به اضافه کردن:
|
||||
1. **`Health.proto`** - برای health check endpoints
|
||||
2. **`NetworkMembership.proto`** - اگر موجود نیست
|
||||
|
||||
#### Proto files در Gateway ها که نیاز consolidation دارن:
|
||||
```
|
||||
BackOffice.BFF/src/Protobufs/ → CMS/src/CMSMicroservice.Protobuf/
|
||||
FrontOffice.BFF/src/Protobufs/ → CMS/src/CMSMicroservice.Protobuf/
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Phase 4: Application Layer Integration
|
||||
|
||||
#### BackOffice.BFF Application CQ → CMS Application
|
||||
|
||||
```
|
||||
BackOffice.BFF/src/BackOffice.BFF.Application/
|
||||
├── CommissionCQ/ → CMS/Application/CommissionCQ/
|
||||
├── ProductsCQ/ → CMS/Application/ProductsCQ/
|
||||
├── UserCQ/ → CMS/Application/UserCQ/
|
||||
└── ...
|
||||
```
|
||||
|
||||
**Strategy**:
|
||||
- مرج کردن Commands/Queries مشابه
|
||||
- حفظ Business Logic موجود در CMS
|
||||
- اضافه کردن Gateway-specific logic به CMS
|
||||
|
||||
#### مثال: CommissionCQ Migration
|
||||
|
||||
**BackOffice.BFF موجود**:
|
||||
- `TriggerWeeklyCalculationCommand`
|
||||
- `GetUserCommissionPayoutsQuery`
|
||||
- `ApproveWithdrawalCommand`
|
||||
|
||||
**CMS موجود**:
|
||||
- `CalculateWeeklyCommissionCommand`
|
||||
- `GetCommissionPayoutsQuery`
|
||||
|
||||
**Strategy**: ترکیب و تکمیل در CMS
|
||||
|
||||
---
|
||||
|
||||
### Phase 5: Client-Side Changes
|
||||
|
||||
#### BackOffice UI Changes
|
||||
|
||||
```csharp
|
||||
// Before (BackOffice → BackOffice.BFF)
|
||||
services.AddGrpcClient<UserContract.UserContractClient>(options =>
|
||||
{
|
||||
options.Address = new Uri("https://backoffice-bff:443");
|
||||
});
|
||||
|
||||
// After (BackOffice → CMS)
|
||||
services.AddGrpcClient<UserContract.UserContractClient>(options =>
|
||||
{
|
||||
options.Address = new Uri("https://cms:443");
|
||||
});
|
||||
```
|
||||
|
||||
#### FrontOffice UI Changes
|
||||
|
||||
```csharp
|
||||
// Before (FrontOffice → FrontOffice.BFF)
|
||||
services.AddGrpcClient<ProductsContract.ProductsContractClient>(options =>
|
||||
{
|
||||
options.Address = new Uri("https://frontoffice-bff:443");
|
||||
});
|
||||
|
||||
// After (FrontOffice → CMS)
|
||||
services.AddGrpcClient<ProductsContract.ProductsContractClient>(options =>
|
||||
{
|
||||
options.Address = new Uri("https://cms:443");
|
||||
});
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 📋 Implementation Plan
|
||||
|
||||
### Week 1: Analysis & Proto Consolidation
|
||||
- [ ] **Day 1**: تحلیل کامل Dependencies بین Gateway ها و CMS
|
||||
- [ ] **Day 2**: Merge کردن Proto files مشابه
|
||||
- [ ] **Day 3**: شناسایی Business Logic های unique در Gateway ها
|
||||
- [ ] **Day 4**: ایجاد migration scripts برای Application Layer
|
||||
- [ ] **Day 5**: طراحی namespace جدید در CMS
|
||||
|
||||
### Week 2: Core Services Migration
|
||||
- [ ] **Day 1-2**: پیادهسازی HealthService و NetworkMembershipService در CMS
|
||||
- [ ] **Day 3-4**: Migration UserService (با Customer-specific logic)
|
||||
- [ ] **Day 5**: تست و validation سرویسهای جدید
|
||||
|
||||
### Week 3: Application Layer Migration
|
||||
- [ ] **Day 1-2**: انتقال CommissionCQ از Gateway ها به CMS
|
||||
- [ ] **Day 3**: انتقال ProductsCQ
|
||||
- [ ] **Day 4**: انتقال UserCQ
|
||||
- [ ] **Day 5**: انتقال باقی CQ modules
|
||||
|
||||
### Week 4: Client Integration & Testing
|
||||
- [ ] **Day 1-2**: تغییر BackOffice client configuration
|
||||
- [ ] **Day 3**: تغییر FrontOffice client configuration
|
||||
- [ ] **Day 4**: End-to-end testing
|
||||
- [ ] **Day 5**: Performance testing و optimization
|
||||
|
||||
### Week 5: Cleanup & Documentation
|
||||
- [ ] **Day 1-2**: حذف Gateway projects از repository
|
||||
- [ ] **Day 3**: بروزرسانی Docker compose و K8s configs
|
||||
- [ ] **Day 4**: بروزرسانی deployment scripts
|
||||
- [ ] **Day 5**: مستندسازی نهایی
|
||||
|
||||
---
|
||||
|
||||
## ⚠️ Risks & Considerations
|
||||
|
||||
### High Risk
|
||||
1. **Breaking Changes**: تغییر endpoint URLs در client ها
|
||||
2. **Business Logic Loss**: احتمال از دست رفتن logic خاص Gateway ها
|
||||
3. **Performance Impact**: CMS ممکنه bottleneck بشه
|
||||
|
||||
### Medium Risk
|
||||
1. **Proto Conflicts**: تداخل message names در Proto files
|
||||
2. **Authorization**: تفاوت در Authorization logic بین Gateway ها
|
||||
3. **Testing Complexity**: نیاز تست کامل همه endpoints
|
||||
|
||||
### Mitigation Strategies
|
||||
- **Gradual Migration**: یک سرویس در هر مرحله
|
||||
- **Feature Flags**: قابلیت switch بین Gateway و CMS
|
||||
- **Comprehensive Testing**: Unit + Integration + End-to-end
|
||||
- **Rollback Plan**: امکان بازگشت سریع در صورت مشکل
|
||||
|
||||
---
|
||||
|
||||
## 🎯 Success Metrics
|
||||
|
||||
### Performance
|
||||
- [ ] Response time کاهش یافته (حذف network hop)
|
||||
- [ ] Throughput افزایش یافته
|
||||
- [ ] Resource usage بهینه شده
|
||||
|
||||
### Architecture
|
||||
- [ ] کد duplication کاهش یافته
|
||||
- [ ] Maintenance complexity کمتر شده
|
||||
- [ ] Deployment pipeline سادهتر شده
|
||||
|
||||
### Developer Experience
|
||||
- [ ] کمتر project برای کار روی یک feature
|
||||
- [ ] Debug و troubleshoot آسانتر
|
||||
- [ ] Documentation کامل و بهروز
|
||||
|
||||
---
|
||||
|
||||
## 📝 Notes
|
||||
|
||||
### Critical Dependencies
|
||||
- همه Proto messages باید compatible باشن
|
||||
- Authorization و Authentication logic حفظ بشه
|
||||
- Database migration نیازی نیست (همون دیتابیس رو استفاده میکنیم)
|
||||
|
||||
### Future Modularity
|
||||
ساختار ماژولار پیشنهادی باعث میشه بعداً بتونیم:
|
||||
- هر ماژول رو به microservice جداگانه تبدیل کنیم
|
||||
- Load balancing بین ماژولها داشته باشیم
|
||||
- Feature-based deployment انجام بدیم
|
||||
|
||||
---
|
||||
|
||||
**Status**: 🔍 Analysis Complete - Ready for Implementation
|
||||
**Next Step**: شروع Phase 1 - سرویسهای جدید
|
||||
**Owner**: Development Team
|
||||
**Estimated Duration**: 5 weeks
|
||||
@@ -0,0 +1,431 @@
|
||||
# Migration Progress: FrontOffice.BFF → CMS Direct Integration
|
||||
|
||||
## Date: 2026-02-01
|
||||
|
||||
## Overview
|
||||
Migration of FrontOffice from BFF layer to direct CMS microservice integration to eliminate unnecessary abstraction layer and improve architecture.
|
||||
|
||||
---
|
||||
|
||||
## Migration Strategy
|
||||
|
||||
### Discovery Phase
|
||||
- **Key Finding**: BFF was acting as a DTO transformation layer
|
||||
- **Insight**: BFF proto files serve as specification for frontend requirements
|
||||
- **Approach**: Systematically compare BFF proto structures with CMS and add missing fields
|
||||
|
||||
### Field Aliasing Strategy
|
||||
Proto3 doesn't support field number reuse, so we use unique field numbers for alias fields:
|
||||
- Original fields keep their numbers (e.g., `name = 2`, `image_url = 8`)
|
||||
- Alias fields get new numbers (e.g., `title = 12`, `image_path = 13`)
|
||||
- Both fields must be populated in service implementations
|
||||
|
||||
---
|
||||
|
||||
## Completed Work
|
||||
|
||||
### ✅ Phase 1: Infrastructure Setup
|
||||
- Changed URL from `localhost:32845` (BFF) to `localhost:32846` (CMS)
|
||||
- Consolidated multiple BFF proto packages into single `Foursat.CMSMicroservice.Protobuf`
|
||||
- Implemented Customer-prefixed API methods for frontend access
|
||||
|
||||
### ✅ Phase 2: Proto Package Updates
|
||||
|
||||
#### Version 0.0.171 (Successful)
|
||||
- Added `models` field aliases in response types:
|
||||
- `GetAllCategoriesForCustomerResponse`: `categories` → `models` (field 2)
|
||||
- `GetCustomerPackagesResponse`: `packages` → `models` (field 1)
|
||||
- `GetAllUserCartsResponse`: `items` → `models` (field 1)
|
||||
- Added missing fields:
|
||||
- `GetUserForCustomerResponse.token` (field 16)
|
||||
- `GetClubMembershipResponse.status` (field 11)
|
||||
- `GetClubMembershipResponse.days_remaining` (field 12)
|
||||
- Removed duplicate validators in `CMSMicroservice.Protobuf/Validator/UserCarts/`
|
||||
|
||||
#### Version 0.0.172 (Current)
|
||||
**Proto Changes:**
|
||||
- **package.proto**: Added `title` (field 12) and `image_path` (field 13) to `CustomerPackageModel`
|
||||
- **usercarts.proto**:
|
||||
- Added `user_cart_id` (field 11) alias to `UpdateUserCartRequest`
|
||||
- Added `product_short_infomation` (field 14) typo alias to `UserCartItem`
|
||||
- Added `created` timestamp (field 10) to `UserCartItem`
|
||||
- **networkmembership.proto**: Added to `NetworkTreeNodeModel`:
|
||||
- `full_name` (field 20) - alias for user_name
|
||||
- `level` (field 21) - alias for network_level
|
||||
- `mobile` (field 14)
|
||||
- `avatar` (field 15)
|
||||
- `position` (field 16)
|
||||
- `left_child` (field 17)
|
||||
- `right_child` (field 18)
|
||||
|
||||
**Service Implementation Changes:**
|
||||
- Updated `PackageService.GetCustomerPackageDetails` to populate:
|
||||
- `Title = "پکیج طلایی"` (duplicate of Name)
|
||||
- `ImagePath = "/images/packages/golden-detail.jpg"` (duplicate of ImageUrl)
|
||||
|
||||
**Build Status:**
|
||||
```bash
|
||||
✅ Proto build: Success
|
||||
✅ Pack version 0.0.172: Success
|
||||
✅ Package location: /home/masoud/Apps/project/FourSat/nupkg/Foursat.CMSMicroservice.Protobuf.0.0.172.nupkg
|
||||
✅ FrontOffice.Main.csproj updated to version 0.0.172
|
||||
```
|
||||
|
||||
### ✅ Phase 3: Error Reduction
|
||||
- **Initial**: 250+ compilation errors
|
||||
- **After 0.0.171**: 217 errors
|
||||
- **After 0.0.172**: **170 errors** ⬇️ (32% reduction)
|
||||
|
||||
---
|
||||
|
||||
## Remaining Work
|
||||
|
||||
### ⚠️ Critical Issues (170 Errors)
|
||||
|
||||
#### 1. Missing Service Methods (8 methods)
|
||||
Need to be added to CMS proto services:
|
||||
|
||||
**ConfigurationContract:**
|
||||
- `GetClubConfigurationAsync`
|
||||
- `GetClubFeaturesAsync`
|
||||
|
||||
**CommissionContract:**
|
||||
- `GetMyCommissionPayoutsAsync`
|
||||
- `GetMyWeeklyBalancesAsync`
|
||||
|
||||
**NetworkMembershipContract:**
|
||||
- `GetMyNetworkTreeAsync`
|
||||
- `GetSubordinateTreeAsync`
|
||||
- `GetMyNetworkStatisticsAsync`
|
||||
|
||||
**UserOrderContract:**
|
||||
- `GetVATRateAsync`
|
||||
|
||||
#### 2. Missing Proto Fields
|
||||
|
||||
**GetWeekDefinitionsRequest** (5 fields):
|
||||
```protobuf
|
||||
int32 page_number = ?;
|
||||
int32 page_size = ?;
|
||||
string search_text = ?;
|
||||
google.protobuf.Int32Value persian_year = ?;
|
||||
google.protobuf.Int32Value gregorian_year = ?;
|
||||
google.protobuf.BoolValue is_active = ?;
|
||||
```
|
||||
|
||||
**WeekDefinitionItem** (2 fields):
|
||||
```protobuf
|
||||
string start_date_persian = ?;
|
||||
string end_date_persian = ?;
|
||||
```
|
||||
|
||||
#### 3. Type Conversion Issues
|
||||
|
||||
**PaginationState conflict:**
|
||||
```
|
||||
Cannot implicitly convert type 'CMSMicroservice.Protobuf.Protos.PaginationState'
|
||||
to 'CMSMicroservice.Protobuf.Protos.City.PaginationState'
|
||||
```
|
||||
Location: `Pages/Profile/Components/EditAddressDialog.razor.cs(45,35)`
|
||||
|
||||
#### 4. Incomplete Alias Population
|
||||
|
||||
Fields with aliases need population in ALL service methods:
|
||||
- `CustomerPackageModel.Title` / `ImagePath` (partially done)
|
||||
- `NetworkTreeNodeModel.FullName` / `Level`
|
||||
- Other alias fields across services
|
||||
|
||||
---
|
||||
|
||||
## Technical Decisions
|
||||
|
||||
### Proto Field Number Strategy
|
||||
**Problem**: Proto3 doesn't allow field number reuse for aliases
|
||||
```protobuf
|
||||
// ❌ This doesn't work:
|
||||
string name = 2;
|
||||
string title = 2; // ERROR: Field number 2 already used
|
||||
|
||||
// ✅ Solution:
|
||||
string name = 2;
|
||||
string title = 12; // New unique number
|
||||
```
|
||||
|
||||
### Why Not Update Frontend?
|
||||
**Preserving Business Logic**: User requirement is "چیزی کم نشه از بیزینس" (don't lose any business logic). Changing frontend field names risks:
|
||||
- Breaking existing functionality
|
||||
- Missing edge cases in BFF transformation logic
|
||||
- Extensive testing burden
|
||||
|
||||
**Field Aliasing Benefits**:
|
||||
- Zero frontend changes required
|
||||
- Gradual migration path
|
||||
- Easy rollback if needed
|
||||
- Maintains backward compatibility
|
||||
|
||||
---
|
||||
|
||||
## Next Steps
|
||||
|
||||
### Priority 1: Add Missing Methods
|
||||
1. Define proto service methods in CMS `.proto` files
|
||||
2. Implement method stubs in CMS service classes
|
||||
3. Return mock/default data initially
|
||||
|
||||
### Priority 2: Add Missing Fields
|
||||
1. Add fields to `GetWeekDefinitionsRequest`
|
||||
2. Add fields to `WeekDefinitionItem`
|
||||
3. Rebuild proto package as version 0.0.173
|
||||
|
||||
### Priority 3: Fix Type Issues
|
||||
1. Resolve `PaginationState` namespace conflict
|
||||
2. Add missing `PaymentGatewayUrl` field
|
||||
3. Fix `PaymentMethod` enum reference
|
||||
|
||||
### Priority 4: Complete Alias Population
|
||||
1. Populate all alias fields in service responses
|
||||
2. Ensure data consistency between original and alias fields
|
||||
|
||||
---
|
||||
|
||||
## Package Version History
|
||||
|
||||
| Version | Status | Changes | Errors |
|
||||
|---------|--------|---------|--------|
|
||||
| 0.0.170 | Baseline | Initial BFF → CMS migration | 250+ |
|
||||
| 0.0.171 | ✅ Success | Models aliases, Token field | 217 |
|
||||
| 0.0.172 | ✅ Success | Title/ImagePath aliases, Network fields | 170 |
|
||||
| 0.0.173 | Planned | Missing methods and fields | TBD |
|
||||
|
||||
---
|
||||
|
||||
## Commands Reference
|
||||
|
||||
### Build Proto Package
|
||||
```bash
|
||||
cd /home/masoud/Apps/project/FourSat/CMS/src/CMSMicroservice.Protobuf
|
||||
dotnet build
|
||||
dotnet pack -c Release -p:PackageVersion=0.0.172 -o ../../../nupkg -p:RunPushTarget=false
|
||||
```
|
||||
|
||||
### Update FrontOffice
|
||||
```bash
|
||||
cd /home/masoud/Apps/project/FourSat/FrontOffice/src/FrontOffice.Main
|
||||
# Edit .csproj to update version number
|
||||
dotnet build
|
||||
```
|
||||
|
||||
### Check Errors
|
||||
```bash
|
||||
cd /home/masoud/Apps/project/FourSat/FrontOffice/src/FrontOffice.Main
|
||||
dotnet build 2>&1 | grep "error CS" | wc -l
|
||||
dotnet build 2>&1 | grep "error CS" | head -20
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Lessons Learned
|
||||
|
||||
1. **BFF Transformation Discovery**: BFF wasn't just routing - it was transforming DTOs. This is critical business logic.
|
||||
|
||||
2. **Proto Field Aliasing**: Proto3 requires unique field numbers. Can't reuse numbers for aliases.
|
||||
|
||||
3. **Systematic Approach**: Comparing BFF proto files as specification prevented missing fields.
|
||||
|
||||
4. **Incremental Progress**: Breaking work into small packages (0.0.171 → 0.0.172) made debugging easier.
|
||||
|
||||
5. **Package Naming**: Real package name is `Foursat.CMSMicroservice.Protobuf`, not `CMSMicroservice.Protobuf`.
|
||||
|
||||
---
|
||||
|
||||
## Notes
|
||||
|
||||
- Post-build push to Nexus disabled with `-p:RunPushTarget=false` due to `--allow-insecure-connections` flag incompatibility
|
||||
- All changes preserve existing business logic per user requirement
|
||||
- Field aliases provide backward compatibility during migration
|
||||
- Final cleanup phase will update frontend to use CMS field names directly (optional future work)
|
||||
|
||||
|
||||
---
|
||||
|
||||
# سابقه مهاجرت اولیه (سرویسهای اولیه)
|
||||
|
||||
# FrontOffice.BFF to CMS Migration Progress
|
||||
|
||||
## Migration Overview
|
||||
مهاجرت سرویسهای FrontOffice.BFF به CMS Microservice با معماری Clean Architecture و gRPC.
|
||||
|
||||
## ✅ Completed Services
|
||||
|
||||
### 1. Categories Service
|
||||
- **Status**: ✅ Complete
|
||||
- **Proto Definition**: `categories.proto`
|
||||
- **Service Implementation**: `CategoryService.cs`
|
||||
- **Methods Migrated**:
|
||||
- Admin Methods:
|
||||
- `AddNewCategory` - افزودن دستهبندی جدید
|
||||
- `UpdateCategory` - بروزرسانی دستهبندی
|
||||
- `DeleteCategory` - حذف دستهبندی
|
||||
- `GetCategory` - دریافت یک دستهبندی
|
||||
- `GetAllCategoriesByFilter` - دریافت لیست دستهبندیها
|
||||
- Customer Methods:
|
||||
- `GetActiveCategoriesForCustomer` - دریافت دستهبندیهای فعال برای مشتری
|
||||
|
||||
### 2. City Service
|
||||
- **Status**: ✅ Complete
|
||||
- **Proto Definition**: `city.proto`
|
||||
- **Service Implementation**: `CityService.cs`
|
||||
- **Methods Migrated**:
|
||||
- Admin Methods:
|
||||
- `AddNewCity` - افزودن شهر جدید
|
||||
- `UpdateCity` - بروزرسانی شهر
|
||||
- `DeleteCity` - حذف شهر
|
||||
- `GetCity` - دریافت یک شهر
|
||||
- `GetAllCitiesByFilter` - دریافت لیست شهرها
|
||||
- Customer Methods:
|
||||
- `GetActiveCitiesForCustomer` - دریافت شهرهای فعال برای مشتری
|
||||
|
||||
### 3. UserCarts Service
|
||||
- **Status**: ✅ Complete
|
||||
- **Proto Definition**: `usercarts.proto`
|
||||
- **Service Implementation**: `UserCartsService.cs`
|
||||
- **Methods Migrated**:
|
||||
- Admin Methods:
|
||||
- `AddNewUserCart` - افزودن سبد خرید جدید
|
||||
- `UpdateUserCart` - بروزرسانی سبد خرید
|
||||
- `DeleteUserCart` - حذف سبد خرید
|
||||
- `GetUserCart` - دریافت سبد خرید (Admin)
|
||||
- `GetAllUserCartsByFilter` - دریافت لیست سبدهای خرید
|
||||
- Customer Methods:
|
||||
- `AddNewUserCartForCustomer` - افزودن محصول به سبد (Customer)
|
||||
- `UpdateUserCartForCustomer` - بروزرسانی تعداد محصول در سبد
|
||||
- `RemoveUserCartForCustomer` - حذف محصول از سبد
|
||||
- `GetCustomerCart` - دریافت سبد خرید مشتری
|
||||
|
||||
## 🛠️ Technical Implementation Details
|
||||
|
||||
### gRPC HTTP Annotations
|
||||
تمام سرویسها با HTTP annotations تعریف شدهاند:
|
||||
- Admin endpoints: `/ServiceName` pattern
|
||||
- Customer endpoints: `/Customer/Action` pattern
|
||||
|
||||
### Clean Architecture Structure
|
||||
```
|
||||
CMSMicroservice.Domain/ # Core business entities
|
||||
CMSMicroservice.Application/ # Business logic & CQRS
|
||||
CMSMicroservice.Infrastructure/ # Data access & external services
|
||||
CMSMicroservice.WebApi/ # gRPC services & controllers
|
||||
CMSMicroservice.Protobuf/ # Protocol buffer definitions
|
||||
```
|
||||
|
||||
### Swagger Integration
|
||||
- Multiple Swagger documents: cms, admin, customer, unified
|
||||
- gRPC HTTP transcoding enabled
|
||||
- Custom CSS styling applied
|
||||
- Conflict resolution implemented
|
||||
|
||||
## 🔧 Issues Resolved
|
||||
|
||||
### 1. Swagger Conflict Resolution
|
||||
**Problem**:
|
||||
```
|
||||
Swashbuckle.AspNetCore.SwaggerGen.SwaggerGeneratorException:
|
||||
Conflicting method/path combination "GET GetUserCart"
|
||||
```
|
||||
|
||||
**Root Cause**:
|
||||
- دو method با operation ID یکسان: `GetUserCart` و `GetUserCartForCustomer`
|
||||
- Swagger از method name برای operation ID استفاده میکند
|
||||
|
||||
**Solutions Attempted**:
|
||||
1. ❌ `CustomOperationIds` - ineffective
|
||||
2. ❌ `ResolveConflictingActions` - incomplete resolution
|
||||
3. ✅ **Method Renaming** - successful
|
||||
|
||||
**Final Solution**:
|
||||
```protobuf
|
||||
// Before (conflicting):
|
||||
rpc GetUserCartForCustomer(GetUserCartForCustomerRequest) returns (GetUserCartForCustomerResponse)
|
||||
|
||||
// After (resolved):
|
||||
rpc GetCustomerCart(GetUserCartForCustomerRequest) returns (GetUserCartForCustomerResponse)
|
||||
```
|
||||
|
||||
### 2. Application Layer Dependencies
|
||||
**Problem**: Build errors در Application layer
|
||||
**Solution**: پاکسازی dependencies و rebuild پروژه
|
||||
|
||||
## 📊 Migration Status Summary
|
||||
|
||||
| Service | Proto ✅ | Implementation ✅ | Build ✅ | Swagger ✅ |
|
||||
|---------|----------|-------------------|----------|------------|
|
||||
| Categories | ✅ | ✅ | ✅ | ✅ |
|
||||
| City | ✅ | ✅ | ✅ | ✅ |
|
||||
| UserCarts | ✅ | ✅ | ✅ | ✅ |
|
||||
|
||||
## 🎯 Next Steps
|
||||
1. **Service Integration Testing** - تست عملکرد سرویسهای migrate شده
|
||||
2. **Business Logic Implementation** - پیادهسازی منطق کسبوکار واقعی
|
||||
3. **Database Integration** - اتصال به لایه دیتا
|
||||
4. **Continue Migration** - ادامه migration سایر سرویسها
|
||||
|
||||
## 🏗️ Technical Architecture
|
||||
|
||||
### gRPC Service Pattern
|
||||
```csharp
|
||||
public class ServiceName : ServiceContract.ServiceContractBase
|
||||
{
|
||||
private readonly IDispatchRequestToCQRS _dispatcher;
|
||||
|
||||
// Customer Methods Section
|
||||
#region Customer Methods
|
||||
public override async Task<Response> CustomerMethod(Request request, ServerCallContext context)
|
||||
{
|
||||
// Implementation
|
||||
}
|
||||
#endregion
|
||||
|
||||
// Admin Methods Section
|
||||
#region Admin Methods
|
||||
public override async Task<Response> AdminMethod(Request request, ServerCallContext context)
|
||||
{
|
||||
// Implementation
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
```
|
||||
|
||||
### Proto File Structure
|
||||
```protobuf
|
||||
syntax = "proto3";
|
||||
import "google/api/annotations.proto";
|
||||
|
||||
service ServiceContract {
|
||||
// ============= Admin Methods =============
|
||||
rpc AdminMethod(Request) returns (Response) {
|
||||
option (google.api.http) = {
|
||||
post: "/AdminEndpoint"
|
||||
body: "*"
|
||||
};
|
||||
};
|
||||
|
||||
// ============= Customer Methods =============
|
||||
rpc CustomerMethod(Request) returns (Response) {
|
||||
option (google.api.http) = {
|
||||
get: "/Customer/Endpoint"
|
||||
};
|
||||
};
|
||||
}
|
||||
```
|
||||
|
||||
## 📈 Performance & Quality
|
||||
- ✅ All services compile successfully
|
||||
- ✅ Swagger documentation accessible
|
||||
- ✅ gRPC HTTP transcoding working
|
||||
- ✅ Clean separation of Admin/Customer concerns
|
||||
- ✅ Consistent naming conventions applied
|
||||
|
||||
---
|
||||
**Last Updated**: January 30, 2026
|
||||
**Migration Phase**: Foundation Services Complete
|
||||
**Next Milestone**: Business Logic Implementation
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user