Skip to content

HappyCoderHackathons/spar

Repository files navigation

Spar

Study smarter. Beat your friends doing it.

Elevator Pitch

Spar turns flashcard studying into a live 1v1 race, two players, same deck, first to master every card wins.

Inspiration

Studying alone is boring and easy to put off. We wanted to make it competitive and social without adding complexity, just drop into a room, pick a deck, and go head-to-head with someone.

What it does

Spar matches two players in a real-time 1v1 flashcard battle. Both players join a shared room and are dealt the same 10 cards from a deck. Each player answers independently, and a live scoreboard updates instantly as both sides make progress. First player to master all their cards wins. Answers are graded with fuzzy matching, so minor typos don't count against you.

How we built it

  • Backend: Python + Flask with WebSockets via flask-sock
  • Real-time sync: MongoDB change streams pushed over WebSocket to both players simultaneously
  • Answer grading: rapidfuzz for fuzzy string matching, normalizes punctuation/casing then applies an 80% similarity threshold
  • Mastery logic: A card is mastered once a player gets it right at least twice and has more correct than wrong answers by a margin of 2
  • Database: MongoDB with a replica set (required for change streams)
  • Hosting: Deployed on Ubuntu via exe.dev

Challenges we ran into

  • MongoDB change streams require a replica set, so a simple standalone Mongo install wasn't enough, we had to configure rs0 on the server
  • Keeping both players' views in sync without polling: change streams let the server push updates the moment either player answers, with no client-side polling
  • Fuzzy answer matching that feels fair, too strict and correct answers get rejected, too loose and wrong answers pass

Accomplishments that we're proud of

  • Real-time live scoreboard with zero polling, pure WebSocket + change streams
  • Fuzzy answer grading that actually works well in practice
  • Clean matchmaking: first player creates a room and waits, second player auto-joins and the game starts instantly

What we learned

  • MongoDB change streams are a powerful primitive for real-time apps, much simpler than maintaining a pub/sub layer ourselves
  • rapidfuzz is fast and accurate enough for answer grading with minimal configuration

What's next for Spar

  • Custom deck creation in-browser
  • More than 2 players per room
  • Persistent user accounts and win/loss history
  • Timed rounds and difficulty modes

Built with

  • Python 3.12
  • Flask
  • flask-sock (WebSockets)
  • MongoDB 8.0 (replica set / change streams)
  • PyMongo
  • rapidfuzz
  • uv
  • exe.dev (hosting)
  • HTML / CSS (vanilla)

Example Decks included

  • US Presidents
  • US State Capitals
  • Country Capitals

About

Study smarter. Beat your friends doing it.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages