Files
Learn_System/docs/classroom-split-plan.md
Maxim Dolgolyov 0e2c3d2939 docs: classroom controller split plan (phase 1 of 2)
Maps 70 functions from 1618-line classroomController.js into 8 files
by domain: sessions, strokes, pages, chat, permissions, sim, admin,
plus _shared helpers. Facade preserves public API unchanged.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-06 17:24:39 +03:00

207 lines
5.8 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# classroomController.js split plan
**Source:** `backend/src/controllers/classroomController.js` — 1618 lines, 70 functions
**Target:** `backend/src/controllers/classroom/` — 8 files
**Strategy:** pure mechanical split, no behaviour changes, facade preserves compatibility
---
## Target structure
```
backend/src/controllers/
classroomController.js ← 8-line re-export facade (unchanged public API)
classroom/
_shared.js ← shared helpers used by multiple files
sessions.js ← session lifecycle + guest tokens
strokes.js ← whiteboard strokes + cursor preview
pages.js ← page CRUD + templates + board theme
chat.js ← chat messages, reactions, attachments, export
permissions.js ← draw permissions, hand-raise, mute, screen, attendance
sim.js ← simulation relay (simOpen/State/Mode/Annotate/Close)
admin.js ← history, notes, templates, admin views
```
---
## File mapping
### `classroom/_shared.js`
Helpers used by 2+ files. Exports: `{ GUEST_EVENTS, emitToSession, hasAccess, canDraw }`
| Symbol | Lines | Used by |
|--------|-------|---------|
| `GUEST_EVENTS` | 2127 | sessions, strokes, pages, permissions, sim |
| `emitToSession` | 3134 | sessions, strokes, pages, chat, permissions, sim |
| `hasAccess` | 3748 | sessions, strokes, pages, chat, permissions, admin |
| `canDraw` | 1318 | strokes |
Imports: `db`, `broadcastToSession` from `ws-server`
---
### `classroom/sessions.js`
Session lifecycle, signal (WebRTC), guest tokens.
| Function | Lines |
|----------|-------|
| `createSession` | 51105 |
| `getSession` | 106128 |
| `endSession` | 129145 |
| `getActiveSession` | 146163 |
| `getMyActive` | 164177 |
| `joinSession` | 178210 |
| `leaveSession` | 211231 |
| `getMySession` | 385433 |
| `signal` | 359384 |
| `generateGuestToken` | 15201531 |
| `revokeGuestToken` | 15321542 |
| `getGuestToken` | 1543end |
Imports: `db`, `crypto`, `invalidateSession`, `emitToUser` (from `ws-server`), `_shared`
---
### `classroom/strokes.js`
Whiteboard stroke CRUD + live cursor/preview broadcast.
| Function | Lines |
|----------|-------|
| `postStrokes` | 568608 |
| `getStrokes` | 609635 |
| `updateStroke` | 636662 |
| `deleteStroke` | 663686 |
| `clearPage` | 687700 |
| `previewStroke` | 815840 |
| `broadcastCursor` | 901918 |
Imports: `db`, `_shared`
---
### `classroom/pages.js`
Page CRUD, templates, board theme.
| Function | Lines |
|----------|-------|
| `getPages` | 701723 |
| `addPage` | 449472 |
| `changePage` | 473488 |
| `updatePageTemplate` | 489503 |
| `updateBoardTheme` | 504518 |
| `renamePage` | 724740 |
| `duplicatePage` | 741769 |
| `deletePage` | 770799 |
Imports: `db`, `_shared`
---
### `classroom/chat.js`
Chat messages, reactions, file attachments, export, CHAT_UPLOADS_DIR setup.
| Symbol | Lines |
|--------|-------|
| `CHAT_UPLOADS_DIR` | 910 |
| `ALLOWED_REACTIONS` | 1027 |
| `sendChat` | 232268 |
| `getChat` | 269320 |
| `pinMessage` | 841864 |
| `reactToMessage` | 10281074 |
| `uploadChatAttachment` | 10191026 |
| `exportChat` | 12441275 |
Imports: `db`, `path`, `fs`, `crypto`, `emitToUser` (from `ws-server`), `_shared`
---
### `classroom/permissions.js`
Draw permits, hand-raise, mute, screen share, online students.
| Function | Lines |
|----------|-------|
| `getParticipants` | 321340 |
| `getAttendance` | 341358 |
| `getOnlineStudents` | 434448 |
| `raiseHand` | 519537 |
| `lowerHand` | 538550 |
| `getHands` | 551567 |
| `allowDraw` | 865882 |
| `revokeDraw` | 883900 |
| `mutePeer` | 800814 |
| `screenStart` | 919930 |
| `screenStop` | 931941 |
Imports: `db`, `emitToUser`, `invalidateDrawCache` (from `ws-server`), `getOnlineUserIds` (from `sse`), `_shared`
---
### `classroom/sim.js`
Simulation relay — teacher broadcasts sim events to students.
| Function | Lines |
|----------|-------|
| `simOpen` | 945958 |
| `simState` | 961976 |
| `simMode` | 979991 |
| `simAnnotate` | 9941004 |
| `simClose` | 10071018 |
Imports: `db`, `_shared`
---
### `classroom/admin.js`
History, notes, board templates, admin dashboards.
| Function | Lines |
|----------|-------|
| `getNotes` | 10751082 |
| `saveNotes` | 10831097 |
| `getClassHistory` | 10981140 |
| `getMyHistory` | 11411188 |
| `getSessionSummary` | 11891243 |
| `getAllNotes` | 12761294 |
| `deleteHistorySession` | 12951320 |
| `adminGetActiveSessions` | 13211341 |
| `adminGetAllSessions` | 13421422 |
| `adminGetTeachersList` | 14231434 |
| `getTemplates` | 14351441 |
| `saveTemplate` | 14421473 |
| `deleteTemplate` | 14741479 |
| `loadTemplate` | 14801519 |
Imports: `db`, `_shared`
---
## Facade (`classroomController.js` after split)
```js
module.exports = {
...require('./classroom/sessions'),
...require('./classroom/strokes'),
...require('./classroom/pages'),
...require('./classroom/chat'),
...require('./classroom/permissions'),
...require('./classroom/sim'),
...require('./classroom/admin'),
};
```
`routes/classroom.js` imports from `'../controllers/classroomController'` — unchanged.
---
## What does NOT change
- All function names — unchanged
- All route bindings in `routes/classroom.js` — unchanged
- All public exports from `classroomController.js` — same set
- DB queries — moved verbatim, not rewritten
- Error responses — unchanged
## Risks
- `simClose` (line 1007) references `emitToSession` — must be imported from `_shared`
- `sendChat` builds URLs with `req.protocol + '://' + req.get('host')` — needs no extra imports
- `getSessionSummary` (line 1189) is 54 lines — complex, move carefully