Refactor domain structure to business layer
- Renamed `domain/` to `business/` to better reflect the organization of code by business logic. - Updated all relevant file paths and references throughout the project to align with the new structure. - Ensured that all models and services are now located under the `business/` directory, maintaining existing functionality while improving clarity.
This commit is contained in:
@@ -12,8 +12,8 @@
|
||||
## TABLE OF CONTENTS
|
||||
|
||||
1. [Overview](#overview)
|
||||
2. [Create Domain Structure](#create-domain-structure)
|
||||
3. [Move Models to Domain](#move-models-to-domain)
|
||||
2. [Create Business Structure](#create-business-structure)
|
||||
3. [Move Models to Business](#move-models-to-business)
|
||||
4. [Create Services](#create-services)
|
||||
5. [Refactor ViewSets](#refactor-viewsets)
|
||||
6. [Testing & Validation](#testing--validation)
|
||||
@@ -24,8 +24,8 @@
|
||||
## OVERVIEW
|
||||
|
||||
### Objectives
|
||||
- ✅ Create `domain/` folder structure
|
||||
- ✅ Move models from `modules/` to `domain/`
|
||||
- ✅ Create `business/` folder structure
|
||||
- ✅ Move models from `modules/` to `business/`
|
||||
- ✅ Extract business logic from ViewSets to services
|
||||
- ✅ Keep ViewSets as thin wrappers
|
||||
- ✅ Preserve all existing API functionality
|
||||
@@ -38,18 +38,18 @@
|
||||
|
||||
---
|
||||
|
||||
## CREATE DOMAIN STRUCTURE
|
||||
## CREATE BUSINESS STRUCTURE
|
||||
|
||||
### 1.1 Create Domain Structure
|
||||
### 1.1 Create Business Structure
|
||||
|
||||
**Purpose**: Organize code by business domains, not technical layers.
|
||||
**Purpose**: Organize code by business logic, not technical layers.
|
||||
|
||||
#### Folder Structure
|
||||
|
||||
```
|
||||
backend/igny8_core/
|
||||
├── domain/ # NEW: Domain layer
|
||||
│ ├── content/ # Content domain
|
||||
├── business/ # NEW: Business logic layer
|
||||
│ ├── content/ # Content business logic
|
||||
│ │ ├── __init__.py
|
||||
│ │ ├── models.py # Content, Tasks, Images
|
||||
│ │ ├── services/
|
||||
@@ -59,7 +59,7 @@ backend/igny8_core/
|
||||
│ │ │ └── content_versioning_service.py
|
||||
│ │ └── migrations/
|
||||
│ │
|
||||
│ ├── planning/ # Planning domain
|
||||
│ ├── planning/ # Planning business logic
|
||||
│ │ ├── __init__.py
|
||||
│ │ ├── models.py # Keywords, Clusters, Ideas
|
||||
│ │ ├── services/
|
||||
@@ -68,12 +68,12 @@ backend/igny8_core/
|
||||
│ │ │ └── ideas_service.py
|
||||
│ │ └── migrations/
|
||||
│ │
|
||||
│ ├── billing/ # Billing domain (already exists)
|
||||
│ ├── billing/ # Billing business logic (already exists)
|
||||
│ │ ├── models.py # Credits, Transactions
|
||||
│ │ └── services/
|
||||
│ │ └── credit_service.py # Already exists
|
||||
│ │
|
||||
│ └── automation/ # Automation domain (Phase 2)
|
||||
│ └── automation/ # Automation business logic (Phase 2)
|
||||
│ ├── models.py
|
||||
│ └── services/
|
||||
```
|
||||
@@ -82,30 +82,30 @@ backend/igny8_core/
|
||||
|
||||
| Task | File | Current Location | New Location | Risk |
|
||||
|------|------|------------------|--------------|------|
|
||||
| **Create domain/ folder** | `backend/igny8_core/domain/` | N/A | NEW | LOW |
|
||||
| **Create content domain** | `domain/content/` | N/A | NEW | LOW |
|
||||
| **Create planning domain** | `domain/planning/` | N/A | NEW | LOW |
|
||||
| **Create billing domain** | `domain/billing/` | `modules/billing/` | MOVE | LOW |
|
||||
| **Create automation domain** | `domain/automation/` | N/A | NEW (Phase 2) | LOW |
|
||||
| **Create business/ folder** | `backend/igny8_core/business/` | N/A | NEW | LOW |
|
||||
| **Create content business** | `business/content/` | N/A | NEW | LOW |
|
||||
| **Create planning business** | `business/planning/` | N/A | NEW | LOW |
|
||||
| **Create billing business** | `business/billing/` | `modules/billing/` | MOVE | LOW |
|
||||
| **Create automation business** | `business/automation/` | N/A | NEW (Phase 2) | LOW |
|
||||
|
||||
---
|
||||
|
||||
## MOVE MODELS TO DOMAIN
|
||||
## MOVE MODELS TO BUSINESS
|
||||
|
||||
### 1.2 Move Models to Domain
|
||||
### 1.2 Move Models to Business
|
||||
|
||||
**Purpose**: Move models from `modules/` to `domain/` to separate business logic from API layer.
|
||||
**Purpose**: Move models from `modules/` to `business/` to separate business logic from API layer.
|
||||
|
||||
#### Content Models Migration
|
||||
|
||||
| Model | Current Location | New Location | Changes Needed |
|
||||
|------|------------------|--------------|----------------|
|
||||
| `Content` | `modules/writer/models.py` | `domain/content/models.py` | Move, update imports |
|
||||
| `Tasks` | `modules/writer/models.py` | `domain/content/models.py` | Move, update imports |
|
||||
| `Images` | `modules/writer/models.py` | `domain/content/models.py` | Move, update imports |
|
||||
| `Content` | `modules/writer/models.py` | `business/content/models.py` | Move, update imports |
|
||||
| `Tasks` | `modules/writer/models.py` | `business/content/models.py` | Move, update imports |
|
||||
| `Images` | `modules/writer/models.py` | `business/content/models.py` | Move, update imports |
|
||||
|
||||
**Migration Steps**:
|
||||
1. Create `domain/content/models.py`
|
||||
1. Create `business/content/models.py`
|
||||
2. Copy models from `modules/writer/models.py`
|
||||
3. Update imports in `modules/writer/views.py`
|
||||
4. Create migration to ensure no data loss
|
||||
@@ -115,12 +115,12 @@ backend/igny8_core/
|
||||
|
||||
| Model | Current Location | New Location | Changes Needed |
|
||||
|------|------------------|--------------|----------------|
|
||||
| `Keywords` | `modules/planner/models.py` | `domain/planning/models.py` | Move, update imports |
|
||||
| `Clusters` | `modules/planner/models.py` | `domain/planning/models.py` | Move, update imports |
|
||||
| `ContentIdeas` | `modules/planner/models.py` | `domain/planning/models.py` | Move, update imports |
|
||||
| `Keywords` | `modules/planner/models.py` | `business/planning/models.py` | Move, update imports |
|
||||
| `Clusters` | `modules/planner/models.py` | `business/planning/models.py` | Move, update imports |
|
||||
| `ContentIdeas` | `modules/planner/models.py` | `business/planning/models.py` | Move, update imports |
|
||||
|
||||
**Migration Steps**:
|
||||
1. Create `domain/planning/models.py`
|
||||
1. Create `business/planning/models.py`
|
||||
2. Copy models from `modules/planner/models.py`
|
||||
3. Update imports in `modules/planner/views.py`
|
||||
4. Create migration to ensure no data loss
|
||||
@@ -130,13 +130,13 @@ backend/igny8_core/
|
||||
|
||||
| Model | Current Location | New Location | Changes Needed |
|
||||
|------|------------------|--------------|----------------|
|
||||
| `CreditTransaction` | `modules/billing/models.py` | `domain/billing/models.py` | Move, update imports |
|
||||
| `CreditUsageLog` | `modules/billing/models.py` | `domain/billing/models.py` | Move, update imports |
|
||||
| `CreditTransaction` | `modules/billing/models.py` | `business/billing/models.py` | Move, update imports |
|
||||
| `CreditUsageLog` | `modules/billing/models.py` | `business/billing/models.py` | Move, update imports |
|
||||
|
||||
**Migration Steps**:
|
||||
1. Create `domain/billing/models.py`
|
||||
1. Create `business/billing/models.py`
|
||||
2. Copy models from `modules/billing/models.py`
|
||||
3. Move `CreditService` to `domain/billing/services/credit_service.py`
|
||||
3. Move `CreditService` to `business/billing/services/credit_service.py`
|
||||
4. Update imports in `modules/billing/views.py`
|
||||
5. Create migration to ensure no data loss
|
||||
|
||||
@@ -152,11 +152,11 @@ backend/igny8_core/
|
||||
|
||||
| Task | File | Purpose | Dependencies |
|
||||
|------|------|---------|--------------|
|
||||
| **Create ContentService** | `domain/content/services/content_generation_service.py` | Unified content generation | Existing Writer logic, CreditService |
|
||||
| **Create ContentService** | `business/content/services/content_generation_service.py` | Unified content generation | Existing Writer logic, CreditService |
|
||||
|
||||
**ContentService Methods**:
|
||||
```python
|
||||
# domain/content/services/content_generation_service.py
|
||||
# business/content/services/content_generation_service.py
|
||||
class ContentGenerationService:
|
||||
def __init__(self):
|
||||
self.credit_service = CreditService()
|
||||
@@ -184,11 +184,11 @@ class ContentGenerationService:
|
||||
|
||||
| Task | File | Purpose | Dependencies |
|
||||
|------|------|---------|--------------|
|
||||
| **Create PlanningService** | `domain/planning/services/clustering_service.py` | Keyword clustering | Existing Planner logic, CreditService |
|
||||
| **Create PlanningService** | `business/planning/services/clustering_service.py` | Keyword clustering | Existing Planner logic, CreditService |
|
||||
|
||||
**PlanningService Methods**:
|
||||
```python
|
||||
# domain/planning/services/clustering_service.py
|
||||
# business/planning/services/clustering_service.py
|
||||
class ClusteringService:
|
||||
def __init__(self):
|
||||
self.credit_service = CreditService()
|
||||
@@ -211,11 +211,11 @@ class ClusteringService:
|
||||
|
||||
| Task | File | Purpose | Dependencies |
|
||||
|------|------|---------|--------------|
|
||||
| **Create IdeasService** | `domain/planning/services/ideas_service.py` | Generate content ideas | Existing Planner logic, CreditService |
|
||||
| **Create IdeasService** | `business/planning/services/ideas_service.py` | Generate content ideas | Existing Planner logic, CreditService |
|
||||
|
||||
**IdeasService Methods**:
|
||||
```python
|
||||
# domain/planning/services/ideas_service.py
|
||||
# business/planning/services/ideas_service.py
|
||||
class IdeasService:
|
||||
def __init__(self):
|
||||
self.credit_service = CreditService()
|
||||
@@ -380,13 +380,13 @@ class TasksViewSet(SiteSectorModelViewSet):
|
||||
|
||||
### Backend Tasks
|
||||
|
||||
- [ ] Create `domain/` folder structure
|
||||
- [ ] Create `domain/content/` folder
|
||||
- [ ] Create `domain/planning/` folder
|
||||
- [ ] Create `domain/billing/` folder (move existing)
|
||||
- [ ] Move Content models to `domain/content/models.py`
|
||||
- [ ] Move Planning models to `domain/planning/models.py`
|
||||
- [ ] Move Billing models to `domain/billing/models.py`
|
||||
- [ ] Create `business/` folder structure
|
||||
- [ ] Create `business/content/` folder
|
||||
- [ ] Create `business/planning/` folder
|
||||
- [ ] Create `business/billing/` folder (move existing)
|
||||
- [ ] Move Content models to `business/content/models.py`
|
||||
- [ ] Move Planning models to `business/planning/models.py`
|
||||
- [ ] Move Billing models to `business/billing/models.py`
|
||||
- [ ] Create migrations for model moves
|
||||
- [ ] Create `ContentGenerationService`
|
||||
- [ ] Create `ClusteringService`
|
||||
@@ -428,7 +428,7 @@ class TasksViewSet(SiteSectorModelViewSet):
|
||||
- ✅ Services are testable independently
|
||||
- ✅ Business logic extracted from ViewSets
|
||||
- ✅ ViewSets are thin wrappers
|
||||
- ✅ All models moved to domain layer
|
||||
- ✅ All models moved to business layer
|
||||
|
||||
---
|
||||
|
||||
|
||||
Reference in New Issue
Block a user