Answer AI Learning Assistant
182
AnswersAi-Backend is a scalable RESTful API built with Node.js, Express.js, and TypeScript, designed to provide AI-generated answers to user questions. It utilizes Prisma as an ORM, Docker for containerization, LangChain for AI-powered question answering, Anthropic API for chat functionality, and Supabase for PostgreSQL database management.
{
"username": "John",
"email": "[email protected]",
"password": "12345678"
}
{
"message": "User registered successfully"
}
POST /api/auth/login:User login endpoint.
{
"email": "[email protected]",
"password": "12345678"
}
{
"message": "Login successful",
"accessToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOjcsImlhdCI6MTcxODgxMTI2NCwiZXhwIjoxNzE4ODEyMTY0fQ.qcXn9CFItBftWpfeOvxa1PQ4CBEFx8LC4HYjP93c4Ew",
"refreshToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOjcsImlhdCI6MTcxODgxMTI2NiwiZXhwIjoxNzE5NDE2MDY2fQ.0c_YsDvYYgoUuXmlgoiq8Lxb7l2SNnkKmfVi9M2X_hQ"
}
POST /api/auth/refresh:Refresh access token endpoint.
refreshToken: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOjcsImlhdCI6MTcxODgxMTI2NiwiZXhwIjoxNzE5NDE2MDY2fQ.0c_YsDvYYgoUuXmlgoiq8Lxb7l2SNnkKmfVi9M2X_hQAuthorization: "accessToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOjcsImlhdCI6MTcxODgxMTQ2NiwiZXhwIjoxNzE4ODEyMzY2fQ.5z_M67PqEMsDQVEAoXntqnev-Z3pnqXFOr4SbMPzeZQ"{
"message": "Tokens refreshed successfully",
"accessToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOjcsImlhdCI6MTcxODgxMTQ2NiwiZXhwIjoxNzE4ODEyMzY2fQ.5z_M67PqEMsDQVEAoXntqnev-Z3pnqXFOr4SbMPzeZQ",
"refreshToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOjcsImlhdCI6MTcxODgxMTQ2NywiZXhwIjoxNzE5NDE2MjY3fQ.p-Nb4diIs5uSBYVkQlufVvlxGn_N72PPRR3xKRBlovo"
}
POST /api/auth/logout:User logout endpoint.
refreshToken: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOjcsImlhdCI6MTcxODgxMTI2NiwiZXhwIjoxNzE5NDE2MDY2fQ.0c_YsDvYYgoUuXmlgoiq8Lxb7l2SNnkKmfVi9M2X_hQAuthorization: "accessToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOjcsImlhdCI6MTcxODgxMTQ2NiwiZXhwIjoxNzE4ODEyMzY2fQ.5z_M67PqEMsDQVEAoXntqnev-Z3pnqXFOr4SbMPzeZQ"{
"message": "Logout successful"
}
GET /api/users/:userId:Retrieve a user profile with a given userId.
Authorization: "accessToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOjcsImlhdCI6MTcxODgxMTQ2NiwiZXhwIjoxNzE4ODEyMzY2fQ.5z_M67PqEMsDQVEAoXntqnev-Z3pnqXFOr4SbMPzeZQ"{
"username": "Shivkumar",
"email": "[email protected]"
}
GET /api/users/:userId/questions:Retrieve all questions asked by a user with a given userId
Authorization: "accessToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOjcsImlhdCI6MTcxODgxMTQ2NiwiZXhwIjoxNzE4ODEyMzY2fQ.5z_M67PqEMsDQVEAoXntqnev-Z3pnqXFOr4SbMPzeZQ"[
{
"id": 1,
"userId": 1,
"question": "Who is your developer?",
"answer": "My developer is Shivkumar Raghuwanshi.",
"createdAt": "2024-06-18T21:00:26.582Z",
"updatedAt": "2024-06-18T21:00:26.582Z"
}
]
POST /api/questions:Accept a user question and return an AI-generated answer
{
"question": "Who is your developer?",
"userId": 1
}
Authorization: "accessToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOjcsImlhdCI6MTcxODgxMTQ2NiwiZXhwIjoxNzE4ODEyMzY2fQ.5z_M67PqEMsDQVEAoXntqnev-Z3pnqXFOr4SbMPzeZQ"[
{
"id": 1,
"userId": 1,
"question": "Who is your developer?",
"answer": "My developer is Shivkumar Raghuwanshi.",
"createdAt": "2024-06-18T21:00:26.582Z",
"updatedAt": "2024-06-18T21:00:26.582Z"
}
]
GET /api/questions/:questionId:Retrieve a specific question and its answer by question ID.
Authorization: "accessToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOjcsImlhdCI6MTcxODgxMTQ2NiwiZXhwIjoxNzE4ODEyMzY2fQ.5z_M67PqEMsDQVEAoXntqnev-Z3pnqXFOr4SbMPzeZQ"{
"id": 1,
"userId": 1,
"question": "Who is your developer?",
"answer": "My developer is Shivkumar Raghuwanshi.",
"createdAt": "2024-06-18T21:00:26.582Z",
"updatedAt": "2024-06-18T21:00:26.582Z"
}
The application uses a relational database schema to store questions, user data, and authentication tokens. The schema is designed to ensure scalability and support for hundreds of thousands of concurrent users.
The database schema includes the following tables:
The use of a relational database with ACID guarantees ensures data integrity and consistency, even in high-concurrency scenarios. Prisma ORM provides type-safe access to the database and simplifies database operations.
The schema defines the following relationships:
This database design allows for efficient querying of user data, questions, and authentication tokens while maintaining data integrity and scalability.
The application is containerized using Docker for easy deployment and scalability. A Dockerfile is provided in the project root, containing instructions for building the Docker image.
If you want to run the project using Docker, you can pull the Docker image from Docker Hub and run it:
The detailed pictorial view of the scalable architecture for Docker containerization on AWS with ECR, ECS (Fargate), ELB, Redis, ElastiCache and PostgreSQL, along with the pipeline flow indicated by numbered steps:
If you want to run the project using Docker, follow these steps:
Content type
Image
Digest
sha256:e21a1a0fb…
Size
551 MB
Last updated
over 2 years ago
docker pull shivkumar56/answerai