# adilmunawar/adiarc architecture

> Architecture diagram of the GitHub repository adilmunawar/adiarc, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-06-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/adilmunawar/adiarc
- Repository: https://github.com/adilmunawar/adiarc

## Overview

1. **What this repo is**
   - AdiARC is a single Next.js dashboard for land-record operations: scanning, auditing, OCR/AI assistance, SQL generation, database status checks, inheritance calculations, and image forensics.
   - It is not a generic CRUD app; the architecture centers on operational tools for legacy SQL-backed land-record workflows.

2. **Primary runtime boundary**
   - The main application lives in **Next.js App Router** under `src/app`.
   - Most routes are thin page shells that load a corresponding tool panel from `src/components/dashboard-tabs`, so the UI is organized as a dashboard of specialized modules rather than independent apps.

3. **UI composition**
   - Shared shell components in `src/components/layout` provide the app-wide structure: authentication, route protection, sidebar navigation, persistent tabs, splash/trial gating, and employee header.
   - Reusable UI primitives in `src/components/ui` supply the local design system, likely based on a component library such as shadcn/ui + Tailwind.

4. **Main feature modules**
   - The dashboard tabs represent distinct subsystems: AI assistant, OCR, mauza scanning/tracking, sync, DB status, daily progress, inventory, image tools, mutation tools, range-gap analysis, SQL generation, PowerShell queries, login management, and wirasat.
   - Each module is isolated at the component level, which makes the diagram best modeled as a shared shell feeding multiple tool-specific views.

5. **Backend API layer**
   - Server-side functionality is exposed through `src/app/api/*` route handlers.
   - The notable API boundaries are database status, mauza scanning, saving scan results, scanning all mauzas, and sync; these are the app’s integration points for long-running or server-side operations.

6. **AI subsystem**
   - `src/ai` contains a Genkit-based AI pipeline, including `flows/db-assistant-flow.ts` and a schema file for LRIMS domain knowledge.
   - This is a separate service-like layer inside the repo: the UI can invoke AI assistance, but the model logic is isolated from the presentation layer.

7. **Data and computation libraries**
   - `src/lib` holds the reusable domain logic: inheritance calculations, image/forensic utilities, generic helpers, and a Supabase client wrapper.
   - These utilities are the bridge between UI/API and backend services, especially for image analysis, forensic metadata extraction, and wirasat calculations.

8. **Background processing**
   - `src/workers/inventory-scanner.worker.ts` indicates client-side worker-based processing for inventory scanning.
   - This creates a distinct execution path for heavy file/directory scanning so the main UI thread stays responsive.

9. **External systems and operational scripts**
   - The repo includes extensive SQL assets in `nodeconfigs`, `Schemas`, and `database-test`, plus PowerShell query bundles under `powershellQueries`.
   - Architecturally, these are not just docs; they are part of the operational toolchain for SQL Server auditing, reporting, mutation lookups, sync, and cleanup workflows.

10. **Persistence and asset layer**
   - Static/manual assets live in `public`, including manuals and robots metadata.
   - Database interaction appears to be a core external dependency, with the app acting as a control plane over SQL scripts, reports, and live DB checks rather than owning the primary business data store itself.

11. **Security and access flow**
   - Auth and access control are handled at the layout level through `AuthProvider`, `RouteGuard`, and trial-expiration UI.
   - This implies the app has an authenticated shell around most functionality, with gated access before users reach the operational tabs.

12. **How data flows through the system**
   - User action starts in a dashboard page, passes into a specialized tab/component, then either:
     - calls a local library for computation,
     - invokes an API route for server-side work,
     - triggers the AI flow for OCR/db assistance, or
     - uses stored SQL/PowerShell assets for database operations.
   - That makes the architecture a multi-tool control surface over legacy land-record data, with clear boundaries between UI, AI, worker processing, and external database automation.

