Technical Case Study: FriendnPal

A detailed breakdown of the architecture, technical decisions, and engineering challenges faced during development.

Technical Case Study: FriendnPal - Scaling AI Mental Health Support

Introduction

FriendnPal is an AI - powered mental health platform providing accessible support through chatbots, therapist booking, and community features.As the Lead Backend Developer, I was responsible for the core API, real - time communication, and the "Pal" AI companion.


The Problem: Accessibility vs.Complexity

Developing mental health tools involves balancing high - end technology with extreme accessibility requirements:

  1. ** Low - Connectivity Barriers:** Users in rural areas lack the bandwidth for complex web apps.
  2. ** Infinite Context:** An AI companion needs to remember past conversations to provide meaningful support.
  3. ** Infrastructure Sustainability:** Scaling AI tokens and WebSocket servers can quickly become cost - prohibitive.

Solution Architecture: Hybrid AI Bridge & WebSocket Mesh

I designed a hybrid architecture that bridges high - end AI processing with low - bandwidth delivery channels.

The Stack:

  • ** Core API:** Node.js(Express) & TypeScript.
  • ** Real - Time:** Socket.io for the mobile app interface.
  • ** AI:** OpenAI GPT Models with custom system prompting.
  • ** Channel Bridge:** WhatsApp Business API for low - connectivity access.
  • ** Infrastructure:** Docker - based deployment(Migrated Azure → AWS / VPS).

Overcoming Key Challenges

Challenge 1: The WhatsApp Extension Bridge

Creating a version of the AI companion that works via SMS / WhatsApp for users without data.

  • ** Problem:** The AI logic lived in a WebSocket - centric app, but WhatsApp uses a Webhook - centric POST model.
  • ** Solution:** Built an "Ingestion Adapter" that abstracts the message source.Whether a message comes via WebSocket or WhatsApp Webhook, it is normalized into a standard "UserMessage" object.This allowed us to use the same AI brain across all channels with zero code duplication.

Challenge 2: Context Management for the "Pal" AI

Ensuring the AI remember's a user's progress without sending an entire book of history every time.

  • ** Problem:** Sending full chat history to AI APIs is expensive and slow.
  • ** Solution:** Implemented a "Sliding Window" context manager using Redis.We store recent message embeddings and a summarized "Memory" of the user's previous sessions. This allows the AI to provide deeply personalized support while keeping token usage and latency low.

Challenge 3: Infrastructure Migration(70 % Cost Reduction)

Scaling the platform while maintaining a sustainable burn rate.

  • ** Problem:** Initial deployment on Azure was costing thousands in managed service fees.
  • ** Solution:** I led the migration to a self - managed VPS / AWS hybrid setup.By containerizing everything with Docker and switching to a self - managed MongoDB cluster on a high - performance VPS, we maintained 99.9 % uptime while slashing monthly infrastructure costs by 70 %.

Results & Impact

* ** Reach:** Successfully served thousands of users through the WhatsApp extension.
  • ** Performance:** Reduced AI response latency to under 2.5 seconds using Redis context caching.
  • ** Stability:** Maintained high availability through two major infrastructure migrations.

Conclusion

FriendnPal is a case study in building with empathy.It shows that by optimizing infrastructure and focusing on multi - channel access, we can bring life - changing technology to those who need it most.


[Visit FriendnPal](https://friendnpal.com) | [App Store](https://apps.apple.com/ng/app/ourpadi/id6648793159);