Skip to content

Feat/ai course generator front - #28

Merged
teamssUTXO merged 10 commits into
CodeStar-Project:devfrom
lmrt0572:feat/ai-course-generator-front
Jun 16, 2026
Merged

Feat/ai course generator front#28
teamssUTXO merged 10 commits into
CodeStar-Project:devfrom
lmrt0572:feat/ai-course-generator-front

Conversation

@lmrt0572

@lmrt0572 lmrt0572 commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Description

Intégration frontend du générateur de cours par IA, connecté à l'endpoint backend POST /api/v1/ai/courses/generate.

Changements

feat(ai): add AI course generator page and actions

  • app/actions/ai.ts — server actions generateAiCourse et importAiCourse (timeout 120s)
  • app/admin/ai-generator/page.tsx — page /admin/ai-generator, accessible aux TEACHER/ADMIN
  • components/admin/ai-generator-form.tsx — formulaire : sujet, niveau, langue, idées clés par tags, animation de chargement, prévisualisation du draft, import vers l'éditeur
  • app/admin/page.tsx — ajout du bouton "AI Generator" sur le dashboard enseignant
  • components/ui/icons.tsx — ajout de XIcon

fix(course-reader): make bookmark button icon-only on desktop

  • Suppression des boutons "Ajouter aux favoris" visibles en permanence sous chaque bloc remplacé par une icône discrète au survol uniquement

Summary by CodeRabbit

New Features

  • Introduced AI Course Generator in the admin panel—teachers can now generate courses by entering a topic, selecting difficulty level and language, and optionally providing key ideas for more focused content
  • Added "AI Generator" button to admin dashboard for quick access

Improvements

  • Refined bookmark button positioning in the course reader

@coderabbitai

coderabbitai Bot commented Jun 10, 2026

Copy link
Copy Markdown

Review Change Stack

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: df227038-043b-4f0f-8360-8981de47deaf

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds an AI course generation feature to the admin panel, including server actions (generateAiCourse, importAiCourse), a new AiGeneratorForm component, an /admin/ai page, and bilingual translations. Aligns the course export/import payload version to 1 across backend (CourseExportDto.CURRENT_VERSION) and frontend (COURSE_PAYLOAD_VERSION), with documentation updates. Also adds iconOnly to BookmarkButton and removes automatic uuid-ossp install from Postgres init.

Changes

AI Course Generator Feature

