Mojtaba Pourkhanlar
About meProjectsBlog

  • 👤About me
  • 🧰Projects
  • ✍️Blog

Feature-Sliced Design

  • مناسب برای پروژه‌های متوسط و بزرگ.
  • همه چیز مربوط به یک feature در یکجا جمع است.
src/
├── app/                 # تنظیمات اصلی اپلیکیشن
│   ├── providers/      # Context Providers
│   ├── store/         # State Management
│   └── router/        # Routing Configuration
├── processes/          # فرآیندهای پیچیده (مثل checkout)
├── pages/             # صفحات اصلی
├── widgets/           # ویجت‌های مستقل
├── features/          # ویژگی‌های کسب‌وکار
│   ├── auth/
│   │   ├── api/      # API calls
│   │   ├── model/    # Types, Interfaces
│   │   ├── ui/       # کامپوننت‌های UI
│   │   └── lib/      # Utilities خاص این feature
│   ├── profile/
│   └── cart/
├── entities/          # موجودیت‌های دامنه
│   ├── user/
│   ├── product/
│   └── order/
├── shared/            # کدهای اشتراکی
│   ├── api/          # API configuration
│   ├── lib/          # Utilities عمومی
│   ├── ui/           # کامپوننت‌های UI عمومی
│   └── config/       # تنظیمات
└── index.tsx

Atomic Design + DDD

src/
├── core/                     # Core Domain
│   ├── domain/              # Business Logic
│   │   ├── entities/        # Domain Entities
│   │   ├── value-objects/   # Value Objects
│   │   ├── aggregates/      # Aggregates
│   │   └── services/        # Domain Services
│   ├── application/         # Application Layer
│   │   ├── use-cases/      # Use Cases
│   │   ├── dto/            # Data Transfer Objects
│   │   └── ports/          # Interfaces
│   └── infrastructure/      # Infrastructure Layer
│       ├── adapters/       # Adapters
│       ├── repositories/   # Data Access
│       └── http/          # HTTP Clients
├── presentation/            # Presentation Layer
│   ├── atoms/              # Basic Components
│   ├── molecules/          # Combined Components
│   ├── organisms/          # Complex Components
│   ├── templates/          # Page Templates
│   └── pages/              # Full Pages
└── shared/                 # Shared Resources
    ├── components/         # Shared Components
    ├── hooks/             # Shared Hooks
    ├── utils/             # Utilities
    └── styles/            # Global Styles

Domain-Driven Design (DDD)

خب Domain-Driven Design یک رویکرد معماری است که تمرکز اصلی آن بر روی مدل‌سازی دامنه کسب‌وکار است. در این معماری، ساختار کد و سازمان‌دهی پروژه حول مفاهیم و قوانین کسب‌وکار شکل می‌گیرد، نه تکنولوژی یا فریم‌ورک‌ها.

  • Domain Layer (لایه دامنه) => [src/core/domain/]

  • Application Layer (لایه کاربرد) => [src/core/application/]

  • Infrastructure Layer (لایه زیرساخت) => [src/infrastructure/]

  • Presentation Layer (لایه نمایش) => [src/presentation/]

مزایا:

1.منطق کسب‌وکار متمرکز: همه قوانین تجاری در یک مکان

2.قابلیت تست بالا: دامنه مستقل از UI/API

3.قابلیت نگهداری: تغییرات آسان با جداسازی مناسب

4.همکاری بهتر: زبان مشترک بین توسعه‌دهندگان و ذینفعان

5.مقیاس‌پذیری: رشد آسان با پیچیدگی کنترل‌شده

چالش‌ها:

1.پیچیدگی اولیه: نیاز به طراحی دقیق

2.و Over-engineering: برای پروژه‌های کوچک ممکن است سنگین باشد

3.منحنی یادگیری: نیاز به درک مفاهیم دامنه

مثال عملی: سیستم مدیریت فروشگاه

src/
├── core/
│   ├── domain/
│   │   ├── entities/
│   │   │   ├── Product.ts
│   │   │   ├── Category.ts
│   │   │   ├── Cart.ts
│   │   │   └── Order.ts
│   │   ├── value-objects/
│   │   │   ├── Money.ts
│   │   │   ├── Address.ts
│   │   │   └── Rating.ts
│   │   ├── aggregates/
│   │   │   ├── ShoppingCartAggregate.ts
│   │   │   └── OrderAggregate.ts
│   │   ├── domain-services/
│   │   │   ├── PricingService.ts
│   │   │   ├── InventoryService.ts
│   │   │   └── ShippingService.ts
│   │   └── events/
│   │       ├── ProductAddedToCart.ts
│   │       ├── OrderPlaced.ts
│   │       └── PaymentProcessed.ts
│   └── application/
│       ├── use-cases/
│       │   ├── AddToCartUseCase.ts
│       │   ├── CheckoutUseCase.ts
│       │   └── TrackOrderUseCase.ts
│       ├── dto/
│       │   ├── CartDTO.ts
│       │   ├── OrderDTO.ts
│       │   └── ProductDTO.ts
│       └── ports/
│           ├── ICartRepository.ts
│           ├── IOrderRepository.ts
│           └── IPaymentGateway.ts
├── infrastructure/
│   ├── repositories/
│   │   ├── HttpCartRepository.ts
│   │   ├── LocalStorageCartRepository.ts
│   │   └── IndexedDBProductRepository.ts
│   ├── api/
│   │   ├── ShopApiClient.ts
│   │   ├── PaymentApiClient.ts
│   │   └── AuthApiClient.ts
│   └── services/
│       ├── RealPaymentGateway.ts
│       ├── MockShippingService.ts
│       └── AnalyticsService.ts
├── presentation/
│   ├── components/
│   │   ├── atoms/
│   │   │   ├── ProductCard.tsx
│   │   │   ├── PriceTag.tsx
│   │   │   └── RatingStars.tsx
│   │   ├── molecules/
│   │   │   ├── ProductListItem.tsx
│   │   │   ├── CartSummary.tsx
│   │   │   └── OrderStatus.tsx
│   │   ├── organisms/
│   │   │   ├── ProductGrid.tsx
│   │   │   ├── ShoppingCart.tsx
│   │   │   └── CheckoutForm.tsx
│   │   ├── templates/
│   │   │   ├── ProductListingTemplate.tsx
│   │   │   ├── CartTemplate.tsx
│   │   │   └── OrderTrackingTemplate.tsx
│   │   └── pages/
│   │       ├── HomePage.tsx
│   │       ├── ProductPage.tsx
│   │       └── CheckoutPage.tsx
│   ├── hooks/
│   │   ├── useCart.ts
│   │   ├── useProducts.ts
│   │   └── useCheckout.ts
│   └── contexts/
│       ├── CartContext.tsx
│       ├── AuthContext.tsx
│       └── ThemeContext.tsx
└── shared/
    ├── utils/
    ├── constants/
    └── types/

جمع بندی

الگوهای طراحی در فرانت‌اند تنها مجموعه‌ای از بهترین‌ها نیستند، بلکه روشی سیستماتیک برای حل مسائل معمول هستند. انتخاب الگوی مناسب به اندازه پروژه، تیم و نیازهای کسب‌وکار بستگی دارد. مهم‌ترین نکته حفظ ثبات در پروژه و تطبیق الگوها با شرایط خاص هر پروژه است.

نکته طلایی: بهترین الگو، الگویی است که تیم شما آن را درک کند، نگهداری آن آسان باشد و نیازهای پروژه شما را برآورده سازد