How everesh/wanikani-tui works
Project type and purpose
• From the file tree and naming conventions, this is a Ruby‐based command‐line full-stack application with a terminal UI (TUI).
• It interacts with the external WaniKani REST API, persists data to a local database, normalizes and queries that data, and presents review sessions in a curses-style interface.
• Key use case: fetch review data (vocabulary/kanji) from WaniKani, store it locally, and guide the user through spaced-repetition reviews in the terminal.
High-level architecture layers
• Presentation layer (the TUI)
• Application/Domain layer (business logic, review engine)
• Persistence layer (database abstractions)
• External integration (WaniKani API)
• Utility/Glue code (data normalization, CJK rendering bridge)
Main components
a. Entry point
• bin/tui.rb (starts the TUI application)
b. Terminal UI (TUI)
• tui/main.rb (bootstraps the UI)
• tui/components/* (menus, spinners)
• tui/windows/* (status lines, title screens)
• CJK renderer submodule (Python script + Ruby bridge: tui/cjk_renderer)
c. Core engine
• lib/engine.rb (coordinates workflows: fetch → persist → review)
• lib/review.rb (review session logic)
d. Persistence layer
• lib/db/database.rb (DB connection, schema init/drop via drop.sql & init.sql)
• lib/db/persister.rb (writes fetched data into DB)
• lib/db/common_query.rb (shared query logic)
e. Utilities
• lib/util/data_normalizer.rb (cleans/structures API data)
• lib/util/data_dir.rb (manages local data paths)
f. External service
• lib/wanikani_api.rb (HTTP client for WaniKani endpoints)
• tmp/mock_wanikani_api.rb (simulated API for testing)
g. Database
Relationships & data flow
• The TUI entry point invokes the Engine
• Engine calls the WaniKani API client → receives JSON → passes through DataNormalizer → hands off to Persister → writes into the local SQLite DB
• For a review session, Engine loads Review objects via CommonQuery → Review logic structures prompts and answers → TUI calls CJKRenderer (via bridge) when heavy CJK rendering is needed → displays to user
• User input flows back through the TUI into the Engine → marks items correct/incorrect → Persister updates review intervals in DB
Architectural patterns & design principles
• Layered architecture: UI ↔ Engine ↔ Persistence ↔ External API
• Single Responsibility: each lib/ folder contains components strictly for one concern (db, error types, util, api, review logic)
• Testable units: extensive test suite under test/ and tmp/ mock data
• Bridge pattern: Ruby-to-Python CJK renderer
Technologies & frameworks
• Ruby (core language)
• Bundler/Gems (Gemfile)
• SQLite (local DB via SQL scripts)
• Curses-style TUI (likely using Ruby’s io/console or similar)
• Python (for advanced CJK rendering)
• Rake (build/test tasks)
Final checklist
• [ ] All major modules/components labeled
• [ ] Notes on data formats and protocols (HTTP/JSON, SQL, STDIN/STDOUT for the renderer)