Quiz App Prompt
Logo Quiz App using Google ADK
An infinite real‑time quiz: display company logos, let users identify them, update scores live, and continue indefinitely while users can join or leave anytime.
Tech Stack:
- Backend: Python with Google ADK (Agents) + FastAPI
- Frontend: React (UI)
- Database: PostgreSQL
- Communication: WebSockets for live leaderboard
- Deployment: Docker (backend, frontend, database)
1. Core Features
-
User Experience
- User enters a nickname (no authentication).
- Presented with a random logo and four multiple-choice answers.
- Scores: +10 for correct, -5 for incorrect.
- Continuous gameplay (no end screen).
- Leaderboard updates live for all connected players.
-
Logos
- Seeded dataset in PostgreSQL or pulled via external API (e.g., Clearbit Logos).
- Logos stored as URLs.
-
Leaderboard
- Real-time updates via WebSockets.
- Shows top 10 players with live ranks.
-
Agent-Driven Orchestration
- LogoQuizAgent (built with Google ADK) manages:
- Fetching logos and building questions.
- Validating answers.
- Updating scores.
- Broadcasting leaderboard changes.
- LogoQuizAgent (built with Google ADK) manages:
2. Architecture Overview
ADK Agent (Python)
- Primary Agent:
LogoQuizAgent
- Built with
LlmAgent
fromgoogle-adk
. - Uses tools for:
- Fetching questions.
- Checking answers.
- Updating and fetching leaderboard.
- Orchestrated with
Runner
andSessionService
for user sessions. - Uses
LoopAgent
or similar for continuous game cycles.
- Built with
Example Agent:
from google.adk.agents import LlmAgent
from google.adk.runners import Runner
from my_logo_tools import get_next_question, check_answer, fetch_leaderboard
logo_agent = LlmAgent(
name="logo_quiz_agent",
model="gemini-2.0-flash",
instruction="""Run infinite quiz rounds: fetch a question, validate user answers, update scores, return next question.""",
tools=[get_next_question, check_answer, fetch_leaderboard],
)
runner = Runner(agent=logo_agent)
Backend (FastAPI + ADK)
-
Endpoints:
POST /join
: Create user session via ADK SessionService.GET /question
: Invokeget_next_question
.POST /answer
: Invokecheck_answer
and update score.GET /leaderboard
: Fetch leaderboard snapshot.WS /ws/leaderboard
: Push leaderboard changes in real time.
Frontend (React)
-
Pages:
- Landing: Nickname input.
- Quiz: Displays logo, options, and score.
- Leaderboard: Side panel with live updates.
-
Uses REST for initial state and WebSocket for leaderboard.
-
State managed by Redux or Zustand.
Database (PostgreSQL)
Tables:
users (id, nickname, score, joined_at)
logos (id, company_name, logo_url)
questions (id, logo_id)
answers_log (id, user_id, question_id, is_correct, timestamp)
Seed logos or fetch dynamically.
Dockerization
Services:
backend
: FastAPI + ADK.frontend
: React build served by Nginx.db
: PostgreSQL with seeded data.- Optional:
pgadmin
for DB inspection.
3. Game Loop Workflow
-
User joins → Backend registers session.
-
Backend requests a question via
get_next_question
(ADK tool). -
Question sent to frontend.
-
User answers → Backend invokes
check_answer
(ADK tool). -
Score updated in DB, leaderboard recalculated via
fetch_leaderboard
. -
WebSocket broadcasts new leaderboard.
-
New question sent automatically; loop continues.
4. Tool Functions (Python)
# my_logo_tools.py
def get_next_question(session_state) -> dict:
# Fetch random logo, build choices, track in session state
return {
"question_id": 123,
"logo_url": "https://cdn.example.com/google.png",
"options": ["Google", "Amazon", "Netflix", "Microsoft"]
}
def check_answer(session_state, question_id, answer) -> dict:
# Verify answer, update score, log entry
correct = answer == "Google" # Example
session_state["score"] += 10 if correct else -5
return {"correct": correct, "new_score": session_state["score"]}
def fetch_leaderboard(session_state) -> list:
# Query DB for top 10 users
return [{"nickname": "Alice", "score": 120}, {"nickname": "Bob", "score": 95}]
Wrapped as ADK tools for LogoQuizAgent
.
5. API Contracts
REST
-
POST /join
{ "nickname": "Deepak" }
Response:
{ "user_id": 1, "nickname": "Deepak", "score": 0 }
-
GET /question
{ "question_id": 12, "logo_url": "https://cdn.example.com/apple.png", "options": ["Apple", "Samsung", "Sony", "Intel"] }
-
POST /answer
{ "user_id": 1, "question_id": 12, "answer": "Apple" }
Response:
{ "correct": true, "new_score": 40 }
-
GET /leaderboard
[ { "nickname": "Alice", "score": 120 }, { "nickname": "Bob", "score": 95 } ]
WebSocket
ws://backend/ws/leaderboard
-
Broadcast:
{ "leaderboard": [ { "nickname": "Alice", "score": 130 }, { "nickname": "Bob", "score": 105 } ] }
6. Folder Structure
quiz-app/
backend/
app/
main.py
agents/
logo_agent.py
tools/
my_logo_tools.py
routes/
users.py
quiz.py
leaderboard.py
websocket.py
Dockerfile
frontend/
src/
components/
pages/
Dockerfile
db/
init.sql
docker-compose.yml
7. Deployment Steps
-
Build Docker images:
docker-compose build
-
Start the stack:
docker-compose up
-
Access frontend at
http://localhost:3000
and backend API athttp://localhost:8000
.
8. Optional Enhancements
- Time limit per question (e.g., 10 seconds).
- Daily/weekly leaderboard resets.
- Admin dashboard for uploading logos.
- Multi-agent setup (e.g., separate
ScoreAgent
,QuestionAgent
using ADK).