How team-mirai-volunteer/mirai-gikai works
Main Components
a. Frontends
• Admin UI (Next.js App Router, React Server + Client components)
• Public Web UI (Next.js App Router, React Server + Client components)
b. Backend / BaaS
• Supabase (PostgreSQL database, Auth, Storage for thumbnails)
• Next.js API Routes (web/src/app/api/chat, api/revalidate)
• Packages:
• packages/supabase (shared Supabase client lib for browser & server)
• packages/seed (DB seeding scripts)
c. AI Chat Service
• Chat handler in web/src/features/chat: uses Supabase for anonymous user, cost-tracker, Langfuse telemetry, and external LLMs.
d. CI/CD & Infrastructure
• GitHub Actions workflows (.github/workflows)
• Vercel deployments (vercel.json in both “admin” and “web”)
• Local supabase CLI (config.toml, migrations/seed.sql)
Relationships & Data Flows
• Admin UI ↔ Supabase Auth & API:
– Users log in via Supabase Auth, Next.js Middleware guards protected routes, UI components call Supabase client and Admin API endpoints to CRUD bills, tags, diet-sessions, stances.
• Public Web UI ↔ Supabase & API:
– SSR/SSG pages fetch bill listings, details, featured tags via Supabase queries and custom API routes (e.g., preview revalidation).
• Chat API (web) ↔ Supabase & LLM Provider:
– Incoming chat requests hit Next.js API Route → handle-chat-request → uses mirai-context & mirai-knowledge → sends prompt to LLM(s) (via prompt-provider, langfuse client) → stores usage events back to Supabase.
• Seed & Migrations ↔ Database:
– packages/seed.run.ts and supabase/migrations/*.sql initialize and evolve the schema.
Architectural Patterns & Principles
– Monorepo workspace (pnpm) sharing code across “admin,” “web,” and “packages.”
– Next.js App Router pattern: server components for data fetching, client components for interactivity.
– Domain-driven “features” folders encapsulating actions, API calls, components, hooks, and types.
– BaaS‐centric backend: minimal custom server code, heavy reliance on Supabase for DB, Auth, and Storage.
– Serverless API Routes for specialized features (chat, revalidation).
Detail Level
– Show the Next.js App Router boundary: highlight server‐side data fetching vs. client components.
– Include the middleware layer for auth checks (middleware.ts).
– Show the shared packages (seed & supabase client) as separate modules that both frontends import.
– Emphasize the chat service flow: request → handle-chat-request → LLM → cost-tracker → telemetry → Supabase.
– Mark how previews are revalidated via the revalidate API route.