Skip to content

Express.js API for flashcard app. Handles authentication, flashcard/topic management, AI integration. Built with Node.js, uses PostgreSQL with Sequelize ORM and Passport.js with JWT.

License

Notifications You must be signed in to change notification settings

gjemiolo-git/flashgen-backend

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Flashcard learning web application

This is the backend API for a flashcard learning web application. It provides endpoints for user authentication, flashcard set management, topic handling, and AI-assisted flashcard generation. It is part of the codebase for PERN stack, utilising PostgreSQL through Sequelize ORM, Passport for authentication with JWT, and OpenAI API.

Features

  • User `authentication (register, login, logout)
  • Flashcard set CRUD operations
  • Topic management
  • AI-assisted flashcard generation
  • Protected and public routes

Technologies Used

  • Node.js
  • Express.js
  • Passport.js for authentication
  • PostgreSQL
  • Sequelize ORM

API Routes

API Routes

Authentication Routes

  • POST /api/auth/register: Register a new user
  • POST /api/auth/login: User login
  • POST /api/auth/logout: User logout

Flashcard Set Routes

  • GET /api/ai/flashcard-sets/:id: Get a specific flashcard set
  • GET /api/ai/dashboard/flashcard-sets: Get user's flashcard sets
  • POST /api/ai/flashcard-sets: Create a new flashcard set with flashcards
  • PUT /api/ai/flashcard-sets/:id/update: Update a flashcard set
  • DELETE /api/ai/flashcard-sets/:id: Delete a flashcard set

Topic Routes

  • POST /api/ai/topics: Create a new topic
  • GET /api/ai/topics/:id: Get a specific topic
  • GET /api/ai/topics: Get all topics
  • GET /api/ai/topics-dashboard/:id: Get topic dashboard
  • DELETE /api/ai/topics/:id: Delete a topic

Flashcard Routes

  • POST /api/ai/flashcards: Generate new flashcards using AI
  • GET /api/ai/flashcards/:id: Get a specific flashcard

Setup and Installation

  1. Clone the repository
  2. Install dependencies: npm install
  3. Set up environment variables in a .env file
  4. Initialize the database
  5. Start the server: npm start

Environment Variables

Environment Variables

Most of the default values assued in ./src/constants/index.js

  • PROJECT_NAME: Name branding for the project

  • NODE_ENV: Set to 'production' for production environment

  • SERVER_PORT: Port number for the server

  • CLIENT_URL: URL of the frontend client for CORS

  • DB_ADDRESS: Address to the database

  • DB_PORT: Port to the database

  • DB_SUPERUSER: Superuser for database

  • DB_PASSWORD: Password for database

  • DB_URL: URL for the database, when deploying - Overwrites local settings when present

  • JWT_SECRET: Secret for JWT

  • COOKIE_DOMAIN: For JWT Security, when domain is not on public suffix list.

  • OPENAI_API_KEYY: API KEY to OpenAI(Spelling due to overriding with local key.)

  • OPENAI_API_URL: URL for OPENAI if different or changed

Authentication

The API uses JSON Web Tokens (JWT) for authentication. Protected routes require a valid JWT to be included in the Authorization header of the request.

Error Handling

The API includes centralized error handling middleware to process and return appropriate error responses.

AI Integration

The API includes routes for AI-assisted flashcard generation. The specific AI model and integration details are implemented in the ./src/controllers/ai.js.

About

Express.js API for flashcard app. Handles authentication, flashcard/topic management, AI integration. Built with Node.js, uses PostgreSQL with Sequelize ORM and Passport.js with JWT.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published