The server is the shared backbone for both clients: authentication, hierarchy/tenant data, assessments/coaching domains, reporting aggregates, guide content, and video storage integration management.
Auth, Password Reset, and Onboarding
01JWT auth with bcrypt hashing, admin-created users, welcome emails, password reset tokens/expiry, first-time login flag, and bearer-token middleware verification.
- Auto-generated initial passwords on admin user creation
- Crypto reset token + expiry on user model
- firstTimeLogin flag for onboarding flow
- Joi validation + JWT middleware
Multi-tenant Identity and Admin Data Model
02Organisation, users, roles, and user-role junction models with audit/status fields and friendly duplicate-key error translation.
- Role examples: System Admin / Trust Admin / User
- UserRole unique compound index
- Organisation and User post-save duplicate key translation
- User model supports org/location/division/level scoping
Assessment Domain + Reporting Pipeline
03Lesson visit assessments capture structured question responses, strength/growth flags, notes, and org hierarchy refs, with aggregation-driven reporting by principle and question.
- Principle and PrincipleQuestion domain models
- Compound indexes on Assessment
- MUI DataGrid filter payload compatibility on reports endpoint
- AssessmentReport output shape with percentages
Coaching and Video Visit Workflow
04CoachingFeed entries and VideoVisit records connect lesson visits, coaching notes, upload status, device metadata, storage provider file references, and audit fields.
- Phase-based coaching workflow (Identify/Action Step/Model/Review)
- VideoVisit status machine (recording -> uploaded/failed)
- Device/app metadata capture
- Optional links to Assessment and CoachingFeed
Guides and Structured Content
05Guide collections support structured rich content blocks for application guidance, deliberate practice, instructional coaching, and project overview content.
- Reusable structured content block schema
- Separate collections per guide category
- Status and publish/archive lifecycle fields
- Admin editing flows via web client
Storage Configuration + Validation
06Per-organisation StorageConfig supports R2 or OneDrive, validation status/error tracking, and secure handling of secrets in API output.
- clientSecret omitted from JSON output (hasClientSecret boolean)
- Validation timestamps and error storage
- Provider-specific config fields (drive/folder/tenant/client)
- Per-org storage settings power mobile upload flows
Storage Services (R2 + OneDrive)
07Cloudflare R2 uses S3-compatible presigned URLs; Microsoft Graph supports client-credentials auth and large-file chunked upload sessions.
- Presigned PUT/GET URLs for R2
- Graph createUploadSession for large files
- Folder resolution by item ID or path
- 501 guard when provider env config is missing
Startup, Security, and Platform Basics
08Express middleware stack with Helmet/Morgan/Multer, route coverage across domain areas, and startup initialization of principles for all organisations.
- Native ESM server
- Helmet + Morgan + Joi validation
- initialisePrinciples at startup
- 20 route files across product/admin domains
Server Testability and Isolation
09Node test runner + Supertest + mongodb-memory-server enable isolated CI-friendly tests without an external database dependency.
- 11 test files across auth/admin/assessments/coaching/guides/storage/video
- Shared test_helpers setup/teardown
- In-memory MongoDB for fast and isolated runs
- API behavior validation with real Express routes