CoolFace
Apppublic

codedematrix/datacollection

sourceHugging Faceupdated 3mo agoView on Hugging Face
0likes
IMPLEMENTATION_PLAN.md295 linesDownload Raw Back to root
1# NCA Data Collection System — Implementation Handoff2 3**Status:** Beta deployment ready  4**Last Updated:** 2026-06-16  5**Deployment Target:** Hugging Face Spaces (https://huggingface.co/spaces/codedematrix/datacollection)6 7---8 9## ✅ Completed Features10 11### Core System (Operational)12- [x] **Provider Management** — Register, activate, suspend providers across 7 categories13- [x] **Form Builder** — Dynamic data collection forms with 11+ field types (text, numeric, grid, file, select, etc.)14- [x] **Submission Workflow** — 8-state workflow (NOT_STARTED → APPROVED/REJECTED) with approval routing15- [x] **User Management** — 4-role RBAC system (Admin, Officer, Data Entry, Approver)16- [x] **Dashboard** — Executive overview with submission statistics, compliance alerts, active periods17- [x] **Audit Logging** — Full audit trail of all system actions with user/timestamp tracking18 19### Compliance System (Fully Implemented)20- [x] **Automatic Missing Data Detection** — Flags missing required fields across submissions21- [x] **Completion Tracking** — Percentage-based progress indicators on provider portal22- [x] **Compliance Dashboard** — NCA staff can view all compliance flags with filters (status, type, provider)23- [x] **Multi-Status Workflow** — Flags support OPEN/ACKNOWLEDGED/IN_PROGRESS/RESOLVED lifecycle24- [x] **Flag Types** — MISSING_DATA, OVERDUE, INCOMPLETE, CORRECTION tracking25- [x] **Email Integration** — Draft compliance notifications with dynamic field counts (ready for SMTP setup)26- [x] **Provider Visibility** — Providers see only their own missing data alerts and completion status27 28### Search & Filtering (Fixed)29- [x] **Submissions Search** — Multi-field search (provider name, form code, period, ID)30- [x] **Providers Search** — By name, licence number, category, status31- [x] **Users Search** — By name/email with role filtering32- [x] **URL Parameter Preservation** — Filters persist via querystring for bookmarking33- [x] **React Query Stability** — Fixed queryKey caching issues (stable string representation)34 35### Data Export (Tested)36- [x] **CSV Export** — Long/narrow format with submission ID, provider, period, form, field name, value37- [x] **Provider Filtering** — Export only selected provider's submissions38- [x] **Period Filtering** — Export only selected reporting period data39- [x] **Sample Data** — Test submissions populated with real SubmissionValue entries40 41### Frontend UI/UX42- [x] **Provider Portal** — Authenticated view showing only own submissions + compliance alerts43- [x] **NCA Dashboard** — Submission statistics, overdue/correction/approval counters44- [x] **Compliance Board** — Flag management with acknowledge/resolve/email actions45- [x] **Responsive Design** — Mobile-friendly layouts across all pages46- [x] **Navigation** — Fixed provider detail → submission detail flow (no broken 404s)47 48---49 50## 🔄 In-Progress / Blocked51 52### Email Functionality53**Status:** 80% ready (framework in place, SMTP not configured)54 55```python56# Location: backend/apps/compliance/views.py:GenerateMissingDataEmailView57# Current state: Generates draft email with field counts58# Remaining: Wire SMTP config to actually send via Django's mail backend59```60 61**What's needed:**621. Add email credentials to `.env`:63   ```64   EMAIL_HOST=smtp.gmail.com65   EMAIL_PORT=58766   EMAIL_HOST_USER=nca.compliance@gmail.com67   EMAIL_HOST_PASSWORD=<app-password>68   DEFAULT_FROM_EMAIL=nca.compliance@gmail.com69   ```702. Celery task to handle async delivery (stub exists at `backend/apps/compliance/tasks.py`)71 72**To deploy:**73- [ ] Configure SMTP in Django settings74- [ ] Test email sending with one provider75- [ ] Set up Celery Beat for periodic compliance tasks76- [ ] Document email template customization77 78---79 80## 🚀 Deployment Checklist81 82### Local Development83```bash84# Terminal 1: Backend85cd backend && python manage.py runserver86 87# Terminal 2: Frontend  88cd frontend && NEXT_PUBLIC_API_URL=http://localhost:8000 npm run dev89 90# Both servers running:91# Backend: http://localhost:800092# Frontend: http://localhost:300093```94 95### Hugging Face Spaces (No-Credit-Card Option)96**Pre-requisites:**97- Hugging Face account (free tier works)98- Space created at: https://huggingface.co/spaces/codedematrix/datacollection99 100**Deployment steps:**101```bash102# 1. Push latest code (already configured in git remotes)103git push huggingface main104 105# 2. Hugging Face will auto-detect Dockerfile and build106# 3. Monitor build logs at: https://huggingface.co/spaces/codedematrix/datacollection/logs107 108# Environment variables to set in Space settings:109DJANGO_SECRET_KEY=<generate-new>110DATABASE_URL=postgresql://user:pass@db:5432/nca_dc111DEBUG=False112ALLOWED_HOSTS=*.hf.space113```114 115**Database:**116- PostgreSQL 15 bundled in docker-compose117- Data persists in `postgres_data` volume118- For persistent deployments, use managed PostgreSQL (e.g., Vercel Postgres, Railway)119 120---121 122## 📊 API Endpoints Reference123 124### Submissions125```126GET    /api/v1/expected-submissions/           List all (with filters: search, workflow_status, provider__category)127GET    /api/v1/expected-submissions/<id>/      Get single submission128POST   /api/v1/expected-submissions/<id>/submit/  Transition to SUBMITTED129PATCH  /api/v1/expected-submissions/<id>/approve/ NCA approval130PATCH  /api/v1/expected-submissions/<id>/reject/  Rejection with feedback131```132 133### Compliance134```135GET    /api/v1/compliance/flags/               List flags (filters: status, flag_type, provider)136PATCH  /api/v1/compliance/flags/<id>/acknowledge/  Set ACKNOWLEDGED status137PATCH  /api/v1/compliance/flags/<id>/resolve/      Set RESOLVED status138POST   /api/v1/compliance/flags/<id>/generate-email/  Create draft email139```140 141### Providers142```143GET    /api/v1/providers/                      List providers (filters: search, category, status)144GET    /api/v1/providers/<id>/                 Get provider details145GET    /api/v1/providers/<id>/submissions/     Get provider's submissions146```147 148### Authentication149```150POST   /api/v1/auth/login/                     JWT token exchange (email/password)151POST   /api/v1/auth/logout/                    Revoke tokens152GET    /api/v1/auth/me/                        Current user profile153```154 155### Exports156```157POST   /api/v1/exports/csv/                    Generate CSV (payload: period_id, provider_id)158```159 160---161 162## 🗂️ Key File Structure163 164```165nca-data-collection/166├── backend/167│   ├── apps/168│   │   ├── compliance/               # Flag detection & email management169│   │   │   ├── models.py             # ComplianceFlag model170│   │   │   ├── views.py              # API endpoints171│   │   │   ├── serializers.py        # DRF serializers172│   │   │   ├── tasks.py              # Celery task stubs173│   │   │   └── management/commands/  # flag_missing_data command174│   │   ├── submissions/              # Submission tracking175│   │   ├── forms_engine/             # Form builder176│   │   ├── providers/                # Provider management177│   │   └── auth/                     # User + JWT auth178│   ├── config/settings.py            # Django settings179│   ├── manage.py180│   └── requirements.txt181├── frontend/182│   ├── app/183│   │   ├── (nca)/                   # NCA staff dashboard184│   │   ├── (provider)/              # Provider portal185│   │   └── auth/                    # Login/logout186│   ├── components/187│   │   ├── layout/TopBar.tsx        # Header with notifications188│   │   └── ui/                      # Reusable UI components189│   ├── lib/190│   │   ├── api.ts                   # Fetch wrapper with JWT191│   │   ├── types.ts                 # TypeScript types192│   │   └── utils.ts                 # Format/label helpers193│   ├── hooks/                        # React Query hooks194│   └── package.json195├── Dockerfile                        # Multi-stage build196├── docker-compose.yml               # Local dev setup197└── README.md198```199 200---201 202## 🔐 Default Test Credentials203 204| Role | Email | Password | Use |205|------|-------|----------|-----|206| NCA Admin | admin@nca.org.gh | testpass123 | Full system access |207| NCA Officer | officer.asante@nca.org.gh | testpass123 | Submission review/approval |208| Vodafone (Data Entry) | dataentry@vodafone.com.gh | testpass123 | Enter/submit data |209| Vodafone (Approver) | admin@vodafone.com.gh | testpass123 | Internal approval before NCA |210 211**⚠️ Before production:** Change all test passwords and disable test accounts in `.env`.212 213---214 215## 🐛 Known Issues & Workarounds216 217### Issue: Provider can't access submission after approval218**Root cause:** After NCA approves, workflow redirects to submission list instead of closing the review modal.  219**Workaround:** Refresh the submissions page; approved submissions are no longer editable by provider.220 221### Issue: Compliance emails not sending222**Root cause:** SMTP not configured.  223**Fix:** See "Email Functionality" section above.224 225### Issue: Search params not persisting on refresh226**Root cause:** ~~queryKey using object reference~~ FIXED in this build (June 16).  227**Current:** Stable queryString passed to React Query ensures proper caching.228 229---230 231## 📈 Monitoring & Debugging232 233### Logs234- **Backend:** `django.log` or stdout from `python manage.py runserver`235- **Frontend:** Next.js build logs in browser DevTools console236- **Database:** PostgreSQL logs in docker-compose237 238### Health Checks239```bash240# Backend API health241curl http://localhost:8000/api/v1/242 243# Frontend home244curl http://localhost:3000/245 246# Database connection247python manage.py dbshell248```249 250### Common Commands251```bash252# Reset migrations (dev only)253python manage.py migrate zero apps.submissions254 255# Run compliance flag detection256python manage.py flag_missing_data257 258# Create test data259python manage.py shell < scripts/seed_test_data.py260 261# Clear cache262rm -rf frontend/.next263```264 265---266 267## 📋 Next Steps for Production268 2691. **Email Setup** → Configure SMTP + test with one provider2702. **Database Migration** → Move from SQLite/local PostgreSQL to managed service2713. **Environment Configuration** → Set production secrets in `.env`2724. **SSL/TLS** → Enable HTTPS on Hugging Face Space2735. **Monitoring** → Set up error tracking (Sentry) and metrics (Prometheus)2746. **Backup Strategy** → Daily PostgreSQL snapshots2757. **Load Testing** → Verify performance with 100+ concurrent providers2768. **Security Audit** → OWASP top 10 review + penetration testing277 278---279 280## 📞 Support & Contacts281 282| Issue | Contact | Channel |283|-------|---------|---------|284| System crashes | DevOps | Slack #incidents |285| Data missing | Compliance Officer | compliance@nca.org.gh |286| User access | Admin | admin@nca.org.gh |287| Feature requests | Product Lead | Linear board |288 289---290 291**Last deploy:** 2026-06-16 (Docker + docker-compose)  292**Next review:** 2026-07-01  293**Maintenance window:** Weekends 22:00-23:00 GMT  294 295