AyurGuru is a web-based chatbot designed to provide personalized ayurvedic remedies and health solutions. This backend is built to handle user authentication, manage conversations, upload medical reports or images and store them securely. It integrates MongoDB and PostgreSQL to ensure seamless and efficient data management.
- Node.js: Backend runtime environment.
- Express.js: Framework for building RESTful APIs.
- MongoDB: Database for managing user data and conversations.
- PostgreSQL: Database for storing file uploads.
- Multer: Middleware for handling file uploads.
- JWT: Secure user authentication.
- Google Sheets API: Storing contact form details securely.
- dotenv: Manage environment variables.
- bcryptjs: Password hashing for secure storage.
- cors: Handle cross-origin requests.
- User Authentication: Secure #/sign-in with JWT tokens.
- Conversations: Real-time personalized chatbot conversations.
- File Uploads: Upload medical reports or images (stored in PostgreSQL).
- File Retrieval: Download uploaded files by filename.
- File Deletion: Delete uploaded files and their references from databases.
- Contact Form: Submits data securely to Google Sheets.
- Personalized Chats: Manage and retrieve chat history.
Follow these steps to set up and run the backend locally:
-
Clone the Repository
git clone https://github.com/Khagesh2409/Ayurguru-backend.git cd Ayurguru-backend
-
Install Dependencies
npm install
-
PostgreSQL query to be writen while deploying Postgre db
CREATE TABLE user_files ( id SERIAL PRIMARY KEY, -- Auto-incrementing primary key user_id VARCHAR(255) NOT NULL, -- User identifier (foreign key reference, if needed) filename VARCHAR(255) NOT NULL, -- Name of the uploaded file file_data BYTEA NOT NULL, -- Binary data of the file file_type VARCHAR(50) NOT NULL, -- Type of the file (image/pdf) uploaded_at TIMESTAMP DEFAULT NOW(), -- Timestamp of file upload (defaults to current time) mongodb_id VARCHAR(255) NOT NULL -- MongoDB ID reference );
-
Environment Variables
Create a.env
file and add the following:MONGO_URI=<MONGO_URI> JWT_SECRET=<SECRET> AUTH_MESSAGE=<AUTH_MESSAGE> PG_URI2=<URL> PG_URI=<URL> SPREADSHEET_ID=<SPREADSHEET_ID> TYPE=<TYPE_OF_ACCOUNT> PROJECT_ID=<PROJECT_ID> PRIVATE_KEY_ID=<GOOGLE_PRIVATE_KEY_ID> PRIVATE_KEY=<PRIVATE_KEY_VALUE> CLIENT_ID=<CLIENT_ID> AUTH_URI=<AUTHENTICATION_URL> TOKEN_URI=<TOKEN_URI> AUTH_PROVIDER_X509_CERT_URL=<CERT_URL> CLIENT_X509_CERT_URL=<CERT_URL> UNIVERSE_DOMAIN=<URL>
-
Run the Application
node app.js
The server will start on
http://localhost:5000
.
-
POST /api/auth/#: User registration.
- Body:
{ "email": "...", "username": "...", "password": "..." }
- Body:
-
POST /api/auth/signin: User login.
- Body:
{ "email": "...", "password": "..." }
- Body:
-
POST /api/auth/is-auth: Verify user authentication.
- Body:
{ "token": "..." }
- Body:
- POST /api/conversations: Retrieve all user conversations.
- POST /api/conversations/new: Start a new conversation.
- POST /api/conversations/:conversationId: Add a new chat message to a conversation.
- GET /api/conversations/:conversationId: Retrieve chats of a specific conversation.
- DELETE /api/conversations/:conversationId: Delete a conversation.
- POST /upload: Upload a medical report or image.
- Form Data:
file
,userId
,mongodb_id
.
- Form Data:
- GET /userfiles/:userId: Get uploaded filenames by user ID.
- GET /pdf/:filename: Download a file by its name.
- DELETE /delete/:userId/:filename: Delete a file from both MongoDB and PostgreSQL.
- POST /api/contact/submit: Submit contact details to Google Sheets.
- Body:
{ "name": "...", "email": "...", "message": "..." }
- Body:
- POST /api/personalizedChats/checkPersonalizedChats: Check if personalized chats exist for a user.
- POST /api/personalizedChats/getPersonalizedChats: Retrieve personalized chats.
- POST /api/personalizedChats/addPersonalizedChat: Add a new personalized chat.
├── config/ # Configuration files
├── middleware/ # Middleware functions
├── models/ # MongoDB models
├── routes/ # API route handlers
├── uploads/ # Temporary file storage
├── app.js # Entry point
├── .env # Environment variables
- Conversations and User Data: Managed with MongoDB.
- File Storage: Uploaded files are stored in PostgreSQL for security and flexibility.
- Chat Personalization: Enables real-time responses tailored to users.
- Contact Management: Stores details in Google Sheets using API.
Feel free to contribute or raise issues. Happy coding! 🚀