4.4 KiB
4.4 KiB
Drama Ling - 專案架構
這是Drama Ling語言學習應用的主要專案資料夾,包含前端和後端代碼。
專案結構
src/
├── backend/ # .NET Core Web API 後端
│ ├── DramaLing.API/ # Web API 專案
│ ├── DramaLing.Application/ # 應用服務層
│ ├── DramaLing.Core/ # 領域模型層
│ ├── DramaLing.Infrastructure/ # 基礎設施層
│ ├── DramaLing.Tests/ # 測試專案
│ └── DramaLing.sln # 解決方案檔
├── mobile/ # Flutter 移動應用
│ ├── lib/
│ │ ├── core/ # 核心功能 (常數、工具、服務)
│ │ ├── features/ # 功能模組 (認證、學習、對話等)
│ │ └── shared/ # 共用組件 (Widget、模型、Provider)
│ └── pubspec.yaml # Flutter 專案配置
└── docker-compose.yml # Docker 開發環境配置
技術棧
後端 (.NET Core)
- .NET 8: 最新的跨平台框架
- ASP.NET Core Web API: RESTful API 服務
- Entity Framework Core: ORM 資料庫存取
- PostgreSQL: 主要資料庫
- Redis: 快取和會話管理
- JWT: 身份驗證
- Swagger/OpenAPI: API 文檔
- Serilog: 結構化日誌
前端 (Flutter)
- Flutter 3.16+: 跨平台移動應用框架
- Dart 3.0+: 程式語言
- Riverpod: 狀態管理
- Go Router: 導航路由
- Dio + Retrofit: HTTP 客戶端
- Hive: 本地資料存儲
- Material 3: UI 設計系統
開發環境設置
必要工具
- .NET 8 SDK
- Flutter 3.16+
- Docker Desktop
- PostgreSQL (或使用Docker)
快速開始
1. 啟動開發環境
# 啟動資料庫和Redis
cd src
docker-compose up -d postgres redis
# 或者啟動完整環境包含API
docker-compose up -d
2. 後端開發
cd src/backend
# 還原套件
dotnet restore
# 建立資料庫
dotnet ef database update --project DramaLing.Infrastructure --startup-project DramaLing.API
# 啟動API服務
dotnet run --project DramaLing.API
# API將在 http://localhost:5000 啟動
# Swagger UI: http://localhost:5000
3. 前端開發
cd src/mobile
# 安裝套件
flutter pub get
# 程式碼生成 (Riverpod, Retrofit 等)
dart run build_runner build
# 啟動Flutter應用 (需要模擬器或實體裝置)
flutter run
API 文檔
- 開發環境: http://localhost:5000
- Swagger UI: http://localhost:5000 (開發模式下)
- API 規格文檔:
../../docs/04_technical/api/
資料庫
連線資訊 (開發環境)
- 主機: localhost
- 埠號: 5432
- 資料庫: dramaling_dev
- 使用者: postgres
- 密碼: password
遷移指令
# 建立遷移
dotnet ef migrations add <MigrationName> --project DramaLing.Infrastructure --startup-project DramaLing.API
# 更新資料庫
dotnet ef database update --project DramaLing.Infrastructure --startup-project DramaLing.API
# 移除最後一個遷移
dotnet ef migrations remove --project DramaLing.Infrastructure --startup-project DramaLing.API
測試
後端測試
cd src/backend
dotnet test
前端測試
cd src/mobile
flutter test
部署
生產環境建構
# 後端
cd src/backend
dotnet publish DramaLing.API -c Release -o publish
# 前端
cd src/mobile
flutter build apk --release # Android
flutter build ios --release # iOS
開發指南
架構原則
- Clean Architecture: 分層架構,依賴倒置
- CQRS: 命令查詢職責分離 (使用 MediatR)
- Feature-based: 按功能模組組織程式碼
- API-first: API 優先設計
編碼規範
- 後端: 遵循 C# 編碼慣例
- 前端: 遵循 Dart/Flutter 編碼慣例
- 命名: 英文命名,中文註釋
- 測試: 單元測試覆蓋率 > 80%
相關文檔
問題回報
如有問題請參考:
授權
版權所有 © 2025 Drama Ling Team