Case Vault ยท Hearing Track ยท Client Crew ยท Court Hub ยท AI Assistant ยท Work Flow ยท Live canvas ยท RBAC team
A practising advocate's life is twelve open tabs, three diaries, a WhatsApp signal storm, and a stack of yellow files. LegalEasy collapses all of that into a single office workspace โ designed for Indian legal practice, written like a love letter to good design.
Two clients, one backend, one MongoDB:
- ๐ฅ๏ธ Web app (this repo) โ Next.js 16 partner-side console
- ๐ฑ Mobile app โ Expo SDK 54 โ
LegalEasyMobileApp
Both share the same Mongo, the same role-based access, the same advocate office.
| ๐ซ Canvas | #f4ede0 โ warm cream paper |
| โซ Ink | #0a1124 โ courtroom-navy |
| ๐ Copper | #c5853a โ gilded brass accents |
| ๐ค Ivory | #f5ebd6 โ soft highlight |
| ๐ Aqua | #56a0a8 โ status pills |
Typography: Crimson Pro (display) ยท Manrope (body) ยท DM Mono (caps & metadata)
"The look of a good chambers โ paper, brass, leather-bound, and quietly confident."
- Full case record: file no., case no., I.A. numbers, CNR, parties, court + hall + place, status, hearing dates
- Six-stage hearing dropdown โ Filed ยท Notice ยท Evidence ยท Arguments ยท Reserved ยท Disposed
- Hearing history archive (auto-pushes the previous date when next-date changes)
- Client contact card with one-tap Call + WhatsApp (pre-written professional reminder)
- Search across file / case / CNR / party / court ยท pre-fetched detail navigation
- Tenant-scoped by
partnerIdโ every query auto-filtered, zero cross-leak
- Today / Tomorrow / Pending tabs with live counts (IST-aware)
- One-tap Call, WhatsApp (pre-written professional reminder), Open
- Inline next-date update on the Pending tab โ row exits the bucket on save
- Client directory with phone, WhatsApp, email, address
- Auto-counts cases per client (by
clientIdor fallback name match) - Call / WhatsApp / Email buttons baked into every card
- Reusable court master โ name, hall/court number, place
- Case-count badges roll up automatically
- 7 office defaults seeded on first visit
- 12 professionally drafted prompt templates (Plaints, Written Statements, Affidavits, Sec 482 quashing, Bail under 437/439, Anticipatory bail under 438, Vakalatnama, Adjournment, Cross-exam plan, Notice + reply, Judgment summary)
- Editable per-partner library โ every change persists to Mongo
- Curated research-tools deck (Indian Kanoon, SCC Online, Manupatra, ChatGPT, Claude)
- ๐จ Full-bleed React Flow canvas โ lists are positionable nodes, cards drag freely between them, edges connect lists with editable labels
- โก Live updates within ~1 second โ when one user moves a card, everyone else watching the same board sees it pulse copper with a floating actor label:
Tejas ยท Junior ยท Civil โ moved this card - ๐๏ธ Presence dock โ top bar shows a live avatar stack of who's currently on the board, hover to see role + designation
- โจ Optimistic UI โ cards and lists appear the moment you press Enter, with a pending state until the server confirms; rollback on failure
- ๐๏ธ Designed canvas controls โ labelled bottom-left toolbar (Zoom ยท Fit ยท Lock ยท Map ยท Help) with keyboard shortcuts (
Ffit,Llock,Mmap,+/โzoom,?help) - ๐ Bell drawer โ board-scoped activity feed + admin's delete-request inbox, all live
- ๐ฑ 7 office defaults seeded on first visit (New Suits & Petitions, Notices, I.A.s / Petitions, C.A.s, Battas, Follow-ups, Instructions)
- ๐จ 7 colour presets (forest ยท copper ยท sea ยท terracotta ยท ochre ยท plum ยท ink)
- Office-wide audit feed โ every change in Work Flow, Cases, Clients, Courts, Prompts, Profile, and Users
- Click any row โ modal with full metadata (changed fields, before/after, board context, deep-link to source)
- Filter pills per family (Cards / Lists / Boards / Cases / Clients / Courts / Prompts / People / Profile)
- Configurable retention (default 30 days; admin can set forever) with TTL-driven Mongo cleanup
- All non-admins can do everything except delete
- Empty list/card created by you? Direct delete โ no friction
- Anything with content? The system asks "why?" โ admin sees it in the canvas bell + Activity / Requests tab โ approves or rejects with optional note
- Existing pending requests are auto-marked obsolete when an admin direct-deletes the target
- Applies to lists, cards, boards, cases, prompts (boards always require admin)
- 5 roles: Admin ยท Advocate ยท Junior ยท Clerk ยท Viewer with colour-coded pills
- Office admin can add staff (email + password + role + designation), reset passwords, deactivate, remove
- Server-enforced permissions, partner-scoped data, can't self-deactivate
- Real-time tiles โ Today ยท Tomorrow ยท Pending ยท Vault counts
- Today's board (cause-list)
- 8 fields (name, phone, email-locked, state, country, bar enrolment, designation, office address)
- View / edit toggle with the same partner-side API used by mobile
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Next.js 16 ยท App Router ยท Turbopack โ
โ React 19 ยท TypeScript 5.9 โ
โ Tailwind v4 (@theme blocks) โ
โ Auth.js v5 (cookie + JWT for mobile) โ
โ Mongoose 9.5 ยท MongoDB Atlas (Mumbai) โ
โ @xyflow/react (canvas) ยท @dnd-kit (cards) โ
โ Upstash Redis (optional โ live-feed probe + rate limit) โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Notable choices
- ๐ Same
/api/app/*endpoints power both web and mobile viarequirePartner(cookie OR JWT) - ๐๏ธ Asia/Kolkata (IST) midnight math centralised in
src/lib/ist-day.ts - ๐ฑ Lazy seeding pattern โ defaults (boards, prompt templates) seed per-partner on first visit
- ๐ฏ Next 16's
proxy.ts(formerlymiddleware.ts) - โก Activity log is the realtime backbone โ every mutation already writes there, so the audit log doubles as the live-update channel
- ๐งช Type-checked end-to-end, every endpoint tenant-scoped server-side
The trick: every mutation already writes to the Activity collection, so the audit log doubles as the realtime change feed. No WebSockets, no vendor lock-in.
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ MongoDB Activity collection โ
โโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ (poll, since=lastSeenId)
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ GET /api/app/activity/live?since=โฆ&board=โฆ โ
โ Probes Upstash first (~95% cache hits skip Mongo)โ
โโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ useBoardLiveFeed hook โ
โ โข adaptive polling: 1s active โ 30s background โ
โ โข BroadcastChannel for same-browser tab fan-out โ
โ โข localStorage persists last-seen id per board โ
โโโโฌโโโโโโโโโโโโฌโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโ
โ โ โ
โผ โผ โผ
BellDrawer Canvas Activity Page
Highlights
Adaptive polling cadence โ 1 s when the canvas is active, 3 s idle, 6 s deep idle, 30 s when backgrounded. Page Visibility API drives the gate.
Coalescing โ bursts from the same actor on the same target type within 4 s are collapsed into one highlight, so bulk creates don't strobe.
Cost โ designed to scale to 500 concurrent canvas viewers on Vercel + the Upstash free tier. Past that, Upstash paid ($10โ30/month). Past ~1,500, swap polling for SSE inside the same hook.
Upstash is optional โ if UPSTASH_REDIS_REST_URL / UPSTASH_REDIS_REST_TOKEN aren't set, the live feed falls through to direct Mongo queries and the rate limiter becomes a no-op. Local dev works untouched.
git clone https://github.com/hyperzen1320/LegalEasy.git
cd LegalEasy
npm installCreate .env.local in the project root:
# Required
MONGODB_URI=mongodb+srv://<user>:<pass>@<cluster>.mongodb.net/legaleasy
AUTH_SECRET=<openssl rand -base64 32>
NEXTAUTH_URL=http://localhost:3000
JWT_SECRET=<another long secret for mobile JWT>
# Optional โ speeds up the live feed at scale (>30 active partners)
# Free tier at upstash.com is plenty until then
UPSTASH_REDIS_REST_URL=
UPSTASH_REDIS_REST_TOKEN=npm run dev
# โ http://localhost:3000- Sign up at
/signup(creates a partner office + admin user) - Or run a seed script under
scripts/
src/
โโโ app/
โ โโโ (marketing)/ ยท Landing pages
โ โโโ admin/ ยท Global-admin console
โ โโโ app/ ยท Partner office workspace
โ โ โโโ activity/ ยท Audit log + delete-request review
โ โ โโโ ai/ ยท AI Assistant + prompt CRUD
โ โ โโโ cases/ ยท Case Vault list + detail + new
โ โ โโโ clients/ ยท Client Crew
โ โ โโโ courts/ ยท Court Hub
โ โ โโโ hearings/ ยท Hearing Track (today/tmrw/pending)
โ โ โโโ profile/ ยท My Profile
โ โ โโโ users/ ยท Users / Advocates (RBAC)
โ โ โโโ workflow/ ยท Work Flow canvas (live multiplayer)
โ โ โโโ components/ ยท Sidebar, Topbar, shared UI
โ โโโ api/
โ โ โโโ admin/* ยท Global admin endpoints
โ โ โโโ app/* ยท Partner-side endpoints (cookie + JWT)
โ โ โ โโโ activity/liveยท Live change feed (probe-then-query)
โ โ โ โโโ delete-requestsยท Approval queue + count
โ โ โ โโโ boards/[id]/heartbeatยท Presence beacon
โ โ โโโ mobile/* ยท Mobile-only auth shims
โ โโโ layout.tsx
โโโ auth.ts ยท Auth.js v5 config
โโโ auth.config.ts ยท Edge-safe authorize callback
โโโ proxy.ts ยท Next 16 routing proxy
โโโ lib/
โ โโโ db.ts ยท Mongo singleton
โ โโโ partner-auth.ts ยท requirePartner() โ ctx with partnerId
โ โโโ jwt.ts ยท Mobile JWT verify/sign
โ โโโ ist-day.ts ยท IST midnight helper
โ โโโ hearings-bucket.ts ยท today/tmrw/pending shared logic
โ โโโ activity.ts ยท logActivity / logWorkflowActivity
โ โโโ upstash.ts ยท Redis client + rate limiter (optional)
โ โโโ broadcast-channel.ts ยท Same-tab fan-out for mutations
โ โโโ use-board-live-feed.ts ยท Adaptive polling hook
โ โโโ use-board-presence.ts ยท Heartbeat + active-users hook
โ โโโ use-optimistic-action.tsยท Generic optimistic mutation
โ โโโ delete-eligibility.ts ยท Smart-delete rule helpers
โ โโโ delete-target.ts ยท Soft-delete dispatcher with cascades
โ โโโ workflow-rbac.ts ยท Per-action role gate
โ โโโ prompt-defaults.ts ยท 12 seeded legal prompts
โ โโโ board-defaults.ts ยท 7 seeded boards + colour presets
โโโ models/
โโโ User.ts ยท userType + role (RBAC) + profile fields
โโโ Partner.ts ยท Office record + branding + subscription
โโโ Case.ts ยท Case + embedded hearings[]
โโโ Client.ts ยท Client directory
โโโ Court.ts ยท Court master
โโโ PromptTemplate.ts ยท AI prompt library
โโโ Board.ts ยท Work Flow boards
โโโ BoardList.ts ยท Canvas lists with positions
โโโ BoardEdge.ts ยท Connections between lists
โโโ Task.ts ยท Cards (with embedded checklists)
โโโ Activity.ts ยท Audit log + realtime backbone
โโโ DeleteRequest.ts ยท Admin approval queue
โโโ BoardPresence.ts ยท "Who's on this board now" (TTL 60s)
โโโ Plan.ts ยท Subscription plans
โโโ AccessRequest.ts ยท Office signup requests
| ๐ข Tenant scoping | Every partner-side query filtered by partnerId from requirePartner(request) |
| ๐ Auth | Auth.js cookie session (web) OR Bearer JWT (mobile) โ same endpoint, same guard |
| ๐ฎ Roles | partner_admin (auth scope) + role (RBAC: admin ยท advocate ยท junior ยท clerk ยท viewer) |
| โ๏ธ Write permissions | All five roles can perform every action except delete |
| ๐๏ธ Delete permissions | Admin direct-deletes anything ยท non-admins can direct-delete only empty lists/cards they created ยท everything else flows through the DeleteRequest queue with admin approval |
| ๐ซ Soft delete | Every model has isDeleted โ nothing is hard-removed |
| ๐ Audit trail | Every mutation writes to Activity with before/after diffs; doubles as the live feed |
- โ๏ธ Phase 1 MVP โ Cases ยท Clients ยท Courts ยท Hearings ยท AI ยท Profile ยท Users RBAC ยท Work Flow boards
- ๐๏ธ Phase 1.5 โ Trello-grade canvas with positioned lists + edges + cards + checklists + drag/drop
- ๐ Phase 2.0 โ Activity timeline UI + click-to-detail ยท cross-module audit log
- ๐ซ Phase 2.1 โ Smart-delete with admin approval queue ยท canvas bell drawer
- โก Phase 2.2 โ Live board sync ยท presence dock ยท optimistic UI ยท designed canvas controls
- ๐ชถ Senior Desk โ personal reminders + advocate-to-advocate internal messaging
- ๐ Notifications โ actionable alerts for hearings, pending dates, workflow due, requests
- ๐ Global search โ single search bar across cases / clients / courts / hearings
- ๐ Hearing report export โ CSV / PDF download from Hearing Track filters
- ๐ Dashboard widgets โ total active cases ยท unread notifications ยท per-advocate workload
- ๐ค Inter-office user requests โ sent / received connection requests for cross-office collaboration
- ๐ฑ Push notifications on mobile ยท iOS-first
- ๐ฒ Mobile parity for live-feed canvas
-
โ ๏ธ Conflict-resolution toast on simultaneous moves - โ๏ธ Magic-link office invites
All AI-generated drafts must be verified, edited and signed by an advocate before filing.
LegalEasy is a tool, never the lawyer. The judgement, the responsibility, the seal โ those are yours.
Built for the Indian advocate. Designed in Chennai ยท Tested in chambers ยท Shipped from Mumbai
โ๏ธ Justice deserves better tooling.