Round system redesign: Phases 1-7 complete

Full pipeline/track/stage architecture replacing the legacy round system.

Schema: 11 new models (Pipeline, Track, Stage, StageTransition,
ProjectStageState, RoutingRule, Cohort, CohortProject, LiveProgressCursor,
OverrideAction, AudienceVoter) + 8 new enums.

Backend: 9 new routers (pipeline, stage, routing, stageFiltering,
stageAssignment, cohort, live, decision, award) + 6 new services
(stage-engine, routing-engine, stage-filtering, stage-assignment,
stage-notifications, live-control).

Frontend: Pipeline wizard (17 components), jury stage pages (7),
applicant pipeline pages (3), public stage pages (2), admin pipeline
pages (5), shared stage components (3), SSE route, live hook.

Phase 6 refit: 23 routers/services migrated from roundId to stageId,
all frontend components refitted. Deleted round.ts (985 lines),
roundTemplate.ts, round-helpers.ts, round-settings.ts, round-type-settings.tsx,
10 legacy admin pages, 7 legacy jury pages, 3 legacy dialogs.

Phase 7 validation: 36 tests (10 unit + 8 integration files) all passing,
TypeScript 0 errors, Next.js build succeeds, 13 integrity checks,
legacy symbol sweep clean, auto-seed on first Docker startup.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-13 13:57:09 +01:00
parent 8a328357e3
commit 331b67dae0
256 changed files with 29117 additions and 21424 deletions

View File

