Repository: bO-05/health-translate-mini
Pull request #4: Feat/multi user chat backend
Author: login: bO-05
Created: 2025-05-19T11:42:47Z | Merged: 2025-05-19T11:53:46Z



<!-- This is an auto-generated comment: release notes by coderabbit.ai -->

## Summary by CodeRabbit

- **New Features**
  - Introduced new API endpoints for chat room management, message sending, and real-time message subscription with automatic language translation.
  - Added support for Supabase integration, enabling database-backed chat and real-time updates.

- **Documentation**
  - Updated the README with setup instructions for Supabase integration, API route descriptions, and environment variable guidance.

- **Chores**
  - Added required Supabase dependencies.
  - Updated configuration and environment example files to reflect new environment variable names and usage.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->


Diff:
diff --git a/.cursorrules b/.cursorrules
index 90d8466..fb624d6 100644
--- a/.cursorrules
+++ b/.cursorrules
@@ -24,10 +24,10 @@ folder_conventions:
   - `components/XXX.tsx` for shared UI.
 env_files:
   - .env.example -> include placeholders for all keys.
-    # MISTRAL_API_KEY=
-    # ELEVEN_API_KEY=
-    # SUPABASE_URL=
-    # SUPABASE_ANON_KEY=
+    MISTRAL_API_KEY=
+    ELEVEN_API_KEY=
+    NEXT_PUBLIC_SUPABASE_URL=
+    NEXT_PUBLIC_SUPABASE_ANON_KEY=
 
 document_tree_file: document-tree.txt
 
diff --git a/.env.example b/.env.example
index f6934b7..04d6f09 100644
--- a/.env.example
+++ b/.env.example
@@ -3,6 +3,6 @@ ELEVEN_API_KEY=
 
 NEXT_PUBLIC_SUPPORTED_LANGS=en,es,id,zh,fr,de,ja,ko,pt,ru,ar,hi
 
-# Optional - for Supabase integration (authentication & history)
-# SUPABASE_URL=
-# SUPABASE_ANON_KEY=
\ No newline at end of file
+# Supabase Project Credentials
+NEXT_PUBLIC_SUPABASE_URL=your_supabase_project_url_here
+NEXT_PUBLIC_SUPABASE_ANON_KEY=your_supabase_anon_key_here
\ No newline at end of file
diff --git a/README.md b/README.md
index e4dc530..89e15db 100644
--- a/README.md
+++ b/README.md
@@ -39,10 +39,16 @@ To run this project locally, you'll need to set up API keys for the translation
     ```env
     MISTRAL_API_KEY=your_mistral_api_key_here
     ELEVEN_API_KEY=your_elevenlabs_api_key_here
+    NEXT_PUBLIC_SUPABASE_URL=your_supabase_project_url_here
+    NEXT_PUBLIC_SUPABASE_ANON_KEY=your_supabase_anon_key_here
     # NEXT_PUBLIC_SUPPORTED_LANGS can be set here if needed, defaults are in app/page.tsx
     ```
     *   `MISTRAL_API_KEY`: Your API key for Mistral AI.
     *   `ELEVEN_API_KEY`: Your API key for ElevenLabs.
+    *   `NEXT_PUBLIC_SUPABASE_URL`: Your Supabase project URL.
+    *   `NEXT_PUBLIC_SUPABASE_ANON_KEY`: Your Supabase project anonymous key.
+
+> **Note:** `NEXT_PUBLIC_SUPABASE_ANON_KEY` is exposed to the browser and is **not a secret key**. You must enable Row Level Security (RLS) in your Supabase project and define appropriate policies to prevent unauthorized access to your data. Never use the service role key in client-side code.
 
 ## Getting Started
 
@@ -74,6 +80,12 @@ HealthTranslateMini/
 ├── .gitignore
 ├── app/
 │   ├── api/
+│   │   ├── room/
+│   │   │   └── route.ts
+│   │   ├── send-message/
+│   │   │   └── route.ts
+│   │   ├── subscribe-messages/
+│   │   │   └── route.ts
 │   │   ├── translate/
 │   │   │   └── route.ts
 │   │   └── tts/
@@ -84,6 +96,9 @@ HealthTranslateMini/
 ├── components/
 │   ├── MicButton.tsx
 │   └── TranscriptPane.tsx
+├── lib/
+│   └── supabase/
+│       └── server.ts
 ├── node_modules/ (Managed by npm)
 ├── .next/ (Build artifacts)
 ├── next-env.d.ts
@@ -107,6 +122,10 @@ HealthTranslateMini/
 - **`public/`**: (Currently empty, for static assets if needed in the future)
 - **`.env.local`**: For local environment variables (API keys). Not committed to Git.
 - **`.env.example`**: Example structure for `.env.local`.
+- **`lib/supabase/server.ts`**: Utility for creating Supabase Edge client.
+- **`app/api/room/route.ts`**: Edge function for creating/joining chat rooms.
+- **`app/api/send-message/route.ts`**: Edge function for sending chat messages.
+- **`app/api/subscribe-messages/route.ts`**: Edge function for subscribing to chat messages via SSE.
 - **`next.config.mjs`**, **`postcss.config.js`**, **`tailwind.config.ts`**, **`tsconfig.json`**: Standard Next.js/Tailwind/TypeScript config files.
 - **`package.json`**, **`package-lock.json`**: npm package management.
 - **`.cursorrules`**: Cursor AI assistant project configuration (internal rules, not user-facing documentation).
