f5173a4def
- CHANGELOG: اضافه Phase 18 BackOffice + فعالسازی درگاه FO + تنظیمات محیطی CMS + مرج پروداکشن - PAYMENT-FINANCE: MerchantId واقعی + تنظیمات محیطی Staging/Production + Magic فاز 6 کامل - ROADMAP: بروزرسانی درصدها + Magic 100% + Payment 97% + DONE section - TECH-02: ساختار فولدر + UserAutoComplete + WalletManagement + دکمههای درگاه - BUSINESS-01: Magic Wallet فاز 1-6 کامل - TECH-04: Migration پروداکشن ExpandDiscountProductFullInformation + حذف u21 تکراری - TECH-03: جزئیات مرج پروداکشن + تنظیمات appsettings.Production.json - MAGIC-WALLET-PLAN: وضعیت کامل - INDEX: بروزرسانی تاریخ
239 lines
7.8 KiB
Markdown
239 lines
7.8 KiB
Markdown
# 🔄 مهاجرت داده، BFF و Gateway
|
||
|
||
> **منابع ادغامشده:** `BACKOFFICE-BFF-MIGRATION.md`, `customer-facing-capabilities-codex.md`, `DATA-TABLE-MAPPINGS.md`, `DATAMIGRATION-README.md`, `FRONTOFFICE-TO-CMS-MIGRATION.md`, `GATEWAY-REMOVAL-MIGRATION-PLAN.md`, `MIGRATION-PROGRESS.md`
|
||
> **آخرین بروزرسانی:** اسفند ۱۴۰۴ (بروزرسانی: Migration پروداکشن)
|
||
|
||
---
|
||
|
||
## ۱. تاریخچه مهاجرتها
|
||
|
||
```
|
||
Timeline:
|
||
▸ فاز ۱: FrontOffice REST → CMS gRPC (مستقیم)
|
||
▸ فاز ۲: BackOffice REST → CMS gRPC (مستقیم)
|
||
▸ فاز ۳: حذف BFF/Gateway
|
||
▸ فاز ۴: حذف API Gateway (Ocelot)
|
||
▸ فاز ۵: یکپارچهسازی Proto packages
|
||
▸ فاز ۶: Data migration از سیستم قدیم
|
||
```
|
||
|
||
---
|
||
|
||
## ۲. حذف BFF (Backend-for-Frontend)
|
||
|
||
### ۲.۱ قبل
|
||
|
||
```mermaid
|
||
flowchart LR
|
||
FO1["FrontOffice"] -->|HTTP/REST| BFF["BFF"]
|
||
BO1["BackOffice"] -->|HTTP/REST| BFF
|
||
BFF -->|gRPC| CMS1["CMS"]
|
||
```
|
||
|
||
**BFF مسئولیتها:** تبدیل REST↔gRPC • Aggregation • Auth proxy • Rate limiting
|
||
|
||
### ۲.۲ بعد (فعلی)
|
||
|
||
```mermaid
|
||
flowchart LR
|
||
FO2["FrontOffice"] -->|gRPC| CMS2["CMS مستقیم"]
|
||
BO2["BackOffice"] -->|gRPC| CMS2
|
||
```
|
||
|
||
**مزایا:** ✅ حذف ۱ سرویس • کاهش ~50ms latency • Type-safety از proto تا UI • سادهسازی debug
|
||
|
||
### ۲.۳ مراحل مهاجرت
|
||
|
||
```
|
||
مرحله ۱: ایجاد gRPC client wrappers در FrontOffice
|
||
ProductService.cs → _client.GetProductsAsync(request)
|
||
OrderService.cs → _client.GetOrdersAsync(request)
|
||
...
|
||
|
||
مرحله ۲: جایگزینی HttpClient با GrpcChannel
|
||
services.AddGrpcClient<ProductServiceClient>(o => {
|
||
o.Address = new Uri(config["Grpc:CmsUrl"]);
|
||
});
|
||
|
||
مرحله ۳: حذف BFF project
|
||
- حذف BFF از solution
|
||
- حذف BFF از docker-compose
|
||
- حذف BFF از K8s manifests
|
||
|
||
مرحله ۴: تست end-to-end
|
||
- تست هر صفحه FrontOffice
|
||
- تست هر صفحه BackOffice
|
||
- Performance benchmark
|
||
```
|
||
|
||
---
|
||
|
||
## ۳. حذف API Gateway (Ocelot)
|
||
|
||
### ۳.۱ قبل
|
||
|
||
```mermaid
|
||
flowchart LR
|
||
CL1["Client"] --> NG1["nginx"] --> OC["Ocelot Gateway"]
|
||
OC --> CMS3["CMS"]
|
||
OC --> BFF2["BFF"]
|
||
OC --> FS1["FileService"]
|
||
```
|
||
|
||
### ۳.۲ بعد
|
||
|
||
```mermaid
|
||
flowchart LR
|
||
CL2["Client"] --> NG2["nginx"] --> ING["K8s Ingress"]
|
||
ING --> CMS4["CMS"]
|
||
ING --> BO3["BackOffice"]
|
||
ING --> FO3["FrontOffice"]
|
||
```
|
||
|
||
### ۳.۳ دلایل حذف
|
||
|
||
```
|
||
✅ Ocelot maintenance burden → حذف
|
||
✅ K8s Ingress → routing بومی
|
||
✅ Let's Encrypt → TLS بومی
|
||
✅ gRPC → type-safe بدون نیاز به gateway
|
||
```
|
||
|
||
---
|
||
|
||
## ۴. FrontOffice to CMS Migration
|
||
|
||
### ۴.۱ Service Mapping
|
||
|
||
| FrontOffice Service | BFF Endpoint (حذفشده) | CMS gRPC Service |
|
||
|--------------------|-----------------------|-------------------|
|
||
| `ProductService` | `GET /api/products` | `ProductService.GetProducts` |
|
||
| `OrderService` | `POST /api/orders` | `OrderService.CreateOrder` |
|
||
| `UserService` | `POST /api/auth/login` | `UserService.Login` |
|
||
| `ClubService` | `GET /api/club/tree` | `ClubService.GetNetworkTree` |
|
||
| `BlogService` | `GET /api/blog/posts` | `BlogService.GetPosts` |
|
||
| `PaymentService` | `POST /api/payment/create` | `PaymentService.CreatePayment` |
|
||
| `FileService` | `POST /api/files/upload` | `FileService.Upload` |
|
||
| `SitePageService` | `GET /api/pages/{type}` | `SitePageService.GetPage` |
|
||
|
||
### ۴.۲ DTO Mapping
|
||
|
||
```
|
||
BFF DTOs (حذفشده) → Proto Messages (فعلی)
|
||
ProductDto → ProductMessage
|
||
OrderDto → OrderMessage
|
||
UserDto → UserMessage
|
||
|
||
Proto-generated classes مستقیم در UI استفاده میشوند
|
||
یا به local DTOs map میشوند (برای UI-specific fields)
|
||
```
|
||
|
||
---
|
||
|
||
## ۵. Data Migration (سیستم قدیم → جدید)
|
||
|
||
### ۵.۱ پروژه DataMigration
|
||
|
||
```
|
||
DataMigration/
|
||
├── FourSat.DataMigration/ ← Console app
|
||
│ ├── Program.cs
|
||
│ ├── Migrators/
|
||
│ │ ├── UserMigrator.cs
|
||
│ │ ├── ProductMigrator.cs
|
||
│ │ ├── OrderMigrator.cs
|
||
│ │ └── ClubMigrator.cs
|
||
│ └── Mappings/
|
||
│ └── TableMappings.cs
|
||
└── FourSat.GeographySeeder/ ← Seed geography data
|
||
├── Program.cs
|
||
└── Data/
|
||
├── provinces.json
|
||
└── cities.json
|
||
```
|
||
|
||
### ۵.۲ Data Table Mappings
|
||
|
||
| جدول مبدأ (قدیم) | جدول مقصد (CMS) | نکات |
|
||
|------------------|-----------------|------|
|
||
| `dbo.Users` | `CMS.Users` | PhoneNumber as primary identifier |
|
||
| `dbo.Products` | `CMS.Products` | ImageUrl migration needed |
|
||
| `dbo.Orders` | `CMS.Orders` | Status enum remapping |
|
||
| `dbo.Categories` | `CMS.Categories` | Hierarchical → ParentId |
|
||
| `dbo.NetworkTree` | `CMS.Users` | Binary tree via NetworkParentId + LegPosition روی User |
|
||
| `dbo.Wallets` | `CMS.UserWallets` | ۳ wallet types: Balance, NetworkBalance, DiscountBalance |
|
||
| `dbo.Transactions` | `CMS.Transactions` | Type enum remapping |
|
||
| `dbo.Memberships` | `CMS.UserClubMemberships` | + Contract creation |
|
||
|
||
### ۵.۳ SQL Scripts مهاجرت
|
||
|
||
| اسکریپت | کاربرد |
|
||
|----------|--------|
|
||
| `MigrateUsersToClubMembership.sql` | انتقال همه کاربران |
|
||
| `MigrateSpecificUsersToClubMembership.sql` | انتقال انتخابی |
|
||
| `ChargeUserWallets.sql` | شارژ اولیه کیفپولها |
|
||
| `AddIsActiveToUserClubFeatures.sql` | افزودن فیلد IsActive |
|
||
| `SeedSitePages.sql` | داده اولیه صفحات سایت |
|
||
| `SystemConfigurations.sql` | مقادیر پیشفرض تنظیمات |
|
||
| `populate-weekly-commission-pools.sql` | داده تاریخی Pool |
|
||
| `update_products_price_10_percent.sql` | افزایش قیمت ۱۰% |
|
||
|
||
### ۵.۴ Migrationهای EF Core اجراشده روی Production (اسفند ۱۴۰۴)
|
||
|
||
| Migration | توضیح | DB |
|
||
|-----------|--------|----|
|
||
| `ExpandDiscountProductFullInformation` | گسترش فیلدهای محصول تخفیفی | KBS (Production `45.149.79.127`) |
|
||
| `AddMagicWalletFields` (u21) | فیلدهای کیفپول جادویی + ClubMembershipCycle | KBS (Production) |
|
||
|
||
> ⚠️ نکته: Migration `u21` در زمان merge تکراری بود (timestampهای `20260222155925` و `20260222160755`). فایل تکراری حذف شد.
|
||
|
||
---
|
||
|
||
## ۶. Geography Seeder
|
||
|
||
```
|
||
FourSat.GeographySeeder:
|
||
• ۳۱ استان
|
||
• ~۱۲۰۰ شهر
|
||
• منبع: دیتای رسمی تقسیمات کشوری
|
||
• فرمت: JSON → EF Core Seed
|
||
|
||
استفاده:
|
||
dotnet run --project FourSat.GeographySeeder
|
||
```
|
||
|
||
---
|
||
|
||
## ۷. Customer-Facing Capabilities Codex
|
||
|
||
### ۷.۱ خلاصه (بزرگترین سند — ۵,۳۰۰ خط)
|
||
|
||
این سند شامل مستندسازی کامل تمام قابلیتهای کاربرمحور سیستم است:
|
||
|
||
| بخش | محتوا |
|
||
|------|--------|
|
||
| **User Journey** | فلوی کامل از ثبتنام تا خرید |
|
||
| **Store Features** | لیست محصول، فیلتر، سبد، پرداخت |
|
||
| **Club Features** | عضویت، درخت، کمیسیون، قرارداد |
|
||
| **Content** | بلاگ، صفحات، SEO |
|
||
| **Admin Features** | مدیریت محصول، سفارش، کاربر |
|
||
| **Integration** | Chatika، ZarinPal، Kavenegar، Daya |
|
||
| **Mobile** | Responsive، PWA (planned) |
|
||
|
||
---
|
||
|
||
## ۸. وضعیت مهاجرت
|
||
|
||
| مهاجرت | وضعیت | درصد |
|
||
|--------|--------|------|
|
||
| FrontOffice BFF → gRPC | ✅ | 100% |
|
||
| BackOffice BFF → gRPC | ✅ | 100% |
|
||
| API Gateway حذف | ✅ | 100% |
|
||
| Data Migration (Users) | ✅ | 100% |
|
||
| Data Migration (Products) | ✅ | 100% |
|
||
| Data Migration (Orders) | ✅ | 100% |
|
||
| Data Migration (Club/Network) | ✅ | 100% |
|
||
| Geography Seeder | ✅ | 100% |
|
||
| Proto package unification | ✅ | 100% |
|
||
| EF Migration پروداکشن | ✅ | 100% |
|