How meghrajjare5273/legalmind works
Project type and purpose
• This is a full-stack Next.js (React + Node.js) application that provides user authentication, protected dashboards, analytics, a chat service, contract review, and research tooling.
• Key features: sign-in/up flows, server-side API endpoints (e.g. chat, RAG, contract analysis), database persistence via Prisma, theming, UI components.
File structure
• Top-level:
• prisma/schema.prisma – database schema
• src/app – Next.js App Router:
– (auth) and (protected) route groups
– API routes under src/app/api (analyze-contract, auth, chat, rag)
– global layout (app/layout.tsx), CSS (globals.css)
• src/components – UI primitives and feature-specific components (auth, landing, protected services, theme toggle, UI controls)
• src/lib – helper modules (auth client, Prisma client, types, utils)
• src/contexts & src/hooks – React context for session, custom hooks
• middleware.ts – global request handling (auth, redirects)
• Config files: next.config.ts, tsconfig.json, eslint, postcss
README for additional insights
• Confirms Next.js App Router usage, deployment via Vercel, optimized font loading.
a. Main components
1. Client / Browser (React in the browser)
2. Next.js Server (Node.js SSR & API layer)
3. Database (PostgreSQL or MySQL via Prisma ORM)
4. External AI Services (e.g. OpenAI for Chat & RAG)
5. Identity Provider (NextAuth or custom JWT flow)
6. CDN / Static Assets (Vercel / public folder)
b. Relationships & data flow
• Browser ↔ Next.js Server: page navigation (SSR/ISR), client-side fetching (React hooks)
• Next.js Server → Database: Prisma queries (user sessions, chat history, analytics data)
• Next.js Server → External AI Services: REST/gRPC calls from API routes (chat, analyze-contract, RAG)
• Static files served from CDN / public folder
• Middleware handles authentication & route protection before hitting server components
c. Architectural patterns & design principles
• App Router with nested layouts → logical separation of “(auth)” vs “(protected)” routes
• MVC‐style controllers: API routes act as controllers, Prisma as the model, React components as the view
• Shared UI component library under src/components/ui → DRY, design system
• Context/Hook pattern for global session & toast notifications
• Separation: frontend (pages + components) vs backend (API routes + lib + prisma)
d. Key technologies/frameworks
• Next.js (App Router, server‐side rendering, API routes)
• React + TypeScript
• Prisma ORM + a relational database
• NextAuth or custom auth handlers in src/lib/auth
• Tailwind/PostCSS for styling, Sonner for toasts
• Vercel for deployment & CDN
Essential architectural elements
• Middleware.ts intercepting and routing auth.
• Prisma’s role in all DB interactions.
• How shared UI components feed into each page.
• Don’t overcomplicate – break into logical subsystems and show their interactions.