Building Mindful: A Mental Wellness App with Flutter, Node.js, AI, and Clean Architecture 🌿

aryprogrammer

Arya Pratap Singh

Posted on September 28, 2024

Building Mindful: A Mental Wellness App with Flutter, Node.js, AI, and Clean Architecture 🌿

App Logo

Mindful-App

Build Status
version

AI USED : LLAMA-8B-8192, FACE EMOTION RECOGNITION MODEL, GEMINI/ANTHROPIC/MISTRAL SUPPORTED (API_KEY REQUIRED)
APP STATUS : ALL CORE FUNCTIONALITIES WORKING (Deployed NodeJs & Postgresql on Render)

What's New in v2.1.2 (Stable Release with Redis Phase 3 Integration)

        - **Improved AI Chat Functionality**
        - **Redis DS Change - HashMaps**
        - **Minor Bug fixes**
        - **Crash Handlers are improved**
        - **Improved Overall Performance - Implemented Impeller**
        - **Settings Tab is now Better**
        - **Redis connection fixes and data privacy improvised**
        - **Redis Cloud Implementation and Fetching in Beta Phase**
        - **Added Redis-base to support syncfusion**
        - **New Feature**: Implemented Syncfusion and Redis for low latency**

        ### Issues are being Resolved - Redis Full-Integration Phase 3
Enter fullscreen mode Exit fullscreen mode