Layer / File(s) Summary
Payload version alignment
apps/backend/.../CourseExportDto.java, apps/frontend/lib/types.ts, docs/hand-off.md
Backend CURRENT_VERSION and Javadoc revised from 2 to 1. Frontend COURSE_PAYLOAD_VERSION = 1 constant introduced with alignment comments. Hand-off docs updated to document version 1 schema, versioning rules, and the export/import scope restriction to version 1.
AI types and server actions
apps/frontend/lib/types.ts, apps/frontend/app/actions/ai.ts
GenerateRequest and AiCourseDraft interfaces defined. GenerateErrorCode and GenerateResult types added to standardize outcomes. generateAiCourse POSTs with a 120s timeout and maps ApiError HTTP statuses (429/503/502) to error codes. importAiCourse wraps importCourse with COURSE_PAYLOAD_VERSION.
AiGeneratorForm component
apps/frontend/components/ui/icons.tsx, apps/frontend/components/admin/ai-generator-form.tsx
XIcon added for delete affordances. AiGeneratorForm implemented with KeyIdeasInput (tag entry with constraints), GeneratingAnimation (step-advancing timeout animation), LevelBadge, and DraftPreview (course summary card with import/regenerate actions). Main form orchestrates generate/regenerate/import state with useTransition.
Admin page, dashboard entry, and translations
apps/frontend/app/admin/ai/page.tsx, apps/frontend/app/admin/page.tsx, apps/frontend/messages/*.json
New admin AI page enforces TEACHER role and renders AiGeneratorForm inside AdminShell. Admin dashboard adds a SparklesIcon glass button linking to /admin/ai-generator. English and French translations added for all adminAi UI strings and errors.adminAi error codes.

BookmarkButton iconOnly Mode and Postgres Init Cleanup

Layer / File(s) Summary
BookmarkButton iconOnly prop and reader page
apps/frontend/components/course/bookmark-button.tsx, apps/frontend/app/courses/[slug]/read/page.tsx
BookmarkButtonProps gains optional iconOnly boolean (default false); label rendering is gated on !iconOnly. CourseReaderPage removes the mobile-only bookmark block and passes iconOnly to the desktop hover bookmark, adjusting its left offset from -left-12 to -left-10.
Postgres init.sql cleanup
docker/postgres/init.sql
Active CREATE EXTENSION IF NOT EXISTS "uuid-ossp" removed and replaced with commented example SQL and explanatory notes.

Sequence Diagram(s)

sequenceDiagram
  participant Admin as Admin (Browser)
  participant AiPage as /admin/ai page
  participant AiGeneratorForm
  participant generateAiCourse as generateAiCourse (server action)
  participant BackendAI as POST /api/v1/ai/courses/generate
  participant importAiCourse as importAiCourse (server action)
  participant importCourse

  Admin->>AiPage: Navigate to AI Generator
  AiPage->>AiGeneratorForm: Render with topic/level/language inputs
  Admin->>AiGeneratorForm: Submit GenerateRequest
  AiGeneratorForm->>generateAiCourse: topic, level, language, keyIdeas
  generateAiCourse->>BackendAI: POST (120s timeout)
  BackendAI-->>generateAiCourse: AiCourseDraft or HTTP error
  generateAiCourse-->>AiGeneratorForm: GenerateResult (ok: draft | error code)
  AiGeneratorForm->>AiGeneratorForm: Show DraftPreview or error UI
  Admin->>AiGeneratorForm: Click Import
  AiGeneratorForm->>importAiCourse: AiCourseDraft
  importAiCourse->>importCourse: version=1, course, pages
  importCourse-->>AiGeneratorForm: course id
  AiGeneratorForm->>Admin: Navigate to /admin/courses/{id}
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

  • CodeStar-Project/codestar#27: Implements the backend AI course generator endpoint (/api/v1/ai/courses/generate) and the shared CoursePayloadDto import contract that generateAiCourse and importAiCourse in this PR directly call and depend on.

Suggested reviewers

  • teamssUTXO

🐇 A rabbit hopped into the admin hall,
Found a sparkly button — "Generate All!"
It typed a topic, picked a level with care,
And watched the AI spin ideas from air. ✨
Pages appeared, blocks gleamed in a row —
One click to import, and off the course goes! 🎓

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 11.76% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title 'Feat/ai course generator front' is vague and uses non-descriptive conventions; it lacks clarity about the specific feature being implemented. Revise the title to be more specific and descriptive, e.g., 'Add AI course generator frontend with server actions and admin page' or 'Implement AI course generator UI with form, dashboard integration, and bookmark improvements'.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@teamssUTXO teamssUTXO added this to the v1.0.0 milestone Jun 11, 2026
@teamssUTXO teamssUTXO linked an issue Jun 11, 2026 that may be closed by this pull request
@teamssUTXO

teamssUTXO commented Jun 12, 2026

Copy link
Copy Markdown
Member

@lmrt0572 ca serait cool si tu pouvais rajouter une petite icone "point d'intérogation" et lorsqu'on clique dessus, ou qu'on passe la souris dessus, ça affiche un message à l'utilisateur sur les bonnes pratiques d'écriture du prompt de génération de cours.

Exemple de texte :

Pour obtenir un meilleur résultats, spécifiez :
Le niveau (master, lycéens première NSI, ...), la structure du cours, le ton, les objectifs, ...

J'espère que je t'aurais donné des idées

@teamssUTXO
teamssUTXO self-requested a review June 13, 2026 21:25
@teamssUTXO

Copy link
Copy Markdown
Member

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jun 14, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🧹 Nitpick comments (2)
apps/frontend/app/admin/ai/page.tsx (1)

15-37: 💤 Low value

Consider the semantic role of the SparklesIcon in PageHeader actions.

The SparklesIcon is passed to the actions prop, which typically holds interactive elements (buttons, links). Since this icon is purely decorative (no onClick, no interaction), it might be more semantically appropriate to pass it as a separate icon or decoration prop, or render it directly in the header content.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@apps/frontend/app/admin/ai/page.tsx` around lines 15 - 37, The SparklesIcon
in the PageHeader component is being passed to the actions prop, which is
semantically intended for interactive elements like buttons and links. Since the
SparklesIcon is purely decorative with no interactive behavior, move it out of
the actions prop and either pass it to a more appropriate prop like icon or
decoration if PageHeader supports it, or render it as a separate decorative
element outside the actions area. Check the PageHeader component definition to
determine the correct semantic prop for decorative icons, then update the
AiGeneratorPage component accordingly to remove the icon from the actions prop.
apps/frontend/app/actions/ai.ts (1)

20-38: ⚡ Quick win

Consider adding runtime validation for the draft structure.

The falsy check on line 27 (if (!draft)) catches null/undefined, but if the backend returns a malformed object (e.g., { course: null, pages: [] }), it would pass through and potentially cause issues downstream in importAiCourse. While TypeScript provides compile-time safety, a defensive runtime check would be more robust.

🛡️ Suggested defensive validation
 export async function generateAiCourse(request: GenerateRequest): Promise<GenerateResult> {
   try {
     const draft = await apiFetch<AiCourseDraft>("/api/v1/ai/courses/generate", {
       method: "POST",
       body: request,
       timeoutMs: 120_000,
     });
-    if (!draft) return { ok: false, error: "empty" };
+    if (!draft || !draft.course || !draft.pages) return { ok: false, error: "empty" };
     return { ok: true, draft };
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@apps/frontend/app/actions/ai.ts` around lines 20 - 38, The generateAiCourse
function only performs a falsy check on the draft object but does not validate
its internal structure, so a malformed response from the backend could pass
through and cause issues downstream. Add a runtime validation function that
checks the draft object has all required properties (such as course and pages)
before returning success. Apply this validation after the falsy check on the
draft variable, and return an error result if the structure validation fails.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@apps/frontend/app/admin/page.tsx`:
- Around line 65-70: The Link component's href attribute is set to
"/admin/ai-generator", but the actual page file is located at
apps/frontend/app/admin/ai/page.tsx, which corresponds to the route "/admin/ai"
in Next.js App Router. Update the href attribute in the Link component from
"/admin/ai-generator" to "/admin/ai" to match the actual route and prevent a 404
error when users click the button.

In `@apps/frontend/app/courses/`[slug]/read/page.tsx:
- Around line 179-188: The BookmarkButton component in the read page is hidden
on mobile devices due to the parent div having the "hidden lg:block" classes
combined with "group-hover:opacity-100" which doesn't work reliably on touch
devices. To fix this, modify the visibility and styling approach for the
BookmarkButton container to be visible and accessible on mobile/tablet screens.
Either make the bookmark button always-visible as an icon-only element on mobile
by adjusting the Tailwind classes (removing "hidden" and adjusting to show on
smaller screens), or implement a tap-to-reveal mechanism by adding a visible
mobile tap target that reveals the BookmarkButton. Ensure the solution maintains
the current desktop experience while providing mobile users with a clear way to
create new bookmarks during reading.

In `@apps/frontend/components/admin/ai-generator-form.tsx`:
- Around line 120-129: In the GeneratingAnimation function, replace the unsafe
type assertion `as string[]` with runtime validation to verify that the
translation value is actually an array before using it. Add a guard that checks
if t.raw("generationSteps") returns an array, and provide a fallback (such as an
empty array or a default steps array) if validation fails. This ensures the
component handles missing or malformed translations gracefully rather than
crashing or rendering incorrectly.

---

Nitpick comments:
In `@apps/frontend/app/actions/ai.ts`:
- Around line 20-38: The generateAiCourse function only performs a falsy check
on the draft object but does not validate its internal structure, so a malformed
response from the backend could pass through and cause issues downstream. Add a
runtime validation function that checks the draft object has all required
properties (such as course and pages) before returning success. Apply this
validation after the falsy check on the draft variable, and return an error
result if the structure validation fails.

In `@apps/frontend/app/admin/ai/page.tsx`:
- Around line 15-37: The SparklesIcon in the PageHeader component is being
passed to the actions prop, which is semantically intended for interactive
elements like buttons and links. Since the SparklesIcon is purely decorative
with no interactive behavior, move it out of the actions prop and either pass it
to a more appropriate prop like icon or decoration if PageHeader supports it, or
render it as a separate decorative element outside the actions area. Check the
PageHeader component definition to determine the correct semantic prop for
decorative icons, then update the AiGeneratorPage component accordingly to
remove the icon from the actions prop.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: a71d4ae5-0385-4070-8b4b-6237d12cca34

📥 Commits

Reviewing files that changed from the base of the PR and between 650e371 and fa78cf6.

📒 Files selected for processing (17)
  • apps/backend/src/main/java/com/codestar/backend/dto/course/CourseExportDto.java
  • apps/frontend/app/actions/ai.ts
  • apps/frontend/app/admin/ai/page.tsx
  • apps/frontend/app/admin/page.tsx
  • apps/frontend/app/courses/[slug]/read/page.tsx
  • apps/frontend/components/admin/ai-generator-form.tsx
  • apps/frontend/components/course/bookmark-button.tsx
  • apps/frontend/components/ui/icons.tsx
  • apps/frontend/lib/types.ts
  • apps/frontend/messages/en.json
  • apps/frontend/messages/fr.json
  • docker/postgres/init.sql
  • docs/2026-06-09-ai-course-generator-design.md
  • docs/README.md
  • docs/design-liquid-glass-citron-dark.md
  • docs/hand-off.md
  • docs/roadmap_frontend.md

Comment thread apps/frontend/app/admin/page.tsx
Comment thread apps/frontend/app/courses/[slug]/read/page.tsx
Comment thread apps/frontend/components/admin/ai-generator-form.tsx

@teamssUTXO teamssUTXO left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checklist to be merged :

  • Premier commentaire
  • Specifier à l'utilisateur via un petit encadré que Groq n'est pas Grok de Twitter (ou Elon Musk ou ce que tu veux.) : "Groq est est une entreprise américaine de semi-conducteur qu'on utilise pour l'outil de generation de cours avec IA"

@lmrt0572

Copy link
Copy Markdown
Contributor Author

Ajout d'une icône ? à côté du titre du formulaire de génération. Au survol (desktop) ou au clic (mobile), un popover affiche des conseils pour obtenir un cours de meilleure qualité.

@teamssUTXO
teamssUTXO merged commit 53f14d8 into CodeStar-Project:dev Jun 16, 2026
1 check passed
@github-project-automation github-project-automation Bot moved this from Backlog to Done in codestar roadmap Jun 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

[Feature] AI Course Generator

2 participants