@@ -60,17 +60,25 @@ async function JuryDashboardContent() {
country: true,
},
},
round: {
stage: {
select: {
id: true,
name: true,
status: true,
votingStartAt: true,
votingEndAt: true,
program: {
windowOpenAt: true,
windowCloseAt: true,
track: {
select: {
name: true,
year: true,
pipeline: {
select: {
program: {
select: {
name: true,
year: true,
},
},
},
},
},
},
},
@@ -88,7 +96,7 @@ async function JuryDashboardContent() {
},
},
orderBy: [
{ round: { votingEndAt: 'asc' } },
{ stage: { windowCloseAt: 'asc' } },
{ createdAt: 'asc' },
],
}),
@@ -98,7 +106,7 @@ async function JuryDashboardContent() {
extendedUntil: { gte: new Date() },
},
select: {
roundId: true,
stageId: true,
extendedUntil: true,
},
}),
@@ -118,49 +126,49 @@ async function JuryDashboardContent() {
const completionRate =
totalAssignments > 0 ? (completedAssignments / totalAssignments) * 100 : 0
// Group assignments by round
const assignmentsByRound = assignments.reduce(
// Group assignments by stage
const assignmentsByStage = assignments.reduce(
(acc, assignment) => {
const roundId = assignment.round.id
if (!acc[roundId]) {
acc[roundId] = {
round: assignment.round,
const stageId = assignment.stage.id
if (!acc[stageId]) {
acc[stageId] = {
stage: assignment.stage,
assignments: [],
}
}
acc[roundId].assignments.push(assignment)
acc[stageId].assignments.push(assignment)
return acc
},
{} as Record<string, { round: (typeof assignments)[0]['round']; assignments: typeof assignments }>
{} as Record<string, { stage: (typeof assignments)[0]['stage']; assignments: typeof assignments }>
)
const graceByRound = new Map<string, Date>()
const graceByStage = new Map<string, Date>()
for (const gp of gracePeriods) {
const existing = graceByRound.get(gp.roundId)
const existing = graceByStage.get(gp.stageId)
if (!existing || gp.extendedUntil > existing) {
graceByRound.set(gp.roundId, gp.extendedUntil)
graceByStage.set(gp.stageId, gp.extendedUntil)
}
}
// Active rounds (voting window open)
// Active stages (voting window open)
const now = new Date()
const activeRounds = Object.values(assignmentsByRound).filter(
({ round }) =>
round.status === 'ACTIVE' &&
round.votingStartAt &&
round.votingEndAt &&
new Date(round.votingStartAt) <= now &&
new Date(round.votingEndAt) >= now
const activeStages = Object.values(assignmentsByStage).filter(
({ stage }) =>
stage.status === 'STAGE_ACTIVE' &&
stage.windowOpenAt &&
stage.windowCloseAt &&
new Date(stage.windowOpenAt) <= now &&
new Date(stage.windowCloseAt) >= now
)
// Find next unevaluated assignment in an active round
// Find next unevaluated assignment in an active stage
const nextUnevaluated = assignments.find((a) => {
const isActive =
a.round.status === 'ACTIVE' &&
a.round.votingStartAt &&
a.round.votingEndAt &&
new Date(a.round.votingStartAt) <= now &&
new Date(a.round.votingEndAt) >= now
a.stage.status === 'STAGE_ACTIVE' &&
a.stage.windowOpenAt &&
a.stage.windowCloseAt &&
new Date(a.stage.windowOpenAt) <= now &&
new Date(a.stage.windowCloseAt) >= now
const isIncomplete = !a.evaluation || a.evaluation.status === 'NOT_STARTED' || a.evaluation.status === 'DRAFT'
return isActive && isIncomplete
})
@@ -168,14 +176,14 @@ async function JuryDashboardContent() {
// Recent assignments for the quick list (latest 5)
const recentAssignments = assignments.slice(0, 6)
// Get active round remaining count
// Get active stage remaining count
const activeRemaining = assignments.filter((a) => {
const isActive =
a.round.status === 'ACTIVE' &&
a.round.votingStartAt &&
a.round.votingEndAt &&
new Date(a.round.votingStartAt) <= now &&
new Date(a.round.votingEndAt) >= now
a.stage.status === 'STAGE_ACTIVE' &&
a.stage.windowOpenAt &&
a.stage.windowCloseAt &&
new Date(a.stage.windowOpenAt) <= now &&
new Date(a.stage.windowCloseAt) >= now
const isIncomplete = !a.evaluation || a.evaluation.status !== 'SUBMITTED'
return isActive && isIncomplete
}).length
@@ -233,7 +241,7 @@ async function JuryDashboardContent() {
</div>
<div className="grid gap-3 sm:grid-cols-2 max-w-md mx-auto">
<Link
href="/jury/assignments"
href="/jury/stages"
className="group flex items-center gap-3 rounded-xl border border-border/60 p-3 transition-all duration-200 hover:border-brand-blue/30 hover:bg-brand-blue/5 hover:-translate-y-0.5 hover:shadow-md dark:hover:border-brand-teal/30 dark:hover:bg-brand-teal/5"
>
<div className="rounded-lg bg-blue-50 p-2 transition-colors group-hover:bg-blue-100 dark:bg-blue-950/40">
@@ -245,7 +253,7 @@ async function JuryDashboardContent() {
</div>
</Link>
<Link
href="/jury/compare"
href="/jury/stages"
className="group flex items-center gap-3 rounded-xl border border-border/60 p-3 transition-all duration-200 hover:border-brand-teal/30 hover:bg-brand-teal/5 hover:-translate-y-0.5 hover:shadow-md"
>
<div className="rounded-lg bg-teal-50 p-2 transition-colors group-hover:bg-teal-100 dark:bg-teal-950/40">
@@ -285,7 +293,7 @@ async function JuryDashboardContent() {
</div>
</div>
<Button asChild size="lg" className="bg-brand-blue hover:bg-brand-blue-light shadow-md">
<Link href={`/jury/projects/${nextUnevaluated.project.id}/evaluate`}>
<Link href={`/jury/stages/${nextUnevaluated.stage.id}/projects/${nextUnevaluated.project.id}/evaluate`}>
{nextUnevaluated.evaluation?.status === 'DRAFT' ? 'Continue Evaluation' : 'Start Evaluation'}
<ArrowRight className="ml-2 h-4 w-4" />
</Link>
@@ -355,7 +363,7 @@ async function JuryDashboardContent() {
<CardTitle className="text-lg">My Assignments</CardTitle>
</div>
<Button variant="ghost" size="sm" asChild className="text-brand-teal hover:text-brand-blue">
<Link href="/jury/assignments">
<Link href="/jury/stages">
View all
<ArrowRight className="ml-1 h-3 w-3" />
</Link>
@@ -370,11 +378,11 @@ async function JuryDashboardContent() {
const isCompleted = evaluation?.status === 'SUBMITTED'
const isDraft = evaluation?.status === 'DRAFT'
const isVotingOpen =
assignment.round.status === 'ACTIVE' &&
assignment.round.votingStartAt &&
assignment.round.votingEndAt &&
new Date(assignment.round.votingStartAt) <= now &&
new Date(assignment.round.votingEndAt) >= now
assignment.stage.status === 'STAGE_ACTIVE' &&
assignment.stage.windowOpenAt &&
assignment.stage.windowCloseAt &&
new Date(assignment.stage.windowOpenAt) <= now &&
new Date(assignment.stage.windowCloseAt) >= now
return (
<div
@@ -386,7 +394,7 @@ async function JuryDashboardContent() {
)}
>
<Link
href={`/jury/projects/${assignment.project.id}`}
href={`/jury/stages/${assignment.stage.id}/projects/${assignment.project.id}`}
className="flex-1 min-w-0 group"
>
<p className="text-sm font-medium truncate group-hover:text-brand-blue dark:group-hover:text-brand-teal transition-colors">
@@ -397,7 +405,7 @@ async function JuryDashboardContent() {
{assignment.project.teamName}
</span>
<Badge variant="secondary" className="text-[10px] px-1.5 py-0 bg-brand-blue/5 text-brand-blue/80 dark:bg-brand-teal/10 dark:text-brand-teal/80 border-0">
{assignment.round.name}
{assignment.stage.name}
</Badge>
</div>
</Link>
@@ -417,19 +425,19 @@ async function JuryDashboardContent() {
)}
{isCompleted ? (
<Button variant="ghost" size="sm" asChild className="h-7 px-2">
<Link href={`/jury/projects/${assignment.project.id}/evaluation`}>
<Link href={`/jury/stages/${assignment.stage.id}/projects/${assignment.project.id}/evaluation`}>
View
</Link>
</Button>
) : isVotingOpen ? (
<Button size="sm" asChild className="h-7 px-3 bg-brand-blue hover:bg-brand-blue-light shadow-sm">
<Link href={`/jury/projects/${assignment.project.id}/evaluate`}>
<Link href={`/jury/stages/${assignment.stage.id}/projects/${assignment.project.id}/evaluate`}>
{isDraft ? 'Continue' : 'Evaluate'}
</Link>
</Button>
) : (
<Button variant="ghost" size="sm" asChild className="h-7 px-2">
<Link href={`/jury/projects/${assignment.project.id}`}>
<Link href={`/jury/stages/${assignment.stage.id}/projects/${assignment.project.id}`}>
View
</Link>
</Button>
@@ -470,7 +478,7 @@ async function JuryDashboardContent() {
<CardContent>
<div className="grid gap-3 sm:grid-cols-2">
<Link
href="/jury/assignments"
href="/jury/stages"
className="group flex items-center gap-4 rounded-xl border border-border/60 p-4 transition-all duration-200 hover:border-brand-blue/30 hover:bg-brand-blue/5 hover:-translate-y-0.5 hover:shadow-md dark:hover:border-brand-teal/30 dark:hover:bg-brand-teal/5"
>
<div className="rounded-xl bg-blue-50 p-3 transition-colors group-hover:bg-blue-100 dark:bg-blue-950/40 dark:group-hover:bg-blue-950/60">
@@ -482,7 +490,7 @@ async function JuryDashboardContent() {
</div>
</Link>
<Link
href="/jury/compare"
href="/jury/stages"
className="group flex items-center gap-4 rounded-xl border border-border/60 p-4 transition-all duration-200 hover:border-brand-teal/30 hover:bg-brand-teal/5 hover:-translate-y-0.5 hover:shadow-md"
>
<div className="rounded-xl bg-teal-50 p-3 transition-colors group-hover:bg-teal-100 dark:bg-teal-950/40 dark:group-hover:bg-teal-950/60">
@@ -501,8 +509,8 @@ async function JuryDashboardContent() {
{/* Right column */}
<div className="lg:col-span-5 space-y-4">
{/* Active Rounds */}
{activeRounds.length > 0 && (
{/* Active Stages */}
{activeStages.length > 0 && (
<AnimatedCard index={8}>
<Card className="overflow-hidden">
<div className="h-1 w-full bg-gradient-to-r from-brand-blue via-brand-teal to-brand-blue" />
@@ -512,28 +520,29 @@ async function JuryDashboardContent() {
<Waves className="h-4 w-4 text-brand-blue dark:text-brand-teal" />
</div>
<div>
<CardTitle className="text-lg">Active Voting Rounds</CardTitle>
<CardTitle className="text-lg">Active Voting Stages</CardTitle>
<CardDescription className="mt-0.5">
Rounds currently open for evaluation
Stages currently open for evaluation
</CardDescription>
</div>
</div>
</CardHeader>
<CardContent className="space-y-4">
{activeRounds.map(({ round, assignments: roundAssignments }) => {
const roundCompleted = roundAssignments.filter(
{activeStages.map(({ stage, assignments: stageAssignments }) => {
const stageCompleted = stageAssignments.filter(
(a) => a.evaluation?.status === 'SUBMITTED'
).length
const roundTotal = roundAssignments.length
const roundProgress =
roundTotal > 0 ? (roundCompleted / roundTotal) * 100 : 0
const isAlmostDone = roundProgress >= 80
const deadline = graceByRound.get(round.id) ?? (round.votingEndAt ? new Date(round.votingEndAt) : null)
const stageTotal = stageAssignments.length
const stageProgress =
stageTotal > 0 ? (stageCompleted / stageTotal) * 100 : 0
const isAlmostDone = stageProgress >= 80
const deadline = graceByStage.get(stage.id) ?? (stage.windowCloseAt ? new Date(stage.windowCloseAt) : null)
const isUrgent = deadline && (deadline.getTime() - now.getTime()) < 24 * 60 * 60 * 1000
const program = stage.track.pipeline.program
return (
<div
key={round.id}
key={stage.id}
className={cn(
'rounded-xl border p-4 space-y-3 transition-all duration-200 hover:-translate-y-0.5 hover:shadow-md',
isUrgent
@@ -543,9 +552,9 @@ async function JuryDashboardContent() {
>
<div className="flex items-start justify-between">
<div>
<h3 className="font-semibold text-brand-blue dark:text-brand-teal">{round.name}</h3>
<h3 className="font-semibold text-brand-blue dark:text-brand-teal">{stage.name}</h3>
<p className="text-xs text-muted-foreground mt-0.5">
{round.program.name} &middot; {round.program.year}
{program.name} &middot; {program.year}
</p>
</div>
{isAlmostDone ? (
@@ -559,13 +568,13 @@ async function JuryDashboardContent() {
<div className="flex justify-between text-sm">
<span className="text-muted-foreground">Progress</span>
<span className="font-semibold tabular-nums">
{roundCompleted}/{roundTotal}
{stageCompleted}/{stageTotal}
</span>
</div>
<div className="relative h-2.5 w-full overflow-hidden rounded-full bg-muted/60">
<div
className="h-full rounded-full bg-gradient-to-r from-brand-teal to-brand-blue transition-all duration-500 ease-out"
style={{ width: `${roundProgress}%` }}
style={{ width: `${stageProgress}%` }}
/>
</div>
</div>
@@ -576,16 +585,16 @@ async function JuryDashboardContent() {
deadline={deadline}
label="Deadline:"
/>
{round.votingEndAt && (
{stage.windowCloseAt && (
<span className="text-xs text-muted-foreground">
({formatDateOnly(round.votingEndAt)})
({formatDateOnly(stage.windowCloseAt)})
</span>
)}
</div>
)}
<Button asChild size="sm" className="w-full bg-brand-blue hover:bg-brand-blue-light shadow-sm">
<Link href={`/jury/assignments?round=${round.id}`}>
<Link href={`/jury/stages/${stage.id}/assignments`}>
View Assignments
<ArrowRight className="ml-2 h-4 w-4" />
</Link>
@@ -598,15 +607,15 @@ async function JuryDashboardContent() {
</AnimatedCard>
)}
{/* No active rounds */}
{activeRounds.length === 0 && (
{/* No active stages */}
{activeStages.length === 0 && (
<AnimatedCard index={8}>
<Card>
<CardContent className="flex flex-col items-center justify-center py-6 text-center">
<div className="rounded-2xl bg-brand-teal/10 p-3 mb-2 dark:bg-brand-teal/20">
<Clock className="h-6 w-6 text-brand-teal/70" />
</div>
<p className="font-semibold text-sm">No active voting rounds</p>
<p className="font-semibold text-sm">No active voting stages</p>
<p className="text-xs text-muted-foreground mt-1 max-w-[220px]">
Check back later when a voting window opens
</p>
@@ -615,8 +624,8 @@ async function JuryDashboardContent() {
</AnimatedCard>
)}
{/* Completion Summary by Round */}
{Object.keys(assignmentsByRound).length > 0 && (
{/* Completion Summary by Stage */}
{Object.keys(assignmentsByStage).length > 0 && (
<AnimatedCard index={9}>
<Card>
<CardHeader className="pb-3">
@@ -624,18 +633,18 @@ async function JuryDashboardContent() {
<div className="rounded-lg bg-brand-teal/10 p-1.5 dark:bg-brand-teal/20">
<BarChart3 className="h-4 w-4 text-brand-teal" />
</div>
<CardTitle className="text-lg">Round Summary</CardTitle>
<CardTitle className="text-lg">Stage Summary</CardTitle>
</div>
</CardHeader>
<CardContent className="space-y-4">
{Object.values(assignmentsByRound).map(({ round, assignments: roundAssignments }) => {
const done = roundAssignments.filter((a) => a.evaluation?.status === 'SUBMITTED').length
const total = roundAssignments.length
{Object.values(assignmentsByStage).map(({ stage, assignments: stageAssignments }) => {
const done = stageAssignments.filter((a) => a.evaluation?.status === 'SUBMITTED').length
const total = stageAssignments.length
const pct = total > 0 ? Math.round((done / total) * 100) : 0
return (
<div key={round.id} className="space-y-2">
<div key={stage.id} className="space-y-2">
<div className="flex items-center justify-between text-sm">
<span className="font-medium truncate">{round.name}</span>
<span className="font-medium truncate">{stage.name}</span>
<div className="flex items-baseline gap-1 shrink-0 ml-2">
<span className="font-bold tabular-nums text-brand-blue dark:text-brand-teal">{pct}%</span>
<span className="text-xs text-muted-foreground">({done}/{total})</span>