Quiz Byte is a backend system that provides a variety of quizzes in computer science and IT. It is built with Go, Oracle DB, and follows Clean Architecture principles with Domain-Driven Design. The system supports user authentication via Google OAuth, AI-powered quiz generation and evaluation, and provides personalized quiz recommendations.
- User Authentication via Google OAuth 2.0
- Category and subcategory-based quiz delivery
- AI-powered quiz generation using Gemini LLM
- LLM-based auto-grading with detailed feedback (completeness, relevance, accuracy)
- Similarity-based answer evaluation using embeddings (OpenAI/Ollama)
- User progress tracking and quiz attempt history
- Personalized quiz recommendations
- RESTful API with comprehensive error handling
- Caching support with Redis (using Port & Adapter pattern)
- Integration tests and DB migration support
- Domain-driven error handling and validation
- Transaction Management: Consistent transaction handling across all service layers for data integrity
- Database Robustness: Enhanced NULL handling for Oracle database compatibility
- Service Layer Improvements: Unified service constructor patterns with transaction support
- User Management: Complete user authentication and profile management
- Quiz Attempt Tracking: Store and retrieve user quiz attempts with detailed evaluation
- AI-Powered Evaluation: Advanced answer evaluation using LLM with multiple scoring metrics
- Embedding-Based Similarity: Smart answer comparison using vector embeddings
- Quiz Generation: Automated quiz generation from text content using AI
- Batch Processing: Bulk quiz creation and management capabilities
- Recommendation System: Personalized quiz suggestions based on user performance
The project follows Clean Architecture principles with Domain-Driven Design:
- Domain Layer: Core business logic, entities, and interfaces
- Service Layer: Application use cases and business logic orchestration with transaction management
- Repository Layer: Data access with adapters and database abstraction
- Handler Layer: HTTP request handling and API endpoints
- Infrastructure Layer: External services (Redis, OAuth, LLM services)
- Adapter Layer: Integration with external services (embeddings, quiz generation)
- Transaction Layer: Consistent transaction boundaries across all operations
graph TB
subgraph "Client Applications"
Android[Android App]
Web[Web Browser]
API_Client[API Client]
end
subgraph "Quiz Byte Backend"
subgraph "API Server"
Router[Fiber Router]
AuthHandler[Auth Handler]
QuizHandler[Quiz Handler]
UserHandler[User Handler]
Middleware[Auth Middleware]
end
subgraph "Service Layer"
AuthService[Auth Service]
QuizService[Quiz Service]
UserService[User Service]
CacheService[Answer Cache Service]
BatchService[Batch Service]
end
subgraph "Domain Layer"
QuizDomain[Quiz Domain]
UserDomain[User Domain]
AuthDomain[Auth Domain]
TxManager[Transaction Manager]
end
subgraph "Repository Layer"
QuizRepo[Quiz Repository]
UserRepo[User Repository]
CategoryRepo[Category Repository]
end
end
subgraph "Batch Processing"
BatchCmd[Batch Command]
QuizGen[Quiz Generator]
DataSeeder[Data Seeder]
end
subgraph "External Services"
GoogleOAuth[Google OAuth 2.0]
Redis[(Redis Cache)]
Oracle[(Oracle Database)]
subgraph "AI Services"
Gemini[Google Gemini API]
OpenAI[OpenAI Embeddings]
Ollama[Ollama Local LLM]
end
end
subgraph "Adapters"
OAuthAdapter[OAuth Adapter]
RedisAdapter[Redis Cache Adapter]
DBAdapter[Database Adapter]
EmbeddingAdapter[Embedding Adapter]
LLMAdapter[LLM Evaluator Adapter]
QuizGenAdapter[Quiz Generation Adapter]
end
%% Client Connections
Android --> Router
Web --> Router
API_Client --> Router
%% API Flow
Router --> Middleware
Middleware --> AuthHandler
Middleware --> QuizHandler
Middleware --> UserHandler
%% Handler to Service
AuthHandler --> AuthService
QuizHandler --> QuizService
UserHandler --> UserService
%% Service Dependencies
AuthService --> UserRepo
QuizService --> QuizRepo
QuizService --> CacheService
UserService --> UserRepo
CacheService --> RedisAdapter
%% Domain Layer
AuthService --> TxManager
QuizService --> TxManager
UserService --> TxManager
%% Repository to Adapters
QuizRepo --> DBAdapter
UserRepo --> DBAdapter
CategoryRepo --> DBAdapter
%% External Service Connections
OAuthAdapter --> GoogleOAuth
RedisAdapter --> Redis
DBAdapter --> Oracle
EmbeddingAdapter --> OpenAI
EmbeddingAdapter --> Ollama
LLMAdapter --> Gemini
QuizGenAdapter --> Gemini
%% Batch Processing
BatchCmd --> QuizGen
BatchCmd --> DataSeeder
QuizGen --> QuizGenAdapter
QuizGen --> EmbeddingAdapter
DataSeeder --> DBAdapter
%% Service to Adapter Connections
AuthService --> OAuthAdapter
QuizService --> LLMAdapter
QuizService --> EmbeddingAdapter
%% Styling
classDef clientApps fill:#e1f5fe
classDef apiLayer fill:#f3e5f5
classDef serviceLayer fill:#e8f5e8
classDef domainLayer fill:#fff3e0
classDef repoLayer fill:#fce4ec
classDef externalServices fill:#f1f8e9
classDef adapters fill:#e0f2f1
classDef batchProcessing fill:#fff8e1
class Android,Web,API_Client clientApps
class Router,AuthHandler,QuizHandler,UserHandler,Middleware apiLayer
class AuthService,QuizService,UserService,CacheService,BatchService serviceLayer
class QuizDomain,UserDomain,AuthDomain,TxManager domainLayer
class QuizRepo,UserRepo,CategoryRepo repoLayer
class GoogleOAuth,Redis,Oracle,Gemini,OpenAI,Ollama externalServices
class OAuthAdapter,RedisAdapter,DBAdapter,EmbeddingAdapter,LLMAdapter,QuizGenAdapter adapters
class BatchCmd,QuizGen,DataSeeder batchProcessing
- Presentation Layer (Handlers): HTTP request/response handling
- Application Layer (Services): Business logic orchestration
- Domain Layer: Core business rules and entities
- Infrastructure Layer (Adapters): External service integration
- Ports: Domain interfaces defining contracts
- Adapters: Infrastructure implementations of those contracts
- Benefits: Testability, flexibility, and maintainability
- Transaction Manager: Ensures data consistency across operations
- Cache Layer: Redis-based caching with embedding similarity
- AI Integration: Multiple LLM providers for different use cases
- Authentication: Secure OAuth 2.0 flow with JWT tokens
- Batch Processing: Automated quiz generation and data seeding
cmd/ # Entry points
api/ # Main API server
batch_add_questions/ # Batch processing tool
migrate/ # Database migration tool
internal/
adapter/ # Infrastructure adapters
embedding/ # Embedding services (OpenAI, Ollama)
quizgen/ # Quiz generation services (Gemini)
cache/ # Cache abstraction and Redis implementation
domain/ # Domain models, entities, and interfaces
quiz.go # Quiz domain model with difficulty constants
user.go # User domain model
evaluator.go # Answer evaluation interfaces
embedding.go # Embedding service interfaces
quizgen.go # Quiz generation interfaces
repository/ # Data access layer
models/ # Database models
quiz_database_adapter.go # Quiz data operations
user_repository.go # User data operations
service/ # Application services
quiz.go # Quiz business logic
user_service.go # User management
auth_service.go # Authentication logic
answer_cache.go # Smart answer caching
batch_service.go # Batch processing
handler/ # HTTP handlers
quiz.go # Quiz API endpoints
user_handler.go # User API endpoints
auth_handler.go # Authentication endpoints
dto/ # API DTOs and request/response models
middleware/ # HTTP middleware (auth, error handling)
logger/ # Structured logging
database/ # DB connection and migration
configs/ # Configuration files
tests/integration/ # Integration tests
- Backend: Go 1.20+
- Database: Oracle Database
- Cache: Redis
- Authentication: Google OAuth 2.0
- AI Services:
- Google Gemini (Quiz Generation)
- OpenAI (Embeddings)
- Ollama (Local Embeddings)
- Testing: Testify, Integration Tests
- Infrastructure: Docker, Docker Compose
- Go 1.20+
- Oracle Database (local/remote)
- Redis Server
- Docker & Docker Compose (recommended)
- API Keys for AI services (optional for basic functionality)
- Clone the repository
git clone <repository-url>
cd quize-byte- Install dependencies
go mod tidy- Set up configuration
cp config.yaml.example config.yaml
# Edit config.yaml with your settings- Start infrastructure services
docker-compose up -d # Starts Oracle DB and Redis- Run database migrations
go run cmd/migrate/main.go- Start the API server
go run cmd/api/main.goKey environment variables and config settings:
database:
user: system
password: oracle
host: localhost
port: 1521
service_name: FREE
redis:
address: localhost:6379
db: 0
auth:
google:
client_id: your-google-client-id
client_secret: your-google-client-secret
redirect_url: http://localhost:8080/auth/google/callback
llm:
gemini:
api_key: your-gemini-api-key
model: gemini-pro
embedding:
source: openai # or "ollama"
openai:
api_key: your-openai-api-key
model: text-embedding-ada-002
ollama:
server_url: http://localhost:11434
model: nomic-embed-textThis section describes various command-line tools available in the project.
This tool is used to populate the database with an initial set of categories, sub-categories, and quizzes. This is useful for setting up a new environment or for testing purposes.
Location of the seeder command:
cmd/seed_initial_data/main.go
Location of the seed data file:
configs/seed_data/initial_english_quizzes.json
How to run the seeder:
- Ensure your database is running and accessible as per the
config.yamlsettings. - Make sure database migrations have been applied:
go run cmd/migrate/main.go
- Run the seeder command from the root of the project:
go run cmd/seed_initial_data/main.go
The command will log its progress to the console. It is designed to be idempotent for categories and sub-categories: it will not create duplicate categories (by name) or duplicate sub-categories (by name, within the same parent category). Quizzes are always added as new items under their respective sub-categories each time the seeder processes that sub-category; it does not check for duplicate quizzes by content.
GET /auth/google/login- Initiate Google OAuth login (redirects to Google consent page)GET /auth/google/callback- Handle OAuth callback with authorization code and state- Query params:
code(required),state(required) - Returns: JSON with
access_tokenandrefresh_token
- Query params:
POST /auth/refresh- Refresh JWT tokens using refresh token- Body:
{"refresh_token": "token_value"} - Returns: New
access_tokenandrefresh_token
- Body:
POST /auth/logout- Logout user (requires authentication)- Headers:
Authorization: Bearer <access_token> - Returns: Logout success message
- Headers:
GET /categories- Get all available quiz categories and subcategories- Public endpoint (no authentication required)
- Returns: Complete category hierarchy
GET /quiz- Get random quiz by subcategory- Query params:
sub_category(required) - Optional authentication (anonymous users supported)
- Returns: Single quiz with question and options
- Query params:
GET /quizzes- Get multiple quizzes by subcategory- Query params:
sub_category(required),count(optional, default 10, max 50) - Optional authentication (anonymous users supported)
- Returns: Array of quizzes
- Query params:
POST /quiz/check- Submit and evaluate quiz answer- Body: Quiz answer submission with AI-powered evaluation
- Optional authentication (anonymous users supported)
- Returns: Detailed evaluation with score, feedback, and analysis
-
GET /users/me- Get user profile information- Headers:
Authorization: Bearer <access_token> - Returns: User profile with basic information
- Headers:
-
GET /users/me/attempts- Get user's quiz attempt history- Headers:
Authorization: Bearer <access_token> - Query params:
limit(optional, default 10) - Items per pagepage(optional, default 1) - Page numbercategory_id(optional) - Filter by categorystart_date(optional, YYYY-MM-DD) - Filter from dateend_date(optional, YYYY-MM-DD) - Filter to dateis_correct(optional, true/false) - Filter by correctnesssort_by(optional, default 'attempted_at') - Sort fieldsort_order(optional, ASC/DESC, default 'DESC') - Sort direction
- Returns: Paginated list of quiz attempts with filtering
- Headers:
-
GET /users/me/incorrect-answers- Get user's incorrect answers for review- Headers:
Authorization: Bearer <access_token> - Query params: Same filtering options as attempts
- Returns: Paginated list of incorrect answers with explanations
- Headers:
-
GET /users/me/recommendations- Get personalized quiz recommendations- Headers:
Authorization: Bearer <access_token> - Query params:
limit(optional, default 10) - Number of recommendationssub_category_id(optional) - Filter by subcategory
- Returns: Personalized quiz recommendations based on performance
- Headers:
- Authentication: JWT-based authentication with Google OAuth 2.0
- Optional Authentication: Some endpoints support both authenticated and anonymous users
- Pagination: User-specific endpoints support pagination with
limit,page, andoffset - Filtering: Advanced filtering options for quiz attempts and results
- Error Handling: Consistent error response format with detailed error codes
- Rate Limiting: Built-in protection against excessive API calls
- CORS Support: Cross-origin requests enabled for web applications
All API responses follow a consistent JSON structure:
Success Response:
{
"data": { /* response data */ },
"status": "success"
}Error Response:
{
"code": "ERROR_CODE",
"message": "Human readable error message",
"status": 400
}Most user-specific endpoints require authentication via Bearer token:
Authorization: Bearer <your_jwt_token>
Anonymous access is supported for basic quiz functionality, allowing users to try quizzes without registration.
The API is fully documented using Swagger/OpenAPI 3.0. You can access the interactive API documentation at:
http://localhost:8090/swagger/
- Interactive Testing: Test API endpoints directly from the browser
- Request/Response Examples: See example requests and responses for each endpoint
- Authentication Testing: Use the "Authorize" button to test protected endpoints
- Schema Documentation: Detailed documentation of all request/response models
- Error Code Reference: Complete list of error codes and their meanings
- Current API version:
v1 - Base URL:
http://localhost:8090/api - Versioning strategy: URL path versioning (
/api/v1/...)
- Start the server:
go run cmd/api/main.go - Visit
http://localhost:8090/swagger/ - Use the "Authorize" button to authenticate with your JWT token
- Try out different endpoints with the interactive interface
The system uses LLM-based evaluation with multiple scoring metrics:
- Score: Overall correctness (0.0-1.0)
- Completeness: How complete the answer is
- Relevance: How relevant the answer is to the question
- Accuracy: Technical accuracy of the answer
- Keyword Matching: Important keywords found in the answer
- Embedding-based similarity search for cached answers
- Reduces redundant LLM calls for similar answers
- Configurable similarity thresholds
- Hash-based storage for multiple answer variations
- Bulk quiz generation from text content
- Automated categorization and difficulty assignment
- Progress tracking and error handling
- Suitable for content migration and bulk updates
- Analyzes user performance patterns
- Recommends quizzes based on knowledge gaps
- Considers subcategory preferences
- Adaptive difficulty progression
go test ./internal/...go test ./tests/integration/...go test -cover ./internal/...- Domain entities are in
internal/domain/ - Business logic is encapsulated in services
- Repository pattern for data access
- Clean separation of concerns
- Domain-specific error types
- Proper HTTP status code mapping
- Structured error responses
- Context-aware error messages
- Interface-based design for testability
- Dependency injection pattern
- Comprehensive test coverage
- Proper logging and monitoring
The application is designed for cloud deployment with:
- Containerized services
- Environment-based configuration
- Health check endpoints
- Graceful shutdown handling
