Skip to content

AI-powered mental health support system with intelligent chatbot for emotional well-being. Providing 24/7 accessible mental health assistance through conversational AI.

License

Notifications You must be signed in to change notification settings

jashinspires/Lyra_Companion

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

11 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

✨ Lyra – Your Empathetic Mental Health Companion

Named after the constellation that guides travelers, Lyra brings light, hope, and clarity during life's emotional challenges.

Python FastAPI Google Gemini Flutter

Compassionate, AI-powered mental health supportβ€”accessible 24/7 through a safe, privacy-first conversational experience.

Features β€’ Demo β€’ Quick Start β€’ Architecture β€’ Contributing


🌟 Vision

Normalize seeking mental health support by offering compassionate, culturally aware, always-available help that complementsβ€”not replacesβ€”licensed therapy.

The Problem We're Solving

  • πŸ• Long wait times and high costs limit access to mental healthcare
  • πŸ˜” Stigma prevents early intervention and open conversations
  • ⚠️ Crisis escalation can occur when support is unavailable at critical moments
  • πŸ€– Generic chatbots miss nuance and cultural sensitivity, risking harm
  • πŸ”“ Many tools ignore privacy, safety, and ethical guardrails

πŸ’‘ Key Features

πŸ—£οΈ Empathetic Conversations

  • Google Gemini 2.5 Pro powered responses
  • Context-aware emotional support
  • Automatic retry with shorter context on token limits
  • Graceful fallback for API failures

πŸ›‘οΈ Safety-First Design

  • Crisis detection with localized helplines
  • Real-time safety evaluation
  • Clear disclaimers throughout
  • Never provides harmful instructions

πŸ“” Personal Journaling

  • Private, reflective space
  • Mood tagging and tracking
  • Entry summaries and insights
  • Export and backup options

πŸ“Š Mood Analytics

  • Daily mood logging
  • Intensity tracking (1-10 scale)
  • Trend visualization
  • Pattern recognition

🎯 Emotion Detection

  • Text-based emotion analysis
  • Personalized coping suggestions
  • Culturally sensitive responses
  • Evidence-based techniques

🌍 Multilingual Support

  • Locale-aware responses
  • Regional crisis resources
  • Culturally appropriate guidance
  • Timezone considerations

πŸ—οΈ Architecture

Tech Stack

Backend

FastAPI (0.115.0)         β†’ High-performance REST API
Uvicorn                   β†’ ASGI server
Google Gemini 2.5 Pro     β†’ LLM for conversations
Pydantic                  β†’ Data validation
Python 3.13+              β†’ Core language

Frontend

Flutter 3.3+              β†’ Cross-platform UI
Riverpod                  β†’ State management
Dio                       β†’ HTTP client
Material Design 3         β†’ Modern UI components

System Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Flutter App    β”‚  ← User Interface (Mobile/Web)
β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚ HTTPS/REST
         β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   FastAPI       β”‚  ← Backend API Layer
β”‚   Gateway       β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚
    β”Œβ”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
    β–Ό          β–Ό          β–Ό          β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚Convo   β”‚ β”‚Safety  β”‚ β”‚Emotion β”‚ β”‚Mood    β”‚
β”‚Service β”‚ β”‚Service β”‚ β”‚Service β”‚ β”‚Service β”‚
β””β”€β”€β”€β”¬β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”˜
    β”‚
    β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Google Gemini  β”‚  ← AI Language Model
β”‚   2.5 Pro      β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Key Design Patterns

  • Service Layer Architecture: Separation of concerns with dedicated services
  • Dependency Injection: Clean, testable code structure
  • Error Recovery: Automatic retry with exponential backoff
  • Fallback Mechanisms: Rule-based responses when AI is unavailable

πŸš€ Quick Start

Prerequisites

  • Python 3.13+ (backend)
  • Flutter 3.3+ (frontend)
  • Google Gemini API Key (Get one here)

Backend Setup

