LogiMath stores all application data in a PostgreSQL 16 (Alpine) database managed by Docker Compose. The schema is defined inDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/whitiue/logiMathApp/llms.txt
Use this file to discover all available pages before exploring further.
src/BackEnd/models.py using SQLAlchemy’s declarative ORM. Four tables cover user accounts, quiz catalogue entries, individual questions, and per-user scoring records. The database is persisted in a named Docker volume (postgres_data) so data survives container restarts.
Container configuration
Thepostgres service in docker-compose.yml uses postgres:16-alpine for a minimal image footprint and mounts an init script at container first-run.
docker-compose.yml
SQLAlchemy base and session
models.py creates the engine from DATABASE_URL, normalises the postgres:// scheme to postgresql:// for SQLAlchemy 2.x compatibility, and calls Base.metadata.create_all to emit CREATE TABLE IF NOT EXISTS for all models on startup.
models.py
Models
User
Stores registered accounts. email has a unique constraint to prevent duplicate registrations.
models.py
| Column | Type | Constraints |
|---|---|---|
id | Integer | Primary key, indexed |
name | String | Indexed |
email | String | Unique, indexed |
password_hash | String | Indexed |
created_at | DateTime | Defaults to utcnow |
Quiz
Represents a quiz in the catalogue. difficulty is a free-form string (e.g. "easy", "hard").
models.py
| Column | Type | Constraints |
|---|---|---|
id | Integer | Primary key, indexed |
title | String | Indexed |
subject | String | |
difficulty | String | |
created_at | DateTime | Defaults to utcnow |
Question
Belongs to a quiz via quiz_id. Carries its own difficulty field to support per-question adaptive difficulty independent of the parent quiz.
models.py
| Column | Type | Constraints |
|---|---|---|
id | Integer | Primary key, indexed |
quiz_id | Integer | Indexed (FK intent) |
question_text | String | |
correct_answer | String | |
difficulty | String |
UserScore
Records a user’s attempt on a quiz. completed tracks whether the attempt is finished, and completed_at is nullable to represent in-progress attempts.
models.py
| Column | Type | Constraints |
|---|---|---|
id | Integer | Primary key, indexed |
user_id | Integer | Indexed (FK intent) |
quiz_id | Integer | Indexed (FK intent) |
score | Float | |
completed | Boolean | Defaults to False |
completed_at | DateTime | Nullable |
Relationships between tables
The models use plain integer foreign key columns (quiz_id, user_id) without SQLAlchemy ForeignKey or relationship declarations. The logical relationships are:
- A
Usercan have manyUserScorerows (one per quiz attempt). - A
Quizcontains manyQuestionrows. - A
Quizcan appear in manyUserScorerows (attempted by many users).
Foreign key constraints and
relationship helpers are not yet defined at the SQLAlchemy level. Referential integrity is enforced only at the application layer for now.