Imported from Its-Atharva-Gupta/ReaderCopilot (
AGENTS.md). Install upstream withnpx skills add Its-Atharva-Gupta/ReaderCopilot. Copyright stays with the author.
AGENTS.md — StudyNest
Repository Truth
StudyNest currently ships as a monorepo with two active apps:
backend/ Django + Django REST Framework API
frontend/ Vite + React + TypeScript client
Work from these directories as the source of truth. Do not reintroduce an older root-level frontend structure.
Product Shape In Code
The current app is a school-focused study platform with:
- Firebase sign-in on the frontend
- Invite-code-gated Django registration
- Notes organized by class, subject, and chapter
- Multi-image note uploads
- Teacher-verification heuristics via red-pen detection
- Note voting plus threaded comments with mentions
- Reader/copilot flows for textbooks and uploaded reading files
- OCR and PDF generation for notes
- Leaderboard and analytics dashboards
Architecture Rules
- Django is the system of record for app data.
- Backend auth trusts Firebase for identity and verifies Firebase ID tokens in Django.
- App-level user metadata is stored in
users.AppUser. - Invite access is enforced through
users.InviteCode. - Development note uploads are stored in Django media storage under
backend/media/. boot-dev.shstarts a repo-local PostgreSQL instance on127.0.0.1:5433and seeds starter taxonomy data.- If Postgres env vars are missing, Django can fall back to SQLite, but the intended local workflow is the boot script plus Postgres.
Current Backend Map
backend/backend/settings.py: env loading, DB config, CORS, DRF auth defaults, media configbackend/backend/urls.py: API routing plus dev-only media serving with CORS headersbackend/users/: Firebase token verification, registration,/me, mentionable users, invite codesbackend/notes/: taxonomy, note CRUD, local image upload, OCR, PDF export, copilot query loggingbackend/social/: vote toggling, threaded comments, replies, edit/delete,@mentionparsingbackend/leaderboard/: top uploaders and top liked contributorsbackend/analytics/: note views, copilot query analytics, dashboard statsbackend/notes/management/commands/seed_taxonomy.py: local seed data for Class 8 subjects/chaptersbackend/notes/management/commands/backfill_note_pdfs.py: rebuild stored note PDFs
Current Frontend Map
frontend/src/App.tsx: routing, auth bootstrap, protected-route gatingfrontend/src/lib/api.ts: Django API client and active note-upload integrationfrontend/src/lib/firebase.ts: Firebase client bootstrapping for authfrontend/src/lib/openrouter.ts: reader copilot calls to OpenRouterfrontend/src/store/useAuthStore.ts: Firebase session + registration statefrontend/src/store/useReaderStore.ts: reader/copilot session statefrontend/src/pages/Home.tsx: landing dashboard for signed-in usersfrontend/src/pages/FeedPage.tsx: main note feedfrontend/src/pages/HandwrittenNotesPage.tsx: teacher-verified note viewfrontend/src/pages/ForumPage.tsx: discussion-oriented note browsingfrontend/src/pages/NoteDetail.tsx: note reader, OCR/PDF actions, voting, commentsfrontend/src/pages/Upload.tsx: active upload flow using Django/api/notes/upload/frontend/src/pages/BooksReaderPage.tsx: textbook/uploaded document reader with copilotfrontend/src/pages/LeaderboardPage.tsx: contributor rankingsfrontend/src/pages/Dashboard.tsx: analytics dashboardfrontend/src/config/books.ts: bundled textbook catalog
Important Behavioral Details
- Protected app routes require both Firebase authentication and successful Django registration.
- Registration consumes an unused invite code and creates
AppUser. - Note creation can mark a note as teacher-verified when red-pen detection is enabled and finds red-pen signals in uploaded images.
- Once a teacher-verified note exists for a chapter, that chapter is locked against new uploads.
- Note detail views create
analytics.NoteViewrows. - Reader/copilot usage can create
analytics.CopilotQueryrows through/api/notes/copilot-query/. - Comments support nested replies, editing, deletion, and mention-handle discovery.
- The frontend still contains a Firebase Storage helper, but the active handwritten-note upload path goes through Django local media storage.
Local Development Workflow
Preferred startup:
./boot-dev.sh
What it does:
- stops previous backend, frontend, and repo-local Postgres processes
- starts PostgreSQL 16 using
.postgres-data/ - creates the
studynestdatabase if needed - runs Django migration
- runs
manage.py seed_taxonomy - starts Django on
127.0.0.1:8000 - starts Vite on
127.0.0.1:5173 - writes logs to
.run/
Environment Notes
Backend expects values such as:
DJANGO_SECRET_KEYDJANGO_DEBUGDATABASE_URLorDB_*FIREBASE_PROJECT_IDENABLE_RED_PEN_CHECK
Frontend expects values such as:
VITE_API_BASE_URLVITE_FIREBASE_API_KEYVITE_FIREBASE_AUTH_DOMAINVITE_FIREBASE_PROJECT_IDVITE_FIREBASE_STORAGE_BUCKETVITE_FIREBASE_MESSAGING_SENDER_IDVITE_FIREBASE_APP_IDVITE_OPENROUTER_API_KEY
Backend OCR currently reads the OpenRouter key from backend env, frontend env, or root env if needed.
Coding Guidance
- Prefer small, direct implementations.
- Keep docs aligned with the code that exists now, not older product intentions.
- Preserve the Firebase-auth plus Django-verification split.
- Treat Django local media storage as the active note-upload implementation unless the code is intentionally migrated.
- When changing note creation, preserve the chapter lock behavior for teacher-verified notes unless product requirements explicitly change.
- When changing analytics or dashboards, remember they are driven by
NoteView,CopilotQuery, votes, comments, and verified-note coverage.
Cleanup Guidance
Keep generated and runtime files out of version control, especially:
.run/.postgres-data/backend/media/backend/db.sqlite3backend/**/__pycache__/- frontend build output
*.tsbuildinfo
Testing Priorities
When touching these areas, prioritize:
- Firebase token verification and
/api/users/register/ - invite-code consumption and
/api/users/me/ - protected route bootstrap in
frontend/src/App.tsx - taxonomy loading and upload flow
- teacher-verified chapter locking
- note detail view tracking, OCR, and PDF export
- vote toggling and nested comment behavior
- leaderboard and analytics dashboard responses
boot-dev.shstartup path and taxonomy seeding