Skip to content

utkarrshgit/ventlog

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Ventlog

A backend service for chat session logging with automated Natural Language Processing (NLP) tagging using the Google Gemini API.

Live URL

The API is deployed and accessible at: https://ventlog.onrender.com.

Features

  • Authentication: Secure user registration, login, and logout using Bcrypt and JWT stored in httpOnly cookies.
  • 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.

Tech Stack

  • 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

Prerequisites

  • Node.js (v18+ recommended)
  • MongoDB instance (Local or Atlas)
  • Google Gemini API Key

Installation & Setup

  1. Clone the repository:
    git clone https://github.com/utkarrshgit/ventlog.git
    cd ventlog
  2. Install dependencies:
    npm install
  3. Configure environment variables: Create a .env file 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
  4. Start the server:
    npm run dev
    The server will start on http://localhost:5001.

API Documentation

Base URL: http://localhost:5001/api
Base URL (Production): https://ventlog.onrender.com/api

Authentication (/auth)

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

Sessions (/sessions)

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

Analytics (/analytics)

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

Background Jobs

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 WeeklySummary document 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.

Project Structure

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

About

A Node.js backend service for logging chat sessions with automated AI-powered NLP tagging (sentiment, mood, and topics) using the Google Gemini API.

Topics

Resources

Stars

Watchers

Forks

Contributors