# CampusAI Malawi 🎓
A WhatsApp-based AI academic assistant for university students in Malawi (UNIMA, MUBAS, and similar institutions).
Built with Node.js, Express, PostgreSQL (+ pgvector), the Baileys WhatsApp library, and the OpenAI API.
## Features
- **📊 GPA tracking** — log completed courses and grades, get your cumulative GPA instantly
- **📚 Course lookup** — look up course info by code, or search by keyword
- **📄 Course materials + RAG** — students upload PDFs (notes, past papers); the bot chunks, embeds, and lets anyone ask questions grounded in that material
- **🤖 AI Q&A** — general academic questions, or course-scoped questions answered from uploaded materials
- **WhatsApp-native onboarding** — new users are walked through picking their university, program, and year on first contact
## Architecture
```
server.js Express health server + boots the WhatsApp client
src/
config/
index.js Env-driven app config
database.js PostgreSQL connection pool
services/
userService.js User CRUD, onboarding, daily AI usage limits
courseService.js Course lookup / search
gpaService.js GPA calculation
materialService.js PDF ingestion, chunking, embeddings, RAG retrieval
aiService.js OpenAI chat + embeddings wrapper
chatHistoryService.js Conversation history persistence
whatsapp/
client.js Baileys socket setup, QR login, reconnect logic
messageHandler.js Extracts text/media from incoming messages
onboarding.js First-contact setup flow (in-memory state machine)
commandRouter.js Parses commands and dispatches to services
utils/
logger.js Winston logger
textUtils.js Phone normalization, text chunking, cosine similarity
db/
schema.sql Full Postgres schema (run via `npm run db:migrate`)
seed.sql UNIMA/MUBAS + sample courses (`npm run db:seed`)
```
## Setup
### 1. Prerequisites
- …