Spaces:
Sleeping
Sleeping
Update README.md
Browse files
CLAUDE.md
ADDED
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# CLAUDE.md
|
2 |
+
|
3 |
+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
|
4 |
+
|
5 |
+
## Development Commands
|
6 |
+
|
7 |
+
### Local Development
|
8 |
+
- `make dev` - Start local Python HTTP server on port 8000
|
9 |
+
- `make dev-python` - Start FastAPI server on port 7860 (production-like)
|
10 |
+
- `npm run dev` - Alternative Python HTTP server command
|
11 |
+
- `python local-server.py 8000` - Direct local server command
|
12 |
+
|
13 |
+
### Docker Development
|
14 |
+
- `make docker-dev` - Start with docker-compose (recommended for production testing)
|
15 |
+
- `make docker-build` - Build Docker image
|
16 |
+
- `make docker-run` - Run container with environment variables
|
17 |
+
- `make logs` - View Docker logs
|
18 |
+
- `make stop` - Stop Docker containers
|
19 |
+
|
20 |
+
### Utilities
|
21 |
+
- `make install` - Install both Python and Node.js dependencies
|
22 |
+
- `make clean` - Remove temporary files and dependencies
|
23 |
+
- `make help` - Show all available commands
|
24 |
+
|
25 |
+
## Architecture Overview
|
26 |
+
|
27 |
+
### Frontend Structure
|
28 |
+
This is a **vanilla JavaScript modular application** with no build step. Key architectural patterns:
|
29 |
+
|
30 |
+
**Module Organization:**
|
31 |
+
- `app.js` - Main application controller, handles UI state and round management
|
32 |
+
- `clozeGameEngine.js` - Core game logic, word selection, and scoring
|
33 |
+
- `bookDataService.js` - Manages book data fetching from Hugging Face Datasets API
|
34 |
+
- `aiService.js` - OpenRouter API integration for AI-powered word selection and contextualization
|
35 |
+
- `chatInterface.js` - Modal-based chat UI for contextual hints
|
36 |
+
- `conversationManager.js` - AI conversation state management for chat functionality
|
37 |
+
- `welcomeOverlay.js` - First-time user onboarding
|
38 |
+
|
39 |
+
**Key Architectural Decisions:**
|
40 |
+
- **No capitalized words as blanks** - All word selection logic filters out capitalized words (proper nouns, sentence starters)
|
41 |
+
- **Progressive difficulty** - Levels 1-2: 1 blank, 3-4: 2 blanks, 5+: 3 blanks
|
42 |
+
- **Batch API processing** - Processes both passages simultaneously to avoid rate limits, with fallback to sequential processing
|
43 |
+
- **Accessible fonts** - Uses system font stack throughout UI, avoiding decorative fonts for accessibility
|
44 |
+
|
45 |
+
### Backend Structure
|
46 |
+
**Dual server setup:**
|
47 |
+
- `app.py` - FastAPI server for production (HuggingFace Spaces), handles environment variable injection
|
48 |
+
- `local-server.py` - Simple HTTP server for local development
|
49 |
+
|
50 |
+
**Environment variable handling:**
|
51 |
+
- Production: FastAPI injects API keys via meta tags, read by `init-env.js`
|
52 |
+
- Local: Environment variables accessed directly via `process.env` or `window`
|
53 |
+
|
54 |
+
### Data Flow
|
55 |
+
1. **Game Initialization**: BookDataService fetches book metadata from HuggingFace
|
56 |
+
2. **Passage Processing**: AIService processes passages via OpenRouter API for word selection and contextualization
|
57 |
+
3. **Word Selection**: Multi-layered selection (AI → manual fallback → emergency fallback) with capitalization filtering
|
58 |
+
4. **Chat System**: Context-aware conversation manager tracks per-blank question state
|
59 |
+
|
60 |
+
### API Dependencies
|
61 |
+
- **OpenRouter API** - AI word selection, contextualization, and chat responses (Google Gemma 3)
|
62 |
+
- **HuggingFace Datasets API** - Book content and metadata retrieval
|
63 |
+
- **External**: CDN-hosted Tailwind CSS and Google Fonts
|
64 |
+
|
65 |
+
### Styling Architecture
|
66 |
+
- **CSS Custom Properties** - Consistent theming with `--aged-paper`, `--typewriter-ink` variables
|
67 |
+
- **Accessible Design** - System fonts, proper contrast, keyboard navigation
|
68 |
+
- **Responsive Layout** - Mobile-first design with progressive enhancement
|
README.md
CHANGED
@@ -58,4 +58,53 @@ To run the Cloze Reader application locally using Docker:
|
|
58 |
|
59 |
### Prerequisites
|
60 |
- Docker installed on your system
|
61 |
-
- Port 7860 available on your machine
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
58 |
|
59 |
### Prerequisites
|
60 |
- Docker installed on your system
|
61 |
+
- Port 7860 available on your machine
|
62 |
+
|
63 |
+
## Architecture Overview
|
64 |
+
|
65 |
+
### Frontend Structure
|
66 |
+
This is a **vanilla JavaScript modular application** with no build step. Key architectural patterns:
|
67 |
+
|
68 |
+
**Module Organization:**
|
69 |
+
- `app.js` - Main application controller, handles UI state and round management
|
70 |
+
- `clozeGameEngine.js` - Core game logic, word selection, and scoring
|
71 |
+
- `bookDataService.js` - Manages book data fetching from Hugging Face Datasets API
|
72 |
+
- `aiService.js` - OpenRouter API integration for AI-powered word selection and contextualization
|
73 |
+
- `chatInterface.js` - Modal-based chat UI for contextual hints
|
74 |
+
- `conversationManager.js` - AI conversation state management for chat functionality
|
75 |
+
- `welcomeOverlay.js` - First-time user onboarding
|
76 |
+
|
77 |
+
```mermaid
|
78 |
+
graph TD
|
79 |
+
A[User loads app] --> B[Welcome Overlay]
|
80 |
+
B --> C[App.js - Main Controller]
|
81 |
+
C --> D[ClozeGameEngine.js]
|
82 |
+
C --> E[ChatInterface.js]
|
83 |
+
|
84 |
+
D --> F[BookDataService.js]
|
85 |
+
F --> G[HuggingFace Datasets API]
|
86 |
+
|
87 |
+
D --> H[AIService.js]
|
88 |
+
H --> I[OpenRouter API - Gemma 3]
|
89 |
+
|
90 |
+
E --> J[ConversationManager.js]
|
91 |
+
J --> H
|
92 |
+
|
93 |
+
D --> K[Word Selection Logic]
|
94 |
+
K --> L[Filter Capitalized Words]
|
95 |
+
K --> M[Progressive Difficulty]
|
96 |
+
|
97 |
+
C --> N[UI State Management]
|
98 |
+
N --> O[Level Progression]
|
99 |
+
N --> P[Score Tracking]
|
100 |
+
N --> Q[Passage Display]
|
101 |
+
|
102 |
+
style A fill:#f9f,stroke:#333,stroke-width:2px
|
103 |
+
style I fill:#bbf,stroke:#333,stroke-width:2px
|
104 |
+
style G fill:#bbf,stroke:#333,stroke-width:2px
|
105 |
+
style L fill:#fbb,stroke:#333,stroke-width:2px
|
106 |
+
```
|
107 |
+
|
108 |
+
---
|
109 |
+
|
110 |
+
[milwright](https://huggingface.co/milwright), *Zach Muhlbauer*, CUNY Graduate Center
|