Skip to content

Repository files navigation

โš–๏ธ LegalEasy

The advocate office, finally on your screen.

Case Vault ยท Hearing Track ยท Client Crew ยท Court Hub ยท AI Assistant ยท Work Flow ยท Live canvas ยท RBAC team

Next.js 16 React 19 TypeScript MongoDB Tailwind v4 Auth.js v5

Phase Region License Maintained


๐Ÿชถ What is this?

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.


๐ŸŽจ The aesthetic โ€” Midnight Counsel

๐ŸŸซ 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."


โœจ Features

๐Ÿ“ Case Vault

  • 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

๐Ÿง‘โ€โš–๏ธ Hearing Track

  • 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 Crew

  • Client directory with phone, WhatsApp, email, address
  • Auto-counts cases per client (by clientId or fallback name match)
  • Call / WhatsApp / Email buttons baked into every card

๐Ÿ›๏ธ Court Hub

  • Reusable court master โ€” name, hall/court number, place
  • Case-count badges roll up automatically
  • 7 office defaults seeded on first visit

๐Ÿช„ AI Assistant

  • 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)

๐Ÿ—‚๏ธ Work Flow โ€” Trello-grade canvas with live multiplayer

  • ๐ŸŽจ 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 (F fit, L lock, M map, +/โˆ’ 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)

๐Ÿ“œ Activity log

  • 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

๐Ÿšซ Smart delete with admin approval

  • 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)

๐Ÿ” Users / Advocates with RBAC

  • 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

๐Ÿ“Š Dashboard

  • Real-time tiles โ€” Today ยท Tomorrow ยท Pending ยท Vault counts
  • Today's board (cause-list)

๐Ÿชช My Profile

  • 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

๐Ÿ—๏ธ Stack

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  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 via requirePartner (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 (formerly middleware.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

โšก How live collaboration works

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.


๐Ÿš€ Getting started

1. Clone & install

git clone https://github.com/hyperzen1320/LegalEasy.git
cd LegalEasy
npm install

2. Environment

Create .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=

3. Run

npm run dev
# โ†’ http://localhost:3000

4. First login

  • Sign up at /signup (creates a partner office + admin user)
  • Or run a seed script under scripts/

๐Ÿ“‚ Project structure

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

๐Ÿ›ก๏ธ Tenancy & permissions

๐Ÿข 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

๐Ÿ›ฃ๏ธ Roadmap

Shipped

  • โš–๏ธ 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

Next up

  • ๐Ÿชถ 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

Later

  • ๐Ÿ“ฑ Push notifications on mobile ยท iOS-first
  • ๐Ÿ“ฒ Mobile parity for live-feed canvas
  • โš ๏ธ Conflict-resolution toast on simultaneous moves
  • โœ‰๏ธ Magic-link office invites

๐Ÿ’Œ The advocate's pact

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.

About

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages