Skip to content

Smart Flashcard Planner

In plain English

Schedules study flashcards automatically based on how confidently you answered each card, bringing harder cards back sooner.

A FastAPI and SQLite tracker pairing modular coursework assessments with a pure Python SuperMemo-2 interval engine.

1. Why I built it

Built to keep weighted deadline tracking paired with testable spaced-repetition scheduling backed by foreign-key integrity.

Problem being solved`INSERT OR REPLACE` in SQLite deletes the existing row before reinserting, silently cascading deletes across child assessments and topics.

2. How it works

Implemented `compute_sm2_schedule()`, `PlannerDatabase`, and FastAPI routes with lifespan cleanup in `src/study_planner/app.py`.

Fixed revision timetables neglect topics nearing memory decay. SM-2 Study Planner pairs module and assessment tracking with a deterministic SuperMemo-2 scheduler (`compute_sm2_schedule()`) that computes interval growth and clamps easiness (`EF ≥ 1.3`).

To avoid cascading deletes triggered by `INSERT OR REPLACE` whenever a module updates, `PlannerDatabase` executes non-destructive `ON CONFLICT(code) DO UPDATE` upserts.

`revision_topics` declares a foreign key referencing `modules(code)` guarded by `threading.RLock()`, SQLite WAL mode, explicit `404` checks, and FastAPI `lifespan` teardown.

3. Output & Source Specimen

SM-2 Deterministic State Transition Table (Starting EF = 2.5)

Review StepGrade (q)New RepsNew EF (min 1.3)Next Interval
Initial -> #1q = 512.6001 day
#1 -> #2q = 522.7006 days
#2 -> #3q = 532.80017 days
#3 -> Lapse (#4)q = 20 (reset)2.4801 day
Exact mathematical output computed by compute_sm2_schedule(quality, reps, ef, interval)Run checks: pytest -v tests/test_planner.py

4. Design Decisions & Challenges

Key Design Decisions

  • 01.Replaced `INSERT OR REPLACE` with `ON CONFLICT(code) DO UPDATE` so child foreign-key rows stay intact.
  • 02.Added `FOREIGN KEY(module_code)` onto `revision_topics` alongside explicit HTTP `404` existence checks.
  • 03.Kept `compute_sm2_schedule()` side-effect-free for deterministic unit testing.

Edge Cases Handled

  • Synchronising FastAPI concurrent database writes cleanly via `threading.RLock()` and WAL journalling.

5. Testing & Limits

Automated Checks

Verified with 4 pytest suites in `tests/test_planner.py` testing SM-2 multi-step schedules, lapse resets, `EF ≥ 1.3` clamping, conflict updates, `/api/overview` summary counts, `?pending_only=true` filtering, and API status codes.

Current Limits & Next Steps

  • Topic recall submissions currently operate through JSON REST endpoints (`POST /api/topics/{id}/review`); interactive inline grading buttons on the HTML index could be added.

6. Key Takeaways

What building Smart Flashcard Planner reinforced

Understanding SQLite's `REPLACE` conflict semantics prevents subtle data-loss bugs wherever `ON DELETE CASCADE` relationships exist.

  • — 4 pytest checks and Ruff lint pass cleanly in CI.
  • — Source hosted at github.com/16lv/sm2-study-planner.

Recent Activity

Latest repository updates

All changes for 16lv/sm2-study-planner

feat: add pending_only assessment filtering and semester selector in web UI

Added ?pending_only=true filtering on GET /api/assessments and replaced the hardcoded semester value with an interactive select control.

2026-11-247daa13b

feat: add study overview summary endpoint and test coverage

Added PlannerDatabase.get_overview() and GET /api/overview reporting module, assessment, and due revision counts.

2026-11-23a58a146

Add python -m study_planner runner and verify editable install in CI

Added __main__.py entrypoint and updated GitHub Actions CI to validate editable package installation and study-planner --help.

2026-11-21362e5fc