← Back to portfolio

Flashcard Engine

Spaced repetition that knows when the exam is.

A revision engine that runs as a single file on a phone, with no install, no account and no internet. It schedules cards the way spaced repetition normally does, except it will never push a card past the date it actually matters.

Standard SM-2 assumes you have forever. Answer a card well three times and it disappears for a week, which is correct if you are learning a language and wrong if you have a hurdle exam on Friday, because the card you know today is the card you will have quietly lost by then. So every interval is clamped to a fraction of the time left before the exam. The effect is provable rather than vibes: with the cap in place, the schedule fits at least two more repetitions of every card into the runway that remains.

The rest of the engine is built around the same constraint, which is that revision happens on a phone, in bed, often with no signal. Each deck is one self-contained HTML file: the cards are a plain data array, the engine is a template, and the build step is a script that joins them. Review and Cram are separate modes, a mastery panel shows which sections are actually weak, and the real lecture diagrams are cropped out of the source slides and sit under the cards that need them, captioned. Every card also carries an explain-it-like-I-know-nothing layer and an inline glossary, which is the part that made it useful to someone starting from zero rather than just a memory aid for someone who already understood.

One subtle failure mode was worth designing around. Saved progress lives in the browser, and if card state were keyed by position, adding or reordering a single card would silently reassign everyone's schedule to the wrong questions. State is keyed by a hash of the question text instead, so the deck can be edited without scrambling what the learner has already earned. Verification ran the real engine, pulled out of the built file rather than a copy of it, against a DOM stub: 30 assertions on the scheduling maths, plus headless screenshots of every interface state.

  • SM-2 spaced repetition
  • constraint-aware scheduling
  • template and data-file build pipeline
  • vanilla JS
  • localStorage state design
  • headless-browser verification
  • offline-first

weekend hack

What it actually took. Version one was a single hand-written file, which was fine until I wanted a second deck and found myself copying an engine by hand. The rebuild into template plus data is the boring decision that made everything after it cheap: a new subject is now a data file. The exam cap came from noticing my own tool was about to do the wrong thing to me, three days before a hurdle exam. That is the whole lesson: an algorithm that is correct in general can still be wrong for the deadline you are actually standing in front of.