An interactive Python learning platform with AST-based code analysis, AI tutoring, and intelligent grading β built as a full-stack SaaS application.
Python Academy is a production-grade e-learning platform designed to teach Python programming through hands-on exercises, real-time code execution, and intelligent feedback. The platform features a modular FastAPI backend with advanced Python services and a modern Vue 3 frontend.
- 100 structured lessons across 12 categories (NhαΊp MΓ΄n β LeetCode Hard)
- Interactive code editor with real-time execution and output display
- Quiz system with scoring, history tracking, and chapter-based organization
- Progress tracking β XP system, lesson completion, study streaks
- AST-based Code Analyzer β Static analysis engine that parses student code into Abstract Syntax Trees to evaluate complexity, detect patterns (functions, loops, comprehensions, classes), calculate nesting depth, and generate actionable refactoring suggestions
- Smart Hint Engine β Uses
difflib.SequenceMatcher+ AST node comparison to structurally compare student code against the expected solution, providing targeted hints like "Missing aforloop" or "Try using a function definition"
A 4-dimensional partial credit scoring system β not just text matching:
| Dimension | Weight | Method |
|---|---|---|
| Output Correctness | 50% | Exact, normalized & line-by-line output comparison |
| Code Quality | 20% | AST structural analysis (independent of answer) |
| Code Style | 20% | Indentation, naming, comments, docstrings |
| Text Similarity | 10% | difflib ratio (reference only) |
Scoring Philosophy β Output is King:
- β Output correct β minimum grade B regardless of approach
- π Different approach (e.g.
whilevsfor) + correct output β creativity bonus +10% - π« Hardcoded answer detected (e.g.
print(15)when logic is required) β capped at grade D β οΈ Syntax errors β capped at grade C
- WebSocket Live Streaming (
asynciosubprocess) β Output streamed line-by-line to frontend - REST API Fallback β Reliable execution with sandboxed subprocess
- Security Sandbox β Multi-level regex-based blocklist prevents
os,subprocess,eval,exec,open, infinite loops
- Weighted scoring algorithm analyzing quiz performance, lesson gaps, and completion patterns
- Personalized "next lesson" suggestions based on student weak areas
- Category-level progress analysis with priority scoring
- Professional PDF reports & certificates via
reportlab - Student progress summary with lesson completion stats
- Local Ollama-powered AI assistant for code explanation, hints, and code review
- Streaming chat interface with contextual code understanding
python-academy/
βββ π server/ # FastAPI Backend (3,783 LoC Python)
β βββ main.py # App entry point + lifespan events
β βββ config.py # Centralized configuration
β βββ π models/
β β βββ schemas.py # Pydantic request/response models
β βββ π routers/
β β βββ analysis.py # /api/analyze, /api/hints, /api/similarity
β β βββ execution.py # /api/run, WebSocket /api/ws/execute
β β βββ export.py # /api/export/pdf
β β βββ progress.py # /api/progress, /api/analytics
β βββ π services/ # Business Logic Layer
β β βββ code_analyzer.py # AST visitor, complexity scoring
β β βββ code_similarity.py # 4-dim scoring + anti-cheat detection
β β βββ smart_hints.py # difflib + AST hint generation
β β βββ recommendation.py # Weighted learning path algorithm
β β βββ database.py # SQLite ORM (6 tables)
β β βββ sandbox.py # Secure code execution
β β βββ live_executor.py # asyncio WebSocket streaming
β β βββ pdf_generator.py # reportlab PDF builder
β βββ π utils/
β β βββ security.py # Code safety checker
β β βββ storage.py # File-based storage (legacy)
β βββ π tests/ # 87 unit tests
β βββ test_analyzer.py # 13 tests β AST analysis
β βββ test_similarity.py # 30 tests β scoring + anti-cheat
β βββ test_hints.py # 12 tests β smart hints
β βββ test_sandbox.py # 15 tests β security & execution
β βββ test_database.py # 17 tests β SQLite operations
β
βββ π src/ # Vue 3 Frontend (4,689 LoC)
β βββ App.vue # Root component + routing
β βββ π components/
β β βββ HomeView.vue # Dashboard with stats & streaks
β β βββ LearnView.vue # Lesson browser + sidebar
β β βββ LessonView.vue # Code editor + all panels
β β βββ QuizView.vue # Quiz engine
β β βββ AITutorView.vue # Chat interface
β βββ π composables/
β β βββ useBackend.js # FastAPI + WebSocket client
β β βββ usePyodide.js # Browser-side Python (fallback)
β β βββ useAITutor.js # Ollama integration
β βββ π stores/
β β βββ academy.js # Pinia state management
β βββ π data/
β β βββ index.js # 100 lessons + quizzes content
β βββ π assets/
β βββ style.css # Premium dark glassmorphism (1,400+ lines)
β
βββ π server/data/
βββ academy.db # SQLite database (auto-created)
-- Normalized SQLite schema with 6 tables
students -- User profiles (id, name, created_at)
lesson_completions -- Completed lessons (student_id, lesson_id, xp, timestamp)
quiz_attempts -- Quiz history (chapter, score, total, percent, timestamp)
code_runs -- Execution logs (code, output, success, exec_time)
analysis_logs -- AST analysis history (complexity, features, suggestions)
study_sessions -- Daily activity tracking (date, lessons, quiz, code_runs)- Python 3.11+
- Node.js 18+
cd server
pip install -r requirements.txt
python main.py
# β
Server running at http://localhost:8000
# π API docs at http://localhost:8000/docsnpm install
npm run dev -- --port 5180
# β
App running at http://localhost:5180# Install Ollama β https://ollama.ai
ollama pull llama3.2
# AI Tutor auto-connects at localhost:1434cd server
python -m pytest tests/ -vtests/test_analyzer.py β 13 passed β
(AST analysis, complexity scoring)
tests/test_similarity.py β 30 passed β
(scoring, anti-cheat, output-first)
tests/test_hints.py β 12 passed β
(difflib, AST comparison, hints)
tests/test_sandbox.py β 15 passed β
(security blocklist, execution)
tests/test_database.py β 17 passed β
(SQLite CRUD, analytics)
βββββββββββββββββββββββββββββββββββββββββ
Total 87 passed β
in 1.84s
| Skill | Where Used |
|---|---|
ast module |
Code analyzer, structural quality scoring, anti-cheat detection |
difflib |
Text similarity, smart hints, code comparison |
asyncio |
WebSocket live execution streaming, subprocess management |
sqlite3 |
Normalized database with 6 tables, row factory, transactions |
| FastAPI | REST API, WebSocket endpoints, Pydantic validation, CORS |
reportlab |
PDF certificate & progress report generation |
| Data Structures | Weighted scoring algorithms, frequency maps, AST trees |
| Design Patterns | Service layer, router pattern, dependency injection |
| Security | Regex-based code blocklist, sandboxed execution, env isolation |
| Testing | 87 unit tests with pytest, edge cases, anti-cheat validation |
| Metric | Value |
|---|---|
| Total Python LoC | 3,783 |
| Total Frontend LoC | 4,689 |
| Python Files | 29 |
| Unit Tests | 87 (all passing) |
| API Endpoints | 12 REST + 1 WebSocket |
| Lessons | 100 across 12 categories |
| Database Tables | 6 (normalized schema) |
| Services | 8 modular business logic modules |
| Method | Endpoint | Description |
|---|---|---|
POST |
/api/run |
Execute Python code in sandbox |
WS |
/api/ws/execute |
WebSocket live output streaming |
POST |
/api/analyze |
AST code analysis |
POST |
/api/hints |
Smart hint generation |
POST |
/api/similarity |
Code similarity + anti-cheat scoring |
GET |
/api/recommendations |
Personalized learning path |
GET/POST |
/api/progress |
Load/save student progress |
GET |
/api/analytics |
Study stats & activity heatmap |
POST |
/api/export/pdf |
Generate PDF report |
GET |
/api/health |
Backend health check |
POST |
/api/quiz |
Submit quiz attempt |
GET |
/api/quiz/:chapter |
Quiz history by chapter |
| Layer | Technology |
|---|---|
| Frontend | Vue 3 (Composition API), Vite 8, Pinia, Chart.js |
| Backend | FastAPI, Uvicorn, Pydantic v2 |
| Database | SQLite 3 (persistent, auto-initialized) |
| Analysis | Python ast, difflib, custom AST visitors |
| ReportLab 4.0 | |
| AI | Ollama (local LLM, optional) |
| Testing | pytest, pytest-asyncio |
| Styling | Custom CSS β dark glassmorphism, 1,400+ lines |
This project was built as a demonstration of Python engineering skills for the Vingroup AI Talent program application.
Built with π Python + β‘ FastAPI + π Vue 3