|
| 1 | +# Word DB Server |
| 2 | + |
| 3 | +Word DB Server is a Go backend server that powers multiple frontend applications for word study in scrabble-like games. |
| 4 | + |
| 5 | +The most specialized of these applications is WordVault, which |
| 6 | +allows users to study alphagrams and track their progress using |
| 7 | +spaced repetition algorithms |
| 8 | + |
| 9 | +## Core Data Models |
| 10 | + |
| 11 | +**Alphagram:** |
| 12 | + |
| 13 | +- Alphabetically sorted letters that can form one or more words |
| 14 | +- Each word must use exactly the letters provided (including duplicates) |
| 15 | +- Example: "NRU" creates words "RUN" and "URN" |
| 16 | +- Belongs to a specific lexicon (dictionary/language ruleset) |
| 17 | +- Same alphagram may have different valid words across lexicons |
| 18 | + |
| 19 | +**Word:** |
| 20 | + |
| 21 | +- Single valid word that can be formed from an alphagram |
| 22 | +- Contains lexicon symbols indicating word status (new, collins-only, etc.) |
| 23 | +- Lexicon symbols show word metadata, not lexicon membership |
| 24 | + |
| 25 | +**Card (WordVault-specific):** |
| 26 | + |
| 27 | +- Base unit for spaced repetition study |
| 28 | +- User and lexicon specific (same alphagram = different cards per user) |
| 29 | +- Tracks study progress and schedules reviews based on performance |
| 30 | + |
| 31 | +**Deck (WordVault-specific):** |
| 32 | + |
| 33 | +- Optional grouping mechanism for cards |
| 34 | +- Allows different study strategies and scheduling parameters |
| 35 | +- Example: separate deck for longer words with different retention targets |
| 36 | + |
| 37 | +## Technical Architecture |
| 38 | + |
| 39 | +### Server Framework |
| 40 | + |
| 41 | +- **Framework:** Built using Connect RPC. Types defined in \*.proto files |
| 42 | +- **HTTP Server:** Configurable port with graceful shutdown handling |
| 43 | +- **Middleware:** Uses alice middleware for logging and request handling |
| 44 | +- **Authentication:** JWT-based authentication with Connect interceptors |
| 45 | + |
| 46 | +### Database Layer |
| 47 | + |
| 48 | +- **Primary Database:** PostgreSQL with pgx/v5 driver and connection pooling |
| 49 | + - Stores user data including wordvault_cards, wordvault_params, wordvault_decks |
| 50 | + - Uses JSONB fields for FSRS (spaced repetition) algorithm data |
| 51 | +- **Migration System:** golang-migrate/v4 with migrations in `db/migrations/` |
| 52 | +- **Query Generation:** sqlc for type-safe SQL queries from `db/queries/` |
| 53 | +- **Lexicon Data:** SQLite databases for word/alphagram lookup |
| 54 | + - Stored in `DataPath/lexica/db/` directory |
| 55 | + - Contains linguistic data optimized for fast searches |
| 56 | + |
| 57 | +### API Structure |
| 58 | + |
| 59 | +**Connect RPC Services:** |
| 60 | + |
| 61 | +- **WordVaultService** (authenticated): Card management, spaced repetition scheduling, deck operations |
| 62 | +- **QuestionSearcher:** Alphagram and word searching functionality |
| 63 | +- **Anagrammer:** Anagram generation, blank tile challenges, build challenges |
| 64 | +- **WordSearcher:** Simple word lookups and definitions |
| 65 | + |
| 66 | +### Key Internal Components |
| 67 | + |
| 68 | +- **internal/wordvault:** FSRS spaced repetition logic using go-fsrs/v3 library |
| 69 | +- **internal/searchserver:** SQLite-based word and alphagram search engine |
| 70 | +- **internal/anagramserver:** GADDAG/KWG-based anagram generation using word-golib |
| 71 | +- **internal/auth:** JWT authentication and context management |
| 72 | +- **dbmaker:** Utility for creating and updating SQLite lexicon databases |
| 73 | + |
| 74 | +### Deployment |
| 75 | + |
| 76 | +- **Containerization:** Docker-based deployment |
| 77 | +- **CI/CD:** GitHub Actions pipeline for automated testing and deployment |
| 78 | +- **Database Management:** Migrations run automatically on startup |
| 79 | + |
| 80 | +## Development Rules |
| 81 | + |
| 82 | +- **Do not run migrations or start the dev server directly** |
| 83 | +- The development environment runs via docker-compose in a separate directory |
| 84 | +- Database and server are containerized and managed externally |
0 commit comments