// Builds a user's roadmap from their onboarding answers and the site's published tutorials. // Pure and client-safe, so the roadmap updates by itself as tutorials are added. import { GOALS, WEEKLY_TIMES, type GoalId, type LearningProfile } from "@/lib/onboarding"; import { getTrack, type TrackSlug } from "@/lib/tracks"; import { tutorialKey, type Level, type TutorialMeta } from "@/lib/tutorial-types"; export type RoadmapStep = { tutorial: TutorialMeta; key: string; // Why it's on the roadmap, e.g. "Make AI video" reason: string; }; export type RoadmapPhase = { level: Level; title: string; summary: string; // True when the phase sits below the user's level: worth a skim, not required optional: boolean; steps: RoadmapStep[]; minutes: number; weeks: number; milestone: string; }; export type Roadmap = { tracks: TrackSlug[]; phases: RoadmapPhase[]; totalSteps: number; totalMinutes: number; }; const RANK: Record = { Beginner: 0, Intermediate: 1, Advanced: 2 }; const PHASES: Record = { Beginner: { title: "Foundations", summary: "Get set up and finish a first real task.", skim: "Skim these if you already know the basics. They set up what comes next.", }, Intermediate: { title: "Build", summary: "Turn the basics into workflows you can repeat.", skim: "Quick refreshers before the advanced material.", }, Advanced: { title: "Go further", summary: "Push the tools to their limits on your own projects.", skim: "", }, }; // What finishing a phase in each track looks like const MILESTONES: Record> = { claude: { Beginner: "Claude Code runs in your project and follows a CLAUDE.md you wrote", Intermediate: "Claude handles multi-step work with the tools you've connected", Advanced: "You run Claude agents on tasks end to end", }, chatgpt: { Beginner: "Codex works in your repo with an AGENTS.md to guide it", Intermediate: "Codex finishes tasks on its own and you review the result", Advanced: "Codex runs parallel cloud tasks across your projects", }, "computer-use": { Beginner: "An agent completes a browser task while you watch", Intermediate: "You hand an agent repeat chores with guardrails in place", Advanced: "Agents drive real apps for you, with a human check where it matters", }, "ai-video": { Beginner: "You have a GPU pod running and know what it costs", Intermediate: "You generate clips with an open model you chose", Advanced: "You tune models and workflows for your own style", }, }; function goalFor(t: TutorialMeta, goals: GoalId[]): string { const goal = GOALS.find((g) => goals.includes(g.id) && g.id !== "current" && g.tracks.includes(t.track)); return goal?.label ?? getTrack(t.track)?.name ?? t.track; } function score(t: TutorialMeta, p: LearningProfile): number { let s = 0; if (t.video && p.format === "video") s += 2; if (!t.video && p.format === "written") s += 2; if (t.video) s += 1; // Earlier-chosen tracks first s -= p.tracks.indexOf(t.track) * 0.5; return s; } export function buildRoadmap(profile: LearningProfile, tutorials: TutorialMeta[]): Roadmap { const tracks = profile.tracks.length ? profile.tracks : GOALS.flatMap((g) => g.tracks); const pool = tutorials.filter((t) => !t.draft && tracks.includes(t.track)); const userRank = RANK[profile.level]; const weekly = WEEKLY_TIMES.find((w) => w.id === profile.weeklyTime)?.minutes ?? 180; const phases = (Object.keys(RANK) as Level[]) .map((level): RoadmapPhase | null => { const steps = pool .filter((t) => t.level === level) .sort((a, b) => score(b, profile) - score(a, profile) || a.minutes - b.minutes) .map((t) => ({ tutorial: t, key: tutorialKey(t), reason: goalFor(t, profile.goals) })); if (steps.length === 0) return null; const optional = RANK[level] < userRank; const minutes = steps.reduce((sum, s) => sum + s.tutorial.minutes, 0); // Practice time on top of the tutorials themselves: trying each one out takes about as long again const weeks = Math.max(1, Math.ceil((minutes * 2) / weekly)); const phaseTracks = tracks.filter((tr) => steps.some((s) => s.tutorial.track === tr)); const milestone = phaseTracks.map((tr) => MILESTONES[tr][level]).join(". "); const def = PHASES[level]; return { level, title: optional ? `${def.title} (refresher)` : def.title, summary: optional ? def.skim : def.summary, optional, steps, minutes, weeks, milestone, }; }) .filter((p): p is RoadmapPhase => p !== null); return { tracks, phases, totalSteps: phases.reduce((n, p) => n + p.steps.length, 0), totalMinutes: phases.reduce((n, p) => n + p.minutes, 0), }; }