Skip to content
amonofreiPublic

About

Full-stack AI-assisted Python debugging tutor combining automated code assessment, graduated Socratic scaffolding, debugging journey replays, learner analytics, personalised transfer exercises, daily challenges and MCP integration.

Topics

Resources

Stars

1 star

Watchers

1 watching

Forks

Repository files navigation

TraceBug

TraceBug is an AI-assisted Python debugging tutor designed for novice programmers. It supports learners in identifying and correcting Python bugs through automated testing, graduated Socratic hints, debugging-history analysis, reflective feedback, transfer practice and daily challenges.

TraceBug was developed as an MSc Computer Science project at the University of Birmingham. The system aims to keep learners actively engaged in the debugging process, using generative AI for guidance, reflection and further practice.

Features

  • topic-based debugging exercises built around small, self-contained Python programs with defined expected behaviour
  • separate Run Code and Submit Solution workflows
  • predefined assertion-based assessment with learner-facing feedback
  • three levels of graduated Socratic hints (AI-generated hints with predefined hints available as a fallback)
  • attempt history with code comparisons and exercise-level debugging journeys
  • learner debugging profiles derived from stored attempt data
  • AI-generated debugging journey replays and progress summaries
  • personalised AI-generated transfer exercises based on previously solved exercises
  • AI-generated daily challenges informed by learner progress and recent challenge history
  • daily challenge clues, progress path and milestone badges
  • topic progress tracking
  • learner-specific access control for generated content
  • user registration, login and protected learner routes
  • configurable invitation-only registration for controlled deployments

Technology Stack

  • Python
  • Flask
  • Jinja2
  • Flask-SQLAlchemy / SQLAlchemy
  • Flask-WTF and WTForms
  • Flask-Login
  • SQLite
  • HTML, CSS and JavaScript
  • Bootstrap
  • OpenAI API
  • Model Context Protocol Python SDK
  • Waitress
  • pytest

Installation and Setup

1. Clone the repository

git clone https://github.com/amonofrei/TraceBug.git
cd TraceBug

2. Create a virtual environment

python -m venv .venv

3. Activate the virtual environment

On Windows PowerShell:

.\.venv\Scripts\Activate.ps1

On macOS/Linux:

source .venv/bin/activate

4. Install the required dependencies

python -m pip install -r requirements.txt

5. Configure AI features (optional)

TraceBug integrates with the OpenAI API to provide personalised hints, debugging journey replays, learner progress summaries, transfer exercises and daily challenges.

The core debugging workflow remains functional without an API key, including code execution, automated assessment, predefined Socratic hints, attempt history and learner analytics.

To enable AI-generated content, create a copy of .env.example named .env in the project root and provide your own OpenAI API key:

OPENAI_API_KEY=your_api_key_here

You may also configure a persistent Flask SECRET_KEY in your environment. If no secret key is provided, the application generates a secure temporary key automatically. Existing sessions will become invalid when the application process restarts.

Private environment files are excluded from version control.

6. Create and seed the database

python setup_db.py

This creates the database tables and loads the predefined core topics, exercises and hints.

Note: running setup_db.py deletes existing hints, attempts, exercises and topics before reseeding them. It should therefore only be used for initial setup or an intentional database reset.

7. Run the Flask application

python -m flask run

The application should then be available at:

http://127.0.0.1:5000

Register a new account to begin using TraceBug.

Waitress study server

The project also includes a Waitress entry point:

python study_server.py

The application should then be available locally at:

http://127.0.0.1:5000

This was used for controlled study access without Flask debug mode.

Running the Tests

Run the full automated test suite:

python -m pytest -v

Run only the code-execution tests:

python -m pytest tests/test_code_execution.py -v

The test suite covers code execution, exercise routes, hint behaviour, learner analytics, transfer practice, daily challenges, route protection and invitation-only registration.

Project Structure

TraceBug/
├── app/
│   ├── services/
│   │   ├── ai_daily_challenge.py
│   │   ├── ai_hints.py
│   │   ├── ai_journey_replay.py
│   │   ├── ai_profile_summary.py
│   │   ├── ai_transfer_exercise.py
│   │   ├── code_execution.py
│   │   ├── daily_challenge_context.py
│   │   ├── daily_challenge_creation.py
│   │   ├── daily_challenge_progress.py
│   │   ├── daily_challenge_validation.py
│   │   ├── debugging_journey.py
│   │   ├── debugging_profile.py
│   │   ├── execution_worker.py
│   │   ├── mcp_client.py
│   │   ├── transfer_exercise_context.py
│   │   ├── transfer_exercise_creation.py
│   │   └── transfer_exercise_validation.py
│   ├── static/
│   │   ├── images/
│   │   └── style.css
│   ├── templates/
│   │   ├── _daily_challenge_history.html
│   │   ├── _daily_challenge_path.html
│   │   ├── _daily_challenge_progress.html
│   │   ├── attempt_details.html
│   │   ├── attempts.html
│   │   ├── base.html
│   │   ├── daily_challenge.html
│   │   ├── daily_challenge_landing.html
│   │   ├── debugging_profile.html
│   │   ├── exercise.html
│   │   ├── exercise_debugging_journey.html
│   │   ├── index.html
│   │   ├── login.html
│   │   ├── registration.html 
│   │   ├── topic_exercises.html
│   │   └── topics.html      
│   ├── __init__.py
│   ├── forms.py
│   ├── models.py
│   └── routes.py
├── data/
│   └── seed_data.py
├── tests/
│   ├── conftest.py
│   ├── test_code_execution.py
│   ├── test_daily_challenge.py
│   ├── test_debugging_profile.py
│   ├── test_exercise_routes.py
│   ├── test_hint_unlocking.py
│   ├── test_invitation_registration.py
│   ├── test_route_protection.py
│   └── test_transfer_progress.py
├── .env.example
├── .flaskenv
├── .gitignore
├── .railwayignore
├── config.py
├── mcp_server.py
├── README.md
├── requirements.txt
├── setup_db.py
└── study_server.py

Architecture Summary

TraceBug follows a layered, modular Flask architecture. Jinja/HTML templates, CSS and JavaScript provide the presentation layer, while Flask routes and WTForms coordinate requests and form handling. SQLAlchemy manages persistent application data, and service modules contain reusable learner analytics, code execution, AI generation and validation logic.

Standard exercises, transfer exercises and daily challenges reuse the same core Exercise, Hint and Attempt models. Type-specific ownership and generation information is stored in separate metadata models.

Learner analytics for the debugging profile and debugging journey are calculated from stored attempt data, while selected learner context is exposed to AI-assisted features through a local Model Context Protocol (MCP) interface.

Generative AI is used for hints, reflective summaries and personalised practice. Submitted code is assessed through assertion-based tests.

Code Execution and Safety

Run Code and Submit Solution use the same subprocess-based execution service. Learner code is executed outside the Flask application process with a timeout, bounded output, blocked interactive input, temporary working directories and process-level cleanup.

Run Code executes only the code currently in the editor and does not create an assessed attempt. Submit Solution uses the same execution pathway but also runs the stored assertion-based tests and retains the application's attempt, hint and progress behaviour.

These controls improve separation and failure handling but do not provide a complete production-grade security sandbox. TraceBug is intended as a controlled educational research prototype rather than a platform for unrestricted execution of arbitrary public code.

Deployment

TraceBug has been deployed on Railway using Waitress as the WSGI server and persistent SQLite storage.

Deployment secrets are managed through environment variables and are not stored in the repository.

The application was initially deployed for controlled participant access and evaluation.

Invitation-only registration

Registration is unrestricted by default for local development.

For controlled deployments, invitation-only registration can be enabled using the following environment variables:

REGISTRATION_INVITE_REQUIRED=1
REGISTRATION_INVITE_TOKEN=your_secure_invitation_token

When enabled, new users must access the registration page through a valid invitation link.

https://your-domain/register?invite=your_secure_invitation_token

Existing users can continue to authenticate normally.

Invitation tokens should be generated securely, stored privately and excluded from version control.

Invitation-only registration reduces exposure to unauthorised users but does not replace operating-system-level code execution isolation.

Author

Ana Maria Onofrei

About

Full-stack AI-assisted Python debugging tutor combining automated code assessment, graduated Socratic scaffolding, debugging journey replays, learner analytics, personalised transfer exercises, daily challenges and MCP integration.

Topics

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages