Skip to content

Latest commit

Β 

History

47 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🚭 Quit-It

An AI-powered addiction recovery companion

Track your sobriety streak, understand your relapse patterns, connect with a supportive community, and get real-time support from an AI coach β€” all in one private, judgment-free space.

Live Demo Backend License

Quit-It Dashboard Preview


✨ Features

  • Community Chat β€” Join addiction-specific communities and chat with others on the same journey in real-time via WebSocket
  • Milestone Celebrations β€” Receive automated congratulations when you hit 7, 30, 90, 180, or 365 days of sobriety
  • Content Moderation β€” Automated tiered moderation flags harmful content (self-harm, hate speech, drug references) and allows user flagging
  • Streak Tracking β€” Visualize your sobriety streak in real time with gamified milestones
  • Daily Check-ins β€” Log your mood every day and monitor emotional patterns over time
  • Relapse Logging β€” Record relapses with context (trigger, mood, intensity) for self-awareness
  • AI Coach β€” Chat with a Gemini-powered coach for real-time personalized support (with HuggingFace fallback)
  • Urge Intervention β€” Hit the urge button mid-craving and get instant AI-guided coping strategies
  • Pattern Insights β€” AI analyzes your relapse history and surfaces actionable behavioral insights
  • Mood Chart β€” Visualize your emotional journey over time with an interactive Recharts graph
  • Multi-addiction support β€” Track multiple habits simultaneously (smoking, alcohol, social media, gambling, and more)
  • Auto-join Communities β€” Automatically joined to the relevant support community when you create an active addiction

πŸ›  Tech Stack

Frontend

Technology Purpose
Next.js 16 (App Router) React framework with server-side rendering
TypeScript Type safety throughout
Tailwind CSS v4 Utility-first styling
Framer Motion Animations and page transitions
Recharts Mood trend charts
Axios HTTP client with interceptors
React Hot Toast Notifications
socket.io-client Real-time community chat
js-cookie Client-side cookie management
lucide-react Icon library
clsx + tailwind-merge Conditional class utilities

Backend

Technology Purpose
Node.js + Express REST API server
TypeScript Type safety throughout
Prisma ORM Database access and migrations
PostgreSQL Primary database
Upstash Redis Caching and rate limiting
IORedis Redis client for BullMQ job queues
BullMQ Background job queues (moderation, milestones, notifications)
Socket.io WebSocket server for real-time community messaging
Google Gemini Primary AI model (via LangChain)
HuggingFace AI fallback model
LangChain AI orchestration layer
JWT + Cookies Authentication
Helmet + CORS Security headers

Infrastructure

Service Purpose
Vercel Frontend hosting
Render Backend hosting
Upstash Managed Redis (caching & rate limiting)
Redis (self-hosted / Docker) BullMQ job queue backend
PostgreSQL Managed database (Render / Neon / Supabase)
Docker Containerized backend with Redis

πŸ—‚ Project Structure

