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.
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 Step | Grade (q) | New Reps | New EF (min 1.3) | Next Interval |
|---|---|---|---|---|
| Initial -> #1 | q = 5 | 1 | 2.600 | 1 day |
| #1 -> #2 | q = 5 | 2 | 2.700 | 6 days |
| #2 -> #3 | q = 5 | 3 | 2.800 | 17 days |
| #3 -> Lapse (#4) | q = 2 | 0 (reset) | 2.480 | 1 day |
Run checks: pytest -v tests/test_planner.py4. 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
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.
feat: add study overview summary endpoint and test coverage
Added PlannerDatabase.get_overview() and GET /api/overview reporting module, assessment, and due revision counts.
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.