# nemona1/nib-legal-flow architecture

> Architecture diagram of the GitHub repository nemona1/nib-legal-flow, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-07). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/nemona1/nib-legal-flow
- Repository: https://github.com/nemona1/nib-legal-flow

## Overview

LAHD is a role-based legal help desk for submitting, routing, reviewing, and resolving legal requests. Users work through role-specific Next.js pages; API routes authenticate and authorize operations, persist domain records in PostgreSQL through Prisma, and support notifications and other services. The map also preserves documented capabilities for identity security, RBAC administration, knowledge search, reporting, and system operations. Several links reflect README-level capabilities because their implementation files were not sampled; those links cite the README rather than implying source inspection.

Main entry points: [`lib/auth.js`](https://github.com/nemona1/nib-legal-flow/blob/main/lib/auth.js) (Authentication and RBAC), [`app/api/requests/route.js`](https://github.com/nemona1/nib-legal-flow/blob/main/app/api/requests/route.js) (Request lifecycle API), [`app/api/requests/[id]/route.js`](https://github.com/nemona1/nib-legal-flow/blob/main/app/api/requests/%5Bid%5D/route.js) (Request actions API), [`lib/prisma.js`](https://github.com/nemona1/nib-legal-flow/blob/main/lib/prisma.js) (PostgreSQL records)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_experience["User experience"]
  node_web["Role-based pages<br/>[page.jsx]"]
  node_requestview["Request detail"]
end

subgraph group_workflow["Legal workflow"]
  node_requestapi["Request lifecycle API<br/>[route.js]"]
  node_requestdetailapi["Request actions API<br/>[route.js]"]
  node_drafts["Legal drafts<br/>[route.js]"]
  node_knowledge["Knowledge base<br/>[route.js]"]
end

subgraph group_identity["Identity and access"]
  node_authui["Sign-in and 2FA<br/>[page.jsx]"]
  node_auth["Authentication and RBAC<br/>[auth.js]"]
  node_permissions["Permission management<br/>[route.js]"]
end

subgraph group_platform["Shared services"]
  node_database[("PostgreSQL records<br/>[prisma.js]")]
  node_notifications["Notifications<br/>[notifications.js]"]
  node_reports["Reports and analytics<br/>[route.js]"]
end

subgraph group_operations["Administration"]
  node_admin["Admin operations<br/>[page.jsx]"]
  node_backup["Backup services<br/>[route.js]"]
  node_settings["System settings<br/>[route.js]"]
end

node_requester(("Requester"))
node_staff(("Legal staff"))

node_requester -->|"submits request"| node_web
node_web -.->|"creates request"| node_requestapi
node_staff -->|"handles requests"| node_requestview
node_requestview -.->|"views and updates"| node_requestdetailapi
node_requestapi -->|"verifies access"| node_auth
node_requestdetailapi -->|"verifies access"| node_auth
node_requestapi -->|"reads and writes"| node_database
node_requestdetailapi -->|"reads and writes"| node_database
node_requestapi -->|"notifies users"| node_notifications
node_requestdetailapi -->|"notifies users"| node_notifications
node_staff -->|"prepares opinions"| node_drafts
node_requester -->|"searches guidance"| node_knowledge
node_authui -.->|"authenticates"| node_auth
node_auth -->|"loads user access"| node_database
node_admin -->|"manages access"| node_permissions
node_permissions -.->|"defines authorization"| node_auth
node_reports -->|"checks access"| node_auth
node_reports -->|"queries records"| node_database
node_admin -->|"manages backups"| node_backup
node_admin -->|"configures system"| node_settings

click node_web "https://github.com/nemona1/nib-legal-flow/blob/main/app/requests/new/page.jsx"
click node_requestview "https://github.com/nemona1/nib-legal-flow/blob/main/app/requests/%5Bid%5D/RequestDetailClient.jsx"
click node_requestapi "https://github.com/nemona1/nib-legal-flow/blob/main/app/api/requests/route.js"
click node_requestdetailapi "https://github.com/nemona1/nib-legal-flow/blob/main/app/api/requests/%5Bid%5D/route.js"
click node_drafts "https://github.com/nemona1/nib-legal-flow/blob/main/app/api/drafts/route.js"
click node_knowledge "https://github.com/nemona1/nib-legal-flow/blob/main/app/api/knowledge/route.js"
click node_authui "https://github.com/nemona1/nib-legal-flow/blob/main/app/login/page.jsx"
click node_auth "https://github.com/nemona1/nib-legal-flow/blob/main/lib/auth.js"
click node_permissions "https://github.com/nemona1/nib-legal-flow/blob/main/app/api/permissions/route.js"
click node_database "https://github.com/nemona1/nib-legal-flow/blob/main/lib/prisma.js"
click node_notifications "https://github.com/nemona1/nib-legal-flow/blob/main/lib/notifications.js"
click node_reports "https://github.com/nemona1/nib-legal-flow/blob/main/app/api/reports/route.js"
click node_admin "https://github.com/nemona1/nib-legal-flow/blob/main/app/admin/page.jsx"
click node_backup "https://github.com/nemona1/nib-legal-flow/blob/main/app/api/admin/backups/route.js"
click node_settings "https://github.com/nemona1/nib-legal-flow/blob/main/app/api/admin/settings/route.js"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_web,node_requestview toneBlue
class node_requestapi,node_requestdetailapi,node_drafts,node_knowledge toneAmber
class node_authui,node_auth,node_permissions,node_requester toneMint
class node_database,node_notifications,node_reports toneRose
class node_admin,node_backup,node_settings,node_staff toneIndigo
```

## Components

### User experience

- [Role-based pages](https://github.com/nemona1/nib-legal-flow/blob/main/app/requests/new/page.jsx): `app/requests/new/page.jsx`
- [Request detail](https://github.com/nemona1/nib-legal-flow/blob/main/app/requests/%5Bid%5D/RequestDetailClient.jsx): `app/requests/[id]/RequestDetailClient.jsx`

### Legal workflow

- [Request lifecycle API](https://github.com/nemona1/nib-legal-flow/blob/main/app/api/requests/route.js): `app/api/requests/route.js`
- [Request actions API](https://github.com/nemona1/nib-legal-flow/blob/main/app/api/requests/%5Bid%5D/route.js): `app/api/requests/[id]/route.js`
- [Legal drafts](https://github.com/nemona1/nib-legal-flow/blob/main/app/api/drafts/route.js): `app/api/drafts/route.js`
- [Knowledge base](https://github.com/nemona1/nib-legal-flow/blob/main/app/api/knowledge/route.js): `app/api/knowledge/route.js`

### Identity and access

- [Sign-in and 2FA](https://github.com/nemona1/nib-legal-flow/blob/main/app/login/page.jsx): `app/login/page.jsx`
- [Authentication and RBAC](https://github.com/nemona1/nib-legal-flow/blob/main/lib/auth.js): `lib/auth.js`
- [Permission management](https://github.com/nemona1/nib-legal-flow/blob/main/app/api/permissions/route.js): `app/api/permissions/route.js`

### Shared services

- [PostgreSQL records](https://github.com/nemona1/nib-legal-flow/blob/main/lib/prisma.js): `lib/prisma.js`
- [Notifications](https://github.com/nemona1/nib-legal-flow/blob/main/lib/notifications.js): `lib/notifications.js`
- [Reports and analytics](https://github.com/nemona1/nib-legal-flow/blob/main/app/api/reports/route.js): `app/api/reports/route.js`

### Administration

- [Admin operations](https://github.com/nemona1/nib-legal-flow/blob/main/app/admin/page.jsx): `app/admin/page.jsx`
- [Backup services](https://github.com/nemona1/nib-legal-flow/blob/main/app/api/admin/backups/route.js): `app/api/admin/backups/route.js`
- [System settings](https://github.com/nemona1/nib-legal-flow/blob/main/app/api/admin/settings/route.js): `app/api/admin/settings/route.js`

### Other components

- **Requester**
- **Legal staff**

## Connections

- Requester → Role-based pages: submits request
- Role-based pages → Request lifecycle API: creates request
- Legal staff → Request detail: handles requests
- Request detail → Request actions API: views and updates
- Request lifecycle API → Authentication and RBAC: verifies access (evidence: `app/api/requests/route.js`)
- Request actions API → Authentication and RBAC: verifies access (evidence: `app/api/requests/[id]/route.js`)
- Request lifecycle API → PostgreSQL records: reads and writes (evidence: `app/api/requests/route.js`)
- Request actions API → PostgreSQL records: reads and writes (evidence: `app/api/requests/[id]/route.js`)
- Request lifecycle API → Notifications: notifies users (evidence: `app/api/requests/route.js`)
- Request actions API → Notifications: notifies users (evidence: `app/api/requests/[id]/route.js`)
- Legal staff → Legal drafts: prepares opinions
- Requester → Knowledge base: searches guidance
- Sign-in and 2FA → Authentication and RBAC: authenticates
- Authentication and RBAC → PostgreSQL records: loads user access (evidence: `lib/auth.js`)
- Admin operations → Permission management: manages access
- Permission management → Authentication and RBAC: defines authorization (evidence: `app/api/permissions/route.js`)
- Reports and analytics → Authentication and RBAC: checks access (evidence: `app/api/reports/route.js`)
- Reports and analytics → PostgreSQL records: queries records (evidence: `app/api/reports/route.js`)
- Admin operations → Backup services: manages backups
- Admin operations → System settings: configures system
