# siddharth-mourya/powerlytic-ui architecture

> Architecture diagram of the GitHub repository siddharth-mourya/powerlytic-ui, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-02-04). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/siddharth-mourya/powerlytic-ui
- Repository: https://github.com/siddharth-mourya/powerlytic-ui

## Overview

##### Project Type & Purpose
- This is a Next.js front-end dashboard application for managing devices, device-models, organizations, users and port-types.
- It uses React components, Next.js App Router, React-Query for data fetching, Context for authentication state, and Axios to call external RESTful APIs.

##### Break Down the File Structure into Logical Layers
- Presentation Layer
– app/(pages)/… (SSR/SSG page entries)
– app/_components (reusable UI primitives)
– app/layout.tsx, providers.tsx (root layout, context providers)
- Data-Fetching Layer
– app/_lib/_react-query-hooks (React-Query hooks per domain: auth, devices, models, orgs, portTypes, values)
– app/_lib/api/axios.ts (Axios instance for HTTP calls)
- Business-Logic & State
– app/_lib/context/AuthContext.tsx (authentication context)
– app/_lib/utils/rbac (role-based access control policies & guards)
- Static & Configuration
– public/ (static assets)
– next.config.ts, tsconfig.json, package.json (build & TypeScript config)

##### Readme for Stack & Deployment
- Next.js v13+ with App Router
- Tailwind/PostCSS (postcss.config.mjs, globals.css)
- Deployed on Vercel by default

##### Main Components & Their Relationships
a. Client (Browser)
- Renders Next.js pages & React components
- Interacts with Next.js server via SSR/SSG and client-side JS
b. Next.js Runtime/Server
- Serves routes under /dashboard, /login, etc.
- Provides API routes if any (none here) or proxies to external APIs
c. UI Component Library
- Accordion, Badge, Button, Tables, Charts
- Layout primitives: Header, SideBar, DashboardLayout
d. Data Layer
- React-Query Queries & Mutations
- Axios HTTP client
e. External RESTful Back-end Services
- Auth service (login, logout, current user)
- Device service (CRUD devices, update values)
- Device-Model service
- Organization service
- Port-Type service
- Values service

##### Architectural Patterns & Principles
- Feature-based folder structure (group by domain: devices, models, orgs)
- Separation of concerns: UI components vs. data-fetch hooks vs. business policies
- Context for cross-cutting concerns (authentication)
- React-Query for server-state management and caching
- Role-based access control via guard components

##### Essential Elements
- Clear component labels (e.g., “DeviceModelList.tsx”, “useDeviceModelsListRQ”)
- Annotations for key design patterns (e.g., “React-Query caching”)

## Diagram (Mermaid)

