You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Star0 (0)You must be signed in to star a repository
About
A RESTful API backend for a community-driven platform where users share life challenges, get AI-powered insights, and connect with others. Built with Express 5, TypeScript, and MongoDB (Mongoose).
The RESTful API powering LifeSolve AI's community platform.
LifeSolve AI is a community-driven platform where people share life challenges, receive instant
AI-powered guidance, and connect with others who genuinely understand. This repository contains the
Express + TypeScript backend that handles all server-side logic.
📖 Description
The LifeSolve AI Backend provides every server-side feature of the platform — problem management,
comments, reactions, direct messaging, notifications, authentication, analytics, and streaming AI
responses powered by Groq. It exposes a clean REST API consumed by the
LifeSolve AI Frontend.
🎯 Overview
The backend is organized around domain modules and provides:
Area
What it does
📝 Problems
CRUD, search, filter, sort, pagination for community posts
💬 Comments & Reactions
Full comment CRUD + like/love/sad reaction toggles
🤖 AI Integration
Streaming AI responses in three modes (solver, chat, quick-chat)
⚡ AI Quick Chat
Ephemeral endpoint — answers are never saved to the database
✉️ Messaging
Real-time private conversations between users
🔔 Notifications
Event-driven notifications for comments, reactions, messages
🔐 Authentication
Bearer token session validation via Better Auth
📊 Statistics
Platform-wide and per-user analytics with daily breakdowns
🎯 Purpose
The backend exists to give LifeSolve AI a secure, scalable, and real-time foundation:
Serve AI responses with streaming (SSE) for a smooth chat experience.
Offer an ephemeral quick-chat mode for the floating widget so anyone can ask the AI anything
without any data being persisted.
Persist user content — problems, comments, conversations, notifications — in MongoDB.
Protect user data with session-based authentication on every mutating route.
✨ Key Features
Feature
Description
Problem CRUD
Full create, read, update, delete with search, filter, pagination
Comment System
Create, edit, delete comments on problems
Reactions
Like, Love, Sad toggle with per-user tracking
AI Solver
Streaming AI responses for structured problem-solving (saved sessions)
AI Chat
Streaming conversational AI for general support (saved sessions)
AI Quick Chat
Streaming AI for the floating widget — no DB writes, no auth required
Direct Messages
Private conversations with user discovery
Notifications
5 event types: problem posted, resolved, comment, reaction, message
User Stats
Per-user post/comment counts with 7-day activity
Platform Stats
Global counts for posts, comments, messages, AI chats, users
Auth Middleware
Session-based authentication via Better Auth tokens
POST /api/ai/quick-chat accepts { messages: [{ role, content }] } and streams an answer back.
It requires no authentication and performs no database writes — the conversation history is sent
by the client and kept only in memory for the duration of the request.
Problems — /api/problems
Method
Path
Auth
Description
GET
/api/problems
—
List problems (search, category, sort, page, limit)
The quick-chat mode intentionally uses no model — it never touches the database.
💻 Installation
Prerequisites
Node.js 18+
npm or yarn
MongoDB instance (local or Atlas)
Groq API key (for AI features)
Setup
# Clone the repository
git clone <repository-url>cd backend
# Install dependencies
npm install
# Create environment file
cp .env.example .env
# Edit .env with your configuration# Required variables:# MONGODB_URI# GROQ_API_KEY (for AI features)# Optional:# PORT# CORS_ORIGIN# Start development server with hot reload
npm run dev
The server will start at http://localhost:5000.
Available Scripts
Script
Command
Description
npm run dev
tsx watch src/index.ts
Development with hot reload
npm run build
tsc
Compile TypeScript to dist/
npm start
node dist/index.js
Run compiled production build
Environment Variables
Variable
Required
Default
Description
PORT
No
5000
Server port
MONGODB_URI
Yes
—
MongoDB connection string
CORS_ORIGIN
No
http://localhost:3000
Allowed CORS origin
GROQ_API_KEY
Yes (for AI)
—
Groq API key for AI features
🔐 Authentication Flow
The frontend handles user registration/login via Better Auth (handled by Next.js API routes)
Better Auth stores sessions in the session MongoDB collection
All protected API routes require an Authorization: Bearer <token> header
The authenticate middleware validates the token, checks expiry, and attaches req.user
User IDs are used throughout the system for ownership and notification routing
The /api/ai/quick-chat endpoint is intentionally public so the floating chat widget works for
both visitors and logged-in users — it performs no DB writes and stores nothing.
🔔 Notification Triggers
Notifications are automatically created by controllers when these events occur:
Event
Triggered By
Receiver
Problem created
createProblem
Post author
Problem resolved
updateProblem (status → resolved)
Post author
New comment
createComment
Problem owner (if not self)
New reaction
toggleReaction
Problem owner (if not self)
New message
sendMessage
Message recipient
🩺 Health Check
GET /api/health
Response: { "status": "ok", "timestamp": "2024-01-01T00:00:00.000Z" }
🤝 Contributing
Fork the repository
Create a feature branch (git checkout -b feature/amazing-feature)
Commit your changes (git commit -m 'Add amazing feature')
Push to the branch (git push origin feature/amazing-feature)
Open a Pull Request
📄 License
This project is private and not licensed for public distribution.
About
A RESTful API backend for a community-driven platform where users share life challenges, get AI-powered insights, and connect with others. Built with Express 5, TypeScript, and MongoDB (Mongoose).