Files
docs/technical/TECH-04-MIGRATION.md
T
masoodafar-web 1b04ba5326 docs: convert all ASCII charts to Mermaid diagrams
Converted 40+ ASCII art diagrams across 12 files to Mermaid:
- flowchart TD/LR for process flows and architecture
- erDiagram for entity relationships
- graph TD for tree structures (binary tree, categories)
- gantt for roadmap sprints

Files: BUSINESS-01 to 05, TECH-01/03/04/05, OVERVIEW-01/02/05
Directory tree structures kept as plain code blocks (Mermaid N/A)
2026-02-18 23:36:39 +03:30

229 lines
7.2 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 🔄 مهاجرت داده، 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`
> **آخرین بروزرسانی:** اسفند ۱۴۰۴
---
## ۱. تاریخچه مهاجرت‌ها
```
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` | افزایش قیمت ۱۰% |
---
## ۶. 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% |