# Navigate to backend
cd backend

# Create virtual environment
python -m venv .venv
source .venv/bin/activate  # On Windows: .venv\Scripts\activate

# Install dependencies
pip install -r requirements.txt

# Create .env file
cp .env.example .env
# Add your GEMINI_API_KEY to .env

# Run the server
uvicorn app.main:app --reload

# API will be available at http://localhost:8000
# Interactive docs at http://localhost:8000/docs

Frontend Setup

# Navigate to frontend
cd frontend

# Get Flutter dependencies
flutter pub get

# Run on Chrome (web)
flutter run -d chrome

# Or run on your connected device
flutter run

Running Tests

# Backend tests
cd backend
pytest tests/ -v

# Run only passing asyncio tests
pytest tests/ -k asyncio -v

πŸ“‘ API Endpoints

Health & Status

GET /api/health

Chat

POST /api/chat/session
Content-Type: application/json

{
  "messages": [
    {"role": "user", "content": "I'm feeling anxious about tomorrow"}
  ],
  "locale": "en-US"
}

Safety Check

POST /api/safety/check
Content-Type: application/json

{
  "text": "I'm having a hard day",
  "locale": "en-US"
}

Mood Tracking

POST /api/mood/{user_id}/logs
Content-Type: application/json

{
  "mood": "anxious",
  "intensity": 6,
  "notes": "Work deadline approaching"
}

Journal Entries

POST /api/journal/{user_id}/entries
Content-Type: application/json

{
  "title": "Evening Reflection",
  "content": "Today was challenging but I made it through",
  "mood": "hopeful",
  "tags": ["daily", "reflection"]
}

🎨 Screenshots

Note: Add screenshots of your application here

[Chat Interface]  [Mood Tracker]  [Journal View]

πŸ” Ethics, Privacy & Safety

Our Commitments

βœ… Not a Substitute for Professional Care

  • Clear disclaimers throughout the app
  • Nudges toward professional help when appropriate
  • Crisis resources readily available

βœ… Privacy First

  • No unnecessary data collection
  • Local storage where possible
  • Clear data handling policies

βœ… Safety Protocols

  • Crisis intent detection
  • Region-specific emergency resources
  • Immediate escalation pathways
  • Never provides harmful instructions

βœ… Transparent Operation

  • Open-source codebase
  • Clear AI boundaries
  • Honest about limitations

Crisis Resources

  • International: findahelpline.com
  • India (Kiran): 1800-599-0019
  • US (988): 988 Suicide & Crisis Lifeline
  • Emergency: Always contact local emergency services (911, 112, etc.)

πŸ§ͺ Testing

Test Coverage

# Run all tests with coverage
pytest tests/ --cov=app --cov-report=html

# Current coverage: Core APIs and services
βœ… Health check
βœ… Chat session flow
βœ… Journal CRUD operations
βœ… Mood logging and trends
βœ… Safety detection
βœ… Gemini response handling

Key Test Files

  • tests/test_api.py - API integration tests
  • tests/test_conversation_service.py - Gemini handling tests
  • tests/conftest.py - Test fixtures and setup

πŸ› οΈ Development

Project Structure

