Skip to content

Repository files navigation

TobeTon Backend

A Node.js REST API backend for the TobeTon application, featuring AI-powered study tools including flashcard generation, quiz generation, summarization, RAG-based chatbot, and study suggestions.


Table of Contents


Features

  • Authentication — JWT-based user registration and login with bcrypt password hashing
  • Flashcard Generation — AI-generated flashcards organized into folders
  • Quiz Generation — AI-generated multiple-choice quizzes with progress tracking
  • Summarization — AI-powered document and note summarization
  • RAG Chatbot — Retrieval-Augmented Generation chatbot using ingested notes
  • Study Suggestions — Personalized AI study recommendations
  • Achievements — User achievement tracking (e.g. folders created, study streaks)
  • Statistics — Per-user quiz scores, study time, and daily activity tracking

Tech Stack

  • Runtime: Node.js
  • Framework: Express.js v5
  • Database: SQLite (sqlite3)
  • Auth: JSON Web Tokens (jsonwebtoken) + bcryptjs
  • AI Integration: RAG pipeline with local vector store
  • Dev Tools: nodemon, dotenv
  • AI Tool: Ollama and LM Studio

Project Structure

TobeTon_Backend/
├── controllers/
│   ├── achievementController.js
│   ├── authController.js
│   ├── cardsController.js
│   ├── chatbotController.js
│   ├── flashcardsController.js
│   ├── flashcardsGenerator.js    # AI flashcard generation
│   ├── folderController.js
│   ├── quizGenerator.js          # AI quiz generation
│   ├── quizzesController.js
│   ├── statisticsController.js
│   ├── studySuggestionsController.js
│   └── summaryController.js
├── data/
│   └── statistics.json
├── db/
│   ├── database.js               # Schema + SQLite connection
│   └── database.sqlite
├── middleware/
│   └── authMiddleware.js         # JWT verification
├── rag/
│   ├── embed.js
│   ├── ingestTXT.js              # Ingests notes.txt on server start
│   ├── retrieve.js
│   └── vectorStore.js
├── routes/
│   ├── achievement.js
│   ├── auth.js
│   ├── cards.js
│   ├── flashcards.js
│   ├── folder.js
│   ├── quiz.js
│   ├── statisticsRoutes.js
│   ├── studySuggestions.js
│   ├── summary.js
│   └── users.js
├── services/
│   ├── cardService.js
│   ├── chatbotService.js
│   ├── flashcardService.js
│   ├── quizSaveService.js
│   ├── ragService.js
│   ├── studySuggestionService.js
│   └── summaryService.js
├── uploads/
│   └── notes.txt                 # Ingested into RAG vector store on startup
├── utils/
│   ├── clean.js
│   ├── format.js
│   ├── jsonExtractor.js
│   └── jsonObjectExtractor.js
├── validators/
├── .gitignore
├── package.json
└── server.js

Getting Started

Prerequisites

  • Node.js v18+
  • npm
  • Ollama

AI Model Used

Database Schema

The SQLite database is initialized automatically on first run via db/database.js.

Table Description
users Stores user credentials (username, hashed password)
folders Study folders per user, with subject, topic, and difficulty
cards Flashcards belonging to a folder and user
quizzes Multiple-choice quiz questions linked to folders and cards
quiz_progress Tracks which cards have been quizzed per folder
achievements Defines available achievements and unlock conditions
user_achievements Records which achievements each user has earned
statistics Aggregate study stats per user (scores, time, quiz counts)
daily_statistics Daily breakdown of flashcard and quiz study time

API Reference

All routes are prefixed from the server root. Routes marked 🔒 require an Authorization: Bearer <token> header.

Auth

Method Route Auth Description
POST /auth/register Register a new user
POST /auth/login Login and receive a JWT

Users

Method Route Auth Description
GET /users/profile/:userId Get user profile
PUT /users/update-username Update username
PUT /users/update-password Update password

Folders

Method Route Auth Description
GET /folders/get 🔒 Get all folders for the authenticated user
POST /folders/create 🔒 Create a new folder
PUT /folders/:id 🔒 Update a folder
DELETE /folders/:id 🔒 Delete a folder

Cards

Method Route Auth Description
GET /cards/folder/:folder_id 🔒 Get all cards in a folder
POST /cards/create 🔒 Create a new card
PUT /cards/:id 🔒 Update a card
DELETE /cards/:id 🔒 Delete a card

Flashcards

Method Route Auth Description
GET /flashcards/folder/:folder_id 🔒 Get all flashcards in a folder
GET /flashcards/:id 🔒 Get a single flashcard
GET /flashcards/random/:folder_id 🔒 Get random flashcards from a folder
GET /flashcards/search 🔒 Search flashcards
POST /flashcards/study 🔒 Mark a flashcard as studied / update study time
POST /flashcards/save-cards 🔒 Bulk save AI-generated flashcards
POST /flashcardsAI Generate AI flashcards

Quizzes

Method Route Auth Description
GET /quiz/folder/:folder_id 🔒 Get all quizzes in a folder
POST /quiz/create 🔒 Create a quiz question
POST /quiz/:id/submit 🔒 Submit an answer for a quiz question
POST /quiz/save-bulk 🔒 Bulk save AI-generated quiz questions
DELETE /quiz/:id 🔒 Delete a quiz question
POST /quizAI Generate AI quiz questions

AI Features

Method Route Auth Description
POST /chatbot Chat with the RAG-powered chatbot
POST /summary/summary-sse Generate a summary (Server-Sent Events)
POST /suggestion/study-suggestions Get AI study suggestions

Achievements

Method Route Auth Description
GET /achievements/:userId Get achievements for a user

Statistics

Method Route Auth Description
GET /statistics 🔒 Get aggregate statistics for the authenticated user
GET /statistics/weekly 🔒 Get weekly study stats
PUT /statistics/quiz 🔒 Update quiz score statistics
PUT /statistics/quiz-study-time 🔒 Update quiz study time
PUT /statistics/study-time 🔒 Update flashcard study time
PUT /statistics/app-usage 🔒 Update total app usage time

Team Tobeton

Developers: 4

Mission: Creating an intelligent study companion that makes learning engaging, efficient, and personalized.

About

Backend for TobeTon

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages