Shared

This directory contains code shared between frontend and backend.

Files

  • types.ts - TypeScript interfaces and spaced repetition algorithm

Important Notes

Code in this directory must work in both environments:

  • ✅ Standard JavaScript/TypeScript
  • ❌ No Deno-specific APIs (Deno.*)
  • ❌ No browser-specific APIs (window, document)
  • ✅ Use only standard ES modules

Types

Data Models

  • Deck - Flashcard deck
  • Card - Individual flashcard with SR parameters
  • StudySession - Completed study session record
  • UserStats - Calculated statistics
  • UserData - Complete user data structure

Algorithm

  • Rating - Enum for card difficulty ratings (1-4)
  • ReviewResult - Result of SR calculation

Spaced Repetition Functions

calculateNextReview()

Implements the SM-2 algorithm to determine:

  • Next review date
  • Updated ease factor
  • Updated interval

isCardDue()

Checks if a card should be shown for review.

generateId()

Creates unique IDs for new records.

Algorithm Details

The SM-2 (SuperMemo 2) algorithm is the foundation of Anki's spaced repetition:

  • easeFactor: How "easy" the card is (higher = longer intervals)
  • interval: Days until next review
  • nextReview: Specific date/time for next review

See ARCHITECTURE.md for full algorithm documentation.