diff --git a/app/api/room/route.ts b/app/api/room/route.ts
new file mode 100644
index 0000000..69d013a
--- /dev/null
+++ b/app/api/room/route.ts
@@ -0,0 +1,86 @@
+import { type NextRequest, NextResponse } from 'next/server';
+import { cookies } from 'next/headers';
+import { createEdgeClient } from '@/lib/supabase/server'; // We'll create this utility file next
+
+export const runtime = 'edge';
+
+function generateRoomCode(length: number = 6): string {
+  // Use crypto.randomUUID for better randomness
+  return crypto.randomUUID().replace(/-/g, '').slice(0, length).toUpperCase();
+}
+
+// POST /api/room - Create a new room
+export async function POST(req: NextRequest) {
+  const cookieStore = cookies();
+  const supabase = createEdgeClient(cookieStore);
+
+  let roomCode = generateRoomCode();
+  let roomCreated = false;
+  let attempts = 0;
+  const maxAttempts = 5;
+  let newRoom;
+
+  while (!roomCreated && attempts < maxAttempts) {
+    attempts++;
+    try {
+      const { data, error } = await supabase
+        .from('rooms')
+        .insert({ room_code: roomCode })
+        .select('id, room_code')
+        .single();
+
+      if (error && error.code === '23505') { // Unique constraint violation
+        roomCode = generateRoomCode();
+        continue;
+      }
+      if (error) {
+        console.error('Error creating room:', error);
+        return NextResponse.json({ error: 'Failed to create room', details: error.message }, { status: 500 });
+      }
+      newRoom = data;
+      roomCreated = true;
+    } catch (e: any) {
+      console.error('Unexpected error creating room:', e);
+      return NextResponse.json({ error: 'Unexpected error creating room', details: e.message }, { status: 500 });
+    }
+  }
+
+  if (!roomCreated) {
+    return NextResponse.json({ error: 'Failed to generate a unique room code after multiple attempts' }, { status: 503 });
+  }
+
+  return NextResponse.json(newRoom, { status: 201 });
+}
+
+// GET /api/room?room_code=XYZ - Join an existing room
+export async function GET(req: NextRequest) {
+  const cookieStore = cookies();
+  const supabase = createEdgeClient(cookieStore);
+  const { searchParams } = new URL(req.url);
+  let roomCode = searchParams.get('room_code') ?? searchParams.get('roomCode');
+
+  if (!roomCode) {
+    return NextResponse.json({ error: 'room_code (or roomCode) query parameter is required' }, { status: 400 });
+  }
+  roomCode = roomCode.toUpperCase();
+
+  try {
+    const { data: room, error } = await supabase
+      .from('rooms')
+      .select('id, room_code')
+      .eq('room_code', roomCode)
+      .single();
+
+    if (error) {
+      console.error('Error fetching room:', error);
+      return NextResponse.json({ error: 'Failed to fetch room', details: error.message }, { status: 500 });
+    }
+    if (!room) {
+      return NextResponse.json({ error: 'Room not found' }, { status: 404 });
+    }
+    return NextResponse.json(room, { status: 200 });
+  } catch (e: any) {
+    console.error('Unexpected error fetching room:', e);
+    return NextResponse.json({ error: 'Unexpected error fetching room', details: e.message }, { status: 500 });
+  }
+} 
\ No newline at end of file
diff --git a/app/api/send-message/route.ts b/app/api/send-message/route.ts
new file mode 100644
index 0000000..29051e1
--- /dev/null
+++ b/app/api/send-message/route.ts
@@ -0,0 +1,104 @@
+import { type NextRequest, NextResponse } from 'next/server';
+import { cookies } from 'next/headers';
+import { createEdgeClient } from '@/lib/supabase/server';
+
+export const runtime = 'edge';
+
+interface SendMessagePayload {
+  roomId: string;
+  userId: string;
+  text: string;
+  lang: string;
+}
+
+// POST /api/send-message - Send a message to a room
+export async function POST(req: NextRequest) {
+  const cookieStore = cookies();
+  const supabase = createEdgeClient(cookieStore);
+
+  let payload: SendMessagePayload;
+  try {
+    payload = await req.json();
+  } catch (error) {
+    return NextResponse.json({ error: 'Invalid JSON payload' }, { status: 400 });
+  }
+
+  const { roomId, userId, text, lang } = payload;
+
+  // Trim and validate input
+  const trimmedRoomId = typeof roomId === 'string' ? roomId.trim() : '';
+  const trimmedUserId = typeof userId === 'string' ? userId.trim() : '';
+  const trimmedText = typeof text === 'string' ? text.trim() : '';
+  const trimmedLang = typeof lang === 'string' ? lang.trim() : '';
+
+  // ISO-639/BCP-47 language code regex (e.g., en, en-US, es, fr, zh-CN)
+  const langCodeRegex = /^[a-z]{2,3}(-[A-Z]{2})?$/;
+
+  // UUID regex
+  const uuidRegex = /^[0-9a-f-]{36}$/i;
+
+  if (!trimmedRoomId || !uuidRegex.test(trimmedRoomId)) {
+    return NextResponse.json({ error: 'Invalid or missing roomId (must be a UUID)' }, { status: 400 });
+  }
+  if (!trimmedUserId || !uuidRegex.test(trimmedUserId)) {
+    return NextResponse.json({ error: 'Invalid or missing userId (must be a UUID)' }, { status: 400 });
+  }
+  if (!trimmedText) {
+    return NextResponse.json({ error: 'Invalid or missing text' }, { status: 400 });
+  }
+  if (!trimmedLang || !langCodeRegex.test(trimmedLang)) {
+    return NextResponse.json({ error: 'Invalid or missing lang (must be ISO-639/BCP-47 code, e.g., en, en-US)' }, { status: 400 });
+  }
+
+  // Check if roomId exists before inserting
+  const { data: roomExists, error: roomError } = await supabase
+    .from('rooms')
+    .select('id')
+    .eq('id', trimmedRoomId)
+    .single();
+  if (roomError) {
+    if (process.env.NODE_ENV !== 'production') {
+      console.error('Error checking room existence:', roomError);
+      return NextResponse.json({ error: 'Database error while checking room existence', details: roomError.message }, { status: 500 });
+    } else {
+      console.error('Error checking room existence');
+      return NextResponse.json({ error: 'Database error while checking room existence' }, { status: 500 });
+    }
+  }
+  if (!roomExists) {
+    return NextResponse.json({ error: 'Room not found' }, { status: 404 });
+  }
+
+  try {
+    const { data, error } = await supabase
+      .from('messages')
+      .insert({
+        room_id: trimmedRoomId,
+        sender_user_id: trimmedUserId,
+        original_text: trimmedText,
+        original_lang: trimmedLang,
+      })
+      .select('id, timestamp')
+      .single();
+
+    if (error) {
+      if (process.env.NODE_ENV !== 'production') {
+        console.error('Error sending message:', error);
+        return NextResponse.json({ error: 'Failed to send message', details: error.message }, { status: 500 });
+      } else {
+        console.error('Error sending message');
+        return NextResponse.json({ error: 'Failed to send message' }, { status: 500 });
+      }
+    }
+
+    return NextResponse.json({ message: 'Message sent successfully', data }, { status: 201 });
+  } catch (e: any) {
+    if (process.env.NODE_ENV !== 'production') {
+      console.error('Unexpected error sending message:', e);
+      return NextResponse.json({ error: 'Unexpected error sending message', details: e.message }, { status: 500 });
+    } else {
+      console.error('Unexpected error sending message');
+      return NextResponse.json({ error: 'Unexpected error sending message' }, { status: 500 });
+    }
+  }
+} 
\ No newline at end of file
diff --git a/app/api/subscribe-messages/route.ts b/app/api/subscribe-messages/route.ts
new file mode 100644
index 0000000..3e816af
--- /dev/null
+++ b/app/api/subscribe-messages/route.ts
@@ -0,0 +1,219 @@
+import { type NextRequest, NextResponse } from 'next/server';
+import { cookies } from 'next/headers';
+import { createEdgeClient } from '@/lib/supabase/server';
+import { RealtimeChannel } from '@supabase/supabase-js';
+
+export const runtime = 'edge';
+
+// Helper function to call Mistral for translation - placeholder
+// In a real app, this would be a robust call to your translation service/route
+async function translateText(text: string, sourceLang: string, targetLang: string): Promise<string> {
+  // This is a placeholder. Ideally, you'd call your existing /api/translate route
+  // or a shared translation utility function.
+  console.log(`TRANSLATE_TEXT_DEBUG: Translating from ${sourceLang} to ${targetLang}: "${text}"`);
+  if (process.env.MISTRAL_API_KEY) {
+    try {
+      const mistralPayload = {
+        model: 'mistral-small-latest', // or your preferred model
+        messages: [
+          {
+            role: 'system',
+            content: `Translate the following medical text from ${sourceLang} to ${targetLang}. Be accurate with medical terminology.`
+          },
+          { role: 'user', content: text }
+        ]
+      };
+
+      const response = await fetch('https://api.mistral.ai/v1/chat/completions', {
+        method: 'POST',
+        headers: {
+          'Content-Type': 'application/json',
+          'Authorization': `Bearer ${process.env.MISTRAL_API_KEY}`,
+        },
+        body: JSON.stringify(mistralPayload),
+      });
+
+      if (!response.ok) {
+        const errorBody = await response.text();
+        console.error('Mistral API Error:', response.status, errorBody);
+        return `[Translation Error: ${response.status}]`;
+      }
+      const result = await response.json();
+      const translated = result.choices[0]?.message?.content.trim();
+      if (translated) {
+          console.log(`TRANSLATE_TEXT_DEBUG: Translated to: "${translated}"`);
+          return translated;
+      } else {
+          console.error('Mistral API Error: Empty translation content', result);
+          return '[Translation Error: Empty content]';
+      }
+    } catch (error: any) {
+      console.error('Error calling Mistral API:', error);
+      return `[Translation Error: ${error.message}]`;
+    }
+  } else {
+    console.warn('MISTRAL_API_KEY not set. Returning original text.');
+    return `[No API Key] ${text}`;
+  }
+}
+
+
+export async function GET(req: NextRequest) {
+  const cookieStore = cookies();
+  const supabase = createEdgeClient(cookieStore);
+  const { searchParams } = new URL(req.url);
+
+  let roomId = searchParams.get('roomId');
+  let myUserId = searchParams.get('myUserId');
+  let myLang = searchParams.get('myLang');
+
+  // Trim and validate
+  roomId = roomId ? roomId.trim() : '';
+  myUserId = myUserId ? myUserId.trim() : '';
+  myLang = myLang ? myLang.trim() : '';
+
+  const uuidRegex = /^[0-9a-f-]{36}$/i;
+  const langCodeRegex = /^[a-z]{2,3}(-[A-Z]{2})?$/;
+
+  if (!roomId || !uuidRegex.test(roomId)) {
+    return NextResponse.json({ error: 'Invalid or missing roomId (must be a UUID)' }, { status: 400 });
+  }
+  if (!myUserId || !uuidRegex.test(myUserId)) {
+    return NextResponse.json({ error: 'Invalid or missing myUserId (must be a UUID)' }, { status: 400 });
+  }
+  if (!myLang || !langCodeRegex.test(myLang)) {
+    return NextResponse.json({ error: 'Invalid or missing myLang (must be ISO-639/BCP-47 code, e.g., en, en-US)' }, { status: 400 });
+  }
+
+  const textEncoder = new TextEncoder();
+  let keepAliveInterval: NodeJS.Timeout;
+
+  const stream = new ReadableStream({
+    async start(controller) {
+      const channelName = `room-${roomId}`;
+      let realtimeChannel: RealtimeChannel;
+      let isControllerClosed = false; // Flag to track controller state
+
+      const handleNewMessage = async (payload: any) => {
+        if (isControllerClosed) {
+          if (process.env.NODE_ENV !== 'production') {
+            console.log('SSE: Controller closed, skipping message processing for payload:', payload);
+          }
+          return;
+        }
+        if (process.env.NODE_ENV !== 'production') {
+          console.log('SSE: New message event from Supabase:', JSON.stringify(payload, null, 2));
+        }
+        const newMessage = payload.new;
+
+        if (newMessage && newMessage.sender_user_id !== myUserId) {
+          if (process.env.NODE_ENV !== 'production') {
+            console.log(`SSE: Processing message ID ${newMessage.id} from other user ${newMessage.sender_user_id}`);
+          }
+          try {
+            let translatedText = newMessage.original_text;
+            if (newMessage.original_lang !== myLang) {
+              if (process.env.NODE_ENV !== 'production') {
+                console.log(`SSE: Message ID ${newMessage.id} needs translation from ${newMessage.original_lang} to ${myLang}.`);
+              }
+              translatedText = await translateText(newMessage.original_text, newMessage.original_lang, myLang);
+              if (process.env.NODE_ENV !== 'production') {
+                console.log(`SSE: Message ID ${newMessage.id} translation result: "${translatedText.substring(0, 100)}..."`);
+              }
+            }
+
+            const messageData = {
+              id: newMessage.id,
+              from: newMessage.sender_user_id,
+              originalText: newMessage.original_text,
+              originalLang: newMessage.original_lang,
+              translatedText: translatedText,
+              myLang: myLang,
+              timestamp: newMessage.timestamp,
+            };
+            
+            const eventString = `data: ${JSON.stringify(messageData)}\n\n`;
+            if (process.env.NODE_ENV !== 'production') {
+              console.log(`SSE: Enqueuing event for message ID ${newMessage.id}: ${eventString.trim()}`);
+            }
+            controller.enqueue(textEncoder.encode(eventString));
+            if (process.env.NODE_ENV !== 'production') {
+              console.log(`SSE: Successfully enqueued event for message ID ${newMessage.id}`);
+            }
+
+          } catch (error: any) {
+            if (process.env.NODE_ENV !== 'production') {
+              console.error(`SSE: Error processing message ID ${newMessage.id}:`, error);
+            }
+          }
+        } else if (newMessage) {
+          if (process.env.NODE_ENV !== 'production') {
+            console.log(`SSE: Ignoring message ID ${newMessage.id} from self (user ${myUserId})`);
+          }
+        } else {
+          if (process.env.NODE_ENV !== 'production') {
+            console.warn('SSE: Received payload.new but it was undefined or null.', payload);
+          }
+        }
+      };
+
+      realtimeChannel = supabase
+        .channel(channelName)
+        .on(
+          'postgres_changes',
+          { event: 'INSERT', schema: 'public', table: 'messages', filter: `room_id=eq.${roomId}` },
+          handleNewMessage
+        )
+        .subscribe((status) => {
+          if (status === 'SUBSCRIBED') {
+            if (process.env.NODE_ENV !== 'production') {
+              console.log(`Successfully subscribed to Supabase Realtime channel: ${channelName}`);
+            }
+          } else if (status === 'CHANNEL_ERROR' || status === 'TIMED_OUT') {
+            if (process.env.NODE_ENV !== 'production') {
+              console.error(`Error status for Supabase Realtime channel ${channelName}: ${status}`);
+            }
+            if (!isControllerClosed) {
+              supabase.removeChannel(realtimeChannel);
+              controller.error(new Error(`Supabase Realtime channel error: ${status}`));
+              controller.close();
+              isControllerClosed = true;
+              clearInterval(keepAliveInterval);
+            }
+          } else {
+            if (process.env.NODE_ENV !== 'production') {
+              console.log(`Supabase Realtime status for ${channelName}: ${status}`);
+            }
+          }
+        });
+
+      // Keep-alive: send a comment event every 10 seconds to prevent timeout
+      keepAliveInterval = setInterval(() => {
+        if (!isControllerClosed) {
+          controller.enqueue(textEncoder.encode(':keepalive\n\n'));
+        }
+      }, 10000);
+
+      // Cleanup on stream cancellation (client disconnects)
+      return () => {
+        console.log(`Client disconnected. Unsubscribing from Supabase Realtime channel: ${channelName}`);
+        clearInterval(keepAliveInterval);
+        if (realtimeChannel) {
+          supabase.removeChannel(realtimeChannel);
+        }
+        if (!isControllerClosed) {
+          // controller.close(); // Controller might be closed by client or by an error already
+          isControllerClosed = true;
+        }
+      };
+    },
+  });
+
+  return new Response(stream, {
+    headers: {
+      'Content-Type': 'text/event-stream',
+      'Cache-Control': 'no-cache',
+      'Connection': 'keep-alive',
+    },
+  });
+}
\ No newline at end of file
diff --git a/lib/supabase/server.ts b/lib/supabase/server.ts
new file mode 100644
index 0000000..266a736
--- /dev/null
+++ b/lib/supabase/server.ts
@@ -0,0 +1,55 @@
+/**
+ * Creates a Supabase client for use in Next.js Edge Runtime API routes (server-side).
+ * It configures the client with cookie-based authentication, using the provided `cookies()`
+ * from `next/headers` to manage session information.
+ *
+ * @param cookieStore The Next.js `RequestCookies` object (from `cookies()`).
+ * @returns A Supabase client instance configured for server-side Edge operations.
+ */
+import { createServerClient, type CookieOptions } from '@supabase/ssr';
+import { cookies } from 'next/headers';
+
+export function createEdgeClient(cookieStore: ReturnType<typeof cookies>) {
+  const supabaseUrl = process.env.NEXT_PUBLIC_SUPABASE_URL;
+  const supabaseAnonKey = process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY;
+
+  if (!supabaseUrl) {
+    throw new Error('Missing environment variable: NEXT_PUBLIC_SUPABASE_URL');
+  }
+  if (!supabaseAnonKey) {
+    throw new Error('Missing environment variable: NEXT_PUBLIC_SUPABASE_ANON_KEY');
+  }
+
+  try {
+    return createServerClient(
+      supabaseUrl,
+      supabaseAnonKey,
+      {
+        cookies: {
+          get(name: string) {
+            return cookieStore.get(name)?.value;
+          },
+          set(name: string, value: string, options: CookieOptions) {
+            cookieStore.set({ name, value, ...options });
+          },
+          remove(name: string, options: CookieOptions) {
+            // Pass all relevant options for cookie removal (excluding 'expires')
+            cookieStore.delete({
+              name,
+              path: options.path,
+              domain: options.domain,
+              maxAge: options.maxAge,
+              sameSite: options.sameSite,
+              secure: options.secure,
+              httpOnly: options.httpOnly,
+            });
+          },
+        },
+      }
+    );
+  } catch (err) {
+    const errMsg = err instanceof Error ? `${err.message}\n${err.stack}` : String(err);
+    console.error('Error creating Supabase client:', errMsg);
+    throw new Error('Failed to create Supabase client: ' + errMsg);
+  }
+} 
\ No newline at end of file
diff --git a/package-lock.json b/package-lock.json
index 5c81086..91d2844 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -8,6 +8,8 @@
       "name": "health-translate-mini",
       "version": "0.1.0",
       "dependencies": {
+        "@supabase/ssr": "^0.4.0",
+        "@supabase/supabase-js": "^2.44.4",
         "lucide-react": "^0.411.0",
         "next": "14.2.5",
         "react": "^18",
@@ -470,6 +472,18 @@
         "node": ">=14"
       }
     },