Main entry points: [`src/components/dashboard-tabs/AiAssistantTab.tsx`](https://github.com/adilmunawar/adiarc/blob/main/src/components/dashboard-tabs/AiAssistantTab.tsx) (Tool tabs), [`src/lib/wirasat-calculator.ts`](https://github.com/adilmunawar/adiarc/blob/main/src/lib/wirasat-calculator.ts) (Core libs), [`src/app/page.tsx`](https://github.com/adilmunawar/adiarc/blob/main/src/app/page.tsx) (Dashboard pages), [`src/components/layout/AuthProvider.tsx`](https://github.com/adilmunawar/adiarc/blob/main/src/components/layout/AuthProvider.tsx) (Auth shell)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_grp_app["Next.js App"]
  node_n_app_shell["App shell<br/>Next.js layout<br/>[layout.tsx]"]
  node_n_app_routes["Dashboard pages<br/>route pages<br/>[page.tsx]"]
end

subgraph group_grp_ui["Dashboard UI"]
  node_n_shell["Auth shell<br/>layout guard<br/>[AuthProvider.tsx]"]
  node_n_tabs["Tool tabs<br/>dashboard modules<br/>[AiAssistantTab.tsx]"]
  node_n_wirasat_ui["Wirasat UI<br/>family-tree view"]
  node_n_ui_kit["UI kit<br/>component primitives<br/>[button.tsx]"]
end

subgraph group_grp_api["API Routes"]
  node_n_api_db["DB status API<br/>route handler<br/>[route.ts]"]
  node_n_api_scan["Scan API<br/>route handler<br/>[route.ts]"]
  node_n_api_sync["Sync API<br/>route handler<br/>[route.ts]"]
end

subgraph group_grp_ai["AI Layer"]
  node_n_ai_flow{{"AI flow<br/>Genkit flow"}}
  node_n_ai_schema["AI schema<br/>domain schema<br/>[lrims_schema.txt]"]
end

subgraph group_grp_lib["Domain Libs"]
  node_n_lib_core["Core libs<br/>domain helpers"]
  node_n_worker["Inventory worker<br/>web worker"]
end

subgraph group_grp_ops["Operational Assets"]
  node_n_sql_assets["SQL assets<br/>sql scripts"]
  node_n_schema_assets["Schema assets<br/>schema files<br/>[schema.sql]"]
  node_n_ps_assets["PowerShell queries<br/>ops scripts"]
  node_n_manuals["Manuals<br/>static docs"]
end

node_n_app_shell -->|"wraps"| node_n_shell
node_n_shell -->|"hosts"| node_n_app_routes
node_n_app_routes -->|"mounts"| node_n_tabs
node_n_tabs -->|"uses"| node_n_ui_kit
node_n_tabs -->|"calls"| node_n_api_db
node_n_tabs -->|"calls"| node_n_api_scan
node_n_tabs -->|"calls"| node_n_api_sync
node_n_tabs -->|"invokes"| node_n_ai_flow
node_n_ai_flow -->|"uses"| node_n_ai_schema
node_n_tabs -->|"computes"| node_n_lib_core
node_n_lib_core -->|"offloads"| node_n_worker
node_n_tabs -->|"references"| node_n_sql_assets
node_n_tabs -->|"references"| node_n_ps_assets
node_n_tabs -->|"references"| node_n_schema_assets
node_n_tabs -->|"documents"| node_n_manuals
node_n_lib_core -.->|"supports"| node_n_api_db
node_n_lib_core -.->|"supports"| node_n_api_scan

click node_n_app_shell "https://github.com/adilmunawar/adiarc/blob/main/src/app/layout.tsx"
click node_n_app_routes "https://github.com/adilmunawar/adiarc/blob/main/src/app/page.tsx"
click node_n_shell "https://github.com/adilmunawar/adiarc/blob/main/src/components/layout/AuthProvider.tsx"
click node_n_tabs "https://github.com/adilmunawar/adiarc/blob/main/src/components/dashboard-tabs/AiAssistantTab.tsx"
click node_n_wirasat_ui "https://github.com/adilmunawar/adiarc/blob/main/src/components/wirasat/FamilyTreeDiagram.tsx"
click node_n_ui_kit "https://github.com/adilmunawar/adiarc/blob/main/src/components/ui/button.tsx"
click node_n_api_db "https://github.com/adilmunawar/adiarc/blob/main/src/app/api/db-status/route.ts"
click node_n_api_scan "https://github.com/adilmunawar/adiarc/blob/main/src/app/api/mauza-scanner/route.ts"
click node_n_api_sync "https://github.com/adilmunawar/adiarc/blob/main/src/app/api/sync/route.ts"
click node_n_ai_flow "https://github.com/adilmunawar/adiarc/blob/main/src/ai/flows/db-assistant-flow.ts"
click node_n_ai_schema "https://github.com/adilmunawar/adiarc/blob/main/src/ai/schema/lrims_schema.txt"
click node_n_lib_core "https://github.com/adilmunawar/adiarc/blob/main/src/lib/wirasat-calculator.ts"
click node_n_worker "https://github.com/adilmunawar/adiarc/blob/main/src/workers/inventory-scanner.worker.ts"
click node_n_sql_assets "https://github.com/adilmunawar/adiarc/blob/main/nodeconfigs/Daily Progress Query.sql"
click node_n_schema_assets "https://github.com/adilmunawar/adiarc/blob/main/Schemas/schema.sql"
click node_n_ps_assets "https://github.com/adilmunawar/adiarc/tree/main/powershellQueries/dailyprogressMutations_JSON"
click node_n_manuals "https://github.com/adilmunawar/adiarc/tree/main/public/Manual"

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_n_app_shell,node_n_app_routes toneBlue
class node_n_shell,node_n_tabs,node_n_wirasat_ui,node_n_ui_kit toneAmber
class node_n_api_db,node_n_api_scan,node_n_api_sync toneMint
class node_n_ai_flow,node_n_ai_schema toneRose
class node_n_lib_core,node_n_worker toneIndigo
class node_n_sql_assets,node_n_schema_assets,node_n_ps_assets,node_n_manuals toneTeal
```

## Components

### Next.js App

App Router routes and page shells

- [App shell](https://github.com/adilmunawar/adiarc/blob/main/src/app/layout.tsx): Next.js layout · Root App Router layout and global styling entry point. · `src/app/layout.tsx`
- [Dashboard pages](https://github.com/adilmunawar/adiarc/blob/main/src/app/page.tsx): route pages · Thin page routes that mount the operational dashboard tools. · `src/app/page.tsx`

### Dashboard UI

Shared shell and feature tabs

- [Auth shell](https://github.com/adilmunawar/adiarc/blob/main/src/components/layout/AuthProvider.tsx): layout guard · Authentication, route protection, sidebar, tabs, header, splash, and trial gating. · `src/components/layout/AuthProvider.tsx`
- [Tool tabs](https://github.com/adilmunawar/adiarc/blob/main/src/components/dashboard-tabs/AiAssistantTab.tsx): dashboard modules · Main feature panels for AI, OCR, scanning, DB status, inventory, mutations, sync, and related tools. · `src/components/dashboard-tabs/AiAssistantTab.tsx`
- [Wirasat UI](https://github.com/adilmunawar/adiarc/blob/main/src/components/wirasat/FamilyTreeDiagram.tsx): family-tree view · Specialized inheritance visualization component. · `src/components/wirasat/FamilyTreeDiagram.tsx`
- [UI kit](https://github.com/adilmunawar/adiarc/blob/main/src/components/ui/button.tsx): component primitives · Reusable design-system primitives used across the dashboard. · `src/components/ui/button.tsx`

### API Routes

Server-side route handlers

- [DB status API](https://github.com/adilmunawar/adiarc/blob/main/src/app/api/db-status/route.ts): route handler · Server endpoint for database status checks. · `src/app/api/db-status/route.ts`
- [Scan API](https://github.com/adilmunawar/adiarc/blob/main/src/app/api/mauza-scanner/route.ts): route handler · Server endpoints for mauza scanning and persisting scan results. · `src/app/api/mauza-scanner/route.ts`
- [Sync API](https://github.com/adilmunawar/adiarc/blob/main/src/app/api/sync/route.ts): route handler · Server endpoint for sync operations. · `src/app/api/sync/route.ts`

### AI Layer

Genkit assistant pipeline and schema

- [AI flow](https://github.com/adilmunawar/adiarc/blob/main/src/ai/flows/db-assistant-flow.ts): Genkit flow · Genkit-based DB assistant orchestration. · `src/ai/flows/db-assistant-flow.ts`
- [AI schema](https://github.com/adilmunawar/adiarc/blob/main/src/ai/schema/lrims_schema.txt): domain schema · LRIMS knowledge schema used by the assistant. · `src/ai/schema/lrims_schema.txt`

### Domain Libs

Reusable computation and integration helpers

- [Core libs](https://github.com/adilmunawar/adiarc/blob/main/src/lib/wirasat-calculator.ts): domain helpers · Inheritance, image forensics, Supabase access, and shared utilities. · `src/lib/wirasat-calculator.ts`
- [Inventory worker](https://github.com/adilmunawar/adiarc/blob/main/src/workers/inventory-scanner.worker.ts): web worker · Background scanning path for inventory processing. · `src/workers/inventory-scanner.worker.ts`

### Operational Assets

SQL, PowerShell, and manual assets

- [SQL assets](https://github.com/adilmunawar/adiarc/blob/HEAD/nodeconfigs/Daily%20Progress%20Query.sql): sql scripts · Operational SQL bundles for reports, audits, mutations, and cleanup. · `nodeconfigs/Daily Progress Query.sql`
- [Schema assets](https://github.com/adilmunawar/adiarc/blob/main/Schemas/schema.sql): schema files · CSV and SQL schema references for land-record structures. · `Schemas/schema.sql`
- [PowerShell queries](https://github.com/adilmunawar/adiarc/tree/main/powershellQueries/dailyprogressMutations_JSON): ops scripts · PowerShell query bundle used for database operations. · `powershellQueries/dailyprogressMutations_JSON`
- [Manuals](https://github.com/adilmunawar/adiarc/tree/main/public/Manual): static docs · User-facing manual and static public assets. · `public/Manual`

## Connections

- App shell → Auth shell: wraps · Root layout provides the authenticated application shell.
- Auth shell → Dashboard pages: hosts · Protected shell renders the dashboard route pages.
- Dashboard pages → Tool tabs: mounts · Pages are thin shells that load the corresponding tool tabs.
- Tool tabs → UI kit: uses · Tool panels compose shared UI primitives.
- Tool tabs → DB status API: calls · DB status tools invoke the status endpoint.
- Tool tabs → Scan API: calls · Scanning tools invoke mauza scan endpoints.
- Tool tabs → Sync API: calls · Sync tools invoke the sync endpoint.
- Tool tabs → AI flow: invokes · AI assistant UI routes requests into the Genkit flow.
- AI flow → AI schema: uses · Assistant flow is grounded in LRIMS schema knowledge.
- Tool tabs → Core libs: computes · Operational tabs rely on local domain logic for calculations and forensic helpers.
- Core libs → Inventory worker: offloads · Heavy inventory scanning can be delegated to a worker.
- Tool tabs → SQL assets: references · SQL generation, auditing, and reporting tools are backed by bundled SQL scripts.
- Tool tabs → PowerShell queries: references · PowerShell query tools expose stored query bundles.
- Tool tabs → Schema assets: references · DB and mutation tools use schema reference files.
- Tool tabs → Manuals: documents · User workflows are supported by static manuals.
- Core libs → DB status API: supports · Shared helpers may back server-side DB checks.
- Core libs → Scan API: supports · Shared helpers may support scan persistence and processing.
