How aadirajput-dev26/ai-legal-system works
This is a Fastify legal-practice backend: authenticated users and organisations manage cases, case materials, collaboration, schedules, and billing through an HTTP API. Case routes expose the principal workflow, including case access and transcript processing; case context assembles related records for AI-assisted work. Other branches cover drafting, chat, documents, tools, notifications, legal updates, and hearing reminders. The graph follows explicit route registrations, sampled calls, and SOURCE INDEX references; unsampled subsystems are included where the tree establishes their role, but their internal links are not inferred.
Main entry points: case.repository.ts Case Records · app.ts Fastify API · case-context.service.ts Case Context · billing.controller.ts Billing Controller
Components 27
API and Access
- Fastify API
src/app.ts - Authentication
src/routes/auth.routes.ts - Auth Controller
src/controllers/auth.controller.ts - JWT Authentication
src/middlewares/authenticate.ts - Case Routes
src/routes/case.routes.ts - Billing Routes
src/routes/billing.routes.ts
Casework
- Case Controller
src/controllers/case.controller.ts - Case Records
src/repositories/case.repository.ts - Case Context
src/services/case-context.service.ts - PostgreSQL Pool
src/lib/db.ts - Documents
src/controllers/document.controller.ts - Case Tools
src/controllers/tool.controller.ts
AI and Drafting
- Drafting
src/controllers/draft.controller.ts - Draft Service
src/services/draft.service.ts - Case Chat
src/controllers/chat.controller.ts - AI Gateway
src/services/gtwy.service.ts - Document Retrieval
src/lib/hippocampus.ts
Operations
- Hearing Reminders
src/workers/hearing.worker.ts - Hearing Records
src/repositories/hearing.repository.ts - Notification Webhooks
src/services/webhook.service.ts - Legal Updates
src/services/legal-update.service.ts
Billing
- Billing Controller
src/controllers/billing.controller.ts - Credit Ledger
src/services/credit.service.ts - Billing Records
src/repositories/billing.repository.ts - Razorpay Payments
src/services/razorpay.service.ts - Usage Metering
src/services/usage.service.ts
Other components
- User
Connections 30
- User → Fastify API: sends requests
src/app.ts - Fastify API → Authentication: registers routes
src/app.ts - Fastify API → Case Routes: registers routes
src/app.ts - Fastify API → Billing Routes: registers routes
src/app.ts - Authentication → JWT Authentication: guards requests
src/routes/auth.routes.ts - Authentication → Auth Controller: dispatches to
src/routes/auth.routes.ts - Case Routes → JWT Authentication: guards requests
src/routes/case.routes.ts - Case Routes → Case Controller: dispatches to
src/routes/case.routes.ts - Case Controller → Case Records: reads cases
src/controllers/case.controller.ts - Case Controller → Case Context: builds context
src/controllers/case.controller.ts - Case Context → Case Records: loads case
src/services/case-context.service.ts - Case Records → PostgreSQL Pool: queries
src/repositories/case.repository.ts - Case Context → Hearing Records: loads hearings
src/services/case-context.service.ts - Case Context → AI Gateway: uses AI gateway
src/services/case-context.service.ts - Case Chat → AI Gateway: calls
src/controllers/chat.controller.ts - Case Chat → Usage Metering: records usage
src/controllers/chat.controller.ts - Documents → AI Gateway: uses
src/controllers/document.controller.ts - Documents → Case Records: loads case
src/controllers/document.controller.ts - Case Tools → Case Records: loads case
src/controllers/tool.controller.ts - Drafting → Draft Service: delegates to
src/controllers/draft.controller.ts - Drafting → Usage Metering: records usage
src/controllers/draft.controller.ts - Hearing Reminders → Hearing Records: selects and updates
src/workers/hearing.worker.ts - Hearing Reminders → Case Records: loads case
src/workers/hearing.worker.ts - Hearing Reminders → Notification Webhooks: sends reminders
src/workers/hearing.worker.ts - Billing Routes → Billing Controller: dispatches to
src/routes/billing.routes.ts - Billing Controller → Credit Ledger: manages credits
src/controllers/billing.controller.ts - Billing Controller → Razorpay Payments: creates payments
src/controllers/billing.controller.ts - Billing Controller → Billing Records: stores billing data
src/controllers/billing.controller.ts - Usage Metering → Credit Ledger: checks ledger
src/services/usage.service.ts - Credit Ledger → PostgreSQL Pool: updates ledger
src/services/credit.service.ts