Lyra_Companion/
β”œβ”€β”€ backend/
β”‚   β”œβ”€β”€ app/
β”‚   β”‚   β”œβ”€β”€ api/              # API routes
β”‚   β”‚   β”‚   └── routes/       # Endpoint handlers
β”‚   β”‚   β”œβ”€β”€ core/             # Configuration & events
β”‚   β”‚   β”œβ”€β”€ models/           # Data models (future DB)
β”‚   β”‚   β”œβ”€β”€ schemas/          # Pydantic models
β”‚   β”‚   β”œβ”€β”€ services/         # Business logic
β”‚   β”‚   β”‚   β”œβ”€β”€ conversation.py  # Gemini integration
β”‚   β”‚   β”‚   β”œβ”€β”€ emotion.py       # Emotion detection
β”‚   β”‚   β”‚   β”œβ”€β”€ safety.py        # Crisis detection
β”‚   β”‚   β”‚   β”œβ”€β”€ mood.py          # Mood tracking
β”‚   β”‚   β”‚   └── journal.py       # Journal management
β”‚   β”‚   └── utils/            # Helper functions
β”‚   β”œβ”€β”€ tests/                # Test suite
β”‚   β”œβ”€β”€ docs/                 # Documentation
β”‚   └── requirements.txt      # Python dependencies
β”‚
└── frontend/
    └── lib/
        β”œβ”€β”€ core/             # App config & providers
        β”œβ”€β”€ features/         # Feature modules
        β”œβ”€β”€ models/           # Data models
        β”œβ”€β”€ screens/          # UI screens
        └── services/         # API clients

Key Files

File Purpose
backend/app/services/conversation.py Gemini API integration with retry logic
backend/app/services/safety.py Crisis detection and safety evaluation
backend/app/core/config.py Environment configuration
frontend/lib/core/providers.dart Riverpod state management

Recent Improvements

✨ Enhanced Gemini Error Handling (Oct 2025)

  • Robust response parsing for empty candidates
  • Automatic retry with shorter context on MAX_TOKENS
  • Comprehensive finish_reason logging
  • Graceful fallback to rule-based responses

See GEMINI_FIX_2025_10_04.md for technical details.


🀝 Contributing

We welcome contributions from:

  • πŸ§‘β€βš•οΈ Mental health professionals
  • 🎨 UX/UI designers
  • πŸ’» Developers
  • πŸ“ Technical writers
  • 🌍 Translators

How to Contribute

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

Development Guidelines

  • Write tests for new features
  • Follow existing code style (Ruff for Python, Dart conventions)
  • Update documentation
  • Ensure all tests pass
  • Add meaningful commit messages

πŸ“š Documentation


🎯 Roadmap

Phase 1: Foundation (Current)

  • FastAPI backend with core services
  • Flutter mobile/web client
  • Google Gemini integration
  • Basic mood tracking
  • Journal functionality
  • Safety detection

Phase 2: Enhancement (Next)

  • User authentication & profiles
  • Persistent database (MongoDB/PostgreSQL)
  • Advanced emotion analytics
  • Coping exercise library
  • Push notifications for check-ins
  • Offline mode support

Phase 3: Scale (Future)

  • Multilingual support (5+ languages)
  • Therapist dashboard (with consent)
  • Community features (moderated)
  • Integration with wearables
  • Insurance/healthcare provider partnerships
  • Research & impact studies

πŸ“„ License

This project is open source and available under the MIT License.


πŸ™‹ About the Creator

Mental health support is deeply personal to me. I've witnessed friends and peers struggle silently due to stigma and access barriers. Lyra is my contribution to making compassionate support feel reachableβ€”anytime, anywhereβ€”while honoring safety, ethics, and human dignity.

If you're working on similar initiatives or want to collaborate, feel free to reach out!


⚠️ Important Disclaimers

This application does not provide medical advice.

Lyra is an empathetic companion, not a licensed therapist or medical professional. It is designed to complementβ€”not replaceβ€”professional mental health care.

When to Seek Professional Help

βœ‹ Seek immediate help if you:

  • Have thoughts of harming yourself or others
  • Are experiencing a mental health crisis
  • Need diagnosis or treatment
  • Require medication management

Resources

  • Crisis Text Line: Text HOME to 741741
  • National Suicide Prevention Lifeline: 1-800-273-8255
  • SAMHSA National Helpline: 1-800-662-4357
  • Emergency Services: 911 (US) or your local emergency number

Built with ❀️ and hope for a world where mental health support is accessible to all

⬆ Back to Top

About

AI-powered mental health support system with intelligent chatbot for emotional well-being. Providing 24/7 accessible mental health assistance through conversational AI.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages