A backend service for chat session logging with automated Natural Language Processing (NLP) tagging using the Google Gemini API.
The API is deployed and accessible at: https://ventlog.onrender.com.
- Authentication: Secure user registration, login, and logout using Bcrypt and JWT stored in
httpOnlycookies. - Session Management: Users can create chat sessions, append messages with timestamps, and close sessions.
- AI-Powered NLP Tagging: Closing a session automatically triggers the Gemini API to analyze the conversation and generate a sentiment (positive/neutral/negative), mood score (1-10), and topic tags.
- Analytics: Protected endpoints provide insights into mood trends over time and the frequency of extracted tags.
- Background Jobs: A scheduled cron job runs automatically every Sunday at midnight to generate a weekly summary (average mood score and top 5 dominant tags) for each user.
- Validation: Strict request body validation using Zod.
- Runtime: Node.js
- Framework: Express.js
- Database: MongoDB (with Mongoose)
- Authentication: JSON Web Tokens (JWT), cookie-parser, bcryptjs
- AI Integration:
@google/generative-ai(Gemini 2.5 Flash) - Validation: Zod
- Scheduling: node-cron
- Node.js (v18+ recommended)
- MongoDB instance (Local or Atlas)
- Google Gemini API Key
- Clone the repository:
git clone https://github.com/utkarrshgit/ventlog.git cd ventlog - Install dependencies:
npm install
- Configure environment variables:
Create a
.envfile in the root directory and add the following:PORT=5000 MONGO_URI=your_mongodb_connection_string JWT_SECRET=your_jwt_secret GEMINI_API_KEY=your_google_gemini_api_key
- Start the server:
The server will start on
npm run dev
http://localhost:5001.
Base URL: http://localhost:5001/api
Base URL (Production): https://ventlog.onrender.com/api
| Method | Endpoint | Description | Body |
|---|---|---|---|
| POST | /register |
Register a new user | { "username": "...", "email": "...", "password": "..." } |
| POST | /login |
Authenticate and set JWT cookie | { "email": "...", "password": "..." } |
| POST | /logout |
Clear the JWT cookie | None |
All session routes require a valid JWT cookie.
| Method | Endpoint | Description | Body |
|---|---|---|---|
| POST | / |
Create a new chat session | None |
| POST | /:sessionId/messages |
Append a message to an open session | { "text": "..." } |
| PATCH | /:sessionId/close |
Close session and trigger Gemini API tagging | None |
| GET | / |
Get all sessions for the authenticated user | None |
| GET | /:sessionId |
Get a specific session by ID | None |
All analytics routes require a valid JWT cookie.
| Method | Endpoint | Description |
|---|---|---|
| GET | /mood-trend |
Get historical mood scores over time from closed sessions |
| GET | /tags |
Get a frequency count of all assigned tags |
| GET | /summary |
Get historical weekly summaries generated by the cron job |
The application includes a background job located in src/jobs/weeklySummary.js.
- Schedule: Runs every Sunday at 00:00 (Midnight) server time (
0 0 * * 0). - Function: Scans all closed sessions from the past 7 days for each user, calculates the average mood score, extracts the top 5 most frequent tags, and saves a
WeeklySummarydocument to the database. Note: When deployed on the Render free tier, the server spins down after 15 minutes of inactivity. The Sunday midnight cron job will only execute if the server is awake.
ventlog/
├── src/
│ ├── config/
│ │ └── db.js # MongoDB connection
│ ├── controllers/
│ │ ├── analyticsController.js
│ │ ├── authController.js
│ │ └── sessionController.js
│ ├── jobs/
│ │ └── weeklySummary.js # Node-cron jobs
│ ├── middleware/
│ │ ├── authMiddleware.js # JWT verification
│ │ └── validateMiddleware.js # Zod validation wrapper
│ ├── models/
│ │ ├── Session.js
│ │ ├── User.js
│ │ └── WeeklySummary.js
│ ├── routes/
│ │ ├── analyticsRoutes.js
│ │ ├── authRoutes.js
│ │ └── sessionRoutes.js
│ ├── utils/
│ │ ├── gemini.js # Gemini API integration
│ │ └── generateToken.js # JWT generation
│ ├── validators/
│ │ └── authValidator.js # Zod schemas
│ └── app.js # Express app setup
├── .env # Environment variables
├── package.json
└── server.js # Entry point