Architecture (in-app summary)

MaaCare is Next.js (App Router) plus Supabase (Auth, Postgres + RLS, Storage, optional Realtime). Gemini and Groq are used only on the server from Route Handlers — keys never ship to the browser.

End-to-end chat and RAG (one diagram)

Mermaid diagram

Multilingual and voice (short)

  • Reply language: Unicode Bangla script or Banglish Latin-token hints choose Bangla vs English system instructions.
  • Retrieval: Bangla user text is translated to English (same Gemini→Groq helper) only to embed and search RAG; the model still answers in the user’s language.
  • Voice: Request field replyChannel: "voice" adds spoken-style rules (no markdown, short sentences), slightly higher temperature, and TTS-friendly copy. Browser capture/playback lives under src/lib/voice/*.

Model defaults (env overrides)

RoleTypicalEnv
Chatgemini-2.5-flashGEMINI_CHAT_MODEL
Chat fallbackllama-3.1-8b-instant on GroqGROQ_CHAT_MODEL
Embeddingstext-embedding-004 (768-D)GEMINI_EMBEDDING_MODEL

Request path and security

  1. proxy refreshes Supabase cookies and gates routes.
  2. APIs use getSessionFromCookies and createSupabaseServerClient; Postgres RLS enforces row access.
  3. Admin UI and /api/admin/* require admin role.

Full reference

The canonical, diagram-heavy document is docs/ARCHITECTURE.md in the repository (chat sequence, failover ladder, RAG ingest vs query, community, realtime, deployment). Update both when you change AI or data paths.

Mermaid diagram

Security notes

  • Service role keys stay server-only.
  • Public /docs does not bypass API authentication.