You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
2.6 KiB
2.6 KiB
2.1 Question Bank Service (Port 8081) - Detailed Implementation Plan
Summary
Implement the Question Bank Service as the source of truth for quiz questions and themes, with public random/get endpoints and admin CRUD/bulk workflows. Runtime stack: Fiber HTTP, PostgreSQL persistence, Redis-backed random-question cache, and shared packages for auth/validation/errors/observability.
Objectives
- Provide
/questions/randomand/questions/{id}for gameplay. - Provide admin endpoints for create/update/delete/list themes/bulk import.
- Implement 85% fuzzy answer matching helper for downstream game-session usage.
- Add observability, health/readiness, and test coverage.
API Endpoints
POST /questions/randomGET /questions/{id}POST /admin/questionsPUT /admin/questions/{id}DELETE /admin/questions/{id}GET /admin/themesPOST /admin/questions/bulk
Data Model
Question fields:
id(UUID)theme(max 100)text(max 1000)answer(max 500)hint(optional, max 500)difficulty(easy|medium|hard, defaultmedium)is_active(defaulttrue)created_at,updated_at
Indexes:
(theme, is_active)(difficulty, is_active)
Core Logic
- Random selection with exclusion list and optional theme/difficulty filters.
- Cache key format:
qb:random:v1:{sha256(filters+sorted_exclusions)}. - Cache TTL:
5m. - Cache invalidation on admin writes via namespace version bump.
- Fuzzy matching utility:
- normalize strings (trim/lower/collapse spaces/remove punctuation)
- compute Levenshtein similarity
- match when score
>= 0.85
Security
- Public endpoints are open for internal service usage.
- Admin endpoints protected by Zitadel JWT middleware.
- Admin authorization requires
adminrole + MFA.
Observability
- Shared logger initialized with service metadata.
- Shared metrics registered and
/metricsexposed. - Shared tracer initialization and shutdown.
/healthand/readyendpoints available.
Configuration
QUESTION_BANK_PORT(default8081)QUESTION_CACHE_TTL(default5m)QUESTION_RANDOM_MAX_EXCLUSIONS(default200)QUESTION_BULK_MAX_ITEMS(default5000)- shared
POSTGRES_*,REDIS_*,TRACING_*,METRICS_*,LOG_LEVEL,ZITADEL_*
Testing Strategy
- Unit tests:
- fuzzy matching threshold behavior
- random selection no-result and cache paths
- HTTP integration tests:
- random/get success
- admin auth guard behavior
- metrics endpoint
- Repository integration test scaffold (optional, DB-backed when env is set)
Verification
From backend/services/question-bank-service:
go test ./...
go vet ./...