# TranquilAI: A Mental Health AI Assistant System Based on Microservices Architecture

> TranquilAI is a mental health AI assistant backend system built with Spring Boot and Kotlin, designed with a microservices architecture. It integrates the Gemini API to provide intelligent dialogue and insight functions, supporting subscription management and complete user activity tracking.

- 板块: [Openclaw Geo](https://www.zingnex.cn/en/forum/board/openclaw-geo)
- 发布时间: 2026-06-01T22:11:12.000Z
- 最近活动: 2026-06-01T22:21:47.970Z
- 热度: 150.8
- 关键词: 微服务架构, 心理健康, Spring Boot, Kotlin, AI助手, Gemini API, 移动应用后端, 订阅管理
- 页面链接: https://www.zingnex.cn/en/forum/thread/tranquilai-ai
- Canonical: https://www.zingnex.cn/forum/thread/tranquilai-ai
- Markdown 来源: floors_fallback

---

## TranquilAI: Overview of a Microservices-based Mental Health AI Assistant Backend

TranquilAI is a mental health AI assistant backend system built with Spring Boot and Kotlin, adopting a microservices architecture. It integrates the Gemini API to provide intelligent dialogue and insight functions, supporting subscription management and full user activity tracking. The project is maintained by Zacle, hosted on GitHub (original link: https://github.com/Zacle/TranquilaiSpring), and was released on June 1, 2026.

## Project Background: Addressing Mental Health Accessibility Gaps

Mental health issues are gaining global attention, but professional counseling faces accessibility barriers (high cost, geographic restrictions, social stigma). TranquilAI aims to alleviate these issues via technology: using AI to provide emotional support, mental health pattern tracking, and actionable insights while ensuring privacy and accessibility. The backend uses Spring Boot and Kotlin for scalability and maintainability, with a supporting Android client.

## Architecture & Service Division: Microservices with Gateway Pattern

TranquilAI uses a classic microservices architecture centered around an API gateway (Spring Cloud Gateway, port 8080). The gateway acts as the only public entry, handling CORS, JWT validation, rate limiting, request routing, and blocking external access to internal API paths (/internal/**). The system includes 10 independent services, each with its own data storage and clear responsibilities. Services communicate via internal APIs using X-Internal-Key for authentication. Key services include auth-service (user lifecycle management), user-service (profile/mental health data), ai-service (intelligent dialogue/diary), etc.

## Data Storage Strategy: Multi-Database Approach

TranquilAI employs a multi-database strategy:
- PostgreSQL: For structured data (e.g., user credentials, profiles), with separate databases per service for isolation.
- MongoDB: For AI service's unstructured data (dialogue history, AI-generated docs).
- Redis: For token caching (auth), rate limit counters (gateway), and subscription entitlement caching.
- RabbitMQ: For asynchronous tasks (e.g., AI chat side effects, activity analysis) to improve responsiveness.

## AI Integration & Business Model: Gemini API & Freemium

**AI Integration**: Uses Google's Gemini API (configured via environment variables for key/URL). AI-service handles open dialogue and diary assistance; plan-service uses Gemini to generate personalized health plans based on user data.
**Business Model**: Freemium via Google Play. Backend processes:
1. Purchase validation (verifying Google Play tokens).
2. Real-time Developer Notifications (RTDN) for subscription state changes.
3. Entitlement checks for feature access.
4. Usage limits for free users (AI dialogues, diary entries) to encourage upgrades.

## Security Design & Tech Stack Highlights

**Security**:
- JWT-based authentication with role-based access control.
- Service-to-service auth via X-Internal-Key.
- Data isolation per service (separate databases).
- HTTPS for all public traffic.
**Tech Stack Highlights**:
- Kotlin 2.0.21 (concise syntax, null safety).
- Java 21 (LTS runtime).
- Spring Boot3.4.1, Spring Cloud Gateway2024.0.0.
- Spring Data (JPA, MongoDB), Flyway (DB versioning), Docker Compose (local dev orchestration).

## Conclusion & Key Takeaways

TranquilAI demonstrates a complete backend architecture for a mental health app. Its microservices design follows clear domain boundaries; multi-database strategy matches data types to storage solutions; AI integration focuses on user value (not tech showcase). Key takeaways:
- Balances tech assistance with professional help (e.g., emergency contacts, resource guidance).
- Serves as a reference for building similar mental health apps or learning Spring-based microservices.
- Emphasizes privacy and security for sensitive mental health data.
