Skip to content

feat: implement AI-powered flashcard system with interactive quiz and flip modes - #287

Open
Imaneelgh wants to merge 2 commits into
Open-TutorAi:mainfrom
Imaneelgh:feature/flashcards-quiz-system
Open

feat: implement AI-powered flashcard system with interactive quiz and flip modes#287
Imaneelgh wants to merge 2 commits into
Open-TutorAi:mainfrom
Imaneelgh:feature/flashcards-quiz-system

Conversation

@Imaneelgh

Copy link
Copy Markdown

Type of change

  • Feature

What this PR does

Implements a comprehensive AI-powered flashcard system that allows students to:

  • Automatically generate flashcards from text or PDF documents using local AI (Ollama)
  • Review using two interactive modes: Quiz (typing answers with fuzzy validation) and Flip (3D card animations)
  • Organize flashcards by subject using tags
  • Track progress with the Leitner spaced repetition algorithm (5 mastery levels)
  • View real-time statistics on a dedicated dashboard

Why it is needed

Students need an efficient way to memorize course content. Manual flashcard creation is time-consuming, and unstructured revision methods are ineffective. This feature automates flashcard generation using AI and implements spaced repetition to optimize long-term learning retention.

Files changed

Backend (7 files)

  • ai/llm/flashcard_generator.py: AI generation with strict validation to prevent hallucinations
  • ai/pdf/pdf_extractor.py: PDF text extraction using pdfplumber
  • data/models/flashcard.py: Flashcard SQLAlchemy model with Leitner fields
  • data/repositories/flashcard_repository.py: Database operations and Leitner algorithm implementation
  • gateway/http/routers/flashcards.py: API endpoints (generate, review, stats, tags, delete)
  • gateway/http/app.py: Router registration for flashcards
  • gateway/http/routers/__init__.py: Module export

Frontend (8 files)

  • ui/src/lib/apis/flashcards/index.ts: API client functions
  • ui/src/lib/components/icons/Flashcards.svelte: Flashcards icon for sidebar
  • ui/src/lib/components/student/elements/Sidebar.svelte: Added Flashcards navigation link
  • ui/src/lib/features/student/components/flashcards/elements/Flashcard.svelte: Reusable flashcard component
  • ui/src/lib/features/student/components/flashcards/pages/QuizReview.svelte: Quiz mode with Levenshtein validation
  • ui/src/lib/features/student/components/flashcards/pages/FlashcardReview.svelte: Flip mode with 3D animations
  • ui/src/routes/student/flashcards/+page.svelte: Dashboard with statistics
  • ui/src/routes/student/flashcards/generate/+page.svelte: Generation page (text/PDF modes)
  • ui/src/routes/student/flashcards/review/+page.svelte: Review page with mode switcher

Documentation (6 files)

  • docs/flashcards-system.md: Technical documentation (API endpoints, data model, algorithms)
  • docs/flashcards-user-guide.md: Step-by-step user guide with screenshot references
  • docs/screenshots/student-flashcards-dashboard.png: Dashboard view
  • docs/screenshots/student-flashcards-generate.png: Generation interface
  • docs/screenshots/student-flashcards-quiz.png: Quiz mode in action
  • docs/screenshots/student-flashcards-flip.png: Flip mode with 3D animation

How to test it

As a Student:

  1. Navigate to Flashcards:

    • Click "Flashcards" in the student sidebar menu (new navigation item)
  2. Test text-based generation:

    • Click "✨ Créer des flashcards"
    • Select "✍️ Texte" tab
    • Paste course content (minimum 100 characters)
    • Enter a subject tag (e.g., "Philosophy", "Python")
    • Adjust number of cards using slider (3-15)
    • Click "🚀 Générer les flashcards"
    • Verify cards are generated and you're redirected to review mode
  3. Test PDF-based generation:

    • Click "✨ Créer des flashcards"
    • Select "📄 PDF" tab
    • Upload a PDF file (max 10MB)
    • Select AI model (phi3:mini for speed or qwen2.5:7b for quality)
    • Enter subject tag
    • Click "Generate flashcards"
    • Verify extraction and generation succeed
  4. Test Quiz mode:

    • Go to "🎯 Commencer la révision" or navigate to review page
    • Select "⌨️ Quiz" mode
    • Read the question displayed
    • Type your answer in the input field
    • Press Enter or click "✓ Valider"
    • Verify immediate feedback (green for correct, red for incorrect)
    • Test fuzzy validation by typing answers with minor typos
    • Verify automatic progression to next question
  5. Test Flip mode:

    • Switch to "🔄 Flip" mode
    • Click anywhere on the card to flip it
    • Verify smooth 3D animation
    • Click "✅ Je sais" if you knew the answer
    • Click "❌ À revoir" if you didn't know
    • Verify card progresses to next or returns to box 1
  6. Verify dashboard statistics:

    • Return to Flashcards dashboard
    • Check "Total" count matches created cards
    • Check "À réviser" shows cards due for review
    • Check "Maîtrisées" shows cards at box 5
    • Verify numbers update after reviews
  7. Test tag filtering:

    • Create flashcards for multiple subjects
    • On dashboard, click on a subject tag
    • Verify only cards from that subject are reviewed

