An AI-powered study companion built with NestJS. It generates personalized study plans, teaches concepts, generates and grades quizzes, chats with students, and emails study reports/reminders.
Built for the AI Automation Internship — Session 4 assignment. Covers all four required integrations:
| Requirement | Implementation |
|---|---|
| AI chatbot (NestJS + OpenAI) | POST /chat, plus AI-driven /study-plan, /teach, /quiz |
| Resend email integration | src/email — sends plans, progress reports, and reminders |
| Swagger API docs | Auto-generated at /api/docs via @nestjs/swagger |
| Sentry monitoring | src/instrument.ts + global SentryExceptionFilter |
- Personalized study plans —
POST /study-plan: give it subjects, exam date, daily hours, level, and weak topics; AI returns a day-by-day schedule with time allocations and priorities. - Concept teaching —
POST /teach: get a tutor-style explanation, key points, a worked example, and common mistakes for any subject/topic. - Quiz generation & evaluation —
POST /quizgenerates mixed MCQ/short-answer questions;POST /quiz/evaluategrades them (MCQs exactly, short answers via AI semantic grading) with per-question feedback. - Study chatbot —
POST /chat: general conversational study companion with message history. - Email delivery (Resend) —
POST /email/study-plan,/email/report,/email/reminder. - Daily reminders —
POST /reminders/subscribe+ a cron job (@nestjs/schedule, default 8am daily) that emails each subscriber their tasks for the day./reminders/send-nowtriggers it manually. - Swagger docs — full interactive API docs at
/api/docs. - Sentry — every unhandled/5xx error is captured with request context;
GET /debug-sentryis a convenience endpoint to verify your Sentry project is receiving events.
src/
instrument.ts # Sentry init (imported first in main.ts)
main.ts # Bootstrap: Swagger, validation, CORS
app.module.ts # Wires all feature modules + global exception filter
common/filters/ # SentryExceptionFilter
openai/ # Shared OpenAI client wrapper (text + JSON completions)
study-plan/ # Personalized study plan generation
teaching/ # Concept explanations
quiz/ # Quiz generation + AI grading
chat/ # Conversational chatbot endpoint
email/ # Resend integration + HTML templates
reminders/ # Subscription store + daily cron reminder job
-
Install dependencies
npm install
-
Configure environment
cp .env.example .env
Fill in:
OPENAI_API_KEY— from https://platform.openai.com/api-keysRESEND_API_KEY— from https://resend.com/api-keys (also setRESEND_FROM_EMAILto a verified sender/domain, or use Resend'sonboarding@resend.devfor testing)SENTRY_DSN— from your Sentry project settings (leave blank to disable Sentry locally)
-
Run it
npm run start:dev
-
Open Swagger docs
http://localhost:3000/api/docs
# 1. Generate a study plan
curl -X POST http://localhost:3000/study-plan \
-H "Content-Type: application/json" \
-d '{
"subjects": ["Database Systems", "Operating Systems", "AI"],
"examDate": "2026-09-10",
"hoursPerDay": 3,
"level": "Intermediate",
"weakTopics": ["Normalization", "Virtual Memory"]
}'
# 2. Teach a struggling topic
curl -X POST http://localhost:3000/teach \
-H "Content-Type: application/json" \
-d '{ "subject": "Database Systems", "topic": "Normalization", "level": "Intermediate" }'
# 3. Generate a quiz
curl -X POST http://localhost:3000/quiz \
-H "Content-Type: application/json" \
-d '{ "subject": "Operating Systems", "topic": "Virtual Memory", "numQuestions": 5 }'
# 4. Evaluate answers (use the questions returned from step 3, plus studentAnswers)
curl -X POST http://localhost:3000/quiz/evaluate \
-H "Content-Type: application/json" \
-d '{ "subject": "Operating Systems", "questions": [...], "studentAnswers": [...] }'
# 5. Email a progress report
curl -X POST http://localhost:3000/email/report \
-H "Content-Type: application/json" \
-d '{
"to": "student@example.com",
"studentName": "Ali",
"examDate": "2026-09-10",
"hoursStudied": 12,
"quizResults": [{ "subject": "Operating Systems", "score": 8, "total": 10 }]
}'
# 6. Subscribe to daily reminders (sent automatically at 8am, or trigger manually)
curl -X POST http://localhost:3000/reminders/subscribe \
-H "Content-Type: application/json" \
-d '{ "email": "student@example.com", "studentName": "Ali", "todaysTasks": "DB — Normalization (60 min)" }'
curl -X POST http://localhost:3000/reminders/send-now- No database — subscriptions live in memory and quizzes are stateless (the quiz + answer key round-trips through the client between generate and evaluate). This keeps the one-week scope focused on the four required integrations. Swapping in TypeORM/Prisma + Postgres would be the natural next step for persistence across restarts and multiple users.
- Sentry filter — only 5xx/unexpected errors are sent to Sentry; expected 4xx validation errors are returned to the client without polluting the error tracker.
- AI JSON mode —
OpenAiService.completeJson()centralizes prompting the model to return strict JSON and defensively strips markdown fences, so every feature (plan/teach/quiz/grading) gets structured, typed output instead of parsing free text.