How e-wakil/legalgpt works
LegalGPT Nepal is a web legal-advice product: a citizen signs in, opens a protected chat, submits a legal question, and receives a streamed AI response. The sampled backend shows chat routing, persistence-related models, and an HTTP inference client; the README documents RAG retrieval and citations, but those internals are not present in the tree. The AI worker and its legal persona are separate runtime components. Edges reflect shown imports/calls or README architecture; unshown RAG and streaming internals are not inferred.
Main entry points: chat.py Chat endpoint · ai_worker.py AI worker · models.py User and chat records · App.tsx App bootstrap
Components 24
Web experience
- App bootstrap
frontend/src/App.tsx - Page routing
frontend/src/Routes/Router.tsx - Chat page
frontend/src/pages/ChatPage.tsx - Chat interface
frontend/src/sections/chat/MessageInterfaceSection.tsx - Conversation sidebar
frontend/src/sections/chat/SidebarSection.tsx - Chat WebSocket hook
frontend/src/hooks/useChatWebSocket.ts
Identity and access
- Chat access gate
frontend/src/Routes/ProtectedRoutes.tsx - User state
frontend/src/store/userStore.tsx - HTTP client
frontend/src/api/axiosInstance.ts - Google sign-in API
backend/app/api/v1/endpoints/auth.py - Token security
backend/app/core/security.py
API and chat
- API router
backend/app/api/v1/api.py - Chat endpoint
backend/app/api/v1/endpoints/chat.py - Auth dependencies
backend/app/api/deps.py - Chat service
backend/app/services/chat_service.py - AI inference client
backend/app/services/ai_service.py - API schemas
backend/app/schemas/schemas.py
Application data
- SQL database
backend/app/core/database.py - User and chat records
backend/app/models/models.py
Legal inference
- AI worker
ai/ai_worker.py - Legal persona prompt
ai/prompts/legal_persona.py - Legal corpus retrieval
- Mistral model
Other components
- Citizen
Connections 29
- Citizen → App bootstrap: uses
- App bootstrap → Page routing: renders
frontend/src/App.tsx - Page routing → Chat access gate: guards chat
frontend/src/Routes/Router.tsx - Chat access gate → HTTP client: checks access
frontend/src/Routes/ProtectedRoutes.tsx - Page routing → Chat page: routes to
frontend/src/Routes/Router.tsx - Chat page → Conversation sidebar: renders
frontend/src/pages/ChatPage.tsx - Chat page → Chat interface: renders
frontend/src/pages/ChatPage.tsx - App bootstrap → HTTP client: checks session
frontend/src/App.tsx - App bootstrap → User state: updates user
frontend/src/App.tsx - Conversation sidebar → HTTP client: loads conversations
frontend/src/sections/chat/SidebarSection.tsx - Chat interface → Chat WebSocket hook: uses chat stream
- HTTP client → API router: calls API
- Google sign-in API → Token security: verifies Google token
backend/app/api/v1/endpoints/auth.py - Google sign-in API → User and chat records: reads and creates user
backend/app/api/v1/endpoints/auth.py - Google sign-in API → SQL database: gets session
backend/app/api/v1/endpoints/auth.py - API router → Chat endpoint: registers routes
backend/app/api/v1/api.py - Chat endpoint → Auth dependencies: authenticates
backend/app/api/v1/endpoints/chat.py - Chat endpoint → AI inference client: requests inference
backend/app/api/v1/endpoints/chat.py - Chat endpoint → User and chat records: uses chat records
backend/app/api/v1/endpoints/chat.py - Chat endpoint → API schemas: uses schemas
backend/app/api/v1/endpoints/chat.py - Auth dependencies → SQL database: queries session
backend/app/api/deps.py - Auth dependencies → User and chat records: loads user
backend/app/api/deps.py - User and chat records → SQL database: maps records
backend/app/models/models.py - AI inference client → AI worker: posts query
- AI worker → Legal persona prompt: uses prompt
ai/ai_worker.py - AI worker → Legal corpus retrieval: retrieves context
- AI worker → Mistral model: generates answer
- AI worker → AI inference client: streams tokens
- Chat service → User and chat records: supports chat records