UI CHANGED

YES

Visible changes:

  • New navigation item: "Flashcards" link added to student sidebar menu (with flashcard icon)
  • Dashboard page:
    • Three statistics cards (Total, À réviser, Maîtrisées)
    • Two action buttons ("Commencer la révision", "Créer des flashcards")
    • Subject tags grid showing all created subjects with card counts
    • Danger zone with "Supprimer toutes les cartes" button
  • Generation page:
    • Mode tabs (✍️ Texte / PDF)
    • Subject input with datalist suggestions
    • Text area for content input (text mode)
    • File upload area (PDF mode)
    • Slider for number of cards (3-15)
    • Submit button with loading state
  • Review page:
    • Mode switcher (⌨️ Quiz / 🔄 Flip)
    • Quiz mode: Question display, answer input field, validation feedback
    • Flip mode: 3D flip card with "Je sais" / "À revoir" buttons
    • Progress indicator showing current card number

Screenshots taken

YES

Screenshot from 2026-07-08 23-32-05 - Shows the main dashboard with statistics cards and subject tags - Demonstrates the clean layout and color scheme aligned with OpenTutorAI design
Screenshot from 2026-07-08 23-47-03
  • Shows the generation interface in text mode
  • Displays the mode tabs, subject input, text area, and slider
Screenshot from 2026-07-09 00-00-45
  • Shows the Quiz mode with a question and answer input field
  • Demonstrates the validation feedback (green success message)
Screenshot from 2026-07-09 00-05-22 Screenshot from 2026-07-09 00-03-35
  • Shows the Flip mode with a card in flipped state
  • Displays the 3D animation and "Je sais" / "À revoir" buttons

All screenshots are referenced in docs/flashcards-user-guide.md following the guide's requirements.

Documentation files created/updated

  • docs/flashcards-system.md: Technical documentation covering:

    • Feature overview and purpose
    • Roles (Student)
    • Data model (Flashcard table structure)
    • API endpoints (generate, generate-from-pdf, due, due/{tag}, review, tags, stats, delete, delete-all)
    • Algorithms (Leitner spaced repetition, Levenshtein fuzzy matching)
    • Files changed
    • Dependencies
  • docs/flashcards-user-guide.md: User guide covering:

    • Overview in simple language
    • Step-by-step instructions for generating flashcards (text and PDF)
    • Step-by-step instructions for Quiz mode
    • Step-by-step instructions for Flip mode
    • How to filter by subject
    • Screenshot references

Breaking changes

NO

This is a new feature that adds functionality without modifying or removing existing features.

Related issues

None

Branch name

feature/flashcards-quiz-system

Dependencies

  • Backend: pdfplumber (for PDF text extraction) - should be added to requirements.txt
  • Frontend: No new dependencies added

Technical highlights

  • Levenshtein distance algorithm: Used for fuzzy answer validation in Quiz mode, tolerating typos up to 15% difference
  • Leitner spaced repetition: 5-box system with intervals (0 days, 1 day, 3 days, 7 days, 30 days)
  • Strict AI validation: Generated answers must exist in source text to prevent hallucinations
  • AI context reset: Each generation starts with empty context to ensure topic isolation
  • Tailwind CSS alignment: UI uses OpenTutorAI's design system with dark mode support
  • Responsive design: Works on desktop and mobile devices

What's missing before submission

  • Ensure pdfplumber is in requirements.txt
  • Verify all screenshots are properly referenced in documentation
  • Test on both light and dark modes
  • Confirm backend server runs without errors
  • Confirm frontend builds without errors (npm run build)

Imaneelgh added 2 commits July 7, 2026 23:46
- Add flashcards router import and registration in gateway/http/app.py
- Add Flashcards icon component
- Add Flashcards link to student sidebar navigation
- Fix 404 errors on flashcards API endpoints
@Imaneelgh
Imaneelgh requested a review from pr-elhajji as a code owner July 8, 2026 23:07
@Imaneelgh

Copy link
Copy Markdown
Author

Hi,

This PR implements a complete AI-powered flashcard system for students with:

Features:

  • AI generation from text and PDF (using Ollama)
  • Quiz mode with fuzzy validation (Levenshtein algorithm)
  • Flip mode with 3D animations
  • Leitner spaced repetition (5 mastery levels)
  • Tag-based organization
  • Dashboard with statistics

Files:

  • 7 backend files (AI, data models, API routes, router registration)
  • 8 frontend files (components, pages, API client, sidebar navigation)
  • 6 documentation files (technical doc, user guide, 4 screenshots)

Fully documented per OpenTutorAI guide:

  • Technical documentation with API endpoints and algorithms
  • User guide with step-by-step instructions
  • 4 screenshots showing the interface

Testing:

  • Backend: All API endpoints tested and working
  • Frontend: All pages load correctly, navigation works
  • Integration: Generation, review, and dashboard all functional

Ready for review! 🙏

Best regards,
Imane

@03ABDALLAH 03ABDALLAH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for the contribution! Please resolve the merge conflicts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants