Đây là project demo xây dựng hệ thống thi online (Test Center) sử dụng:
- Domain Driven Design (DDD)
- Clean Architecture
- Rich Domain Model
- Tactical DDD Pattern
- Laravel 10
- PHP 8.1+
Mục tiêu của project:
- Demo cách evolve từ MVC/service layer sang DDD
- Giảm business logic phình trong service
- Tăng khả năng mở rộng business
- Tách biệt business với framework/infrastructure
- Làm tài liệu training nội bộ về DDD + Clean Architecture
Hệ thống hiện tại hỗ trợ:
- Single Choice Question
- Multiple Choice Question
- Fill Blank Question
- Matching Question
- Tạo đề thi
- Submit bài thi
- Chấm điểm
- Tính tổng điểm
- Domain Event khi submit
Project đã implement domain invariant:
- Không cho negative score
- Không cho duplicate multiple choice answer
- Không cho empty fill blank answer
- Không cho invalid matching pair
src/
├── Application/
├── Domain/
└── Infrastructure/Controller
-> Application
-> Domain
<- InfrastructureOuter -> InnerDomain layer:
- không biết Laravel
- không biết Database
- không biết Redis
- không biết HTTP
- không biết Queue
Chứa:
- Entity
- Value Object
- Aggregate
- Domain Service
- Domain Event
- Repository Interface
Ví dụ:
Domain/
├── Question/
├── Submission/
├── Shared/
└── Exam/Application layer chỉ orchestration:
- load aggregate
- execute business behavior
- persist
- publish event
- return response DTO
Ví dụ:
SubmitExamHandlerImplement:
- Repository
- Event Bus
- ORM
- Persistence
- External Service
Ví dụ:
EloquentQuestionRepository
LaravelEventBusQuestion tự behavior:
$question->grade($answer);
$question->createAnswer($payload);Ví dụ:
Score
QuestionText
AcceptedAnswers
MatchingPair
UserID
ExamIDVí dụ:
Submission Aggregatechịu trách nhiệm:
- consistency boundary
- submission lifecycle
- domain event recording
Ví dụ:
ScoringServiceDùng cho:
- cross entity logic
- grading workflow
Ví dụ:
ExamSubmittedFlow:
Domain
-> recordEvent()
Application
-> publish()Business logic nằm trong Domain.
Không nằm ở:
God ServiceSử dụng:
Polymorphismthay vì:
switch ($question->type)Khi thêm loại question mới:
EssayQuestion
TrueFalseQuestionkhông cần sửa logic cũ.
Ví dụ:
new Score(-10);=> Exception
| MVC/Service Layer | DDD + Clean Architecture |
|---|---|
| Business logic phình trong service | Business behavior nằm trong domain |
| Nhiều if/else | Polymorphism |
| Khó scale business | Scale tốt hơn |
| Coupling cao | Boundary rõ ràng |
| Entity chỉ chứa data | Rich Domain Model |
| Framework-centric | Domain-centric |
Project được thiết kế để dễ mở rộng cho:
- Weighted Score
- Retry Policy
- Time Limit
- Random Question
- Section Score
- AI Grading
- Essay Question
- Partial Grading
- Detect tab switch
- Detect copy paste
- Webcam monitoring
- Suspicious behavior detection
- Leaderboard
- Ranking
- Analytics
- Question difficulty
- Completion rate
- Nhiều trung tâm thi
- Tenant policy riêng
- Scoring strategy riêng
- PHP 8.1+
- Composer
- Laravel
git clone <repository-url>composer installcp .env.example .envphp artisan key:generatephp artisan migratephp artisan db:seedphp artisan servephp artisan testhoặc:
vendor/bin/phpunit| Concept | Có áp dụng |
|---|---|
| Entity | ✅ |
| Value Object | ✅ |
| Aggregate | ✅ |
| Domain Service | ✅ |
| Domain Event | ✅ |
| Repository | ✅ |
| Rich Domain Model | ✅ |
| Invariant Protection | ✅ |
| Clean Architecture | ✅ |
| Polymorphism | ✅ |
Project này được xây dựng để:
- training DDD
- training Clean Architecture
- demo scaling business complexity
- demo refactor từ MVC sang DDD
- demo tactical DDD thực tế
DDD không phải:
đổi tên folderDDD là:
Model business complexity bằng behaviorliem04