Photo Management (per specs/photo-management.md): - Sharp integration for 3-size compression (thumb/medium/full) - WebP output with 80-90% quality - Client-side compression with browser-image-compression - PhotoUpload component with camera/drag-drop support - Upload API with bulk support and stats endpoint Testing: - Backend: Jest tests for all major API endpoints - Frontend: Vitest tests for utilities and API clients - CI: Updated Forgejo workflow for test execution Specs (100% coverage): - visitor-management.md (Phase 8) - messaging.md (Phase 9) - audit-and-documents.md (Phase 10) - accessibility-i18n.md (Phase 11) - hardware-integration.md (Phase 12) - advanced-features.md (Phase 13) Documentation: - OpenAPI 3.0 spec (docs/openapi.yaml) - All endpoints documented with schemas
2.5 KiB
2.5 KiB
Feature Spec: Audit Trail & Document Management
Priority: 🔴 Critical (Compliance)
Phase: 10
Status: ✅ Implemented
Overview
Zero-friction compliance reporting. Every action logged, every document versioned, instant report generation for inspectors.
Audit Log
Model: AuditLog
id: UUIDuserId: FK to Useraction: string (CREATE, UPDATE, DELETE, VIEW, LOGIN, etc.)entityType: string (Batch, Room, Plant, etc.)entityId: stringbeforeData: JSON (state before change)afterData: JSON (state after change)ipAddress: stringuserAgent: stringtimestamp: datetimemetadata: JSON (additional context)
API Endpoints
GET /api/audit/logs- Query logs with filtersGET /api/audit/logs/:entityType/:entityId- Entity historyGET /api/audit/summary- Dashboard statisticsGET /api/audit/export- CSV/JSON export
Implementation Notes
- Immutable storage (append-only, no deletions)
- Automatic logging via middleware
- 7-year retention for compliance
- Indexes on entityType, entityId, timestamp
Document Management
Model: Document
id: UUIDtitle: stringtype: enum (SOP, POLICY, FORM, CERTIFICATE, LICENSE, OTHER)category: stringcontent: string (markdown) OR fileUrlcurrentVersion: numberstatus: enum (DRAFT, PENDING_APPROVAL, APPROVED)requiresAck: booleancreatedById: FKapprovedById: FK (optional)approvedAt: datetime (optional)
Model: DocumentVersion
id: UUIDdocumentId: FKversion: numbercontent: string OR fileUrlchangeNotes: stringcreatedById: FKcreatedAt: datetime
Model: DocumentAck
id: UUIDdocumentId: FKuserId: FKversion: numberacknowledgedAt: datetime
API Endpoints
GET /api/documents- List documentsPOST /api/documents- Create documentGET /api/documents/:id- Get with versionsPUT /api/documents/:id- Update (creates new version)POST /api/documents/:id/approve- Approve documentPOST /api/documents/:id/acknowledge- Ack documentGET /api/documents/:id/ack-status- Who has ackedGET /api/documents/:id/versions- Version history
Compliance Reports
Available Reports
- Audit Summary - Actions by type, user, time period
- Document Compliance - Ack rates, pending reviews
- User Activity - Login history, action counts
- Entity History - Full change log for any entity
Export Formats
- CSV (for spreadsheets)
- JSON (for integrations)
- PDF (for auditors)