Academic year
Course versions, the year version and bulk publishing, recurring lessons (series), convergences, per-edition content, user flow, limits and tests of the academic year. Only built behaviour, with code references.
Status (05/10/2026). The cycle engine, series, convergences, wizard, control room, archive and "Set up your school year" are in production (phases 0–4, branch feat/academic-year). Year versions (§2) and "This year only" edits without versions (§3.5) are on branch release/anno-versioni, the Recurrences step (§3.6) on release/anno-ricorrenze: covered by unit tests (tests/unit/academic-year-versions.spec.ts); the E2E runs on the test academies happen after the release (§8). Paths are relative to backend/ unless they say web-next/. User guide: Academic years and Versions and the academic year. See also Lesson change propagation and Substitutions.
1. Course versions today
A course has a linear row of versions (course_versions, one per change): each version is a snapshot of pointers (course, chapters[].lectures[]) to the main documents or their revisions (course_revisions, chapter_revisions, lecture_revisions).
| concept | rule | where |
|---|---|---|
| the latest | exactly one: the newest by createdAt; the builder edits it | apps/course/src/app/course-versions/course-versions.repository.ts:234 |
| the published one | exactly one with status: published (the newest) | course-versions.repository.ts:253 |
| grouping in the Versions panel | every version is born a root (parentId = _id); a change on a draft moves the chain under the new one (shown as a revision of the same draft) | libs/common/src/common/models/microservices/course/course-version.model.ts:83, apps/course/src/app/course-versions/services/course-versions-change.service.ts:950 |
What creates a version. Every change goes through CourseVersionsChangeService.handleChanges (course-versions-change.service.ts:69), one per course at a time:
| latest version | change | effect |
|---|---|---|
| published (or draft/rejected of a course already published) | handleChangesOnPublished (:182) → handleUpdate (:689) | new draft version vN+1 on top, with a new revision of the entity; the published one does not change |
| draft of a never-published course | handleChangesOnDraft (:233) | new version on top; the main document is updated, the previous version points to a revision with the old content |
createCycleanddeleteCyclego throughhandleChanges: they create a version (apps/course/src/app/courses/service/course-cycles.service.ts:165,:72).updateCycledoes not create versions: it writes the dates on the course the latest version points to (course-cycles.service.ts:305, write at:368).- Lesson edits from the calendar go through
batchUpdateLectures→handleUpdateManyon the latest version (apps/course/src/app/lectures/service/lectures-upsert.service.ts:2345,course-versions-upsert.service.ts:269): if the latest is published, a draft is born. Fields: title, dates, duration, description, frequency, links, attachments. Subject and books are written separately, always on the lesson, without versions. Exception for academic-year editions: §3.5.
Version actions.
| action | what it does | where |
|---|---|---|
| Create version | copies the latest into a new version on top | course-versions-upsert.service.ts:110 |
| Restore | copies the chosen version on top (new version, restored); the others stay | course-versions-upsert.service.ts:62 |
| Publish | the latest goes online right away: the previously published one becomes "unpublished" and the new one published. If going online fails, the version stays a draft and can be published again | courses-status.service.ts |
| Publish a non-latest version | first a restore (on top), then publishing | courses-status.service.ts:120 |
No review (27/10/2026). Course review is gone: no workspace queue, no Aladia review, no AI auto-approval, no VERIFYING state. Whoever can press "Publish" (course.update on the course) puts the version online for every course (internal, public, personal), in a single service (apps/gateway/src/gateway/controllers/course/courses/course-publication.service.ts). Paid courses still need Stripe Connect; free ones don't (libs/common/src/common/guards/stripe-onboarding.guard.ts). The old endpoints PATCH /courses/:id/review, PATCH /courses/:id/withdraw-review, GET /courses/search/verifying and /marketplace/reviews/* answer 410 Gone. The migration scripts/migrations/2026-10-course-review-removed.js moved every pending/VERIFYING version back to draft (nothing was auto-published). Content-moderation strikes can still suspend publishing.
2. Versions in the academic year
Decision of 05/10. Pure rules in libs/common/src/common/academic-year/year-versions.ts.
2.1 Starting version
| case | starts from | where |
|---|---|---|
| the course has a published version | the latest published one | startVersionOf, year-versions.ts:78 |
| never published | the latest draft (not an "open draft") | same |
| a teacher's open draft (latest, newer than the published one, not published) | left out; with Include the draft it starts from it | openDraftOf, year-versions.ts:52 |
| a version picked by hand in the wizard | that one | same |
The wizard's Courses step reads POST /academic-years/versions (gateway AcademicYearPublicationService.startVersions, course app CourseYearVersionsService.startOf, apps/course/src/app/courses/service/course-year-versions.service.ts:74): per course the start, the published one, the open draft with its author's name and the 10 latest versions. Choices go into choices.versions ([{ courseId, versionId?, includeDraft? }]). The open draft triggers no notice: it stays in the history, untouched and restorable.
2.2 Creating the year
For every chosen course the preparation (AcademicYearsService.run, apps/calendar/src/app/academic-years/academic-years.service.ts:345, choice at :379) asks the course app for a new draft version (CourseEditionsService.ensureInYearVersion, apps/course/src/app/courses/service/course-editions.service.ts:195):
- title
yearVersionTitle(year-versions.ts:42): "2027/28" → "Anno 2027/28"; - a copy of the starting version (
CourseVersionsChangeService.branchVersion,course-versions-change.service.ts:992): it becomes the latest; the published one and the teacher's draft don't change; - the year's cycle inside the copy (
CourseCyclesService.createCycleInNewVersion,course-cycles.service.ts:235): on an already-published course in a new course revision, on a never-published one on the main document. If the start already has a cycle in the period (the first cycle of a class born for the year) the version is just the copy; - the edition's own lessons enter from the year version onwards (
attachToVersions,course-editions.service.ts:661): the published version doesn't see them; - the version carries
academicYearId; the edition (course_editions) recordsversionIdandstartVersionId; the year (academic_years.courses[])versionId,startVersionIdand the open draft (draft: { id, profileId, createdAt, included }).
Resumable: if the course's year version already exists it is reused with its cycle. Nothing is published at creation.
Example: Maths 3A has v3 published (June) and Ms Rossi's draft v4 (September).
| moment | v3 | v4 (Rossi's draft) | v5 "Anno 2027/28" |
|---|---|---|---|
| before the wizard | published | draft, latest | — |
| after "Create" (draft not included) | published | draft, untouched | draft, latest, copy of v3 + 2027/28 cycle |
| after "Publish the year" | unpublished | draft, untouched | published |
With Include the draft v5 is a copy of v4.
Cancel the preparation (dropYearVersion, course-editions.service.ts:528): if nobody edited the year version afterwards, it disappears with its course revision and the latest goes back to the previous one; if it was edited, the cycle is removed as usual (deleteCycle, which creates a version).
2.3 Publish the year
Bulk publishing (gateway AcademicYearPublicationService.publish, apps/gateway/src/gateway/controllers/academic-years/academic-year-publication.service.ts:102):
- for the courses not yet published, the course app finds the version to publish (
CourseYearVersionsService,course-year-versions.service.ts): the course's latest version (the year version or a later edit of it), as long as it still has the year's cycle; - per course (three at a time): paid without the owner's Stripe Connect → error; otherwise the same road as "Publish" (§1): the version goes online directly, for every course (internal and public alike). There is no review and no "only dates change" option. The previously published version becomes "unpublished";
- the calendar app records the outcome per course (
academic-years.service.ts):publishedorerrorwith its reason; it publishes the editions of the courses that passed; the first time at least one course passes the year becomesactive, teacher changes are applied and teachers are notified.
Before publishing, the dialog calls POST /academic-years/:id/publication-plan and shows how many courses go online and those to fix.
Outcomes (in academic_years.courses[].publication, shown in the control room and as a publication-failed item in "To fix"):
| outcome | reasons |
|---|---|
| published | the course went online; legacy-edition for a year prepared before versions (only the edition is published, as back then) |
| error | stripe-onboarding-required, publish-refused, year-version-superseded (the latest version no longer has the cycle: a "Restore" removed it), year-version-missing, the error message |
Repeatable and idempotent: on an active year with failed courses canRetryPublication (academic-years.service.ts) enables Retry unpublished courses; courses already published are not redone; with no errors a new "Publish" answers 409.
2.4 Editions and versions
Each edition born from the wizard records the version it comes from (course_editions.versionId, and startVersionId); earlier years' editions are not touched (the year version is born next to them, not in their place). On publishing, as for any live course, handleCourseReview moves the course's members to the published version (course_members.versionId, oldVersionId = the previous one): the content of their cycle does not change, because the year version is a copy of the published one plus the new cycle's own lessons, and every cycle sees its own lessons plus the introduction (§5). With "Include the draft" (or a hand-picked version) that version's differences reach every cycle, as with any publishing.
3. Recurring lessons (series)
3.1 What a series is
course_series (calendar app, libs/common/src/common/models/microservices/calendar/course-series.model.ts): a recurring lesson of a course.
rule:weekly/once,interval(weeks),weekdays(ISO, 1 = Monday),startTime"HH:mm",durationMinutes,timezone,anchorOffsetDays,spanDays. Wall-clock time in the academy's time zone: 9:00 stays 9:00 across daylight-saving changes (occurrencesOf,libs/common/src/common/academic-year/series-rule.ts:92).template: title, description, place, room, Meet link, links, attachments, books, subject and level.convergenceKey,sourceKey,aliases(heads of the series generated in later years),sourceLectureIds(source lessons in order),origin(migration|engine|onboarding),confidence,exceptions.
3.2 Rebuilding for existing courses
reconstructSeries (libs/common/src/common/academic-year/series-reconstruction.ts:129), on the fly for courses without series (CourseSeriesService.forCourses, apps/calendar/src/app/academic-years/course-series.service.ts:70) or with the migration:
- make-ups are dropped (rows with
originalEventId); the original lesson counts at its date; - grouped by
recurringId(none: a single lesson); - days, time and duration: the most frequent in the last third of the series, at least 3 rows (
:195); a mid-year "this and following" change is the new plan, the earlier stretch counts asreplanned; - template: the most frequent; convergence: the most frequent
sharedId; - confidence (
:245):high≤ 10% off plan,medium≤ 30%,lowbeyond → "Timetable rebuilt with low confidence" in "To fix".
3.3 Holidays and closures
Occurrences are generated on the new dates and skip the new year's holidays and closures (closedDaysFor); a one-off (once) lesson on a closed day is a lesson-on-closure conflict in the preview.
3.4 Exceptions not carried and "Applies to"
The engine starts from the series, not from the occurrences: moved, suspended, made-up, forked lessons and substitutions are not carried. Every edit to a course lesson writes series_changes (SeriesChangesService.recordEventUpdate, apps/calendar/src/app/academic-years/series-changes.service.ts:69), one row per field:
- This year only (default); a single occurrence always applies to this year only (
effectiveAppliesTo,libs/common/src/common/academic-year/series-changes.ts:63); - Also in the baseline (following years) on "this and following"/"all": it also writes the series right away (with "Edit everywhere", the series of the whole convergence);
- the wizard's "Changes to carry" step preselects the baseline ones; content changed "this year only" and not chosen goes back to its previous value in the copy (
contentReverts,libs/common/src/common/academic-year/year-input.ts:136).
3.5 Calendar edits that don't create versions
On academic-year editions (cycles in course_editions with academicYearId) a "This year only" edit (the default, and always for a single occurrence) stays in the edition: it is written on the cycle's own lesson (and on its open revision in the latest version, if any), with dates on the edition's cycle, without course versions (applyThisYearEditionUpdates, lectures-upsert.service.ts:2420; rule splitThisYearEditionEvents, apps/course/src/app/lectures/service/edition-lecture-update.util.ts:22). "Also in the baseline" follows the usual versioning (§1) and also writes the series. The calendar sends the "Applies to" with the lesson update (appliesToOf, apps/calendar/src/app/calendar-events/service/calendar-events-upsert.service.ts:85; LectureEventUpdatedDto.appliesTo, cycleId). Realignments without "Applies to" (nightly reconciliation) count as "this year only". Courses without academic years and out-of-year cycles: unchanged.
3.6 The wizard's "Recurrences" step
Between "Courses" and "Convergences" the wizard shows, for each chosen course, its series (including those rebuilt on the fly): name, subject and level, days, time, duration, interval, teacher and confidence (low-confidence ones highlighted). Existing series can only be corrected, no additions or removals:
| field | rule |
|---|---|
| days | 1–7 (ISO), at least one; with new days the first lesson goes back to the Monday of its week, also every 2 weeks (correctedRule, libs/common/src/common/academic-year/series-corrections.ts) |
| time | local "HH:mm" |
| duration | 5–720 minutes |
| interval | every 1–8 weeks |
| teacher | it is the subject and level teacher (there's no per-series teacher): changing it here changes the "Teachers" step row, applied on publishing |
PATCH /academic-years/series/:seriesId (AcademicYearsService.correctSeries, apps/calendar/src/app/academic-years/academic-years.service.ts) writes the series right away (CourseSeriesService.correct: origin: 'wizard', confidence: 'high') and one series_changes row per field (kind: 'correction', appliesTo: 'baseline', scope: 'all', SeriesChangesService.recordCorrection). So:
- preview and creation use the corrected series; it also applies to later years;
- the current year doesn't change (no event touched);
- a corrected series is no longer "Timetable rebuilt with low confidence";
- rebuilding with
refreshdoesn't overwrite it (it only rewritesorigin: 'migration'); - corrections don't show among the "Changes to carry" (they're already in the baseline) and can't be undone by unticking.
Convergences: if the series has a convergenceKey and other series with the same key are among the chosen courses, the wizard asks "Correct the whole convergence?": with Correct the whole convergence the correction applies to all (alsoSeriesIds); with Only this one the convergence keeps different times and ends up in "To fix" as "Shared lesson with different times across courses" (ruleMismatch).
Example: Science of Liceo 2B (Friday at 12, medium confidence) corrected to 15:00 → in 2027/28 all its lessons at 15:00; 2026/27 stays at 12; 2028/29 will start from 15:00.
4. Convergences
A convergence is the same lesson in several courses: series of different courses with the same convergenceKey (the original sharedId). In the new year there is one event per occurrence with one row per calendar and the same sharedId (generateGroup, apps/calendar/src/app/academic-years/cycle-engine.service.ts:199). Rules (planYear, libs/common/src/common/academic-year/year-plan.ts:94):
| situation | result | where it shows |
|---|---|---|
| all the convergence's courses chosen | lesson shared by all | — |
| one course left out, ≥ 2 remain | shared among those left | Convergences changed in the preview, with "Also include …" |
| 1 remains | a normal lesson of that course | Convergences changed (becomes: single, :212) |
| 0 remain | not generated | — |
| convergence unticked in the Convergences step | one lesson per course | — |
| different times across courses | the first series' rule is used; "Shared lesson with different times across courses" in "To fix" | ruleMismatch, :141 |
| same teacher in two overlapping lessons | "Teacher booked twice at the same time" conflict in the preview and "To fix" | teacher-double-booked, :279 |
Example (test dataset): Maths year 1 is shared by Liceo 1A, Liceo 1B and Serale 1 (C1); English by Tecnico 3 INF and 3 ELE (C3). Leaving out Serale 1 and Tecnico 3 ELE:
| convergence | before | after |
|---|---|---|
| C1 Maths year 1 | 1A + 1B + Serale 1 | shared 1A + 1B |
| C3 English | 3 INF + 3 ELE | normal lesson of 3 INF |
| C2, C4 | whole | whole |
5. Per-edition content
A generated edition has its own lessons: copies with a single entry in cycles (its cycle); course_editions.ownContent says which cycles have them (isEditionLecture, libs/common/src/common/academic-year/edition-lectures.ts:27). A cycle with its own lessons sees those plus the ones without a cycle (the introduction: on-demand, born with the course), which apply to every cycle (decision of 07/10, lectureBelongsToCycle); the other cycles see the historical lessons. This applies to the preview, the player and the chapter lessons (aggregateCycleDateToLectures); the attendance register lists only live lessons, so it does not change. Attendance, grades and recordings stay in their cycle.
Matching by position (linkLectures, cycle-engine.service.ts:388; copy in CourseEditionsService.createLectures, course-editions.service.ts:296): the series' new occurrences, by date, are matched to the source lessons in the same position (sourceLectureIds[i]) and copy their title, description, attachments, links and books (COPIED_FIELDS, :66), subject, access level, chapter.
| the number of lessons in the new year… | effect |
|---|---|
| is the same | each new lesson copies the one in the same position |
| grows (fewer closures, longer year) | the extra lessons come from the series template (title, description, attachments, links, books, subject) in the chapter covering the date, otherwise the last one |
| shrinks (more closures) | the last source lessons are not copied |
Chapters and structure stay shared; the chapters' dates for the new cycle are those of cycle 1 shifted by calendar days. Own lessons enter the versions from the year version onwards (§2.2).
6. User flow
- Teaching › Planner › Year › Prepare the new year (Owner and Admin): a seven-step wizard in a centred dialog (
web-next/components/academic-years/prepare-year-dialog.tsx): Dates and closures → Courses (with starting version and "Include the draft") → Recurrences (series corrections, §3.6) → Convergences → Changes to carry → Teachers → Preview (counts, conflicts, Convergences changed). - Create: the year is born
preparing; the preparation runs in the background, resumable (complete groups skipped, half-done ones redone; automatic resume of jobs stalled for 2 minutes,resumeStale,academic-years.service.ts:117). Each course gets its "Anno …" draft version; nothing is published. - Control room (
web-next/components/academic-years/academic-year-control-room.tsx, in the Planner?view=year&year=<id>): progress, To fix (each item links to where it is fixed; conflicts can be Ignored), PDF summary, course list with lessons, version state ("draft version", "teacher's draft not included") and outcome. - Publish the year (when nothing blocks): a dialog with the summary of the courses that go online and those to fix; then the outcome per course (published or error); Retry unpublished courses if any failed.
- Close year (on an active year):
archived, editions read-only (ArchivedYearsGuard,course_editions.archivedAt). - Cancel the preparation (while
preparing,academic-years.service.ts:775): removes editions, lessons, calendars and year versions (§2.2); earlier years and teachers' drafts stay.
"Set up your school year" (academy without courses, setup-school-year-dialog.tsx) creates classes, subjects and series, then the same year with the same engine; "Publish the year" also publishes, in bulk, the classes still in draft (internal courses: direct).
7. Known limits and what it doesn't do yet
- New convergences: the new year can't add or merge convergences; they can only be kept, reduced or split.
- Recurrences: only existing series can be corrected (days, time, duration, interval); series can't be added or removed (to not recreate one, untick it in the "Convergences" step), and the teacher stays the subject and level teacher.
- Assignments (
exams_coursehas no cycle): not copied into the new year. - Students: the new year starts empty; no promotion.
- A cycle created from the course page (even if it joins a year,
generateCycle,academic-years.service.ts:810) follows the old road: cycle in the latest version, no year version, published with the course. - For a never-published course all versions point to the main documents: the "draft" can't be kept apart (§1).
- "This year only" edits on editions don't update chapter durations.
8. Tests
| spec | covers | how |
|---|---|---|
tests/unit/academic-year-versions.spec.ts | start (published, draft excluded/included, hand-picked, never published), one version per course and resume, per-course plan (idempotency, superseded version), bulk publishing (direct, already done, Stripe, refusal), outcomes in the calendar (active year, retry), "this year only" edits without versions | cd backend && npx jest -c jest.unit.config.cjs tests/unit/academic-year-versions.spec.ts |
tests/unit/academic-year-series-corrections.spec.ts | "Recurrences" step: validation, changed fields, days realigned to Monday, saved series (origin wizard, high confidence, baseline row), convergence extended on confirmation or with different times (ruleMismatch), another academy's series refused | same |
tests/unit/internal-course-publish.spec.ts | "Publish": direct for every course | same |
tests/unit/academic-year-core.spec.ts, cycle-engine.spec.ts, cycle-phase0.spec.ts, academic-year-phase34.spec.ts, academic-year-wiring.spec.ts, academic-year-resume.spec.ts | rules, DST, closures, rebuilding, convergences, conflicts, "Applies to", engine, archive, resume | same |
web-next/e2e/help/flows/academic-year/academic-year.spec.mjs | on the ACYEAR dataset ("Collaudo convergenze" academy): a "teacher" draft before the wizard; N "Anno 2027/28" draft versions, nothing published at creation, draft untouched; series, local time, counts; exceptions not carried; convergences; teachers; bulk "Publish the year" with per-course outcome, previous published "unpublished", draft in history, year cycle in the student's version, second "Publish" 409; "Recurrences" step: Science of Liceo 2B corrected to 15:00 → in 2027/28 at 15:00; source year untouched | node web-next/e2e/help/flows/_support/seed-academic-year.mjs --apply then node web-next/e2e/help/flows/run.mjs academic-year/academic-year [--shots] |
web-next/e2e/help/flows/academic-year/onboarding.spec.mjs | "Set up your school year"; a year version per class from the latest draft; direct bulk publishing (internal classes); cycle visible to the student | node web-next/e2e/help/flows/run.mjs academic-year/onboarding [--shots] |
The parts in §2 and §3.5 can be tested on the test academies only after the release of backend and web-next.
Appendix A. API
Gateway apps/gateway/src/gateway/controllers/academic-years/academic-years.controller.ts, Owner and Admin of the active academy (the list also for staff):
| route | what it does |
|---|---|
GET /academic-years | the academy's years |
GET /academic-years/defaults | time zone and holidays (step 1) |
POST /academic-years/source | series, convergences, changes, subjects/levels with today's teachers |
POST /academic-years/versions | starting version, published, open draft (with author) and recent versions per course |
POST /academic-years/preview | groups, counts, conflicts, convergences changed, closed days |
POST /academic-years · GET/PATCH /academic-years/:id | create (with choices), read, change |
POST /academic-years/:id/prepare | start or resume the preparation |
POST /academic-years/:id/cancel | cancel the preparation |
GET /academic-years/:id/summary | control room: year, "To fix", canPublish, canRetryPublication, report |
POST /academic-years/:id/acknowledge | "Ignore"/"Restore" |
POST /academic-years/:id/publication-plan | courses that go online and those to fix |
POST /academic-years/:id/publish | bulk publishing, all direct (or retry) |
POST /academic-years/:id/close | archive |
PATCH /academic-years/series/:seriesId | { correction: { weekdays?, startTime?, durationMinutes?, interval? }, alsoSeriesIds?, yearStart? } → "Recurrences" step |
POST /academic-years/series/reconstruct · POST /academic-years/series | rebuild series; series from a timetable (onboarding) |
Appendix B. Phase 0 (cycle fixes, in production)
The old clone of cycle 1's calendar (handleCycleCalendars) was replaced by the engine; the defects closed (duplicated make-up, lost suspensions/place/room/Meet, holidays not skipped, first event's members on all, inherited sharedId, DST in UTC, members $pull that removed nothing, duplicated cycle entries) are in docs/CALENDAR_PROPAGATION_MAP.md §11 and tests/unit/cycle-phase0.spec.ts.
Appendix C. Migrations
| migration | what |
|---|---|
scripts/migrations/2026-10-cycle-calendars-phase0.js | removes the inherited sharedId from cycle 2+ calendars and deleted cycles from members; report of duplicated calendars |
scripts/migrations/2026-10-academic-year-series.js | rebuilds course_series for live courses (optional) |
scripts/migrations/2026-10-academic-year-current.js | per academy, the Current year from the cycles containing DATE; course_editions with ownContent: false |
All PHASE=plan (default) → PHASE=apply → PHASE=rollback; filters ORG, ONLY. Year versions need no migration: the new fields (course_versions.academicYearId, course_editions.versionId/startVersionId, academic_years.courses[].versionId/startVersionId/draft/publication) are optional; a year prepared before publishes only the editions, as back then (legacy-edition).