How sameer-ssr99/nyaya-ai works
Project Type and Purpose
• Nyaya.ai is a full-stack web application: an AI-powered legal assistant specializing in Indian law.
• Frontend: Next.js (app router), React components, internationalization.
• Backend: Next.js API routes, Supabase (PostgreSQL + Auth) for database and authentication.
• External AI service: Puter.js AI loaded from CDN in the browser.
High-Level Architecture Components
• Client (Browser/mobile):
• Next.js pages/components (chat interface, document generator, lawyer directory, dashboard, stories, KYR content)
• Global CSS and shadcn/ui for styling
• Puter.js AI script loaded via CDN
• Supabase client library for auth and data queries
• API Layer (Next.js “app/api”):
• /api/chat, /api/chat/start
• /api/documents/enhance, /api/enhance-document
• /api/bookmarks
• Each route handles HTTP requests, applies business logic, calls AI or database
• Backend Services:
• Supabase:
– Auth (signup, login, session management via middleware.ts)
– Database tables for users, chats, documents, KYR articles, lawyers, case stories, bookmarks
• Database migration scripts in /scripts
• External AI Service:
• Puter.js AI (loaded in client, invoked by API routes via window.puter.ai.chat)
• Deployment & Hosting:
• Vercel (or similar) for Next.js app (serverless functions for API routes)
• Supabase hosted PostgreSQL
Relationships and Data Flows
• User → Frontend:
• Client sends UI requests (page navigation, form submissions)
• User interacts with chat page, document generator, lawyer directory
• Frontend → Next.js API:
• Fetch calls to endpoints: /api/chat, /api/documents/enhance, /api/bookmarks, etc.
• Supabase client used directly in server components for data fetching
• API → Supabase Database:
• CRUD operations for chats, documents, user profile, stories, KYR content
• API → External AI (Puter.js):
• Chat endpoint orchestrates AI prompts/responses
• Document enhancement endpoint passes user text to AI, receives enriched content
• Authentication Flow:
• User signs up/logs in via Supabase Auth
• Auth middleware protects API routes and pages
• JWT/session tokens stored in cookies/localStorage
• Internationalization:
• lib/i18n provides context and translations for multi-language support
Architectural Patterns and Principles
• Next.js App Router for file-based routing (separates pages and API routes).
• Client-side AI integration (Puter.js) with serverless API orchestration.
• Supabase as BaaS: unified Auth + Database layer.
• Separation of concerns:
• UI layer (components/)
• Data/services layer (lib/supabase, lib/utils)
• API layer (app/api)
• Scripts for database schema
• Modular, reusable React components (shadcn/ui patterns).