KEYNOTE : FINDINGS WHILE USING AI APIs

  1. DEPLOYMENT AND UNREFINED USAGE IS THE SIMPLISTIC APPROACH TO INTEGRATION. IT TAKES LESS TIME TO GENERATE THE CONTENT AND FETCH IT IN JSON Format for further processing by the DOMAIN LAYER entities.

  2. MANY OF THE PAID APIs ESPECIALLY ANTHROPIC-CLAUDE-SONET-3.5 AND MISTRAL-LLAMA-7.3B REQUIRE SLIGHLTY MORE PROCESSING TIME THEREBY INCREASING THE REQ-RES-STATUS TIME.

  3. FINE TUNING OF THE MODELS IS A TIME TAKING PROCEDURE AS THE DATASET GEN FOR REQUIRED OUTPUT IS TO BE MANUALLY GENERATED OR IMPLEMENTED.

  4. THE AI-API USED FOR ILLUSTRATION PURPOSES "LLAMA-8B-8192" (previously "GEMINI-1.5-FLASH") DOES PROVIDE ACCURATE RESPONSE FOR THE FOLLOWING SITUATION (WHICH "GEMINI-1.5-FLASH" DIDN'T) :
    TIME SYNC ACROSS THE APP (i.e definition of morning etc.)
    PROPER JSON FORMATING (INCLUDES THE WORD "json" IN RESPONSE
    WHICH IS TO BE OMIITED SPECIFICALLY FOR THE INNER LAYER
    ENITITES TO FUNCTION)

  5. ANTHROPIC-AI/SDK API(claude-3-5-sonnet) WAS FOUND TO BE MOST SUITABLE AS COMPARED TO gpt-3.5-turbo.

DEMO LINK OF WORKING

PREPRODUCTION INSIDERS

Introduction

In today’s fast-paced world, where stress and anxiety have become all too common, I wanted to create something meaningful—something that could help people reclaim their mental well-being. That’s how Mindful, a mental wellness app, was born. This post will walk you through the journey of building Mindful, from choosing the right technologies to incorporating AI for personalized advice and relaxation features.

What is Mindful?

Mindful is a personalized mental wellness companion designed to help users manage their stress and anxiety. Through personalized AI-driven advice and a soothing music player, Mindful aims to guide users toward better mental health and mindfulness. ADDED FOR EXTRA COMFORT...


Features

🧠 Personalized AI-Driven Advice

One of the core features of Mindful is the personalized advice system powered by LLAMA-8B-8192 (previously : Gemini), an AI developed by meta and fine tuned by me to offer mental health tips tailored to individual needs. While LLAMA-8B-8192 (previously : Gemini) powers the current version, I’ve written the code for other APIs which require paid API_KEYS FOR integration with more advanced AI systems like Anthropic, Open AI, and Mistral. They require PAID API KEYS.

🎶 Relaxation Music Player

To further enhance mindfulness, Mindful includes a curated music player with a library of relaxing tracks to help users unwind. Whether you're meditating or just taking a break, the app's music player offers a peaceful escape. Feel free to add your playlist to the db.

🎨 Intuitive Design

Mental wellness apps should be stress-free to use. With Mindful, the focus is on simplicity and functionality. The user interface is designed to be minimalistic and intuitive, providing users with easy access to resources without overwhelming them. I found inspiration from various sources—more on that below!


Architecture and Technologies

Building an app like Mindful requires a solid foundation. Here’s a breakdown of the technologies and architecture that power the app:

🚀 Backend: Node.js, PostgreSQL, and Firebase

The backend is built with Node.js, providing the scalability needed for growing user traffic. PostgreSQL stores user data (with your key) securely, while Firebase manages real-time syncing with auth, making the app fast and responsive.Tensorflow to create the FER Model using FER2013 Dataset.

🧱 Clean Architecture and SOLID Principles

To ensure that Mindful is maintainable and future-proof, I adopted clean architecture and followed the SOLID principles. This modular approach separates business logic, user interfaces, and infrastructure, allowing for easy updates and testing as the app grows.

Key Architectural Decisions:

  • ModelView-ViewModel pattern to handle user requests and business logic.

  • Separation of concerns for better code management and maintainability.

  • Extensibility built-in so new AI features and wellness tools can be integrated smoothly in future updates.

💻 Check Out the Code

If you're curious to see how the app is structured or want to contribute, head over to the GitHub Repository.
FEEL FREE TO DOWNLOAD THE RELEASE BUT MAKE SURE TO FIRST RUN THE SERVER.


The Machine Learning Model: AI-Powered Mental Health Advice

The AI FACE DETECTION engine is central to the Mindful experience. I trained the initial model using TensorFlow, and now the app provides correct detection based on user camera input. It can be further used for many purposes.

Want to check out the model?

Here’s the Colab Notebook where I trained and fine-tuned the model. Feel free to explore, experiment, or even enhance the model if you're interested in contributing to the AI aspect!


UI Inspiration: Designing Mindful’s Look and Feel

Designing a mental wellness app requires careful consideration of both aesthetics and functionality. I wanted the user experience to be as stress-free as possible, so I sought out minimalist, calming design elements.

I found inspiration on Figma, where I designed and prototyped Mindful’s UI. The app features soft colors, intuitive buttons, and easy navigation to reduce user overwhelm.

Interested in the design?

Check out the Figma File to see how I brought the UI to life. It’s a work-in-progress, so feel free to offer feedback!


Architecture

The Mindful app employs a clean architecture pattern, allowing for separation of concerns and enhancing maintainability. This design makes the app adaptable to future changes and ensures a robust user experience. By adhering to SOLID principles, Mindful promotes best practices that facilitate development and testing.

Getting Started

To run Mindful locally, follow these steps:

  1. Clone the repository:
   git clone https://github.com/ARYPROGRAMMER/mindful.git
   cd server/mental-health-api/
Enter fullscreen mode Exit fullscreen mode
  1. Install dependencies:
   npm install
Enter fullscreen mode Exit fullscreen mode
  1. Setup environment variables (OPTIONAL, USE MINE): Changes in API_KEY (if needed) to be done in :
   mental-health-api/
   ├──...          
   ├──...         
   ├──...          
   ├──...        
   ├── server.js          # Main server file
   ├── infrastructure/               
       ├── geminiai/   
       ├   └── geminiService.js  # NEW API KEY ADDING SLOT
       └──── db/    
              └── index.js  # PostGres Setup

Enter fullscreen mode Exit fullscreen mode
  1. Run the Server:
   npm start
Enter fullscreen mode Exit fullscreen mode
  1. Run the App:
   cd ../../lib/
   flutter clean
   flutter pub get
   flutter run

Enter fullscreen mode Exit fullscreen mode

Alternatively you could use :

   flutter build apk
Enter fullscreen mode Exit fullscreen mode
  1. Structure of DB:

    Songs Table

    This is the structure of the songs table in the public schema.

    Column Type Collation Nullable Default
    title character varying(100) false
    author character varying(100) false
    songlink character varying(256) false
    id bigint false nextval('songs_id_seq'::regclass)
    imageid character varying(256) true

    Notes:

    • The id column is auto-incremented using the nextval('songs_id_seq'::regclass) function.
    • imageid is optional and can store a link or identifier for the image associated with the song.

What’s Next?

I’m planning to continuously evolve Mindful, with upcoming features like meditation sessions, enhanced AI capabilities, and more personalized recommendations. The goal is to build a complete mental wellness toolkit right in your pocket.

If you’d like to contribute ideas or code, please do! Mindful is an open-source project, and I’m excited to see how the community can help shape its future. You can submit pull requests or open issues on the GitHub Repository.


Final Thoughts

Creating Mindful has been an enriching experience, and I hope it can positively impact users by helping them manage stress, anxiety, and overall mental health. The combination of AI-driven advice, relaxation tools, and user-friendly design make Mindful a comprehensive companion for mental wellness.

Mental health is as important as physical health, and Mindful strives to be a tool that helps users prioritize their well-being in a meaningful and practical way.

Thanks for reading! I’d love to hear your thoughts on the project or discuss anything related to mental wellness tech. Feel free to leave a comment or reach out directly.


Contact ME

For questions or feedback, please reach out to me at:


Let’s make mindfulness accessible TO ALL, one step at a time.

💖 💪 🙅 🚩
aryprogrammer
Arya Pratap Singh

Posted on September 28, 2024

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related