# hwy21i/apex-develoment architecture

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

- Interactive diagram: https://gitdiagram.com/hwy21i/apex-develoment
- Repository: https://github.com/hwy21i/apex-develoment

## Overview

This repository is a construction-operations ERP: users manage projects and operational records through a Next.js application, while API routes authenticate requests, perform domain operations, and persist data in MongoDB. The graph highlights project/task management, procurement and inventory, reporting/search, and shared access/runtime layers. The README is only the generic Next.js starter README; domain capabilities are inferred from the repository tree and sampled source. Unsampled modules are included only where their paths and roles are clear; their internal links are omitted when evidence is unavailable.

Main entry points: [`app/api/tasks/route.ts`](https://github.com/hwy21i/apex-develoment/blob/main/app/api/tasks/route.ts) (Task API), [`lib/db/mongodb.ts`](https://github.com/hwy21i/apex-develoment/blob/main/lib/db/mongodb.ts) (MongoDB connector), [`lib/auth/guard.ts`](https://github.com/hwy21i/apex-develoment/blob/main/lib/auth/guard.ts) (Permission guard), [`app/api/dashboard/route.ts`](https://github.com/hwy21i/apex-develoment/blob/main/app/api/dashboard/route.ts) (Dashboard metrics)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_experience["User experience"]
  node_shell["App shell<br/>[AppShell.tsx]"]
  node_userprovider["Session provider<br/>[UserProvider.tsx]"]
  node_records_hook["Record client<br/>[useRecords.ts]"]
  node_project_ui["Project workspace<br/>[page.tsx]"]
end

subgraph group_operations["Project operations"]
  node_projects_api["Projects API<br/>[route.ts]"]
  node_tasks_ui["Task workspace<br/>[page.tsx]"]
  node_tasks_api["Task API<br/>[route.ts]"]
  node_dashboard_api["Dashboard metrics<br/>[route.ts]"]
end

subgraph group_supply["Supply and inventory"]
  node_procurement_ui["Procurement requests<br/>[page.tsx]"]
  node_receipts_api["Goods receipts<br/>[route.ts]"]
  node_inventory_ui["Inventory workspace<br/>[page.tsx]"]
end

subgraph group_platform["Platform services"]
  node_search_api["Global search<br/>[route.ts]"]
  node_reports_api["PDF reports<br/>[route.ts]"]
  node_auth_api["Authentication API<br/>[route.ts]"]
  node_auth_guard["Permission guard<br/>[guard.ts]"]
  node_access["Project access<br/>[access.ts]"]
  node_audit["Audit service<br/>[audit.ts]"]
end

subgraph group_persistence["Persistence"]
  node_mongo["MongoDB connector<br/>[mongodb.ts]"]
  node_project_model[("Project records<br/>[Project.ts]")]
  node_task_model[("Task records<br/>[Task.ts]")]
  node_supply_models[("Supply records<br/>[GoodsReceipt.ts]")]
end

node_user(("ERP user"))

node_user -.->|"uses"| node_shell
node_shell -->|"reads session"| node_userprovider
node_userprovider -->|"fetches session"| node_auth_api
node_userprovider -->|"requests logout"| node_auth_api
node_records_hook -->|"fetches projects"| node_projects_api
node_records_hook -.->|"supports records"| node_inventory_ui
node_tasks_ui -->|"uses shell"| node_shell
node_procurement_ui -->|"uses shell"| node_shell
node_tasks_api -->|"checks permission"| node_auth_guard
node_tasks_api -->|"checks project access"| node_access
node_tasks_api -->|"connects database"| node_mongo
node_tasks_api -->|"reads and writes"| node_task_model
node_tasks_api -->|"logs changes"| node_audit
node_tasks_api -.->|"refreshes metrics"| node_project_model
node_dashboard_api -->|"checks permission"| node_auth_guard
node_dashboard_api -->|"connects database"| node_mongo
node_dashboard_api -->|"queries projects"| node_project_model
node_dashboard_api -->|"queries tasks"| node_task_model
node_receipts_api -->|"checks permission"| node_auth_guard
node_receipts_api -->|"checks project access"| node_access
node_receipts_api -->|"connects database"| node_mongo
node_receipts_api -->|"creates receipts"| node_supply_models
node_search_api -->|"connects database"| node_mongo
node_search_api -->|"searches projects"| node_project_model
node_search_api -->|"searches tasks"| node_task_model
node_reports_api -->|"connects database"| node_mongo
node_reports_api -->|"checks permission"| node_auth_guard
node_reports_api -->|"queries projects"| node_project_model
node_auth_guard -->|"loads user"| node_mongo

click node_shell "https://github.com/hwy21i/apex-develoment/blob/main/components/layout/AppShell.tsx"
click node_userprovider "https://github.com/hwy21i/apex-develoment/blob/main/components/auth/UserProvider.tsx"
click node_records_hook "https://github.com/hwy21i/apex-develoment/blob/main/hooks/useRecords.ts"
click node_project_ui "https://github.com/hwy21i/apex-develoment/blob/main/app/projects/%5BprojectId%5D/overview/page.tsx"
click node_projects_api "https://github.com/hwy21i/apex-develoment/blob/main/app/api/projects/route.ts"
click node_tasks_ui "https://github.com/hwy21i/apex-develoment/blob/main/app/projects/%5BprojectId%5D/tasks/page.tsx"
click node_tasks_api "https://github.com/hwy21i/apex-develoment/blob/main/app/api/tasks/route.ts"
click node_dashboard_api "https://github.com/hwy21i/apex-develoment/blob/main/app/api/dashboard/route.ts"
click node_procurement_ui "https://github.com/hwy21i/apex-develoment/blob/main/app/procurement/requests/page.tsx"
click node_receipts_api "https://github.com/hwy21i/apex-develoment/blob/main/app/api/goods-receipts/route.ts"
click node_inventory_ui "https://github.com/hwy21i/apex-develoment/blob/main/app/inventory/page.tsx"
click node_search_api "https://github.com/hwy21i/apex-develoment/blob/main/app/api/search/route.ts"
click node_reports_api "https://github.com/hwy21i/apex-develoment/blob/main/app/api/reports/pdf/route.ts"
click node_auth_api "https://github.com/hwy21i/apex-develoment/blob/main/app/api/auth/me/route.ts"
click node_auth_guard "https://github.com/hwy21i/apex-develoment/blob/main/lib/auth/guard.ts"
click node_access "https://github.com/hwy21i/apex-develoment/blob/main/lib/services/access.ts"
click node_audit "https://github.com/hwy21i/apex-develoment/blob/main/lib/services/audit.ts"
click node_mongo "https://github.com/hwy21i/apex-develoment/blob/main/lib/db/mongodb.ts"
click node_project_model "https://github.com/hwy21i/apex-develoment/blob/main/models/Project.ts"
click node_task_model "https://github.com/hwy21i/apex-develoment/blob/main/models/Task.ts"
click node_supply_models "https://github.com/hwy21i/apex-develoment/blob/main/models/GoodsReceipt.ts"

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_shell,node_userprovider,node_records_hook,node_project_ui,node_user toneBlue
class node_projects_api,node_tasks_ui,node_tasks_api,node_dashboard_api toneAmber
class node_procurement_ui,node_receipts_api,node_inventory_ui toneMint
class node_search_api,node_reports_api,node_auth_api,node_auth_guard,node_access,node_audit toneRose
class node_mongo,node_project_model,node_task_model,node_supply_models toneIndigo
```

## Components

### User experience

- [App shell](https://github.com/hwy21i/apex-develoment/blob/main/components/layout/AppShell.tsx): `components/layout/AppShell.tsx`
- [Session provider](https://github.com/hwy21i/apex-develoment/blob/main/components/auth/UserProvider.tsx): `components/auth/UserProvider.tsx`
- [Record client](https://github.com/hwy21i/apex-develoment/blob/main/hooks/useRecords.ts): `hooks/useRecords.ts`
- [Project workspace](https://github.com/hwy21i/apex-develoment/blob/main/app/projects/%5BprojectId%5D/overview/page.tsx): `app/projects/[projectId]/overview/page.tsx`

### Project operations

- [Projects API](https://github.com/hwy21i/apex-develoment/blob/main/app/api/projects/route.ts): `app/api/projects/route.ts`
- [Task workspace](https://github.com/hwy21i/apex-develoment/blob/main/app/projects/%5BprojectId%5D/tasks/page.tsx): `app/projects/[projectId]/tasks/page.tsx`
- [Task API](https://github.com/hwy21i/apex-develoment/blob/main/app/api/tasks/route.ts): `app/api/tasks/route.ts`
- [Dashboard metrics](https://github.com/hwy21i/apex-develoment/blob/main/app/api/dashboard/route.ts): `app/api/dashboard/route.ts`

### Supply and inventory

- [Procurement requests](https://github.com/hwy21i/apex-develoment/blob/main/app/procurement/requests/page.tsx): `app/procurement/requests/page.tsx`
- [Goods receipts](https://github.com/hwy21i/apex-develoment/blob/main/app/api/goods-receipts/route.ts): `app/api/goods-receipts/route.ts`
- [Inventory workspace](https://github.com/hwy21i/apex-develoment/blob/main/app/inventory/page.tsx): `app/inventory/page.tsx`

### Platform services

- [Global search](https://github.com/hwy21i/apex-develoment/blob/main/app/api/search/route.ts): `app/api/search/route.ts`
- [PDF reports](https://github.com/hwy21i/apex-develoment/blob/main/app/api/reports/pdf/route.ts): `app/api/reports/pdf/route.ts`
- [Authentication API](https://github.com/hwy21i/apex-develoment/blob/main/app/api/auth/me/route.ts): `app/api/auth/me/route.ts`
- [Permission guard](https://github.com/hwy21i/apex-develoment/blob/main/lib/auth/guard.ts): `lib/auth/guard.ts`
- [Project access](https://github.com/hwy21i/apex-develoment/blob/main/lib/services/access.ts): `lib/services/access.ts`
- [Audit service](https://github.com/hwy21i/apex-develoment/blob/main/lib/services/audit.ts): `lib/services/audit.ts`

### Persistence

- [MongoDB connector](https://github.com/hwy21i/apex-develoment/blob/main/lib/db/mongodb.ts): `lib/db/mongodb.ts`
- [Project records](https://github.com/hwy21i/apex-develoment/blob/main/models/Project.ts): `models/Project.ts`
- [Task records](https://github.com/hwy21i/apex-develoment/blob/main/models/Task.ts): `models/Task.ts`
- [Supply records](https://github.com/hwy21i/apex-develoment/blob/main/models/GoodsReceipt.ts): `models/GoodsReceipt.ts`

### Other components

- **ERP user**

## Connections

- ERP user → App shell: uses
- App shell → Session provider: reads session (evidence: `components/layout/AppShell.tsx`)
- Session provider → Authentication API: fetches session (evidence: `components/auth/UserProvider.tsx`)
- Session provider → Authentication API: requests logout (evidence: `components/auth/UserProvider.tsx`)
- Record client → Projects API: fetches projects (evidence: `hooks/useRecords.ts`)
- Record client → Inventory workspace: supports records (evidence: `app/inventory/page.tsx`)
- Task workspace → App shell: uses shell
- Procurement requests → App shell: uses shell (evidence: `app/procurement/requests/page.tsx`)
- Task API → Permission guard: checks permission (evidence: `app/api/tasks/route.ts`)
- Task API → Project access: checks project access (evidence: `app/api/tasks/route.ts`)
- Task API → MongoDB connector: connects database (evidence: `app/api/tasks/route.ts`)
- Task API → Task records: reads and writes (evidence: `app/api/tasks/route.ts`)
- Task API → Audit service: logs changes (evidence: `app/api/tasks/route.ts`)
- Task API → Project records: refreshes metrics (evidence: `app/api/tasks/route.ts`)
- Dashboard metrics → Permission guard: checks permission (evidence: `app/api/dashboard/route.ts`)
- Dashboard metrics → MongoDB connector: connects database (evidence: `app/api/dashboard/route.ts`)
- Dashboard metrics → Project records: queries projects (evidence: `app/api/dashboard/route.ts`)
- Dashboard metrics → Task records: queries tasks (evidence: `app/api/dashboard/route.ts`)
- Goods receipts → Permission guard: checks permission (evidence: `app/api/goods-receipts/route.ts`)
- Goods receipts → Project access: checks project access (evidence: `app/api/goods-receipts/route.ts`)
- Goods receipts → MongoDB connector: connects database (evidence: `app/api/goods-receipts/route.ts`)
- Goods receipts → Supply records: creates receipts (evidence: `app/api/goods-receipts/route.ts`)
- Global search → MongoDB connector: connects database (evidence: `app/api/search/route.ts`)
- Global search → Project records: searches projects (evidence: `app/api/search/route.ts`)
- Global search → Task records: searches tasks (evidence: `app/api/search/route.ts`)
- PDF reports → MongoDB connector: connects database (evidence: `app/api/reports/pdf/route.ts`)
- PDF reports → Permission guard: checks permission (evidence: `app/api/reports/pdf/route.ts`)
- PDF reports → Project records: queries projects (evidence: `app/api/reports/pdf/route.ts`)
- Permission guard → MongoDB connector: loads user (evidence: `lib/auth/guard.ts`)