```mermaid
graph TB
    %% Presentation Layer
    subgraph "Presentation Layer" 
        direction TB
        Pages["app/(pages)/…"]:::presentation
        Layout["app/layout.tsx"]:::presentation
        Providers["app/providers.tsx"]:::presentation
        SharedUI["app/_components/"]:::presentation
        subgraph "Dashboard Layout & Navigation"
            direction TB
            DashboardLayout["DashboardLayout.tsx"]:::presentation
            Header["Header.tsx"]:::presentation
            SideBar["SideBar.tsx"]:::presentation
            Authenticator["Authenticator.tsx"]:::presentation
        end
        subgraph "Authentication Pages"
            direction TB
            LoginPage["login/page.tsx"]:::presentation
            LoginForm["LoginForm.tsx"]:::presentation
        end
    end

    %% Business Logic & State Layer
    subgraph "Business Logic & State" 
        direction TB
        AuthContext["AuthContext.tsx"]:::util
        subgraph "RBAC Utilities"
            direction TB
            RoleProtectedGuard["RoleProtectedGuard.tsx"]:::util
            Can["can.ts"]:::util
            Permissions["permissions.ts"]:::util
            Policies["policies/"]:::util
        end
    end

    %% Data-Fetching Layer
    subgraph "Data-Fetching Layer"
        direction TB
        subgraph "React-Query Hooks"
            direction TB
            subgraph "Auth Hooks"
                useCurrentUser["useCurrentLoggedinUserRQ.ts"]:::data
                useLogin["useLoginMutation.ts"]:::data
                useLogout["useLogout.ts"]:::data
            end
            subgraph "Device Hooks"
                useDevices["useDevicesRQ.ts"]:::data
            end
            subgraph "Device-Model Hooks"
                useModelList["useDeviceModelsList.tsx"]:::data
                useModelDetails["useDeviceModelDetailsRQ.tsx"]:::data
                useModelMut["useDeviceModelMutation.tsx"]:::data
            end
            subgraph "Organization Hooks"
                useOrgs["useOrganizationsRQ.tsx"]:::data
                useOrgById["useOrganizationByIdRQ.tsx"]:::data
                useOrgsMut["useOrganizationsMutation.tsx"]:::data
            end
            subgraph "Port-Type Hooks"
                portTypes["portTypes.tsx"]:::data
                addPort["addPortType.tsx"]:::data
                updatePort["updatePortType.tsx"]:::data
                deletePort["deletePortType.tsx"]:::data
            end
            subgraph "Values Hooks"
                useValues["useValuesRQ.ts"]:::data
            end
        end
        Axios["axios.ts"]:::data
    end

    %% External Services
    subgraph "External RESTful Services"
        direction TB
        AuthService["Auth Service (POST/GET)"]:::external
        DeviceService["Device Service"]:::external
        ModelService["Device-Model Service"]:::external
        OrgService["Organization Service"]:::external
        PortTypeService["Port-Type Service"]:::external
        ValuesService["Values Service"]:::external
    end

    %% Connections
    Browser["User Browser"]:::external
    NextRuntime["Next.js Runtime/Server"]:::external

    Browser -->|"HTTP Request"| NextRuntime
    NextRuntime -->|"renders"| Pages
    Pages -->|"wrap with"| Layout
    Layout -->|"provides"| Providers
    Providers -->|"injects"| AuthContext
    AuthContext -->|"guards via"| RoleProtectedGuard

    Pages -->|"calls hook"| useCurrentUser
    Pages -->|"calls hook"| useLogin
    Pages -->|"calls hook"| useLogout
    Pages -->|"calls hook"| useDevices
    Pages -->|"calls hook"| useModelList
    Pages -->|"calls hook"| useModelDetails
    Pages -->|"calls hook"| useModelMut
    Pages -->|"calls hook"| useOrgs
    Pages -->|"calls hook"| useOrgById
    Pages -->|"calls hook"| useOrgsMut
    Pages -->|"calls hook"| portTypes
    Pages -->|"calls hook"| addPort
    Pages -->|"calls hook"| updatePort
    Pages -->|"calls hook"| deletePort
    Pages -->|"calls hook"| useValues

    useCurrentUser -->|GET| Axios
    useLogin -->|POST| Axios
    useLogout -->|POST| Axios
    useDevices -->|GET| Axios
    useModelList -->|GET| Axios
    useModelDetails -->|GET| Axios
    useModelMut -->|POST/PUT/DELETE| Axios
    useOrgs -->|GET| Axios
    useOrgById -->|GET| Axios
    useOrgsMut -->|POST/PUT/DELETE| Axios
    portTypes -->|GET| Axios
    addPort -->|POST| Axios
    updatePort -->|PUT| Axios
    deletePort -->|DELETE| Axios
    useValues -->|GET| Axios

    Axios -->|"HTTP Call"| AuthService
    Axios -->|"HTTP Call"| DeviceService
    Axios -->|"HTTP Call"| ModelService
    Axios -->|"HTTP Call"| OrgService
    Axios -->|"HTTP Call"| PortTypeService
    Axios -->|"HTTP Call"| ValuesService

    %% Click Events
    click Pages "https://github.com/siddharth-mourya/powerlytic-ui/tree/main/app/(pages)/"
    click Layout "https://github.com/siddharth-mourya/powerlytic-ui/blob/main/app/layout.tsx"
    click Providers "https://github.com/siddharth-mourya/powerlytic-ui/blob/main/app/providers.tsx"
    click SharedUI "https://github.com/siddharth-mourya/powerlytic-ui/tree/main/app/_components/"
    click DashboardLayout "https://github.com/siddharth-mourya/powerlytic-ui/blob/main/app/_components/layout/DashboardLayout.tsx"
    click Header "https://github.com/siddharth-mourya/powerlytic-ui/blob/main/app/_components/layout/Header.tsx"
    click SideBar "https://github.com/siddharth-mourya/powerlytic-ui/blob/main/app/_components/layout/SideBar.tsx"
    click Authenticator "https://github.com/siddharth-mourya/powerlytic-ui/blob/main/app/_components/layout/Authenticator.tsx"
    click LoginPage "https://github.com/siddharth-mourya/powerlytic-ui/blob/main/app/(pages)/login/page.tsx"
    click LoginForm "https://github.com/siddharth-mourya/powerlytic-ui/blob/main/app/(pages)/login/LoginForm.tsx"
    click useCurrentUser "https://github.com/siddharth-mourya/powerlytic-ui/blob/main/app/_lib/_react-query-hooks/auth/useCurrentLoggedinUserRQ.ts"
    click useLogin "https://github.com/siddharth-mourya/powerlytic-ui/blob/main/app/_lib/_react-query-hooks/auth/useLoginMutation.ts"
    click useLogout "https://github.com/siddharth-mourya/powerlytic-ui/blob/main/app/_lib/_react-query-hooks/auth/useLogout.ts"
    click useDevices "https://github.com/siddharth-mourya/powerlytic-ui/blob/main/app/_lib/_react-query-hooks/device/useDevicesRQ.ts"
    click useModelList "https://github.com/siddharth-mourya/powerlytic-ui/blob/main/app/_lib/_react-query-hooks/deviceModels/useDeviceModelsList.tsx"
    click useModelDetails "https://github.com/siddharth-mourya/powerlytic-ui/blob/main/app/_lib/_react-query-hooks/deviceModels/useDeviceModelDetailsRQ.tsx"
    click useModelMut "https://github.com/siddharth-mourya/powerlytic-ui/blob/main/app/_lib/_react-query-hooks/deviceModels/useDeviceModelMutation.tsx"
    click useOrgs "https://github.com/siddharth-mourya/powerlytic-ui/blob/main/app/_lib/_react-query-hooks/organizations/useOrganizationsRQ.tsx"
    click useOrgById "https://github.com/siddharth-mourya/powerlytic-ui/blob/main/app/_lib/_react-query-hooks/organizations/useOrganizationByIdRQ.tsx"
    click useOrgsMut "https://github.com/siddharth-mourya/powerlytic-ui/blob/main/app/_lib/_react-query-hooks/organizations/useOrganizationsMutation.tsx"
    click portTypes "https://github.com/siddharth-mourya/powerlytic-ui/blob/main/app/_lib/_react-query-hooks/portTypes/portTypes.tsx"
    click addPort "https://github.com/siddharth-mourya/powerlytic-ui/blob/main/app/_lib/_react-query-hooks/portTypes/addPortType.tsx"
    click updatePort "https://github.com/siddharth-mourya/powerlytic-ui/blob/main/app/_lib/_react-query-hooks/portTypes/updatePortType.tsx"
    click deletePort "https://github.com/siddharth-mourya/powerlytic-ui/blob/main/app/_lib/_react-query-hooks/portTypes/deletePortType.tsx"
    click useValues "https://github.com/siddharth-mourya/powerlytic-ui/blob/main/app/_lib/_react-query-hooks/values/useValuesRQ.ts"
    click Axios "https://github.com/siddharth-mourya/powerlytic-ui/blob/main/app/_lib/api/axios.ts"
    click AuthContext "https://github.com/siddharth-mourya/powerlytic-ui/blob/main/app/_lib/context/AuthContext.tsx"
    click RoleProtectedGuard "https://github.com/siddharth-mourya/powerlytic-ui/blob/main/app/_lib/utils/rbac/RoleProtectedGuard.tsx"
    click Can "https://github.com/siddharth-mourya/powerlytic-ui/blob/main/app/_lib/utils/rbac/can.ts"
    click Permissions "https://github.com/siddharth-mourya/powerlytic-ui/blob/main/app/_lib/utils/rbac/permissions.ts"
    click Policies "https://github.com/siddharth-mourya/powerlytic-ui/tree/main/app/_lib/utils/rbac/policies/"
    click Static "https://github.com/siddharth-mourya/powerlytic-ui/tree/main/public/"
    click nextConfig "https://github.com/siddharth-mourya/powerlytic-ui/blob/main/next.config.ts"
    click tsconfig "https://github.com/siddharth-mourya/powerlytic-ui/blob/main/tsconfig.json"
    click pkg "https://github.com/siddharth-mourya/powerlytic-ui/blob/main/package.json"
    click postcss "https://github.com/siddharth-mourya/powerlytic-ui/blob/main/postcss.config.mjs"
    click globals "https://github.com/siddharth-mourya/powerlytic-ui/blob/main/globals.css"

    %% Styles
    classDef presentation fill:#D0E7FF,stroke:#0366d6,stroke-width:1px
    classDef data fill:#DFFFE0,stroke:#006400,stroke-width:1px
    classDef util fill:#F0F0F0,stroke:#808080,stroke-width:1px
    classDef external fill:#FFE4B5,stroke:#FF8C00,stroke-width:1px
```
