Jiso is a comprehensive mental health platform that leverages AI technology to provide personalized support through mood tracking, journaling, therapy chat, and data-driven insights. This repository contains the backend API that powers the Jiso application.
Jiso's backend is built on a modern MERN stack architecture (MongoDB, Express, React, Node.js) with integrated AI capabilities. The system leverages natural language processing to analyze user inputs and provide therapeutic responses, personal insights, and actionable suggestions.
Key features include:
- Conversational AI therapy with a CBT-based approach
- Mood and emotion tracking
- Journaling with AI-generated summaries
- Personal goals and struggles management
- Weekly and monthly AI-generated insights
- Comprehensive analytics dashboard
Jiso uses Qwen 2.5 7B, an open-source LLM from Alibaba Cloud, to power its AI capabilities. The system employs several AI components:
- Therapeutic Chat: A conversational AI that implements cognitive behavioral therapy techniques
- Journal Analysis: Automatic summarization of journal entries at multiple levels of detail
- Theme Extraction: Identification of recurring patterns in user mood, journaling, and conversations
- Insight Generation: Weekly and monthly analysis of user data to provide personalized insights
- Suggestion Creation: AI-generated practical recommendations based on user goals and struggles
For local development or deployments without external AI services, we recommend using Ollama to run the Qwen 2.5 7B model locally:
- Install Ollama from ollama.ai
- Pull or Run the Qwen 2.5 7B model:
ollama run qwen2.5
- Configure your
.envfile to use Ollama's API:AI_SERVICE_ENDPOINT=http://localhost:11434/v1 AI_SERVICE_APIKEY=ollama AI_MODEL_NAME=qwen2:7b
Ollama provides an OpenAI-compatible API that works seamlessly with our integration, allowing for easy local development without relying on external services.
├── ai/ # AI integration components
│ ├── chat.ai.js # Therapeutic chat implementation
│ ├── context.ai.js # Context analysis for themes
│ ├── insight.ai.js # Insights and suggestions generation
│ ├── journal.ai.js # Journal summarization
│ └── builders/ # Context building utilities
├── controllers/ # API route controllers
├── middlewares/ # Express middlewares
├── models/ # Mongoose data models
├── routes/ # API route definitions
├── utils/ # Utility functions
├── mailersend/ # Email functionality
├── server.js # Main application entry point
└── data-dictionary.md # Detailed data model documentation
The application uses several interconnected MongoDB models:
- User: Authentication and profile information
- UserContext: Personalized user context including goals, struggles, and themes
- Journal: User journal entries with AI-generated summaries
- Mood: Emotional state tracking
- Chat: Conversations with the AI therapist
- Insight: AI-generated insights and suggestions
Detailed schema information is available in the data-dictionary.md file.
- Node.js (v16+)
- MongoDB
- Ollama (for local AI model serving) or alternative AI service endpoint
- Clone the repository
git clone https://github.com/yourusername/jiso-backend.git
cd jiso-backend- Install dependencies
npm install- Create a
.envfile with the following variables:
PORT=8888 # Port the server will run on
NODE_ENV=development # Environment (development, production)
MONGO_URI=your_mongodb_connection_string # MongoDB connection URL
JWT_SECRET=your_jwt_secret # Secret for JWT tokens
JWT_REFRESH_SECRET=your_refresh_secret # Secret for JWT refresh tokens
CLIENT_URL=http://localhost:5173 # URL to your frontend application
AI_SERVICE_ENDPOINT=http://localhost:11434/v1 # Endpoint for LLM API (Ollama default)
AI_SERVICE_APIKEY=ollama # API key for AI service
AI_MODEL_NAME=qwen2:7b # Model name to use
MAILERSEND_API_KEY=your_mailersend_api_key # API key for MailerSend
EMAIL_DOMAIN_NAME=your_email_domain # Email domain for sending emails
CRON_API_KEY=test # A strong password with minimum 10-15 characters
- Start the development server
npm run devThe API is organized into the following routes:
- Auth:
/api/v1/auth- User authentication and profile management - User Context:
/api/v1/context- User goals, struggles, and theme management - Journals:
/api/v1/journals- Journal entry CRUD operations - Moods:
/api/v1/moods- Mood entry CRUD operations - Insights:
/api/v1/insights- Access to AI-generated insights - Chats:
/api/v1/chats- Conversation management with the AI therapist - Dashboard:
/api/v1/dashboard- Analytics and data visualization endpoints - Cron:
/api/v1/cron- Scheduled tasks for AI processing
The application includes several automated processes that run periodically:
- Weekly Context Updates: Analyzes user data to identify weekly themes
- Monthly Context Updates: Provides deeper analysis over a monthly timeframe
- Weekly Insight Generation: Creates personalized insights based on weekly themes
- Monthly Insight Generation: Produces more comprehensive monthly insights
- Journal Summarization: Automatically summarizes new journal entries
- Chat Summarization: Creates concise summaries of therapy conversations
- JWT-based authentication with refresh tokens
- Email verification for new accounts
- Password reset functionality
- API key protection for cron jobs
- MongoDB document-level access control
The backend provides extensive AI generated analytics for data visualization:
- Mood trends and emotion frequency analysis
- Journal analytics with emotion and tag tracking
- Goal completion metrics
- Chat session analysis
- Kuldeep Solanki