Skip to content

App that asks questions to you at the end of your long day. "How have you been." Track your emotional journey.

Notifications You must be signed in to change notification settings

Modas101/Supportily

Repository files navigation

AI Therapist Webapp - Supportive Listener

An empathetic mental health AI chatbot built with Next.js, providing emotional support through reflective dialogue and long-term conversation continuity.

Features

πŸ€— Empathetic Support

  • Acts as a compassionate listener for venting and emotional support
  • Uses reflective dialogue and active listening techniques
  • Provides a non-judgmental space for self-expression

🧠 Smart Memory Management

  • Automatic conversation summarization to prevent context overflow
  • Maintains long-term continuity across sessions
  • Stores summaries of older conversations while keeping recent messages in full context
  • Prevents token limits from interrupting meaningful conversations
  • Persistent conversations using localStorage - your conversation continues even after closing the browser

🚨 Crisis-Safe Design

  • Detects concerning language patterns (self-harm, suicidal ideation)
  • Responds with care and validation, never directive or alarming
  • Gently suggests professional resources when appropriate
  • Displays crisis hotline information when needed

βš•οΈ Non-Clinical Approach

  • Never presents as a therapist or medical professional
  • Clearly communicates its role as supportive listener only
  • Encourages professional help for serious mental health concerns

🎨 Modern UI

  • Built with Next.js 15, React 18, and TypeScript
  • Styled with Tailwind CSS and shadcn/ui components
  • Responsive design that works on all devices
  • Clean, calming interface

Technology Stack

  • Framework: Next.js 15 (App Router)
  • Language: TypeScript
  • Styling: Tailwind CSS
  • UI Components: shadcn/ui
  • AI Provider: DeepSeek API (OpenAI-compatible)
  • Icons: Lucide React

Getting Started

Prerequisites

Installation

  1. Clone the repository or navigate to the project directory:
cd "AI therapist webapp"
  1. Install dependencies:
npm install
  1. Create a .env file in the root directory:
cp .env.example .env
  1. Add your DeepSeek API key to .env:
DEEPSEEK_API_KEY=your_api_key_here
DEEPSEEK_API_BASE=https://api.deepseek.com/v1
  1. Run the development server:
npm run dev
  1. Open http://localhost:3000 in your browser.

How It Works

Memory Management

The app uses a sophisticated memory system to maintain conversation continuity without hitting context limits:

  1. Recent Messages: Keeps the last 4-10 messages in full context
  2. Automatic Summarization: When message count exceeds threshold, older messages are summarized
  3. Summary Storage: Stores up to 3 conversation summaries for long-term context
  4. Seamless Continuity: AI can reference earlier conversations through summaries

Crisis Detection

The system monitors for concerning language patterns:

  • Keyword detection for self-harm, suicidal ideation, etc.
  • Severity assessment (low, moderate, high)
  • Adaptive response that's caring but not alarmist
  • Automatic display of crisis resources

System Prompt

The AI is guided by a comprehensive system prompt that ensures:

  • Warm, empathetic, non-judgmental responses
  • Reflective listening and validation
  • Open-ended questions to encourage exploration
  • Clear boundaries (not a therapist)
  • Appropriate crisis response protocols

Project Structure

β”œβ”€β”€ app/
β”‚   β”œβ”€β”€ api/
β”‚   β”‚   └── chat/
β”‚   β”‚       └── route.ts          # Chat API endpoint
β”‚   β”œβ”€β”€ globals.css                # Global styles
β”‚   β”œβ”€β”€ layout.tsx                 # Root layout
β”‚   └── page.tsx                   # Home page
β”œβ”€β”€ components/
β”‚   β”œβ”€β”€ ui/                        # shadcn/ui components
β”‚   └── chat-interface.tsx         # Main chat interface
β”œβ”€β”€ lib/
β”‚   β”œβ”€β”€ deepseek.ts               # DeepSeek API client
β”‚   β”œβ”€β”€ memory.ts                 # Memory management system
β”‚   └── utils.ts                  # Utility functions
β”œβ”€β”€ package.json
β”œβ”€β”€ tailwind.config.ts
β”œβ”€β”€ tsconfig.json
└── README.md

API Routes

POST /api/chat

Send a message and receive a response.

Request:

{
  "message": "I'm feeling really overwhelmed today",
  "sessionId": "session-123"
}

Response:

{
  "message": "I hear you - feeling overwhelmed can be really difficult...",
  "sessionId": "session-123",
  "crisisDetected": false,
  "crisisSeverity": "none"
}

DELETE /api/chat?sessionId=session-123

Clear the conversation history for a session.

Configuration

Environment Variables

Memory Settings

Adjust in lib/memory.ts:

  • MAX_RECENT_MESSAGES: Number of recent messages to keep (default: 10)
  • SUMMARIZE_THRESHOLD: Trigger summarization after this many messages (default: 8)

Crisis Detection

Customize crisis keywords in lib/deepseek.ts:

  • Add or remove keywords in the crisisKeywords array
  • Adjust severity thresholds

Important Notes

Limitations

  • Not a substitute for professional help: This is a supportive tool, not therapy
  • No emergency response: Cannot call emergency services or intervene in crises
  • Privacy: Conversations are stored locally in browser localStorage and in server memory during the session
  • AI limitations: May occasionally provide imperfect responses
  • Browser storage: Clearing browser data will erase conversation history

Ethical Considerations

This app is designed with care for vulnerable users:

  • Never claims to be a medical professional
  • Encourages seeking professional help when appropriate
  • Provides crisis resources proactively
  • Uses non-directive, supportive language
  • Respects user autonomy and feelings

Production Deployment

For production use, consider:

  • Implementing persistent session storage (Redis, database)
  • Adding user authentication
  • Implementing rate limiting
  • Adding conversation encryption
  • Monitoring for abuse or misuse
  • Legal review and compliance (HIPAA, etc.)
  • Professional consultation for mental health use cases

Crisis Resources

If you or someone you know is in crisis:

License

This project is provided as-is for educational and supportive purposes.

Disclaimer

This application is not a substitute for professional mental health care. If you are experiencing a mental health crisis or emergency, please contact emergency services or a crisis hotline immediately.

The AI responses are generated by machine learning and may not always be appropriate or accurate. Users should exercise judgment and seek professional help for serious mental health concerns.

About

App that asks questions to you at the end of your long day. "How have you been." Track your emotional journey.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages