# KMC Performance Monitoring System - PRD

## Project Overview
Enterprise-grade Performance Monitoring System for Kenya Meat Commission (KMC) to track livestock operations, sales, and stock management across multiple shops.

## Original Problem Statement
Build a complete, production-ready Performance Monitoring System for KMC that tracks:
- Daily sales workflow (Draft → Submit → Post)
- Stock management for HQ and Kibarani (Mombasa)
- Livestock operations (cattle and shoats)
- Payment methods (Co-op, KCB, E-Citizen, Swipe - NO cash)
- Role-based access control (6 roles)

## Tech Stack
- **Frontend**: React 18, Tailwind CSS, Shadcn/UI, Recharts
- **Backend**: FastAPI (Python), JWT Authentication
- **Database**: MongoDB
- **Branding**: KMC colors (#141240 Navy, #1D7AD9 Blue, #D71920 Red)

## User Personas & Roles

| Role | Permissions |
|------|-------------|
| Supervisor | Shop-level sales entry and submission |
| Admin Officer | Sales verification and posting |
| SCM | HQ stock management |
| Kibarani Officer | Mombasa/Kibarani stock management |
| Management | Read-only dashboard access |
| System Admin | Full system access |

## Core Requirements

### Implemented Features ✅
1. **Authentication & RBAC**
   - JWT-based authentication
   - Role-based page access control
   - User management (create, activate/deactivate)

2. **Dashboard**
   - KPI cards: Cattle/Shoats Received & Slaughtered, Sales, Stock, Pending
   - Sales by Shop stacked bar chart
   - Payment Methods pie chart
   - Stock Position bar chart
   - Out-of-Stock Heatmap
   - Sales vs Slaughter Trend line chart

3. **Sales Management**
   - Sales Entry with payment breakdown
   - Draft → Submit → Return → Post workflow
   - Admin approval process
   - Error correction via adjustments

4. **Stock Management**
   - HQ and Kibarani stock entry
   - Stock categories: MOB Beef, Loose Beef, Lamb, Shoats, Offals, KMC Products (VAP)
   - Stock status indicators (In Stock, Low, Out of Stock)

5. **Reports**
   - Date range filtering
   - Shop filtering
   - CSV export
   - Summary statistics

6. **Audit Logging**
   - All CRUD operations logged
   - User and timestamp tracking

### Shops Configured
- Athi River
- Landhies
- Makupa
- Kitengela
- Thika
- Utawala

### Sample Data Seeded
- 6 shops with opening dates
- 6 users with different roles
- 14 days of sales data
- 7 days of stock data
- 14 days of livestock data
- Production operations

## Implementation History

### 2026-02-16: MVP Complete
- Full backend API with FastAPI
- Complete frontend with all 9 pages
- KMC branding with official colors and logo
- Interactive charts using Recharts
- JWT authentication with role-based access
- Sample data seeding
- Bug fixes: ObjectId serialization, role permissions

## API Endpoints

### Auth
- POST `/api/auth/login` - User login
- POST `/api/auth/register` - User registration  
- GET `/api/auth/me` - Get current user

### Sales
- GET `/api/sales` - List sales entries
- POST `/api/sales` - Create sales entry
- PUT `/api/sales/{id}` - Update sales entry
- POST `/api/sales/{id}/submit` - Submit for approval
- POST `/api/sales/{id}/return` - Return with comments
- POST `/api/sales/{id}/post` - Final approval

### Stock
- GET `/api/stock` - List stock entries
- POST `/api/stock` - Create stock entry
- GET `/api/stock/latest` - Get latest stock

### Dashboard
- GET `/api/dashboard/stats` - KPI statistics
- GET `/api/dashboard/sales-by-shop` - Shop sales chart data
- GET `/api/dashboard/payment-breakdown` - Payment pie chart
- GET `/api/dashboard/stock-position` - Stock bar chart
- GET `/api/dashboard/sales-trend` - 7-day trend data
- GET `/api/dashboard/out-of-stock` - Heatmap data

## Prioritized Backlog

### P0 - Critical (Next Sprint)
- [ ] Excel import for bulk sales/stock entry
- [ ] Excel template download

### P1 - High Priority
- [ ] Real-time notifications for pending submissions
- [ ] Mobile-responsive improvements
- [ ] Production operations tracking page
- [ ] Adjustment entries for posted records

### P2 - Medium Priority
- [ ] Email notifications for supervisors
- [ ] Advanced reporting with date ranges
- [ ] Shop performance comparison
- [ ] Historical trend analysis

### P3 - Low Priority
- [ ] Dark mode theme
- [ ] Print-friendly reports
- [ ] API rate limiting
- [ ] Bulk operations

## Demo Credentials
- **Admin**: admin@kmc.go.ke / admin123
- **Supervisor**: supervisor@kmc.go.ke / password123
- **Admin Officer**: admin.officer@kmc.go.ke / password123
- **SCM**: scm@kmc.go.ke / password123
- **Kibarani**: kibarani@kmc.go.ke / password123
- **Management**: management@kmc.go.ke / password123