+    "node_modules/@rollup/rollup-linux-x64-gnu": {
+      "version": "4.41.0",
+      "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-x64-gnu/-/rollup-linux-x64-gnu-4.41.0.tgz",
+      "integrity": "sha512-XMLeKjyH8NsEDCRptf6LO8lJk23o9wvB+dJwcXMaH6ZQbbkHu2dbGIUindbMtRN6ux1xKi16iXWu6q9mu7gDhQ==",
+      "cpu": [
+        "x64"
+      ],
+      "optional": true,
+      "os": [
+        "linux"
+      ]
+    },
     "node_modules/@rtsao/scc": {
       "version": "1.1.0",
       "resolved": "https://registry.npmjs.org/@rtsao/scc/-/scc-1.1.0.tgz",
@@ -482,6 +496,87 @@
       "integrity": "sha512-zxnHvoMQVqewTJr/W4pKjF0bMGiKJv1WX7bSrkl46Hg0QjESbzBROWK0Wg4RphzSOS5Jiy7eFimmM3UgMrMZbQ==",
       "dev": true
     },
+    "node_modules/@supabase/auth-js": {
+      "version": "2.69.1",
+      "resolved": "https://registry.npmjs.org/@supabase/auth-js/-/auth-js-2.69.1.tgz",
+      "integrity": "sha512-FILtt5WjCNzmReeRLq5wRs3iShwmnWgBvxHfqapC/VoljJl+W8hDAyFmf1NVw3zH+ZjZ05AKxiKxVeb0HNWRMQ==",
+      "dependencies": {
+        "@supabase/node-fetch": "^2.6.14"
+      }
+    },
+    "node_modules/@supabase/functions-js": {
+      "version": "2.4.4",
+      "resolved": "https://registry.npmjs.org/@supabase/functions-js/-/functions-js-2.4.4.tgz",
+      "integrity": "sha512-WL2p6r4AXNGwop7iwvul2BvOtuJ1YQy8EbOd0dhG1oN1q8el/BIRSFCFnWAMM/vJJlHWLi4ad22sKbKr9mvjoA==",
+      "dependencies": {
+        "@supabase/node-fetch": "^2.6.14"
+      }
+    },
+    "node_modules/@supabase/node-fetch": {
+      "version": "2.6.15",
+      "resolved": "https://registry.npmjs.org/@supabase/node-fetch/-/node-fetch-2.6.15.tgz",
+      "integrity": "sha512-1ibVeYUacxWYi9i0cf5efil6adJ9WRyZBLivgjs+AUpewx1F3xPi7gLgaASI2SmIQxPoCEjAsLAzKPgMJVgOUQ==",
+      "dependencies": {
+        "whatwg-url": "^5.0.0"
+      },
+      "engines": {
+        "node": "4.x || >=6.0.0"
+      }
+    },
+    "node_modules/@supabase/postgrest-js": {
+      "version": "1.19.4",
+      "resolved": "https://registry.npmjs.org/@supabase/postgrest-js/-/postgrest-js-1.19.4.tgz",
+      "integrity": "sha512-O4soKqKtZIW3olqmbXXbKugUtByD2jPa8kL2m2c1oozAO11uCcGrRhkZL0kVxjBLrXHE0mdSkFsMj7jDSfyNpw==",
+      "dependencies": {
+        "@supabase/node-fetch": "^2.6.14"
+      }
+    },
+    "node_modules/@supabase/realtime-js": {
+      "version": "2.11.2",
+      "resolved": "https://registry.npmjs.org/@supabase/realtime-js/-/realtime-js-2.11.2.tgz",
+      "integrity": "sha512-u/XeuL2Y0QEhXSoIPZZwR6wMXgB+RQbJzG9VErA3VghVt7uRfSVsjeqd7m5GhX3JR6dM/WRmLbVR8URpDWG4+w==",
+      "dependencies": {
+        "@supabase/node-fetch": "^2.6.14",
+        "@types/phoenix": "^1.5.4",
+        "@types/ws": "^8.5.10",
+        "ws": "^8.18.0"
+      }
+    },
+    "node_modules/@supabase/ssr": {
+      "version": "0.4.1",
+      "resolved": "https://registry.npmjs.org/@supabase/ssr/-/ssr-0.4.1.tgz",
+      "integrity": "sha512-000i7y4ITXjXU0T1JytZYU33VbUNklX9YN47hCweaLKsTBAEigJJJCeq3G+/IiwEggBt58Vu0KQ3UGXON7OmDQ==",
+      "dependencies": {
+        "cookie": "^0.6.0"
+      },
+      "optionalDependencies": {
+        "@rollup/rollup-linux-x64-gnu": "^4.9.5"
+      },
+      "peerDependencies": {
+        "@supabase/supabase-js": "^2.43.4"
+      }
+    },
+    "node_modules/@supabase/storage-js": {
+      "version": "2.7.1",
+      "resolved": "https://registry.npmjs.org/@supabase/storage-js/-/storage-js-2.7.1.tgz",
+      "integrity": "sha512-asYHcyDR1fKqrMpytAS1zjyEfvxuOIp1CIXX7ji4lHHcJKqyk+sLl/Vxgm4sN6u8zvuUtae9e4kDxQP2qrwWBA==",
+      "dependencies": {
+        "@supabase/node-fetch": "^2.6.14"
+      }
+    },
+    "node_modules/@supabase/supabase-js": {
+      "version": "2.49.4",
+      "resolved": "https://registry.npmjs.org/@supabase/supabase-js/-/supabase-js-2.49.4.tgz",
+      "integrity": "sha512-jUF0uRUmS8BKt37t01qaZ88H9yV1mbGYnqLeuFWLcdV+x1P4fl0yP9DGtaEhFPZcwSom7u16GkLEH9QJZOqOkw==",
+      "dependencies": {
+        "@supabase/auth-js": "2.69.1",
+        "@supabase/functions-js": "2.4.4",
+        "@supabase/node-fetch": "2.6.15",
+        "@supabase/postgrest-js": "1.19.4",
+        "@supabase/realtime-js": "2.11.2",
+        "@supabase/storage-js": "2.7.1"
+      }
+    },
     "node_modules/@swc/counter": {
       "version": "0.1.3",
       "resolved": "https://registry.npmjs.org/@swc/counter/-/counter-0.1.3.tgz",
@@ -516,11 +611,15 @@
       "version": "20.17.47",
       "resolved": "https://registry.npmjs.org/@types/node/-/node-20.17.47.tgz",
       "integrity": "sha512-3dLX0Upo1v7RvUimvxLeXqwrfyKxUINk0EAM83swP2mlSUcwV73sZy8XhNz8bcZ3VbsfQyC/y6jRdL5tgCNpDQ==",
-      "dev": true,
       "dependencies": {
         "undici-types": "~6.19.2"
       }
     },
+    "node_modules/@types/phoenix": {
+      "version": "1.6.6",
+      "resolved": "https://registry.npmjs.org/@types/phoenix/-/phoenix-1.6.6.tgz",
+      "integrity": "sha512-PIzZZlEppgrpoT2QgbnDU+MMzuR6BbCjllj0bM70lWoejMeNJAxCchxnv7J3XFkI8MpygtRpzXrIlmWUBclP5A=="
+    },
     "node_modules/@types/prop-types": {
       "version": "15.7.14",
       "resolved": "https://registry.npmjs.org/@types/prop-types/-/prop-types-15.7.14.tgz",
@@ -556,6 +655,14 @@
         "tailwindcss": "*"
       }
     },
+    "node_modules/@types/ws": {
+      "version": "8.18.1",
+      "resolved": "https://registry.npmjs.org/@types/ws/-/ws-8.18.1.tgz",
+      "integrity": "sha512-ThVF6DCVhA8kUGy+aazFQ4kXQ7E1Ty7A3ypFOe0IcJV8O/M511G99AW24irKrW56Wt44yG9+ij8FaqoBGkuBXg==",
+      "dependencies": {
+        "@types/node": "*"
+      }
+    },
     "node_modules/@typescript-eslint/parser": {
       "version": "7.2.0",
       "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-7.2.0.tgz",
@@ -1515,6 +1622,14 @@
       "integrity": "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==",
       "dev": true
     },
+    "node_modules/cookie": {
+      "version": "0.6.0",
+      "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.6.0.tgz",
+      "integrity": "sha512-U71cyTamuh1CRNCfpGY6to28lxvNwPG4Guz/EVjgf3Jmzv0vlDp1atT9eS5dDjMYHucpHbWns6Lwf3BKz6svdw==",
+      "engines": {
+        "node": ">= 0.6"
+      }
+    },
     "node_modules/cross-spawn": {
       "version": "7.0.6",
       "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.6.tgz",
@@ -5098,6 +5213,11 @@
         "node": ">=8.0"
       }
     },
+    "node_modules/tr46": {
+      "version": "0.0.3",
+      "resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz",
+      "integrity": "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw=="
+    },
     "node_modules/ts-api-utils": {
       "version": "1.4.3",
       "resolved": "https://registry.npmjs.org/ts-api-utils/-/ts-api-utils-1.4.3.tgz",
@@ -5265,8 +5385,7 @@
     "node_modules/undici-types": {
       "version": "6.19.8",
       "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.19.8.tgz",
-      "integrity": "sha512-ve2KP6f/JnbPBFyobGHuerC9g1FYGn/F8n1LWTwNxCEzd6IfqTwUQcNXgEtmmQ6DlRrC1hrSrBnCZPokRrDHjw==",
-      "dev": true
+      "integrity": "sha512-ve2KP6f/JnbPBFyobGHuerC9g1FYGn/F8n1LWTwNxCEzd6IfqTwUQcNXgEtmmQ6DlRrC1hrSrBnCZPokRrDHjw=="
     },
     "node_modules/unrs-resolver": {
       "version": "1.7.2",
@@ -5345,6 +5464,20 @@
       "integrity": "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==",
       "dev": true
     },
+    "node_modules/webidl-conversions": {
+      "version": "3.0.1",
+      "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz",
+      "integrity": "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ=="
+    },
+    "node_modules/whatwg-url": {
+      "version": "5.0.0",
+      "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz",
+      "integrity": "sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==",
+      "dependencies": {
+        "tr46": "~0.0.3",
+        "webidl-conversions": "^3.0.0"
+      }
+    },
     "node_modules/which": {
       "version": "2.0.2",
       "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz",
@@ -5554,6 +5687,26 @@
       "integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==",
       "dev": true
     },
+    "node_modules/ws": {
+      "version": "8.18.2",
+      "resolved": "https://registry.npmjs.org/ws/-/ws-8.18.2.tgz",
+      "integrity": "sha512-DMricUmwGZUVr++AEAe2uiVM7UoO9MAVZMDu05UQOaUII0lp+zOzLLU4Xqh/JvTqklB1T4uELaaPBKyjE1r4fQ==",
+      "engines": {
+        "node": ">=10.0.0"
+      },
+      "peerDependencies": {
+        "bufferutil": "^4.0.1",
+        "utf-8-validate": ">=5.0.2"
+      },
+      "peerDependenciesMeta": {
+        "bufferutil": {
+          "optional": true
+        },
+        "utf-8-validate": {
+          "optional": true
+        }
+      }
+    },
     "node_modules/yaml": {
       "version": "2.8.0",
       "resolved": "https://registry.npmjs.org/yaml/-/yaml-2.8.0.tgz",
diff --git a/package.json b/package.json
index fadb8a7..8c22343 100644
--- a/package.json
+++ b/package.json
@@ -9,6 +9,8 @@
     "lint": "next lint"
   },
   "dependencies": {
+    "@supabase/ssr": "^0.6.1",
+    "@supabase/supabase-js": "^2.49.4",
     "lucide-react": "^0.411.0",
     "next": "14.2.5",
     "react": "^18",


Reviews:
user: login: coderabbitai[bot]
body: **Actionable comments posted: 3**

<details>
<summary>🧹 Nitpick comments (2)</summary><blockquote>

<details>
<summary>README.md (1)</summary><blockquote>

`125-128`: **Inconsistent list formatting.**

The list items for new file descriptions use dashes (-) while the rest of the document uses asterisks (*) for unordered lists. This inconsistency was flagged by markdown linting.

Change the list style to maintain consistency:

```diff
-<!-- file_end -->- **`lib/supabase/server.ts`**: Utility for creating Supabase Edge client.
-<!-- file_end -->- **`app/api/room/route.ts`**: Edge function for creating/joining chat rooms.
-<!-- file_end -->- **`app/api/send-message/route.ts`**: Edge function for sending chat messages.
-<!-- file_end -->- **`app/api/subscribe-messages/route.ts`**: Edge function for subscribing to chat messages via SSE.
+* **`lib/supabase/server.ts`**: Utility for creating Supabase Edge client.
+* **`app/api/room/route.ts`**: Edge function for creating/joining chat rooms.
+* **`app/api/send-message/route.ts`**: Edge function for sending chat messages.
+* **`app/api/subscribe-messages/route.ts`**: Edge function for subscribing to chat messages via SSE.
```

<details>
<summary>🧰 Tools</summary>

<details>
<summary>🪛 LanguageTool</summary>

[uncategorized] ~125-~125: Loose punctuation mark.
Context: ...v.local`. - **`lib/supabase/server.ts`**: Utility for creating Supabase Edge clie...

(UNLIKELY_OPENING_PUNCTUATION)

---

[uncategorized] ~126-~126: Loose punctuation mark.
Context: ...ge client. - **`app/api/room/route.ts`**: Edge function for creating/joining chat...

(UNLIKELY_OPENING_PUNCTUATION)

---

[uncategorized] ~127-~127: Loose punctuation mark.
Context: ...s. - **`app/api/send-message/route.ts`**: Edge function for sending chat messages...

(UNLIKELY_OPENING_PUNCTUATION)

---

[uncategorized] ~128-~128: Loose punctuation mark.
Context: ...*`app/api/subscribe-messages/route.ts`**: Edge function for subscribing to chat m...

(UNLIKELY_OPENING_PUNCTUATION)

</details>
<details>
<summary>🪛 markdownlint-cli2 (0.17.2)</summary>

125-125: Unordered list style
Expected: asterisk; Actual: dash

(MD004, ul-style)

---

126-126: Unordered list style
Expected: asterisk; Actual: dash

(MD004, ul-style)

---

127-127: Unordered list style
Expected: asterisk; Actual: dash

(MD004, ul-style)

---

128-128: Unordered list style
Expected: asterisk; Actual: dash

(MD004, ul-style)

</details>

</details>

</blockquote></details>
<details>
<summary>app/api/subscribe-messages/route.ts (1)</summary><blockquote>

`88-90`: **`NodeJS.Timeout` type leaks Node globals into Edge build**

Edge runtime is compiled with `lib: ["dom"]` by default; `NodeJS` types are absent, triggering `Cannot find namespace 'NodeJS'` unless `@types/node` is force-installed (undesirable for edge bundles).

```diff
-let keepAliveInterval: NodeJS.Timeout;
+let keepAliveInterval: ReturnType<typeof setInterval>;
```

This keeps the correct typing without importing Node globals.

</blockquote></details>

</blockquote></details>

<details>
<summary>📜 Review details</summary>

**Configuration used: CodeRabbit UI**
**Review profile: CHILL**
**Plan: Pro**


<details>
<summary>📥 Commits</summary>

Reviewing files that changed from the base of the PR and between 425082be524ce0c6250e612a378274d4563f4689 and 44e1616ec8515e70ac9278ea509724ebc8da44ce.

</details>

<details>
<summary>⛔ Files ignored due to path filters (1)</summary>

* `package-lock.json` is excluded by `!**/package-lock.json`

</details>

<details>
<summary>📒 Files selected for processing (8)</summary>

* `.cursorrules` (1 hunks)
* `.env.example` (1 hunks)
* `README.md` (4 hunks)
* `app/api/room/route.ts` (1 hunks)
* `app/api/send-message/route.ts` (1 hunks)
* `app/api/subscribe-messages/route.ts` (1 hunks)
* `lib/supabase/server.ts` (1 hunks)
* `package.json` (1 hunks)

</details>

<details>
<summary>🧰 Additional context used</summary>

<details>
<summary>🪛 LanguageTool</summary>

<details>
<summary>README.md</summary>

[uncategorized] ~46-~46: Loose punctuation mark.
Context: ...ge.tsx     ```     *   `MISTRAL_API_KEY`: Your API key for Mistral AI.     *   `E...

(UNLIKELY_OPENING_PUNCTUATION)

---

[uncategorized] ~47-~47: Loose punctuation mark.
Context: ...for Mistral AI.     *   `ELEVEN_API_KEY`: Your API key for ElevenLabs.     *   `N...

(UNLIKELY_OPENING_PUNCTUATION)

---

[uncategorized] ~48-~48: Loose punctuation mark.
Context: ...Labs.     *   `NEXT_PUBLIC_SUPABASE_URL`: Your Supabase project URL.     *   `NEX...

(UNLIKELY_OPENING_PUNCTUATION)

---

[uncategorized] ~49-~49: Loose punctuation mark.
Context: ...     *   `NEXT_PUBLIC_SUPABASE_ANON_KEY`: Your Supabase project anonymous key.  >...

(UNLIKELY_OPENING_PUNCTUATION)

---

[uncategorized] ~125-~125: Loose punctuation mark.
Context: ...v.local`. - **`lib/supabase/server.ts`**: Utility for creating Supabase Edge clie...

(UNLIKELY_OPENING_PUNCTUATION)

---

[uncategorized] ~126-~126: Loose punctuation mark.
Context: ...ge client. - **`app/api/room/route.ts`**: Edge function for creating/joining chat...

(UNLIKELY_OPENING_PUNCTUATION)

---

[uncategorized] ~127-~127: Loose punctuation mark.
Context: ...s. - **`app/api/send-message/route.ts`**: Edge function for sending chat messages...

(UNLIKELY_OPENING_PUNCTUATION)

---

[uncategorized] ~128-~128: Loose punctuation mark.
Context: ...*`app/api/subscribe-messages/route.ts`**: Edge function for subscribing to chat m...

(UNLIKELY_OPENING_PUNCTUATION)

</details>

</details>
<details>
<summary>🪛 markdownlint-cli2 (0.17.2)</summary>

<details>
<summary>README.md</summary>

125-125: Unordered list style
Expected: asterisk; Actual: dash

(MD004, ul-style)

---

126-126: Unordered list style
Expected: asterisk; Actual: dash

(MD004, ul-style)

---

127-127: Unordered list style
Expected: asterisk; Actual: dash

(MD004, ul-style)

---

128-128: Unordered list style
Expected: asterisk; Actual: dash

(MD004, ul-style)

</details>

</details>

</details>

<details>
<summary>🔇 Additional comments (8)</summary><blockquote>

<details>
<summary>package.json (1)</summary>

`12-13`: **Supabase dependencies look good!**

The addition of Supabase dependencies (`@supabase/ssr` and `@supabase/supabase-js`) is a good choice for implementing multi-user chat functionality. These versions are appropriate for the intended use case.

</details>
<details>
<summary>.env.example (1)</summary>

`6-8`: **Environment variables properly configured for Supabase integration.**

The `NEXT_PUBLIC_` prefix correctly follows Next.js conventions for client-exposed variables. The placeholder values clearly indicate what needs to be replaced.


Remember that exposing the Supabase anon key client-side requires proper Row Level Security (RLS) policies in your Supabase project. Have you set up RLS policies to protect your data?

</details>
<details>
<summary>.cursorrules (1)</summary>

`27-30`: **Configuration correctly updated for Supabase integration.**

The environment variable placeholders have been properly updated and the `NEXT_PUBLIC_` prefix aligns with Next.js conventions and matches the changes in `.env.example`.

</details>
<details>
<summary>README.md (4)</summary>

`42-43`: **Environment variable examples correctly documented.**

The Supabase environment variables match those in `.env.example`, maintaining consistency across the project.

---

`48-51`: **Good security documentation for Supabase integration.**

The security note about `NEXT_PUBLIC_SUPABASE_ANON_KEY` is important and correctly emphasizes the need for Row Level Security policies.

<details>
<summary>🧰 Tools</summary>

<details>
<summary>🪛 LanguageTool</summary>

[uncategorized] ~48-~48: Loose punctuation mark.
Context: ...Labs.     *   `NEXT_PUBLIC_SUPABASE_URL`: Your Supabase project URL.     *   `NEX...

(UNLIKELY_OPENING_PUNCTUATION)

---

[uncategorized] ~49-~49: Loose punctuation mark.
Context: ...     *   `NEXT_PUBLIC_SUPABASE_ANON_KEY`: Your Supabase project anonymous key.  >...

(UNLIKELY_OPENING_PUNCTUATION)

</details>

</details>

---

`83-88`: **New API routes for chat functionality well-structured.**

The organization of routes for room management, message sending, and message subscription follows good practices for API design.

---

`99-101`: **Supabase utility location follows project conventions.**

Placing the Supabase client utility in the `lib` directory is a good architectural choice.

</details>
<details>
<summary>app/api/room/route.ts (1)</summary>

`32-37`: **Verify Supabase unique-violation code**

You’re matching Postgres code `23505`, but Supabase JS v2 surfaces `error.code` only for PostgREST errors; for SQL constraint violations it sets `error.details` & `error.message`.  
Please confirm with:

```ts
if (error && error.code === '23505') { /* … */ }
```

If this check never triggers, fallback to inspecting `error.message?.includes('duplicate key value')`.

</details>

</blockquote></details>

</details>

<!-- This is an auto-generated comment by CodeRabbit for review status -->
state: COMMENTED
author_association: NONE
submitted_at: 2025-05-19T11:49:08Z

Review comments:
diff_hunk: @@ -0,0 +1,55 @@
+/**
+ * Creates a Supabase client for use in Next.js Edge Runtime API routes (server-side).
+ * It configures the client with cookie-based authentication, using the provided `cookies()`
+ * from `next/headers` to manage session information.
+ *
+ * @param cookieStore The Next.js `RequestCookies` object (from `cookies()`).
+ * @returns A Supabase client instance configured for server-side Edge operations.
+ */
+import { createServerClient, type CookieOptions } from '@supabase/ssr';
+import { cookies } from 'next/headers';
+
+export function createEdgeClient(cookieStore: ReturnType<typeof cookies>) {
+  const supabaseUrl = process.env.NEXT_PUBLIC_SUPABASE_URL;
+  const supabaseAnonKey = process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY;
+
+  if (!supabaseUrl) {
+    throw new Error('Missing environment variable: NEXT_PUBLIC_SUPABASE_URL');
+  }
+  if (!supabaseAnonKey) {
+    throw new Error('Missing environment variable: NEXT_PUBLIC_SUPABASE_ANON_KEY');
+  }
+
+  try {
+    return createServerClient(
+      supabaseUrl,
+      supabaseAnonKey,
+      {
+        cookies: {
+          get(name: string) {
+            return cookieStore.get(name)?.value;
+          },
+          set(name: string, value: string, options: CookieOptions) {
+            cookieStore.set({ name, value, ...options });
+          },
+          remove(name: string, options: CookieOptions) {
+            // Pass all relevant options for cookie removal (excluding 'expires')
+            cookieStore.delete({
+              name,
+              path: options.path,
+              domain: options.domain,
+              maxAge: options.maxAge,
+              sameSite: options.sameSite,
+              secure: options.secure,
+              httpOnly: options.httpOnly,
+            });
path: lib/supabase/server.ts
user: login: coderabbitai[bot]
body: _⚠️ Potential issue_

**Incorrect `cookies()` API usage breaks compilation & runtime**

`cookieStore.set` and `cookieStore.delete` expect positional arguments, not an object literal.  
The current calls will:

1. Fail type-checking (TS2345).
2. Throw at runtime in Edge because the overload cannot be resolved.

Fix by passing `name`, `value`, and `options`/`options?` positionally:

```diff
- set(name: string, value: string, options: CookieOptions) {
-   cookieStore.set({ name, value, ...options });
- },
- remove(name: string, options: CookieOptions) {
-   cookieStore.delete({
-     name,
-     path: options.path,
-     domain: options.domain,
-     maxAge: options.maxAge,
-     sameSite: options.sameSite,
-     secure: options.secure,
-     httpOnly: options.httpOnly,
-   });
- },
+ set(name: string, value: string, options: CookieOptions) {
+   cookieStore.set(name, value, options);
+ },
+ remove(name: string, options: CookieOptions) {
+   cookieStore.delete(name, options);
+ },
```



<!-- suggestion_start -->

<details>
<summary>📝 Committable suggestion</summary>

> ‼️ **IMPORTANT**
> Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

```suggestion
          get(name: string) {
            return cookieStore.get(name)?.value;
          },
          set(name: string, value: string, options: CookieOptions) {
-            cookieStore.set({ name, value, ...options });
+            cookieStore.set(name, value, options);
          },
          remove(name: string, options: CookieOptions) {
-            // Pass all relevant options for cookie removal (excluding 'expires')
-            cookieStore.delete({
-              name,
-              path: options.path,
-              domain: options.domain,
-              maxAge: options.maxAge,
-              sameSite: options.sameSite,
-              secure: options.secure,
-              httpOnly: options.httpOnly,
-            });
+            // Pass all relevant options for cookie removal (excluding 'expires')
+            cookieStore.delete(name, options);
          },
```

</details>

<!-- suggestion_end -->

<details>
<summary>🤖 Prompt for AI Agents</summary>

```
In lib/supabase/server.ts around lines 29 to 45, the calls to cookieStore.set
and cookieStore.delete incorrectly pass an object literal instead of positional
arguments, causing TypeScript errors and runtime failures. Fix this by changing
cookieStore.set to pass name, value, and options as separate positional
arguments, and cookieStore.delete to pass name and options positionally,
ensuring options is passed as an optional parameter where appropriate.
```

</details>

<!-- This is an auto-generated comment by CodeRabbit -->
created_at: 2025-05-19T11:49:08Z
author_association: NONE
diff_hunk: @@ -0,0 +1,104 @@
+import { type NextRequest, NextResponse } from 'next/server';
+import { cookies } from 'next/headers';
+import { createEdgeClient } from '@/lib/supabase/server';
+
+export const runtime = 'edge';
+
+interface SendMessagePayload {
+  roomId: string;
+  userId: string;
+  text: string;
+  lang: string;
+}
+
+// POST /api/send-message - Send a message to a room
+export async function POST(req: NextRequest) {
+  const cookieStore = cookies();
+  const supabase = createEdgeClient(cookieStore);
+
+  let payload: SendMessagePayload;
+  try {
+    payload = await req.json();
+  } catch (error) {
+    return NextResponse.json({ error: 'Invalid JSON payload' }, { status: 400 });
+  }
+
+  const { roomId, userId, text, lang } = payload;
+
+  // Trim and validate input
+  const trimmedRoomId = typeof roomId === 'string' ? roomId.trim() : '';
+  const trimmedUserId = typeof userId === 'string' ? userId.trim() : '';
+  const trimmedText = typeof text === 'string' ? text.trim() : '';
+  const trimmedLang = typeof lang === 'string' ? lang.trim() : '';
+
+  // ISO-639/BCP-47 language code regex (e.g., en, en-US, es, fr, zh-CN)
+  const langCodeRegex = /^[a-z]{2,3}(-[A-Z]{2})?$/;
+
+  // UUID regex
+  const uuidRegex = /^[0-9a-f-]{36}$/i;
+
+  if (!trimmedRoomId || !uuidRegex.test(trimmedRoomId)) {
+    return NextResponse.json({ error: 'Invalid or missing roomId (must be a UUID)' }, { status: 400 });
+  }
+  if (!trimmedUserId || !uuidRegex.test(trimmedUserId)) {
+    return NextResponse.json({ error: 'Invalid or missing userId (must be a UUID)' }, { status: 400 });
+  }
+  if (!trimmedText) {
+    return NextResponse.json({ error: 'Invalid or missing text' }, { status: 400 });
+  }
+  if (!trimmedLang || !langCodeRegex.test(trimmedLang)) {
+    return NextResponse.json({ error: 'Invalid or missing lang (must be ISO-639/BCP-47 code, e.g., en, en-US)' }, { status: 400 });
+  }
+
+  // Check if roomId exists before inserting
+  const { data: roomExists, error: roomError } = await supabase
+    .from('rooms')
+    .select('id')
+    .eq('id', trimmedRoomId)
+    .single();
+  if (roomError) {
+    if (process.env.NODE_ENV !== 'production') {
+      console.error('Error checking room existence:', roomError);
+      return NextResponse.json({ error: 'Database error while checking room existence', details: roomError.message }, { status: 500 });
+    } else {
+      console.error('Error checking room existence');
+      return NextResponse.json({ error: 'Database error while checking room existence' }, { status: 500 });
+    }
+  }
+  if (!roomExists) {
+    return NextResponse.json({ error: 'Room not found' }, { status: 404 });
+  }
+
path: app/api/send-message/route.ts
user: login: coderabbitai[bot]
body: _⚠️ Potential issue_

**`room` existence check always yields 500 – use `.maybeSingle()` or handle “no rows” code**

`supabase.from('rooms').select(...).single()` returns an error with code `PGRST116` when no row matches, so the `roomError` branch will fire and you’ll return **500** instead of the intended **404**.  
Switch to `.maybeSingle()` (v2) or inspect the error code:

```diff
-const { data: roomExists, error: roomError } = await supabase
-  .from('rooms')
-  .select('id')
-  .eq('id', trimmedRoomId)
-  .single();
+const { data: roomExists, error: roomError } = await supabase
+  .from('rooms')
+  .select('id')
+  .eq('id', trimmedRoomId)
+  .maybeSingle(); // ← no error when zero rows
```

```ts
if (roomError) {
  // genuine DB failure – retain 500 logic
}
if (!roomExists) {
  return NextResponse.json({ error: 'Room not found' }, { status: 404 });
}
```
This prevents false 500s and correctly surfaces 404s.

<details>
<summary>🤖 Prompt for AI Agents</summary>

```
In app/api/send-message/route.ts around lines 53 to 71, the current use of
.single() causes a 500 error when no room matches, instead of returning a 404.
Replace .single() with .maybeSingle() to avoid treating "no rows" as an error,
or alternatively check the error code to distinguish between genuine DB errors
and no results. Then, keep the 500 response for real errors and return a 404
response when no room is found.
```

</details>

<!-- This is an auto-generated comment by CodeRabbit -->
created_at: 2025-05-19T11:49:08Z
author_association: NONE
diff_hunk: @@ -0,0 +1,104 @@
+import { type NextRequest, NextResponse } from 'next/server';
+import { cookies } from 'next/headers';
+import { createEdgeClient } from '@/lib/supabase/server';
+
+export const runtime = 'edge';
+
+interface SendMessagePayload {
+  roomId: string;
+  userId: string;
+  text: string;
+  lang: string;
+}
+
+// POST /api/send-message - Send a message to a room
+export async function POST(req: NextRequest) {
+  const cookieStore = cookies();
+  const supabase = createEdgeClient(cookieStore);
+
+  let payload: SendMessagePayload;
+  try {
+    payload = await req.json();
+  } catch (error) {
+    return NextResponse.json({ error: 'Invalid JSON payload' }, { status: 400 });
+  }
+
+  const { roomId, userId, text, lang } = payload;
+
+  // Trim and validate input
+  const trimmedRoomId = typeof roomId === 'string' ? roomId.trim() : '';
+  const trimmedUserId = typeof userId === 'string' ? userId.trim() : '';
+  const trimmedText = typeof text === 'string' ? text.trim() : '';
+  const trimmedLang = typeof lang === 'string' ? lang.trim() : '';
+
+  // ISO-639/BCP-47 language code regex (e.g., en, en-US, es, fr, zh-CN)
+  const langCodeRegex = /^[a-z]{2,3}(-[A-Z]{2})?$/;
+
+  // UUID regex
+  const uuidRegex = /^[0-9a-f-]{36}$/i;
+
+  if (!trimmedRoomId || !uuidRegex.test(trimmedRoomId)) {
+    return NextResponse.json({ error: 'Invalid or missing roomId (must be a UUID)' }, { status: 400 });
+  }
+  if (!trimmedUserId || !uuidRegex.test(trimmedUserId)) {
+    return NextResponse.json({ error: 'Invalid or missing userId (must be a UUID)' }, { status: 400 });
+  }
path: app/api/send-message/route.ts
user: login: coderabbitai[bot]
body: _🛠️ Refactor suggestion_

**Strengthen UUID validation**

The current pattern `^[0-9a-f-]{36}$` allows invalid formats such as `------------`, `abc-def`, etc.  
A stricter RFC 4122 pattern protects against malformed IDs:

```diff
-const uuidRegex = /^[0-9a-f-]{36}$/i;
+const uuidRegex =
+  /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
```

(Same regex is repeated in other files ‑ consider extracting to a shared util).  



<!-- suggestion_start -->

<details>
<summary>📝 Committable suggestion</summary>

> ‼️ **IMPORTANT**
> Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

```suggestion
  const uuidRegex =
    /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;

  if (!trimmedRoomId || !uuidRegex.test(trimmedRoomId)) {
    return NextResponse.json({ error: 'Invalid or missing roomId (must be a UUID)' }, { status: 400 });
  }
  if (!trimmedUserId || !uuidRegex.test(trimmedUserId)) {
    return NextResponse.json({ error: 'Invalid or missing userId (must be a UUID)' }, { status: 400 });
  }
```

</details>

<!-- suggestion_end -->

<details>
<summary>🤖 Prompt for AI Agents</summary>

```
In app/api/send-message/route.ts around lines 38 to 45, the current UUID
validation regex is too permissive and allows invalid formats. Replace the regex
with a stricter RFC 4122 compliant pattern that validates the UUID structure
precisely. Additionally, consider extracting this regex into a shared utility
function to reuse across files and avoid duplication.
```

</details>

<!-- This is an auto-generated comment by CodeRabbit -->
created_at: 2025-05-19T11:49:08Z
author_association: NONE

PR comments:
user: login: vercel[bot]
created_at: 2025-05-19T11:42:51Z
body: [vc]: #iA88z4+u3tWu9/jILOAxm0DUsfIL4JiA2VcxqFPsSus=:eyJpc01vbm9yZXBvIjp0cnVlLCJ0eXBlIjoiZ2l0aHViIiwicHJvamVjdHMiOlt7Im5hbWUiOiJoZWFsdGgtdHJhbnNsYXRlLW1pbmkiLCJsaXZlRmVlZGJhY2siOnsicmVzb2x2ZWQiOjAsInVucmVzb2x2ZWQiOjAsInRvdGFsIjowLCJsaW5rIjoiaGVhbHRoLXRyYW5zbGF0ZS1taW5pLWdpdC1mZWF0LW11bHRpLXVzZXItYTJlYWEzLWJvMDVzLXByb2plY3RzLnZlcmNlbC5hcHAifSwiaW5zcGVjdG9yVXJsIjoiaHR0cHM6Ly92ZXJjZWwuY29tL2JvMDVzLXByb2plY3RzL2hlYWx0aC10cmFuc2xhdGUtbWluaS9CU28xOWVIa0RnRHlmeUJ0QlF6b3hWdVgyVEtFIiwicHJldmlld1VybCI6ImhlYWx0aC10cmFuc2xhdGUtbWluaS1naXQtZmVhdC1tdWx0aS11c2VyLWEyZWFhMy1ibzA1cy1wcm9qZWN0cy52ZXJjZWwuYXBwIiwibmV4dENvbW1pdFN0YXR1cyI6IkRFUExPWUVEIn1dfQ==
**The latest updates on your projects**. Learn more about [Vercel for Git ↗︎](https://vercel.link/github-learn-more)

| Name | Status | Preview | Comments | Updated (UTC) |
| :--- | :----- | :------ | :------- | :------ |
| **health-translate-mini** | ✅ Ready ([Inspect](https://vercel.com/bo05s-projects/health-translate-mini/BSo19eHkDgDyfyBtBQzoxVuX2TKE)) | [Visit Preview](https://health-translate-mini-git-feat-multi-user-a2eaa3-bo05s-projects.vercel.app) | 💬 [**Add feedback**](https://vercel.live/open-feedback/health-translate-mini-git-feat-multi-user-a2eaa3-bo05s-projects.vercel.app?via=pr-comment-feedback-link) | May 19, 2025 11:42am |


author_association: NONE
user: login: coderabbitai[bot]
created_at: 2025-05-19T11:42:54Z
body: <!-- This is an auto-generated comment: summarize by coderabbit.ai -->
<!-- walkthrough_start -->

## Walkthrough

This update introduces Supabase integration for chat room management and real-time messaging, including API routes for room creation, message sending, and message subscription with translation support. It adds new configuration placeholders, environment variable documentation, and Supabase client utilities, alongside dependency updates for Supabase libraries.

## Changes

| File(s)                                      | Change Summary |
|----------------------------------------------|---------------|
| `.cursorrules`, `.env.example`               | Updated environment variable placeholders for Supabase integration, making them active and reflecting Next.js naming conventions. |
| `README.md`                                  | Added documentation for Supabase integration, new API routes, environment variables, and Supabase client utility. Expanded project structure section. |
| `app/api/room/route.ts`                      | Added Edge API route for room creation (with unique code generation and retries) and room retrieval by code, using Supabase. |
| `app/api/send-message/route.ts`              | Added Edge API route for sending validated messages to a room, with Supabase database interaction and error handling. |
| `app/api/subscribe-messages/route.ts`        | Added Edge API route for real-time message subscription via SSE, with language-aware translation using Mistral API and Supabase realtime channels. |
| `lib/supabase/server.ts`                     | Added utility for creating a Supabase client configured for Next.js Edge Runtime, handling cookies and environment variables. |
| `package.json`                               | Added `@supabase/ssr` and `@supabase/supabase-js` as new dependencies. |

## Sequence Diagram(s)

```mermaid
sequenceDiagram
    participant Client
    participant API_Room as /api/room
    participant API_Send as /api/send-message
    participant API_Subscribe as /api/subscribe-messages
    participant Supabase
    participant Mistral

    %% Room creation
    Client->>API_Room: POST /api/room
    API_Room->>Supabase: Insert new room with unique code
    Supabase-->>API_Room: Room created or error
    API_Room-->>Client: Room data or error

    %% Room retrieval
    Client->>API_Room: GET /api/room?room_code=...
    API_Room->>Supabase: Fetch room by code
    Supabase-->>API_Room: Room data or not found
    API_Room-->>Client: Room data or error

    %% Send message
    Client->>API_Send: POST /api/send-message
    API_Send->>Supabase: Validate room, insert message
    Supabase-->>API_Send: Message inserted or error
    API_Send-->>Client: Message ID/timestamp or error

    %% Subscribe to messages
    Client->>API_Subscribe: GET /api/subscribe-messages (SSE)
    API_Subscribe->>Supabase: Subscribe to room messages (realtime)
    Supabase-->>API_Subscribe: New message event
    alt Message language != client language
        API_Subscribe->>Mistral: Translate message text
        Mistral-->>API_Subscribe: Translated text
    end
    API_Subscribe-->>Client: SSE event with (translated) message
```

## Poem

> 🐰  
> Supabase hops into our code,  
> With rooms and chats in real-time mode.  
> Messages leap from here to there,  
> Translated swiftly through the air.  
> Edge routes bloom, configs align—  
> A garden of features, simply divine!  
> —Rabbit 🥕

<!-- walkthrough_end -->

<!-- announcements_start -->

> [!NOTE]
> <details>
> <summary>⚡️ AI Code Reviews for VS Code, Cursor, Windsurf</summary>
> 
> CodeRabbit now has a plugin for VS Code, Cursor and Windsurf. This brings AI code reviews directly in the code editor. Each commit is reviewed immediately, finding bugs before the PR is raised. Seamless context handoff to your AI code agent ensures that you can easily incorporate review feedback.
> Learn more [here](http://coderabbit.ai/ide).
> 
> </details>

---

> [!NOTE]
> <details>
> <summary>⚡️ Faster reviews with caching</summary>
> 
> CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure `Review - Disable Cache` at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the `Data Retention` setting under your Organization Settings.
> Enjoy the performance boost—your workflow just got faster.
> 
> </details>

<!-- announcements_end -->
<!-- internal state start -->


<!-- DwQgtGAEAqAWCWBnSTIEMB26CuAXA9mAOYCmGJATmriQCaQDG+Ats2bgFyQAOFk+AIwBWJBrngA3EsgEBPRvlqU0AgfFwA6NPEgQAfACgjoCEejqANiS4AxEtQD0zbBfGRsiSo1jVIAtAwA1mS0BgBy2MwClFwALAYAqp4UXAIA8mAADACsRvrG4FAh/ABmOATEZMo09Eys7Fy8/MKi4lIy8kxKVKrqWjr5JlBwqKiY5YSk5FQ1CvUYnJBUAO6QiJHMaBTycgrdKmqa2rpghgWmBhoM2BSI+BQULtIcBgBE7wYAxJ+QAIIAkpVptQ6GsNlt5PgygwfBhSIgzLASJAAAZXG53B5PRAohQYErwIg3ajwfBYZZoZDYbi0EH0AhLEjMfBSOZsBaQTYUYK3SAACk+AEpICUKCxIGQJPAxRh2bhIBItvAVFYeBYAiRYPgLN1kPAsLgkajJQB9AlWHFrVqkjAaSAAZW4ongBIYaAsFlkABpIIbkYqKMqBBbUQBZf726AAJV+ABkTb8AAr/E0AaQAogBNFE+lHp2PpgBq6bCCeTaazOdR9oSid+ACFfvb0yaElHY1XMPQUTW643mwmwmlSxns5BlpRkTDMKR6fgwxHo3GyynRwBeKt5gvF0tJ1dZje5sLpgAa0BNiYS9dj/wAwibew2my227HD+gMN3j2eL1eb/fH37FtfiHEcD1xChpCdMRJBIT0fWWdRYF9I11UQeVcGWed3TuRkMDQNg5xQDAGAsbAlBQ5EUW/c9L2vO8TVxXgSAJAAPO0RmQac4WRTZgmQP0JQwKUZTlBUlRVZFuHVBhNW1XV0Bg1ku0ZEorDEKkaTp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lMgsig28ljqwnvPLBUDcAhnlMcgFO4woEZKlY2bUCvHBjNaBAjwFlFMYv9JB1Smtn9a60JvyhJspUBlQPloLlpQWuup36vyP44Mv7fxbkf47lf42CHWTY/5cCUtw4kAZN0vsB8juvTOzPWAdPFPQAT3aMTJOhBvXOIB6BKFkmjsLA3mOOCUuORNHp2MXBQ2BAUqbN3AYD+FwVBHAizBIW+NiJAxoVYSYZKBOj+IkQeuoisu7scu4h0pFIpMAB6mQGglmGg6OcLX7bLngYTtcYAPkf7E05BgHKOGgsQXxaHVY3q6A3BDbqIr7IQ6JBzcMncBUgkKIx7p7PkZIrymqdoK8/ArVER3ivEvdcDMtZComQyzCZNhHH70gzeFO6ExZvH77OJCyCUcFFai5Ni8DdaiD78rbqDb+baXbwCpt/jzN+5Lav8GDiAqCZIGClHyaBHYnBu2HvqoIlDxnYK1HGAaIsF9CZwQwQkzaZQu+kwCFswpCXAKw3jIiBmh2PQhw/QJwhgLnpM6gJopRiAJokEUosqdAJs8j8o+QBgLnsQsQJA6OlmOXogTd2Q6O2QJAQJmQAQXxKOQJTd9gx2XxQJKOWXAgDATdtImXGJaXEXLA3U0XsUcXQyNUE4tAJoxQ+gQAA -->

<!-- internal state end -->
<!-- finishing_touch_checkbox_start -->

<details open="true">
<summary>✨ Finishing Touches</summary>

- [ ] <!-- {"checkboxId": "7962f53c-55bc-4827-bfbf-6a18da830691"} --> 📝 Generate Docstrings

</details>

<!-- finishing_touch_checkbox_end -->
<!-- tips_start -->

---



<details>
<summary>🪧 Tips</summary>

### Chat

There are 3 ways to chat with [CodeRabbit](https://coderabbit.ai?utm_source=oss&utm_medium=github&utm_campaign=bO-05/health-translate-mini&utm_content=4):

- Review comments: Directly reply to a review comment made by CodeRabbit. Example:
  - `I pushed a fix in commit <commit_id>, please review it.`
  - `Explain this complex logic.`
  - `Open a follow-up GitHub issue for this discussion.`
- Files and specific lines of code (under the "Files changed" tab): Tag `@coderabbitai` in a new review comment at the desired location with your query. Examples:
  - `@coderabbitai explain this code block.`
  -	`@coderabbitai modularize this function.`
- PR comments: Tag `@coderabbitai` in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
  - `@coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.`
  - `@coderabbitai read src/utils.ts and explain its main purpose.`
  - `@coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.`
  - `@coderabbitai help me debug CodeRabbit configuration file.`

### Support

Need help? Create a ticket on our [support page](https://www.coderabbit.ai/contact-us/support) for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

### CodeRabbit Commands (Invoked using PR comments)

- `@coderabbitai pause` to pause the reviews on a PR.
- `@coderabbitai resume` to resume the paused reviews.
- `@coderabbitai review` to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
- `@coderabbitai full review` to do a full review from scratch and review all the files again.
- `@coderabbitai summary` to regenerate the summary of the PR.
- `@coderabbitai generate docstrings` to [generate docstrings](https://docs.coderabbit.ai/finishing-touches/docstrings) for this PR.
- `@coderabbitai generate sequence diagram` to generate a sequence diagram of the changes in this PR.
- `@coderabbitai resolve` resolve all the CodeRabbit review comments.
- `@coderabbitai configuration` to show the current CodeRabbit configuration for the repository.
- `@coderabbitai help` to get help.

### Other keywords and placeholders

- Add `@coderabbitai ignore` anywhere in the PR description to prevent this PR from being reviewed.
- Add `@coderabbitai summary` to generate the high-level summary at a specific location in the PR description.
- Add `@coderabbitai` anywhere in the PR title to generate the title automatically.

### CodeRabbit Configuration File (`.coderabbit.yaml`)

- You can programmatically configure CodeRabbit by adding a `.coderabbit.yaml` file to the root of your repository.
- Please see the [configuration documentation](https://docs.coderabbit.ai/guides/configure-coderabbit) for more information.
- If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: `# yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json`

### Documentation and Community

- Visit our [Documentation](https://docs.coderabbit.ai) for detailed information on how to use CodeRabbit.
- Join our [Discord Community](http://discord.gg/coderabbit) to get help, request features, and share feedback.
- Follow us on [X/Twitter](https://twitter.com/coderabbitai) for updates and announcements.

</details>

<!-- tips_end -->
author_association: NONE
user: login: coderabbitai[bot]
created_at: 2025-05-19T11:44:05Z
body: > [!NOTE]
> Generated docstrings for this pull request at https://github.com/bO-05/health-translate-mini/pull/5
author_association: NONE