quit-it/
β”œβ”€β”€ frontend/                        # Next.js app
β”‚   β”œβ”€β”€ app/
β”‚   β”‚   β”œβ”€β”€ (auth)/                  # Sign-in, Sign-up pages
β”‚   β”‚   └── (dashboard)/             # Protected app pages
β”‚   β”‚       β”œβ”€β”€ page.tsx             # Dashboard home
β”‚   β”‚       β”œβ”€β”€ checkin/             # Daily check-in
β”‚   β”‚       β”œβ”€β”€ coach/               # AI coach chat
β”‚   β”‚       β”œβ”€β”€ community/           # Community chat page
β”‚   β”‚       β”œβ”€β”€ insights/            # AI pattern analysis
β”‚   β”‚       β”œβ”€β”€ settings/            # User settings
β”‚   β”‚       └── onboarding/          # First-time setup
β”‚   β”œβ”€β”€ components/
β”‚   β”‚   β”œβ”€β”€ coach/                   # ChatWindow, MessageBubble
β”‚   β”‚   β”œβ”€β”€ community/               # CommunityHeader, MessageBubble, FlagMenu, MessageInput, MilestoneToast
β”‚   β”‚   β”œβ”€β”€ dashboard/               # StreakCard, MoodChart, UrgeButton
β”‚   β”‚   └── ui/                      # Button, Card, Modal
β”‚   β”œβ”€β”€ context/                     # AuthContext
β”‚   β”œβ”€β”€ hooks/                       # useCoach, useCheckin, useStreak, useCommunity, useSocket
β”‚   β”œβ”€β”€ services/                    # API service layer
β”‚   β”œβ”€β”€ lib/                         # Axios instance, utils, request wrapper
β”‚   β”œβ”€β”€ types/                       # TypeScript types
β”‚   └── middleware.ts                # Route protection
β”‚
└── backend/                         # Express API
    β”œβ”€β”€ src/
    β”‚   β”œβ”€β”€ modules/                 # Feature modules
    β”‚   β”‚   β”œβ”€β”€ auth/                # Register, login, logout
    β”‚   β”‚   β”œβ”€β”€ user/                # Profile
    β”‚   β”‚   β”œβ”€β”€ addiction/           # Addiction CRUD
    β”‚   β”‚   β”œβ”€β”€ checkin/             # Daily check-ins
    β”‚   β”‚   β”œβ”€β”€ relapse/             # Relapse logging
    β”‚   β”‚   β”œβ”€β”€ ai/                  # Coach, urge, insights
    β”‚   β”‚   └── community/           # Community list, join/leave, messages
    β”‚   β”œβ”€β”€ queues/                  # BullMQ queue definitions (notification, milestone, moderation)
    β”‚   β”œβ”€β”€ workers/                 # BullMQ workers (milestone broadcasts, moderation scanning)
    β”‚   β”œβ”€β”€ events/                  # Event emitter for community lifecycle events
    β”‚   β”œβ”€β”€ config/                  # DB, Redis, BullMQ Redis, Socket.io, env, constants
    β”‚   β”œβ”€β”€ middlewares/             # Auth, validate, rate limit
    β”‚   β”œβ”€β”€ services/                # Streak, AI service, Gemini, HuggingFace, cache
    β”‚   └── utils/                   # Errors, response helper, prompt builder, asyncHandler, seed
    └── prisma/
        └── schema.prisma            # Database schema (incl. Community, CommunityMessage, CommunityMember, ModerationFlag)

πŸš€ Getting Started

Prerequisites

  • Node.js 18+
  • PostgreSQL database
  • Upstash Redis account (caching + rate limiting)
  • Redis instance for BullMQ (or use Docker Compose)
  • Google Gemini API key
  • HuggingFace API key (fallback)

1. Clone the repository

git clone https://github.com/Puspak29/quit-it.git
cd quit-it

2. Set up the backend

cd backend
npm install

Create a .env file:

PORT=8080
NODE_ENV=development
DATABASE_URL=<YOUR_POSTGRES_CONNECTION_STRING>
FRONTEND_URL=http://localhost:3000

# JWT
JWT_SECRET=your-super-secret-jwt-key
JWT_EXPIRES_IN=7d

# Redis (Upstash β€” caching & rate limiting)
UPSTASH_REDIS_REST_URL=<YOUR_UPSTASH_URL>
UPSTASH_REDIS_REST_TOKEN=<YOUR_UPSTASH_TOKEN>

# Redis (direct β€” BullMQ job queues)
REDIS_QUEUE_URL=redis://localhost:6379

# AI β€” Primary
GEMINI_API_KEY=<YOUR_GEMINI_API_KEY>

# AI β€” Fallback
HF_API_KEY=<YOUR_HUGGINGFACE_API_KEY>

# Firebase Cloud Messaging (optional β€” for push notifications)
FIREBASE_PROJECT_ID=<YOUR_FIREBASE_PROJECT_ID>
FIREBASE_CLIENT_EMAIL=<YOUR_FIREBASE_CLIENT_EMAIL>
FIREBASE_PRIVATE_KEY=<YOUR_FIREBASE_PRIVATE_KEY>

Option A: Local Redis

Install and run Redis locally on port 6379, or use Docker Compose:

docker compose up -d redis

Option B: Full Docker Compose

docker compose up --build

This starts both the backend (port 8080) and a Redis instance for BullMQ.

Then run database migrations and seed communities:

npm run db:generate
npm run db:migrate
npm run db:seed
npm run dev

3. Set up the frontend

