A course recommendation system built with multiple programming paradigms. Offers two recommendation pipelines: a non-AI path powered by a Prolog inference engine, and an AI path using Google Gemini.
| Paradigm | Where | Why |
|---|---|---|
| Logic (Prolog) | api/prolog/rules.pl |
defines course facts, prerequisite chains, and recommendation rules. |
| OOP | api/models.py |
Django models (Major, Course) encapsulate data with relationships. |
| Functional | api/ai_is_calling.py |
Data transformation pipeline using map/lambda for normalizing topics, pure functions (build_prompt, parse) that take input and return output with no side effects. |
| Imperative | api/prolog_engine.py, api/views.py |
Sequential execution flow assert facts, run queries in order, collect results, clean up. |
api/prolog/rules.pl contains:
- Course facts:
course(Name, Difficulty, Topic, Major)~300 courses across 20+ majors - Prerequisite facts:
prerequisite(Course, PrerequisiteCourse) - Dynamic predicates:
completed/1,student_preference/1,prefers_difficulty/1,student_major/1asserted per-request by the Python engine - Helper rules:
major_matches/1if no major is asserted, matches any majoreffectively_completed/1if you completedmath2,math1is inferred as completed since it's a prerequisite
The engine tries progressively relaxed queries:
- Strict: matches topic + difficulty + major
- Drop topic: keeps difficulty + major
- Drop difficulty: keeps topic + major
- Drop both: major only
Each level has two clauses: one for courses with prerequisites (checks all are met), one for courses with no prerequisites.
| Method | Endpoint | Description |
|---|---|---|
GET |
/api/majors/ |
List all majors |
GET |
/api/courses/?major=<name> |
List course names for a major |
POST |
/api/recommend/prolog/ |
Prolog recommendation |
POST |
/api/recommend/ai/ |
AI recommendation (Gemini) |
{
"liked_topics": ["mathematics", "algorithms"],
"completed_courses": ["math1", "math2"],
"preferred_difficulty": "hard",
"major": "computer_and_systems"
}Same request body. Uses Gemini to generate recommendations based on a structured prompt that includes the prerequisite graph from the Django database.
cd backend
python -m venv venv
source venv/bin/activate
pip install -r requirements.txtRequires SWI-Prolog installed on the system (sudo apt install swi-prolog).
Create backend/.env:
GEMINI_API_KEY=your_key_here
python manage.py migrate
python manage.py runservernpm install
npx expo start- Backend: Django + Django REST Framework
- Prolog Engine: SWI-Prolog via PySwip
- AI: Google Gemini API (
gemini-2.5-flash) - Mobile: Expo / React Native (TypeScript)
- Database: SQLite