Files
portal-api/INFRASTRUCTURE_ACTION_ITEMS.md
T

119 lines
3.9 KiB
Markdown

# Infrastructure Management Module - Action Items
## 🔴 P0 - CRITICAL (Ngay lập tức)
### 1. Authorization - Implement Laravel Policies
- [ ] Tạo Policy classes cho: vCenter, Datacenter, Host, Datastore, Network, Folder
- [ ] Thêm middleware `can:` vào tất cả infrastructure routes trong `routes/admin.php`
- [ ] Xóa view-level RBAC checks trong Blade files
- [ ] Định nghĩa permission constants thay vì hard-coded strings
### 2. Database - FK Constraints & Indexes
- [ ] Thêm FK constraint cho `module_folder.module_datacenter_id`
- [ ] Thêm index cho `module_network.module_host_id`
- [ ] Thêm index cho `module_datastore.module_host_id`
- [ ] Thêm composite index: `(vcenter_id, status)`, `(datacenter_id, status)`
### 3. Database - Soft Deletes
- [ ] Thêm soft deletes cho bảng: module_vcenter, module_datacenter, module_host, module_datastore, module_network, module_folder
- [ ] Update Models thêm `SoftDeletes` trait
- [ ] Update Repositories xử lý soft delete queries
---
## 🟡 P1 - HIGH PRIORITY (Trong 30 ngày)
### 4. API Design - Versioning & Authentication
- [ ] Tạo API route group `/api/v1/`
- [ ] Implement API Resources/Transformers cho các entities
- [ ] Thêm Sanctum authentication cho API
- [ ] Thêm rate limiting cho sync endpoints
### 5. Performance - Caching & Queries
- [ ] Implement Redis cache với tags theo vCenter/datacenter
- [ ] Fix cache invalidation khi có updates
- [ ] Thêm eager loading `with(['vCenter'])` trong controllers
- [ ] Tạo index cho `findByName` (full-text hoặc index)
### 6. Tree Explorer - Lazy Loading
- [ ] Tạo API endpoint cho tree lazy-load: `/api/v1/infrastructure/tree`
- [ ] Implement expand-on-demand pattern
- [ ] Cache tree structure với short TTL
---
## 🟢 P2 - MEDIUM PRIORITY (Trong 60 ngày)
### 7. Domain Modeling - Refactoring
- [ ] Tạo module/Infrastructure/Resources thay thế presentation logic trong Models
- [ ] Di chuyển `getStatus()` HTML rendering từ Model sang Resource
- [ ] Thêm scope methods cho common queries
### 8. Multi-tenancy Preparation
- [ ] Thêm cột `tenant_id` vào tất cả infrastructure tables
- [ ] Tạo global scope cho tenant filtering
- [ ] Update repositories handle tenant context
### 9. Sync Jobs - Event Driven
- [ ] Tạo Infrastructure events: DatacenterSynced, HostSynced, etc.
- [ ] Implement event listeners cho cache invalidation
- [ ] Thêm queue prioritization cho sync jobs
- [ ] Implement job locking tránh race conditions
---
## 🔵 P3 - FUTURE (60-90 ngày)
### 10. Technical Debt
- [ ] Tạo constants class cho permissions
- [ ] Refactor password handling (统一 encryption approach)
- [ ] Thêm API documentation (Swagger/OpenAPI)
- [ ] Tách biệt Read/Write repositories
### 11. SPA Migration Preparation
- [ ] Tạo dedicated API controllers cho SPA
- [ ] Implement proper JSON error responses
- [ ] Thêm pagination metadata vào responses
- [ ] Tạo API documentation
---
## 📊 Progress Tracking
| Category | Total | Completed | In Progress | Pending |
|----------|-------|-----------|-------------|---------|
| P0 - Critical | 10 | | | |
| P1 - High | 10 | | | |
| P2 - Medium | 10 | | | |
| P3 - Future | 4 | | | |
---
## 📝 Notes
### Database Migrations Needed:
```
1. add_soft_deletes_to_infrastructure_tables.php
2. add_missing_indexes_and_fk.php
3. add_tenant_id_to_infrastructure_tables.php
```
### Files to Create:
```
app/Policies/vCenterPolicy.php
app/Policies/DatacenterPolicy.php
app/Policies/HostPolicy.php
app/Policies/DatastorePolicy.php
app/Policies/NetworkPolicy.php
app/Policies/FolderPolicy.php
app/Http/Resources/Api/v1/vCenterResource.php
app/Http/Resources/Api/v1/DatacenterResource.php
app/Events/Infrastructure/DatacenterSynced.php
app/Listeners/Infrastructure/InvalidateDatacenterCache.php
```
### Key Dependencies:
- Laravel Sanctum (API auth)
- Redis (caching)
- Spatie Laravel-permission (RBAC) - optionally