6.0 KiB
6.0 KiB
TASK-BEFE-001: System Refactoring for Scale & Security (v2.0)
Status: REVIEW Priority: HIGH Target Version: v2.0.0 Effort: 4 Weeks (Phased)
🎯 Objective
Refactor the DMS system (Backend & Frontend) to support High Scalability (100k+ Documents), Enhanced Security (RBAC/Audit), and Enterprise-Grade UX. This task consolidates three key initiatives:
- Advanced Storage Management: Optimize file storage for large datasets (Data Integrity).
- Admin Panel Refactor: Secure and reorganize the administrative interface.
- Document Management Interface: Improve frontend performance and usability for large document lists.
📅 Roadmap & Phases
| Phase | Focus Area | Key Deliverables |
|---|---|---|
| Phase 1 | Security & Core Fixes | Admin Bypass Removal, Session Kill Switch, Storage Permissions |
| Phase 2 | Data Integrity & Storage | New Storage Logic (Issue Date), Schema Adjustments, Bulk RBAC API |
| Phase 3 | Frontend Foundation | Server-side DataTable, New Folder Structure, API Optimization |
| Phase 4 | UX & Migration | Admin UI Reorg, Document Tabs, Legacy Data Migration |
🛠️ Implementation Checklist
1. Advanced Storage Management (Backend)
Goal: Shift from "Upload Date" to "Issue Date" storage logic and implement deep directory structures for performance.
1.1 Database Schema (Data Integrity)
- Verify Date Columns: Ensure
rfa,correspondence,drawing_revisionshave a reliableissue_dateordocument_date. - Update Attachments Table: Add
reference_datecolumn toattachmentsto freeze the storage path date (prevents broken paths if document date changes).
1.2 FileStorageService Refactor
- Update
commit()Logic: Change storage path generation logic.- Old:
/permanent/YYYY/MM/uuid.pdf(based on execution time) - New:
/permanent/{DocumentType}/{YYYY}/{MM}/{uuid}.pdf(based onissue_date)
- Old:
- Fail-safe Logic: Implement fallback to
created_atifissue_dateis missing.
1.3 Infrastructure & Security
- Deep Directory Structure: Implement logic to handle nested folders to verify Inode limits.
- Path Isolation: Ensure Web Server (NestJS) has
ReadOnlyaccess topermanentstorage,Writeonly for specific services. - Streaming Proxy: Enforce file access via API Stream only (Check RBAC -> Stream File), never expose direct static paths.
1.4 Data Migration (Legacy Support)
- Develop Migration Script:
- Scan
attachmentswhereis_temporary = false. - Retrieve
issue_datefrom parent entity. - Move file to new structure.
- Update
stored_pathin DB.
- Scan
2. Admin Panel Refactor (Frontend & Backend)
Goal: Secure the Admin Panel and reorganize the UI for better usability.
2.1 Critical Security Fixes (Immediate)
- Remove Hardcoded Bypass: Delete
const isAdmin = true;infrontend/app/(admin)/layout.tsx. Validatesession.user.rolefrom JWT. - Middleware Enforcement: Update
frontend/middleware.tsto strictly requireADMINorDCroles for/admin/**routes. - Session Kill Switch: Implement Backend endpoint and Frontend UI to revoke active user sessions.
2.2 Backend Optimization
- Bulk RBAC Update: Create
PUT /roles/permissions/bulkendpoint to handle multiple permission changes in a single transaction (Fixes Loop API issue). - Audit Log Pagination: Update
AuditLogServiceto support Server-side Pagination (page,limit,filters).
2.3 Frontend Reorganization (UI/UX)
- Refactor Folder Structure: Group admin pages logically:
/admin/access-control/(Users, Roles, Sessions)/admin/doc-control/(Numbering, Workflows, Master Data)/admin/monitoring/(Audit Logs, Health)/admin/settings/
- Shared Components: Implement
AdminPageHeaderandAdminDataTablefor consistency.
3. Document Management Interface (Frontend)
Goal: Support browsing 100k+ documents with high performance and better UX.
3.1 Performance (Server-Side Logic)
- Update Hooks: Refactor
useDrawings(and others) to acceptpage,limit,sort,filterparams. - ServerDataTable Component: Create a reusable Table component that handles Server-side pagination and sorting events efficiently.
3.2 UI Structure & Navigation
- Tabbed Interface: Split documents by category (e.g., Contract / Shop / As-Built) using Tabs to load data lazily.
- Visual Cues: Add distinct Badges for Revision Status (e.g., "Current" vs "Superseded").
3.3 Data Integrity Features
- Pre-upload Validation: Implement
NumberPreviewCardto check Document Number availability in real-time before submission. - Revision Guard: Validate
nextPossibleRevisionto prevent skipping revisions (e.g., A -> C).
📂 Technical Guidelines
Backend: Bulk Permission DTO
export class BulkRolePermissionDto {
@IsNumber()
roleId: number;
@IsArray()
@ValidateNested({ each: true })
@Type(() => PermissionChangeDto)
changes: PermissionChangeDto[];
}
Frontend: Sidebar Navigation Structure
const adminMenu = [
{ title: "Overview", items: [{ title: "Dashboard", href: "/admin/dashboard" }] },
{ title: "Access Control", items: [
{ title: "Users", href: "/admin/access-control/users" },
{ title: "Roles & Matrix", href: "/admin/access-control/roles" }
]
},
// ...
];
✅ Acceptance Criteria
- Security: Non-admin users MUST NOT access any
/adminroute. - Performance: Document lists with 100k records must load first page in < 200ms.
- Data Integrity: Files are stored in structure
/permanent/{Type}/{Year}/{Month}/. - Reliability: Bulk Permission updates are atomic (all or nothing).