
Astra - AI-Powered Chat Application
Astra is a modern, real-time chat application that leverages Google's Gemini AI for intelligent conversations. Built with React, TypeScript, and Vite, it offers a seamless chat experience with features like conversation management, real-time typing indicators, and AI-powered responses.
🌟 Features
Real-time AI chat with streaming via Google Gemini, providing token-by-token responses for instant feedback
Session-aware conversations saved in Supabase (
chat_sessions, chat_messages)Automatic session creation on server and propagation to the client via
X-Conversation-IdSecure authentication with Supabase and Bearer tokens
Sidebar conversation list with TanStack Query caching and virtualization for large histories
Smart auto-scroll only when the user is at the bottom during streaming
Keyboard-friendly UX (Enter to send, Shift+Enter for newline)
Auto-resizing input for comfortable typing backed by a custom hook
TypeScript-first codebase for safety and maintainability
🚀 Technologies Used
Frontend
React 19 with TypeScript
Vite for fast development and building
TailwindCSS for styling
shadcn/ui for UI components
React Hook Form with Zod for form validation
TanStack Query for server state management
Lucide React for icons
Backend
Supabase
Authentication
Database
Real-time subscriptions
Google Gemini AI for chat responses
Streaming API implementation
ElevenLabs for voice chat
🔍 Key Technical Implementations
Client streaming fetch (Conversation)
Path:
src/components/chat/Conversation.tsx in handleSendMessageServer API with streaming and exposed headers
Path:
server/index.js in app.post("/api/chat", ...)Sidebar conversations: query + virtualization
Path:
src/components/AppSidebar.tsxLoading messages on selection
Path:
src/components/Dashboard.tsx🛠️ Architecture
Frontend Architecture
Context API for global state (e.g.
SelectedConversationContext)Custom hooks (e.g.
use-auto-resize-textarea) for reusable UX logicComponent composition:
Dashboard orchestrates NewChat vs Conversation vs VoiceChatTanStack Query for server state and caching (
chat_sessions)TypeScript everywhere for safety and IDE support
Security Considerations
Input sanitization
Form validation
Auth token management
Rate limiting
Error handling
📦 Installation
Clone the repository:
Install dependencies:
Set up environment variables:
Run the development server:
Run the API server:
Ensure
.env in server/ contains SUPABASE_URL, SUPABASE_SERVICE_ROLE_KEY, and GEMINI_API_KEY.🤝 Contributing
Fork the repository
Create your feature branch:
Commit your changes:
Push to the branch:
Open a Pull Request
Commit Guidelines
Use conventional commits
Keep commits atomic and focused
Include relevant tests
Update documentation
🔐 Security Measures
Input Validation
Zod schemas for form validation
Sanitization of user inputs
Type checking with TypeScript
Authentication
JWT token management
Secure session handling
API Security
Rate limiting
CORS configuration
Error handling
📝 License
This project is licensed under the MIT License - see the LICENSE file for details.
🙏 Acknowledgments
Google Gemini AI team
Supabase team
shadcn/ui
Built with ❤️ by ShyneADL
RAG Setup Instructions
Prerequisites
Node.js (v18 or higher)
Supabase account
Google AI API key (for Gemini and embeddings)
Environment Variables
Create a
.env file in the server directory with the following variables:Database Setup
Run the SQL migration in your Supabase dashboard:
The therapy knowledge base will be automatically populated on first server startup.
Installation
Install client dependencies:
Install server dependencies:
Running the Application
Start the server:
Start the client (in a new terminal):
RAG System Architecture
The RAG system consists of three main components:
1. Embedding Service (server/lib/embedding-service.js)
server/lib/embedding-service.js)Generates vector embeddings using Google's text-embedding-004 model
Calculates cosine similarity for document retrieval
2. Vector Database (server/lib/vector-db.js)
server/lib/vector-db.js)Stores therapy knowledge with embeddings in Supabase
Performs semantic search for relevant therapeutic content
Manages conversation history context
3. Therapist RAG Chat (server/lib/therapist-rag.js)
server/lib/therapist-rag.js)Main RAG orchestration function
Detects topic deviation using keyword analysis
Builds therapeutic prompts with relevant context
Maintains focus on mental health conversations
Therapeutic Features
Topic Deviation Prevention
The system automatically detects when users try to discuss non-mental health topics and gently redirects them back to therapeutic conversations.
Knowledge Base Categories
therapeutic_approach: CBT, DBT, and other therapy methodstherapeutic_technique: Active listening, validation, etc.mental_health_condition: Anxiety, depression support strategiescrisis_management: Safety protocols and resource guidanceprofessional_ethics: Boundary setting and scope limitationsCrisis Management
The system includes built-in crisis detection and appropriate resource guidance while maintaining professional boundaries.
API Endpoints
POST /api/chat - Main chat endpoint with RAG integrationGET /api/health - Health check endpointContributing
Follow the established code patterns
Ensure all therapeutic content is evidence-based
Test topic deviation scenarios thoroughly
Maintain professional therapeutic boundaries in all responses
License
This project is licensed under the ISC License.
0 likes · 7 views · Oct 30, 2025
Developed Astra, an AI-powered chat app using React, TypeScript, an.
Timeline
Aug 15, 2025 - Sep 15, 2025