Skip to content

yassinegab/chatwell

Repository files navigation

ChatWell - AI Mental Health Assistant

Symfony PHP MySQL OpenRouter Deepgram OpenAI

A camera-enabled conversational AI mental health assistant built with Symfony 6, featuring speech-to-text, AI-powered responses, and text-to-speech capabilities.

Features

  • Voice Interaction - Speak naturally with the AI coach using microphone input
  • AI-Powered Responses - Conversational AI powered by OpenRouter (Claude 3 Haiku)
  • Text-to-Speech - AI responses are spoken aloud using OpenAI TTS
  • Emotion Analysis - Real-time sentiment analysis detecting mood and stress levels
  • Crisis Detection - Automatic detection of crisis keywords with safe, supportive responses
  • Modern UI - Clean, intuitive interface with animated AI avatar
  • Secure - User authentication, CSRF protection, and rate limiting

Architecture

┌─────────────────────────────────────────────────────────────┐
│                     Browser (Frontend)                       │
│  ┌──────────┐  ┌──────────┐  ┌──────────┐  ┌──────────┐ │
│  │  WebRTC  │  │  STT     │  │  TTS     │  │  UI      │ │
│  │  Camera  │──│  (audio) │──│  (play)  │  │  Panel   │ │
│  └──────────┘  └──────────┘  └──────────┘  └──────────┘ │
└─────────────────────────────────────────────────────────────┘
                           │ AJAX/Fetch
                           ▼
┌─────────────────────────────────────────────────────────────┐
│                    Symfony 6 Backend                         │
│  ┌──────────┐  ┌──────────┐  ┌──────────┐  ┌──────────┐   │
│  │ Security │  │  AI      │  │  STT     │  │  TTS     │   │
│  │ (Firewall│──│ Service  │──│ Service  │──│ Service  │   │
│  │ RateLim) │  │(OpenRoute)│ │(Deepgram)│ │(OpenAI)  │   │
│  └──────────┘  └──────────┘  └──────────┘  └──────────┘   │
│                            │                                 │
│                            ▼                                 │
│  ┌─────────────────────────────────────────────────────┐    │
│  │              Doctrine ORM (MySQL)                    │    │
│  │  UserSession │ Conversation │ Message │ EmotionAnalysis│
│  └─────────────────────────────────────────────────────┘    │
└─────────────────────────────────────────────────────────────┘

Tech Stack

Component Technology
Backend Symfony 6.4 (PHP 8.1+)
Frontend Twig + Vanilla JavaScript
Database MySQL 8.0
ORM Doctrine
AI (LLM) OpenRouter (Claude 3 Haiku)
Speech-to-Text Deepgram
Text-to-Speech OpenAI TTS
Security Symfony Security

Getting Started

Prerequisites

  • PHP 8.1 or higher
  • MySQL 8.0 or higher
  • Composer
  • Web browser with camera/microphone support

Installation

  1. Clone the repository

    git clone https://github.com/yourusername/chatwell.git
    cd chatwell
  2. Install dependencies

    composer install
  3. Configure environment

    Edit .env file:

    DATABASE_URL="mysql://user:password@127.0.0.1:3306/chatwell?serverVersion=8.0.32&charset=utf8mb4"
  4. Create database

    php bin/console doctrine:database:create
    php bin/console doctrine:schema:create
  5. Create a user

    php bin/console app:create-user your@email.com your_password
  6. Start the server

    php -S localhost:8000 -t public
  7. Access the application

    Open http://localhost:8000 and login with your credentials.

API Keys Configuration

The application uses the following AI services. Update the service files to use your own keys:

  • OpenRouter - src/Service/OpenRouterService.php
  • Deepgram - src/Service/DeepgramService.php
  • OpenAI TTS - src/Service/OpenAITtsService.php

Project Structure

chatwell/
├── src/
│   ├── Controller/
│   │   ├── AiAssistantController.php   # Main API endpoints
│   │   └── SecurityController.php      # Authentication
│   ├── Entity/
│   │   ├── User.php
│   │   ├── UserSession.php
│   │   ├── Conversation.php
│   │   ├── Message.php
│   │   └── EmotionAnalysis.php
│   ├── Service/
│   │   ├── OpenRouterService.php       # AI chat
│   │   ├── DeepgramService.php         # Speech-to-text
│   │   ├── OpenAITtsService.php       # Text-to-speech
│   │   ├── EmotionAnalysisService.php  # Sentiment analysis
│   │   └── RateLimiterService.php      # Rate limiting
│   └── Command/
│       └── CreateUserCommand.php
├── templates/
│   ├── base.html.twig
│   ├── ai_assistant/
│   │   └── index.html.twig
│   └── security/
│       └── login.html.twig
├── public/
│   ├── js/
│   │   └── ai-assistant.js            # WebRTC & AJAX
│   └── css/
│       └── ai-assistant.css
├── config/
│   └── packages/
└── SETUP.md

AI Behavior Guidelines

The AI assistant follows these principles:

  • ✅ Provides emotional support and active listening
  • ✅ Offers stress management techniques
  • ✅ Suggests mindfulness and relaxation exercises
  • ✅ Keeps responses under 150 words
  • ❌ Never diagnoses medical conditions
  • ❌ Never replaces professional mental health care

Crisis Detection

The AI automatically detects crisis keywords (self-harm, suicide, etc.) and responds with:

  • Empathetic acknowledgment
  • Crisis hotline information
  • Encouragement to seek professional help

Security Features

  • Form-based authentication
  • CSRF protection on all forms
  • Rate limiting (10 requests/minute per user)
  • Input validation
  • Password hashing with Symfony password hasher

License

This project is for educational purposes. Please review and comply with the terms of service for all AI providers used.

Acknowledgments


Made with ❤️ for mental wellness

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors