Skip to content

This application is a secure and scalable backend service built with Node.js and Express.js, providing user authentication, question handling, and AI-generated answers using OpenAI's API. It includes features like JWT-based authentication, refresh tokens, and Docker containerization for easy deployment.

Notifications You must be signed in to change notification settings

coderavdhesh/Avdhesh-Gupta-AnswerAi-Backend

Repository files navigation

🌟 AnswerAi Backend Service 🌟

Welcome to the Backend Service! This service, built with Node.js and Express.js, is designed to handle user requests and generate AI-powered answers. It's secure, scalable, and ready to integrate with a frontend application.

Video Link of Demo on YouTube

https://youtu.be/DnnjjRh2EZw?si=kTnAi0LJdLj4jl4B

🚀 Features

  • User Management: Create and manage user accounts.
  • AI Integration: Generate answers using AI.
  • Authentication & Authorization: Secure endpoints with JWT.
  • Scalability: Designed to handle a large number of concurrent users.
  • Dockerized: Easy deployment with Docker.

📋 Table of Contents

🛠 Prerequisites

Make sure you have the following installed:

🔧 Environment Variables

Create a .env file in the root directory and add the following:

MONGO_URI=<Your MongoDB URI>
JWT_SECRET=<Your JWT Secret>
OPENAI_API_KEY=<Your OpenAI API Key>
PORT=5003

📦 Installation

Clone the repository and install dependencies:

git clone https://github.com/coderavdhesh/Avdhesh-Gupta-AnswerAi-Backend.git
cd path/to/Avdhesh-Gupta-AnswerAi-Backend
npm install

🏃 Running the Application locally

Start the application:

npm src/app.js

The server will run on http://localhost:5003, locally on your laptop.

✅ Running Tests

Run the tests using Jest:

npm test

🐳 Docker Setup

Build the Docker Image of the DockerFile:

docker build -t answerai-backend .

Run the Docker container(deploy the app locally):

docker run -p 5003:5003 answerai-backend

🐳 Docker Compose Setup (Best for the multiple DockerFiles)

Build the Docker Image of the DockerFile, using Docker compose:

docker compose build

Run the Docker container(deploy the app locally):

docker run -p 5003:5003 answerai-backend

Run the Docker container(to run the unit test cases):

docker compose run -t tests

📚 API Endpoints

  • Auth
POST /api/auth/login  : Login a user.
POST /api/auth/logout  : Logout a user.
POST /api/auth/refresh  : Refresh access token.
  • Users
GET /api/users  : to reteive all the users in the database
POST /api/users/newUser  : Create a new user account.
GET /api/users/:userId  : Retrieve a user profile.
GET /api/users/:userId/questions  : To retrive all the question of the specific user
  • Questions
POST /api/questions: Accept user question and return AI-generated answer.
GET /api/questions/:questionId: Retrieve a specific question and answer by question ID.

🏗 Architecture Diagram

Below is a high-level architecture diagram of the service:

Architecture Diagram

📖 License

This project is licensed under the MIT License. See the LICENSE file for details.

About

This application is a secure and scalable backend service built with Node.js and Express.js, providing user authentication, question handling, and AI-generated answers using OpenAI's API. It includes features like JWT-based authentication, refresh tokens, and Docker containerization for easy deployment.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published