# sampath0411/cdas-project architecture

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

- Interactive diagram: https://gitdiagram.com/sampath0411/cdas-project
- Repository: https://github.com/sampath0411/cdas-project

## Overview

#### Purpose and Entry Points
This is a Next.js App Router application for recording, managing, analyzing, and exporting equipment-delay data. The root route and layouts establish application-wide rendering; route groups separate authentication from the protected dashboard.
- `src/app/page.tsx`
- `src/app/layout.tsx`
- `src/app/(auth)/login/page.tsx`

#### Authentication and Access Boundary
Supabase-backed authentication is integrated at client, server, middleware, and admin contexts. Request middleware is the primary route-protection/session-refresh boundary; authenticated application content is organized beneath the dashboard route group. Client-side guards and an auth provider support UI session state.
- `middleware.ts`
- `src/lib/supabase/middleware.ts`
- `src/lib/supabase/server.ts`
- `src/components/auth/auth-guard.tsx`
- `src/providers/auth-provider.tsx`

#### Dashboard Shell and Analytics
The authenticated dashboard layout provides navigation and shared dashboard chrome. Its landing page composes KPI, trend, distribution, recent-entry, and delayed-equipment views, making it the primary reporting/operational overview surface.
- `src/app/(dashboard)/layout.tsx`
- `src/app/(dashboard)/dashboard/page.tsx`
- `src/components/dashboard/kpi-cards-grid.tsx`
- `src/components/dashboard/monthly-trends-chart.tsx`
- `src/components/layout/sidebar.tsx`

#### Delay Recording and Reporting Flow
Users submit delay records through the delay-entry route and its server actions. Delay-report pages render filtering, tabular data, and multiple chart visualizations. Validation defines the input boundary before persistence; delay data can also cross an HTTP export boundary as an API response.
- `src/app/(dashboard)/delay-entry/actions.ts`
- `src/components/delays/delay-entry-form.tsx`
- `src/app/(dashboard)/delay-reports/page.tsx`
- `src/components/delays/delay-filters.tsx`
- `src/app/api/export/delays/route.ts`
- `src/lib/validations/delay.ts`

#### Equipment Master Data
Equipment management is a separate domain workflow covering equipment, sub-equipment, and shops. The page-level server actions form the mutation boundary, while dialogs and lists supply CRUD-oriented UI for the hierarchy used by delay entry and analysis.
- `src/app/(dashboard)/equipment/page.tsx`
- `src/app/(dashboard)/equipment/actions.ts`
- `src/components/equipment/equipment-tabs.tsx`
- `src/components/equipment/sub-equipment-form-dialog.tsx`
- `src/components/equipment/shop-list.tsx`

#### Administration, Profile, and Preferences
User administration has dedicated actions and role/status presentation. Individual profile and password changes are distinct from broader application settings such as theme and notifications.
- `src/app/(dashboard)/users/actions.ts`
- `src/components/users/users-data-table.tsx`
- `src/app/(dashboard)/profile/page.tsx`
- `src/app/(dashboard)/settings/page.tsx`

#### Persistence, Security, and Runtime
The runtime is TypeScript/Next.js with React UI components and server actions/API routes. Supabase is the external backend for authentication and database access; schema migrations, seed data, and row-level security policies are versioned in-repo. An admin Supabase client is a privileged boundary and should remain server-only.
- `src/lib/supabase/client.ts`
- `src/lib/supabase/admin.ts`
- `supabase/migrations/001_schema.sql`
- `supabase/migrations/002_rls.sql`
- `scripts/full-setup.sql`

Main entry points: [`src/app/(dashboard)/layout.tsx`](https://github.com/sampath0411/cdas-project/blob/master/src/app/(dashboard)/layout.tsx) (Dashboard shell), [`src/lib/supabase/server.ts`](https://github.com/sampath0411/cdas-project/blob/master/src/lib/supabase/server.ts) (Server Supabase client), [`middleware.ts`](https://github.com/sampath0411/cdas-project/blob/master/middleware.ts) (Request middleware), [`src/app/(dashboard)/delay-entry/actions.ts`](https://github.com/sampath0411/cdas-project/blob/master/src/app/(dashboard)/delay-entry/actions.ts) (Delay server actions)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["Next.js Application"]
  node_root["Root app shell<br/>App Router entry<br/>[layout.tsx]"]
  node_home["Root route<br/>public page<br/>[page.tsx]"]
  node_dashboard_shell["Dashboard shell<br/>protected layout<br/>[layout.tsx]"]
  node_dashboard["Dashboard overview<br/>analytics page<br/>[page.tsx]"]
  node_profile_settings["Profile and settings<br/>preference routes<br/>[page.tsx]"]
end

subgraph group_auth["Authentication"]
  node_login["Login route<br/>auth page<br/>[page.tsx]"]
  node_middleware{{"Request middleware<br/>route protection<br/>[middleware.ts]"}}
  node_supabase_middleware["Middleware auth client<br/>Supabase adapter<br/>[middleware.ts]"]
  node_auth_ui["Auth UI state<br/>provider and guard<br/>[auth-provider.tsx]"]
end

subgraph group_delay["Delay Operations"]
  node_delay_entry["Delay entry form<br/>recording UI"]
  node_delay_actions{{"Delay server actions<br/>mutation boundary<br/>[actions.ts]"}}
  node_delay_validation["Delay validation<br/>input schema<br/>[delay.ts]"]
  node_delay_reports["Delay reports<br/>reporting page<br/>[page.tsx]"]
  node_delay_export{{"Delay export API<br/>HTTP endpoint<br/>[route.ts]"}}
end

subgraph group_master["Master Data &amp; Admin"]
  node_equipment["Equipment management<br/>master-data page<br/>[page.tsx]"]
  node_equipment_actions{{"Equipment actions<br/>mutation boundary<br/>[actions.ts]"}}
  node_user_admin{{"User administration<br/>admin actions<br/>[actions.ts]"}}
end

subgraph group_data["Supabase Backend"]
  node_supabase_server["Server Supabase client<br/>database client<br/>[server.ts]"]
  node_supabase_admin{{"Admin Supabase client<br/>privileged client<br/>[admin.ts]"}}
  node_supabase[("Supabase service<br/>auth and database")]
  node_database_policy["Schema and RLS migrations<br/>database policy<br/>[002_rls.sql]"]
end

node_root -->|"renders"| node_home
node_root -->|"provides session state"| node_auth_ui
node_middleware -->|"uses"| node_supabase_middleware
node_supabase_middleware -->|"refreshes session"| node_supabase
node_middleware -.->|"redirects unauthenticated"| node_login
node_middleware -->|"permits authenticated"| node_dashboard_shell
node_dashboard_shell -->|"hosts"| node_dashboard
node_dashboard_shell -->|"hosts"| node_delay_entry
node_dashboard_shell -->|"hosts"| node_delay_reports
node_dashboard_shell -->|"hosts"| node_equipment
node_dashboard_shell -->|"hosts"| node_profile_settings
node_delay_entry -->|"submits"| node_delay_actions
node_delay_actions -->|"validates with"| node_delay_validation
node_delay_actions -->|"persists through"| node_supabase_server
node_delay_reports -->|"queries through"| node_supabase_server
node_delay_export -->|"exports queried data"| node_supabase_server
node_equipment -->|"mutates through"| node_equipment_actions
node_equipment_actions -->|"persists through"| node_supabase_server
node_user_admin -->|"uses privileged access"| node_supabase_admin
node_supabase_server -->|"accesses"| node_supabase
node_supabase_admin -->|"admin access"| node_supabase
node_database_policy -->|"defines schema and RLS"| node_supabase

click node_root "https://github.com/sampath0411/cdas-project/blob/master/src/app/layout.tsx"
click node_home "https://github.com/sampath0411/cdas-project/blob/master/src/app/page.tsx"
click node_login "https://github.com/sampath0411/cdas-project/blob/master/src/app/(auth)/login/page.tsx"
click node_middleware "https://github.com/sampath0411/cdas-project/blob/master/middleware.ts"
click node_supabase_middleware "https://github.com/sampath0411/cdas-project/blob/master/src/lib/supabase/middleware.ts"
click node_auth_ui "https://github.com/sampath0411/cdas-project/blob/master/src/providers/auth-provider.tsx"
click node_dashboard_shell "https://github.com/sampath0411/cdas-project/blob/master/src/app/(dashboard)/layout.tsx"
click node_dashboard "https://github.com/sampath0411/cdas-project/blob/master/src/app/(dashboard)/dashboard/page.tsx"
click node_delay_entry "https://github.com/sampath0411/cdas-project/blob/master/src/components/delays/delay-entry-form.tsx"
click node_delay_actions "https://github.com/sampath0411/cdas-project/blob/master/src/app/(dashboard)/delay-entry/actions.ts"
click node_delay_validation "https://github.com/sampath0411/cdas-project/blob/master/src/lib/validations/delay.ts"
click node_delay_reports "https://github.com/sampath0411/cdas-project/blob/master/src/app/(dashboard)/delay-reports/page.tsx"
click node_delay_export "https://github.com/sampath0411/cdas-project/blob/master/src/app/api/export/delays/route.ts"
click node_equipment "https://github.com/sampath0411/cdas-project/blob/master/src/app/(dashboard)/equipment/page.tsx"
click node_equipment_actions "https://github.com/sampath0411/cdas-project/blob/master/src/app/(dashboard)/equipment/actions.ts"
click node_user_admin "https://github.com/sampath0411/cdas-project/blob/master/src/app/(dashboard)/users/actions.ts"
click node_profile_settings "https://github.com/sampath0411/cdas-project/blob/master/src/app/(dashboard)/profile/page.tsx"
click node_supabase_server "https://github.com/sampath0411/cdas-project/blob/master/src/lib/supabase/server.ts"
click node_supabase_admin "https://github.com/sampath0411/cdas-project/blob/master/src/lib/supabase/admin.ts"
click node_database_policy "https://github.com/sampath0411/cdas-project/blob/master/supabase/migrations/002_rls.sql"

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_root,node_home,node_dashboard_shell,node_dashboard,node_profile_settings toneBlue
class node_login,node_middleware,node_supabase_middleware,node_auth_ui toneAmber
class node_delay_entry,node_delay_actions,node_delay_validation,node_delay_reports,node_delay_export toneMint
class node_equipment,node_equipment_actions,node_user_admin toneRose
class node_supabase_server,node_supabase_admin,node_supabase,node_database_policy toneIndigo
```

## Components

### Next.js Application

App Router routes, layouts, server actions, and API handlers.

- [Root app shell](https://github.com/sampath0411/cdas-project/blob/master/src/app/layout.tsx): App Router entry · `src/app/layout.tsx`
- [Root route](https://github.com/sampath0411/cdas-project/blob/master/src/app/page.tsx): public page · `src/app/page.tsx`
- [Dashboard shell](https://github.com/sampath0411/cdas-project/blob/master/src/app/(dashboard)/layout.tsx): protected layout · Shared navigation and authenticated application chrome. · `src/app/(dashboard)/layout.tsx`
- [Dashboard overview](https://github.com/sampath0411/cdas-project/blob/master/src/app/(dashboard)/dashboard/page.tsx): analytics page · Composes KPI, trend, distribution, recent-entry, and delay views. · `src/app/(dashboard)/dashboard/page.tsx`
- [Profile and settings](https://github.com/sampath0411/cdas-project/blob/master/src/app/(dashboard)/profile/page.tsx): preference routes · Personal profile/password changes and application preferences. · `src/app/(dashboard)/profile/page.tsx`

### Authentication

Session protection and Supabase auth integration.

- [Login route](https://github.com/sampath0411/cdas-project/blob/master/src/app/(auth)/login/page.tsx): auth page · `src/app/(auth)/login/page.tsx`
- [Request middleware](https://github.com/sampath0411/cdas-project/blob/master/middleware.ts): route protection · Refreshes sessions and enforces protected-route access. · `middleware.ts`
- [Middleware auth client](https://github.com/sampath0411/cdas-project/blob/master/src/lib/supabase/middleware.ts): Supabase adapter · `src/lib/supabase/middleware.ts`
- [Auth UI state](https://github.com/sampath0411/cdas-project/blob/master/src/providers/auth-provider.tsx): provider and guard · Client session state and guarded UI access. · `src/providers/auth-provider.tsx`

### Delay Operations

Recording, reporting, and export of delay data.

- [Delay entry form](https://github.com/sampath0411/cdas-project/blob/master/src/components/delays/delay-entry-form.tsx): recording UI · `src/components/delays/delay-entry-form.tsx`
- [Delay server actions](https://github.com/sampath0411/cdas-project/blob/master/src/app/(dashboard)/delay-entry/actions.ts): mutation boundary · `src/app/(dashboard)/delay-entry/actions.ts`
- [Delay validation](https://github.com/sampath0411/cdas-project/blob/master/src/lib/validations/delay.ts): input schema · `src/lib/validations/delay.ts`
- [Delay reports](https://github.com/sampath0411/cdas-project/blob/master/src/app/(dashboard)/delay-reports/page.tsx): reporting page · Filtering, tables, and chart visualizations. · `src/app/(dashboard)/delay-reports/page.tsx`
- [Delay export API](https://github.com/sampath0411/cdas-project/blob/master/src/app/api/export/delays/route.ts): HTTP endpoint · Returns delay data across an API boundary. · `src/app/api/export/delays/route.ts`

### Master Data & Admin

Equipment hierarchy and user management workflows.

- [Equipment management](https://github.com/sampath0411/cdas-project/blob/master/src/app/(dashboard)/equipment/page.tsx): master-data page · Manages equipment, sub-equipment, and shops. · `src/app/(dashboard)/equipment/page.tsx`
- [Equipment actions](https://github.com/sampath0411/cdas-project/blob/master/src/app/(dashboard)/equipment/actions.ts): mutation boundary · `src/app/(dashboard)/equipment/actions.ts`
- [User administration](https://github.com/sampath0411/cdas-project/blob/master/src/app/(dashboard)/users/actions.ts): admin actions · Manages user roles and status. · `src/app/(dashboard)/users/actions.ts`

### Supabase Backend

External auth/database service and versioned database policy.

- [Server Supabase client](https://github.com/sampath0411/cdas-project/blob/master/src/lib/supabase/server.ts): database client · Server-side application access to Supabase. · `src/lib/supabase/server.ts`
- [Admin Supabase client](https://github.com/sampath0411/cdas-project/blob/master/src/lib/supabase/admin.ts): privileged client · Server-only privileged administrative access. · `src/lib/supabase/admin.ts`
- **Supabase service**: auth and database
- [Schema and RLS migrations](https://github.com/sampath0411/cdas-project/blob/master/supabase/migrations/002_rls.sql): database policy · Versioned schema and row-level security definitions. · `supabase/migrations/002_rls.sql`

## Connections

- Root app shell → Root route: renders
- Root app shell → Auth UI state: provides session state
- Request middleware → Middleware auth client: uses
- Middleware auth client → Supabase service: refreshes session
- Request middleware → Login route: redirects unauthenticated
- Request middleware → Dashboard shell: permits authenticated
- Dashboard shell → Dashboard overview: hosts
- Dashboard shell → Delay entry form: hosts
- Dashboard shell → Delay reports: hosts
- Dashboard shell → Equipment management: hosts
- Dashboard shell → Profile and settings: hosts
- Delay entry form → Delay server actions: submits
- Delay server actions → Delay validation: validates with
- Delay server actions → Server Supabase client: persists through
- Delay reports → Server Supabase client: queries through
- Delay export API → Server Supabase client: exports queried data
- Equipment management → Equipment actions: mutates through
- Equipment actions → Server Supabase client: persists through
- User administration → Admin Supabase client: uses privileged access
- Server Supabase client → Supabase service: accesses
- Admin Supabase client → Supabase service: admin access
- Schema and RLS migrations → Supabase service: defines schema and RLS
