2026-03-06 11:33:32 -06:00
# CPAS Violation Tracker
2026-03-06 23:18:28 -06:00
Single-container Dockerized web app for CPAS violation documentation and workforce standing management.
Built with **React + Vite ** (frontend), **Node.js + Express ** (backend), **SQLite ** (database), and **Puppeteer ** (PDF generation).
---
2026-03-06 11:33:32 -06:00
## The only requirement on your machine: Docker Desktop
2026-03-06 23:18:28 -06:00
Everything else — Node.js, npm, React build, Chromium for PDF — happens inside Docker.
2026-03-06 11:33:32 -06:00
---
## Quickstart (Local)
```bash
# 1. Build the image (installs all deps + compiles React inside Docker)
docker build -t cpas-tracker .
# 2. Run it
docker run -d --name cpas-tracker \
-p 3001:3001 \
-v cpas-data:/data \
cpas-tracker
# 3. Open
# http://localhost:3001
```
## Export for Unraid
```bash
docker save cpas-tracker | gzip > cpas-tracker.tar.gz
```
Then follow README_UNRAID_INSTALL.md.
## Update After Code Changes
```bash
docker build -t cpas-tracker .
docker stop cpas-tracker && docker rm cpas-tracker
docker run -d --name cpas-tracker -p 3001:3001 -v cpas-data:/data cpas-tracker
```
2026-03-06 23:18:28 -06:00
---
## Features
### Company Dashboard
- Live table of all employees sorted by active CPAS points (highest risk first)
- Summary stat cards: total employees, elite standing (0 pts), with active points, at-risk count, highest active score
- **At-risk badge**: flags employees within 2 points of the next tier escalation
- Search/filter by name, department, or supervisor
- Click any employee name to open their full profile modal
2026-03-07 09:40:34 -06:00
- **📋 Audit Log** button — filterable, paginated view of all system write actions
2026-03-06 23:18:28 -06:00
### Violation Form
- Select existing employee or enter new employee by name
- **Employee intelligence**: shows current CPAS standing badge and 90-day violation count before submitting
- Violation type dropdown grouped by category; shows prior 90-day counts inline
- **Recidivist auto-escalation**: if an employee has prior violations of the same type, points slider auto-sets to maximum per policy
- Repeat offense badge with prior count displayed
- Context-sensitive fields (time, minutes late, amount, location, description) shown only when relevant to violation type
- **Tier crossing warning** (TierWarning component): previews what tier the new points would push the employee into before submission
- Point slider for discretionary adjustments within the violation's min/max range
- One-click PDF download immediately after submission
### Employee Profile Modal
2026-03-07 09:40:34 -06:00
- Full violation history with resolution status and **amendment count badge ** per record
- **✎ Edit Employee** button — update name, department, or supervisor inline
- **Merge Duplicate** tab — reassign all violations from a duplicate record and delete it
- **Amend** button per active violation — edit non-scoring fields (location, notes, witness, etc.) with a full field-level diff history
2026-03-06 23:18:28 -06:00
- Negate / restore individual violations (soft delete with resolution type + notes)
- Hard delete option for data entry errors
- PDF download for any historical violation record
2026-03-07 09:40:34 -06:00
### Audit Log
- Append-only log of every write action: employee created/edited/merged, violation logged/amended/negated/restored/deleted
- Filterable by entity type (employee / violation) and action
- Paginated with load-more; accessible from the Dashboard toolbar
### Violation Amendment
- Edit submitted violations' non-scoring fields without delete-and-resubmit
- Point values, violation type, and incident date are immutable
- Every change is stored as a field-level diff (old → new value) with timestamp and actor
2026-03-06 23:18:28 -06:00
### CPAS Tier System
| Points | Tier | Label |
|--------|------|-------|
| 0– 4 | 0– 1 | Elite Standing |
| 5– 9 | 1 | Realignment |
| 10– 14 | 2 | Administrative Lockdown |
| 15– 19 | 3 | Verification |
| 20– 24 | 4 | Risk Mitigation |
| 25– 29 | 5 | Final Decision |
| 30+ | 6 | Separation |
Scores are computed over a **rolling 90-day window ** (negated violations excluded).
### PDF Generation
- Puppeteer + system Chromium (bundled in Docker image)
- Generated on-demand per violation via `GET /api/violations/:id/pdf`
- Filename: `CPAS_<EmployeeName>_<IncidentDate>.pdf`
- PDF captures prior active points **at the time of the incident ** (snapshot stored on insert)
---
## API Reference
| Method | Endpoint | Description |
|--------|----------|-------------|
| GET | `/api/health` | Health check |
| GET | `/api/employees` | List all employees |
| POST | `/api/employees` | Create or upsert employee |
2026-03-07 09:40:34 -06:00
| PATCH | `/api/employees/:id` | Edit employee name, department, or supervisor |
| POST | `/api/employees/:id/merge` | Merge duplicate employee into target; reassigns all violations |
2026-03-06 23:18:28 -06:00
| GET | `/api/employees/:id/score` | Get active CPAS score for employee |
| GET | `/api/dashboard` | All employees with active points + violation counts |
| POST | `/api/violations` | Log a new violation |
2026-03-07 09:40:34 -06:00
| GET | `/api/violations/employee/:id` | Get violation history for employee (with resolutions + amendment counts) |
2026-03-06 23:18:28 -06:00
| PATCH | `/api/violations/:id/negate` | Negate a violation (soft delete + resolution record) |
| PATCH | `/api/violations/:id/restore` | Restore a negated violation |
2026-03-07 09:40:34 -06:00
| PATCH | `/api/violations/:id/amend` | Amend non-scoring fields with field-level diff logging |
| GET | `/api/violations/:id/amendments` | Get amendment history for a violation |
2026-03-06 23:18:28 -06:00
| DELETE | `/api/violations/:id` | Hard delete a violation |
| GET | `/api/violations/:id/pdf` | Download violation PDF |
2026-03-07 09:40:34 -06:00
| GET | `/api/audit` | Paginated audit log (filterable by entity_type, entity_id) |
2026-03-06 23:18:28 -06:00
---
2026-03-06 11:33:32 -06:00
## Project Structure
```
2026-03-06 23:18:28 -06:00
cpas/
2026-03-07 09:40:34 -06:00
├── Dockerfile # Multi-stage: builds React + runs Express w/ Chromium
2026-03-06 11:33:32 -06:00
├── .dockerignore
2026-03-07 09:40:34 -06:00
├── package.json # Backend (Express) deps
├── server.js # API + static file server
2026-03-06 11:33:32 -06:00
├── db/
2026-03-07 09:40:34 -06:00
│ ├── schema.sql # Tables + 90-day active score view
│ └── database.js # SQLite connection (better-sqlite3) + auto-migrations
2026-03-06 23:18:28 -06:00
├── pdf/
2026-03-07 09:40:34 -06:00
│ └── generator.js # Puppeteer PDF generation
└── client/ # React frontend (Vite)
2026-03-06 11:33:32 -06:00
├── package.json
├── vite.config.js
├── index.html
└── src/
├── main.jsx
├── App.jsx
├── data/
2026-03-07 09:40:34 -06:00
│ └── violations.js # All CPAS violation definitions + groups
2026-03-06 23:18:28 -06:00
├── hooks/
│ └── useEmployeeIntelligence.js # Score + history hook
2026-03-06 11:33:32 -06:00
└── components/
2026-03-07 09:40:34 -06:00
├── CpasBadge.jsx # Tier badge + color logic
├── TierWarning.jsx # Pre-submit tier crossing alert
├── Dashboard.jsx # Company-wide leaderboard + audit log trigger
├── ViolationForm.jsx # Violation entry form
├── EmployeeModal.jsx # Employee profile + history modal
├── EditEmployeeModal.jsx # Employee edit + merge duplicate
├── AmendViolationModal.jsx # Non-scoring field amendment + diff history
├── AuditLog.jsx # Filterable audit log panel
├── NegateModal.jsx # Negate/resolve violation dialog
└── ViolationHistory.jsx # Violation list component
2026-03-06 11:33:32 -06:00
```
2026-03-06 23:18:28 -06:00
---
## Database Schema
2026-03-07 09:40:34 -06:00
Six tables + one view:
2026-03-06 23:18:28 -06:00
- **`employees` ** — id, name, department, supervisor
- **`violations` ** — full incident record including `prior_active_points` snapshot at time of logging
- **`violation_resolutions` ** — resolution type, details, resolved_by (linked to violations)
2026-03-07 09:40:34 -06:00
- **`violation_amendments` ** — field-level diff log for violation edits; one row per changed field per amendment
- **`audit_log` ** — append-only record of every write action (action, entity_type, entity_id, performed_by, details, timestamp)
2026-03-06 23:18:28 -06:00
- **`active_cpas_scores` ** (view) — sum of points for non-negated violations in rolling 90 days, grouped by employee
---
2026-03-06 23:21:24 -06:00
## Roadmap
### ✅ Completed
| Phase | Feature | Description |
|-------|---------|-------------|
| 1 | Container scaffold | Docker multi-stage build, Express server, SQLite schema |
| 1 | Base violation form | Employee fields, violation type, incident date, point submission |
| 2 | Employee intelligence | Live CPAS standing badge and 90-day count shown before submitting |
| 2 | Prior violation highlighting | Violation dropdown annotates types with 90-day recurrence counts |
| 2 | Recidivist auto-escalation | Points slider auto-maximizes on repeat same-type violations |
| 2 | Violation history | Per-employee history list with resolution status |
| 3 | PDF generation | Puppeteer/Chromium PDF per violation, downloadable immediately post-submit |
| 3 | Prior-points snapshot | `prior_active_points` captured at insert time for accurate historical PDFs |
| 4 | Company dashboard | Sortable employee table with live tier badges and at-risk flags |
| 4 | Stat cards | Summary counts: total, clean, active, at-risk, highest score |
| 4 | Tier crossing warning | Pre-submit alert when new points push employee to next tier |
| 4 | Employee profile modal | Full history, negate/restore, hard delete, per-record PDF download |
| 4 | Negate & restore | Soft-delete violations with resolution type + notes, fully reversible |
2026-03-07 09:40:34 -06:00
| 5 | Employee edit / merge | Update employee name/dept/supervisor; merge duplicate records without losing history |
| 5 | Violation amendment | Edit non-scoring fields with field-level audit trail |
| 5 | Audit log | Append-only log of all system writes; filterable panel in the dashboard |
---
### 📋 In Progress
#### Reporting & Visibility
- **Expiration timeline** — per-employee view showing which active violations roll off the 90-day window and when; lets supervisors anticipate tier drops before they happen
- **Employee notes / flags** — free-text notes attached to an employee record (e.g. "on PIP", "union member") visible in the profile modal without affecting scoring
2026-03-06 23:18:28 -06:00
2026-03-06 23:21:24 -06:00
---
2026-03-07 09:40:34 -06:00
### 💡 Proposed
2026-03-06 23:21:24 -06:00
#### Reporting & Analytics
- **Violation trends chart** — line/bar chart of violations per day/week/month, filterable by department or supervisor; useful for identifying systemic patterns vs. individual incidents
- **Department heat map** — grid view showing violation density and average CPAS score by department; helps supervisors identify team-level risk
- **CSV / Excel export** — bulk export of violations or dashboard data for external reporting or payroll integration
#### Employee Management
- **Supervisor view** — scoped dashboard showing only the employees under a given supervisor, useful for multi-supervisor environments
#### Violation Workflow
- **Acknowledgment signature field** — a "received by employee" name/date field on the violation form that prints on the PDF, replacing the blank signature line
- **Draft / pending violations** — save a violation as draft before finalizing, useful when incidents need review before being officially logged
- **Bulk violation import** — CSV import for migrating historical records from paper logs or a prior system
#### Notifications & Escalation
- **Tier escalation alerts** — email or in-app notification when an employee crosses into Tier 2+ so the relevant supervisor is automatically informed
- **Scheduled summary digest** — weekly email to supervisors listing their employees' current standings and any approaching tier thresholds
- **At-risk threshold configuration** — make the "at-risk" warning threshold (currently hardcoded at 2 pts) configurable per deployment
#### Infrastructure & Ops
- **Multi-user auth** — simple login with role-based access (admin, supervisor, read-only); currently the app has no auth and is assumed to run on a trusted internal network
- **Automated DB backup** — cron job or Docker health hook to snapshot `/data/cpas.db` to a mounted backup volume or remote location on a schedule
- **Dark/light theme toggle** — the UI is currently dark-only; a toggle would improve usability in bright environments
---
*Proposed features are suggestions based on common HR documentation workflows. Priority and implementation order should be driven by actual operational needs.*