# Backend: enrolled counts per course, and where each student is **Labels:** backend, analytics The course cards now show "N students" from `Course.enrolledCount` (optional field in `packages/data/src/index.ts`). In the demo the seed computes it once from the sample students. Students can't read each other's records, so the real number has to come from the backend. ## Needed - **Enrolled count per course.** Keep `enrolledCount` on each course doc up to date when an enrollment is created or revoked (purchase, admin grant, free). A counter updated in the same write as the enrollment is enough; recount nightly to self-heal. - **Where each student is.** For admins: per course, how many students are on each chapter/section right now, and per student their current lesson. Derive from `Student.progress` (latest `updatedAt` per course → that lesson's chapter). Expose as an admin view or a nightly aggregate doc per course, e.g. `courseStats/{courseId} = { enrolled, bySection: { [chapterId]: n }, completed }`. ## Done when - [ ] A purchase shows up in the course's student count without a redeploy - [ ] Admins can see, per course, how many students are in each section and who is stuck where - [ ] Remove the seed-time computation in `packages/db/seed/demo-seed.mjs` (marked `ponytail:`)