cd frontend
npm install

Create a .env.local file:

NEXT_PUBLIC_API_URL=http://localhost:8080

Start the development server:

npm run dev

Open http://localhost:3000 in your browser.


🌐 Deployment

Backend β†’ Render

  1. Create a new Web Service on Render
  2. Connect your GitHub repo, set root directory to backend
  3. Set build command: npm install && npm run build && npm run db:generate
  4. Set start command: npm start
  5. Add all environment variables from .env (use a managed Redis provider for BullMQ, e.g., Redis Cloud)

Frontend β†’ Vercel

  1. Import your GitHub repo on Vercel
  2. Set root directory to frontend
  3. Add environment variable:
    NEXT_PUBLIC_API_URL=https://your-backend.onrender.com
    
  4. Deploy

Note: The frontend proxies all /api/* requests to the backend via the NEXT_PUBLIC_API_URL env var. Authentication uses a bearer token stored in a cookie (frontend-token), and Next.js middleware redirects unauthenticated users to /sign-in.


🏘 Community System

The community feature provides real-time, addiction-specific support groups:

How it works

  • Pre-seeded Communities β€” One community per addiction type is created at startup via npm run db:seed
  • Auto-join β€” When you create an active addiction, you're automatically added to the corresponding community
  • Real-time Chat β€” Messages are sent and received via WebSocket (Socket.io) β€” no page refresh needed
  • Live Indicators β€” Shows connection status and live member count

Moderation

  • Automated Scanning β€” Every message passes through a BullMQ worker that checks against tiered keyword lists
    • SELF_HARM β†’ message hidden immediately
    • HATE_SPEECH / AUTO_KEYWORD β†’ message flagged for review
  • User Flagging β€” Members can flag messages as spam, hate speech, or self-harm
  • Flagged messages are hidden from other users but still visible to the sender

Milestones

When a user posts a message and their streak matches a milestone (7, 30, 90, 180, or 365 days), a BullMQ job broadcasts a congratulatory toast to the entire community in real-time.


πŸ”Œ API Endpoints

Auth

Method Endpoint Description
POST /api/auth/register Create account
POST /api/auth/login Sign in
POST /api/auth/logout Sign out

User

Method Endpoint Description
GET /api/user/me Get current user
PATCH /api/user/profile Update profile

Addiction

Method Endpoint Description
POST /api/addiction Create addiction
GET /api/addiction List addictions
PATCH /api/addiction/:id Update addiction

Check-ins

Method Endpoint Description
POST /api/checkin Submit daily check-in
GET /api/checkin Get check-in history

Relapses

Method Endpoint Description
POST /api/relapse Log a relapse
GET /api/relapse Get relapse history

AI

Method Endpoint Description
POST /api/ai/chat Send message to AI coach
GET /api/ai/history Get chat history
POST /api/ai/urge Trigger urge intervention
GET /api/ai/insight Get AI pattern insight

Community

Method Endpoint Description
GET /api/communities List all communities (with membership status)
GET /api/communities/:id Get community details
POST /api/communities/:id/join Join a community
DELETE /api/communities/:id/leave Leave a community
GET /api/communities/:id/messages Paginated message history (cursor-based)

WebSocket Events

Event Direction Description
community:join Client β†’ Server Join a community room
community:send Client β†’ Server Send a chat message
community:flag Client β†’ Server Report a message
community:message Server β†’ Client New message broadcast
community:milestone Server β†’ Client Milestone achievement broadcast
community:message:hidden Server β†’ Client Message removed by moderation

πŸ”’ Security

  • Passwords hashed with bcrypt (10 rounds)
  • Auth via bearer token stored in httpOnly cookie β€” not accessible via JavaScript
  • All routes protected by JWT middleware
  • Helmet security headers on all responses
  • CORS restricted to frontend origin
  • Rate limiting on AI and community endpoints via Redis
  • Generic error messages on login to prevent user enumeration
  • Content moderation β€” Tiered keyword filtering with automated flagging/hiding
  • Community message length capped at 1000 characters

πŸ“„ License

ISC Β© Puspak29


Built with ❀️ to help people reclaim their lives

About

An AI-powered addiction recovery companion that tracks streaks, logs relapses, and provides personalized AI coaching support.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages