Case 4 of 4
NextGen MasterQuiz
Trivia web app I built on my own as the final project of the Python programming course at Tokio School. A Selenium bot collects the questions, a Flask API stores them in MySQL and serves them, and an Angular front end runs the game with JWT login and a leaderboard.
Stack
Context
A course project with every layer in it
The brief was a game that takes trivia questions from a web page, stores them and gives them back to the player at random, with a score at the end. I took it as a way to improve at back end and front end in the same project.
Starting requirements
Collect trivia questions and answers from a public web page
Store them in a database
Serve them to the player in random order
Return a final score from 1 to 10
The challenge
How it arrived
A course assignment and two things to learn at once: I had never built an application in Angular, and I still had to choose a Python framework for the server.
How it shipped
A working application: registration and login, random or category-based quizzes, answers checked on the server and a leaderboard with every player's score. Back end and front end are separate repositories that talk over HTTP.
Delivery
A Flask server and an Angular client
The server is split into modules and exposes a REST API. The client is built in Angular 16.2.4.
Decisions
Three decisions, one constraint
I was the only developer and I was learning the front-end framework as I went. That shaped all three.
01
Back endFlask instead of Django
I weighed both. Flask had more documentation close to what I wanted to build and a gentler learning curve, and that mattered: I was learning Angular on the front end at the same time.
02
ArchitectureOne module per responsibility
The server is five files. scraper_bot.py collects the questions with Selenium and writes them to MySQL. auth_module.py handles registration, login and sessions with JSON Web Tokens. trivia_module.py builds the quizzes and checks the answers. db_mysql.py manages the database connection and models.py defines categories and questions. A new feature can go in as a new module.
03
Front endObservables, a guard and an interceptor
Application state and asynchronous data run on observables. AuthService and MyTriviaService hold the business logic and the calls to the API. An AuthGuard protects the quiz and leaderboard routes, and an AuthInterceptor adds the token to every outgoing request. Registration, login and quiz answers use reactive forms.
Impact
It met the course requirements and left me with a working base in Python, Flask and Angular.
Álvaro Fajardo
Design, front-end and development on this project
Author's notes