# machadop1407/nextjs-inventory-management-app architecture

> Architecture diagram of the GitHub repository machadop1407/nextjs-inventory-management-app, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-05-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/machadop1407/nextjs-inventory-management-app
- Repository: https://github.com/machadop1407/nextjs-inventory-management-app

## Overview

1. **Overall shape**
   - This is a single Next.js App Router application, not a separate frontend/backend split.
   - The repo is a full-stack inventory system where UI, auth, server actions, and database access live together in one codebase.

2. **Route structure**
   - The `app/` directory defines the main user-facing flows: `dashboard`, `inventory`, `add-product`, `settings`, and `sign-in`.
   - `app/page.tsx` is the root entry point, while `app/layout.tsx` and `app/globals.css` provide the shared shell and styling across the app.
   - `app/loading.tsx` indicates route-level loading states are part of the UX.

3. **Authentication boundary**
   - Authentication is handled through **Stack Auth**, with dedicated integration files in `lib/auth.ts`, `stack/client.tsx`, `stack/server.tsx`, and the catch-all route `app/handler/[...stack]/page.tsx`.
   - That handler route is the main auth callback/bridge between Stack Auth and the Next.js app.
   - The `sign-in` route is the public entry for unauthenticated users, while the management pages are presumably protected.

4. **Protected application shell**
   - `components/sidebar.tsx` suggests the authenticated experience is built around a persistent navigation shell.
   - The sidebar likely anchors the dashboard, inventory, add-product, and settings sections, making the app feel like an internal admin console rather than a public site.

5. **Inventory data layer**
   - `prisma/schema.prisma`, `prisma/migrations/`, and `lib/prisma.ts` show the persistence layer is **Prisma + PostgreSQL**.
   - The database schema and migrations define the inventory domain model, and Prisma is the main boundary between app logic and the database.
   - `prisma/seed.ts` implies the repo includes initial/demo data for development or onboarding.

6. **Write operations and business logic**
   - `lib/actions/products.ts` is the key server-side action module for product CRUD.
   - This is the main mutation path: form submissions or page actions go through Next.js server actions, then Prisma writes to the database.
   - Because it is in `lib/actions`, business rules are centralized outside the page components.

7. **Read paths and analytics**
   - `app/dashboard/page.tsx` likely aggregates inventory metrics, while `components/products-chart.tsx` renders visual analytics.
   - The chart component uses a client-side charting library pattern, consistent with the README’s mention of Recharts.
   - This creates a read-heavy analytics flow: database → server-rendered page data → chart/table UI.

8. **Inventory list experience**
   - `app/inventory/page.tsx` plus `components/pagination.tsx` indicate the product list is designed for larger datasets.
   - Search/filtering and pagination are part of the UI boundary, reducing load and keeping the inventory view scalable.
   - The inventory page is likely the main operational screen for browsing and managing items.

9. **UI composition**
   - The app mixes server-rendered pages with selective client components for interactivity and visualization.
   - Shared presentational pieces live in `components/`, while route-specific screens live in `app/`.
   - `app/add-product/page.tsx` is likely a form-driven screen that submits through server actions rather than a separate API layer.

10. **Deployment/runtime implications**
   - The architecture is built for **Vercel-style deployment** with a managed PostgreSQL database.
   - Because auth, rendering, and mutations happen in the Next.js runtime, the app stays stateless at the app layer; persistence lives in Postgres.
   - The main external dependencies that shape the architecture are Stack Auth for identity, Prisma for persistence, and Recharts/Lucide for UI/analytics presentation.

Main entry points: [`components/sidebar.tsx`](https://github.com/machadop1407/nextjs-inventory-management-app/blob/main/components/sidebar.tsx) (Sidebar), [`app/dashboard/page.tsx`](https://github.com/machadop1407/nextjs-inventory-management-app/blob/main/app/dashboard/page.tsx) (Dashboard), [`app/inventory/page.tsx`](https://github.com/machadop1407/nextjs-inventory-management-app/blob/main/app/inventory/page.tsx) (Inventory), [`app/layout.tsx`](https://github.com/machadop1407/nextjs-inventory-management-app/blob/main/app/layout.tsx) (Shell)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["App Router"]
  node_root["Home<br/>route entry<br/>[page.tsx]"]
  node_layout["Shell<br/>[layout.tsx]"]
  node_loading["Loading<br/>route state<br/>[loading.tsx]"]
end

subgraph group_auth["Auth"]
  node_sign_in["Sign in<br/>public route<br/>[page.tsx]"]
  node_handler["Auth bridge<br/>callback route<br/>[page.tsx]"]
  node_lib_auth["Auth config<br/>[auth.ts]"]
  node_stack_client["Client auth<br/>stack client<br/>[client.tsx]"]
  node_stack_server["Server auth<br/>stack server<br/>[server.tsx]"]
end

subgraph group_inventory["Inventory"]
  node_dashboard["Dashboard<br/>analytics page<br/>[page.tsx]"]
  node_inventory_page["Inventory<br/>list page<br/>[page.tsx]"]
  node_add_product["Add product<br/>form page<br/>[page.tsx]"]
  node_settings["Settings<br/>account page<br/>[page.tsx]"]
  node_products_actions["Product actions<br/>server actions<br/>[products.ts]"]
end

subgraph group_data["Data Layer"]
  node_prisma_client["Prisma client<br/>db client<br/>[prisma.ts]"]
  node_schema["Schema<br/>data model<br/>[schema.prisma]"]
  node_migrations["Migrations<br/>[migration.sql]"]
  node_seed["Seed data<br/>bootstrap data<br/>[seed.ts]"]
end

subgraph group_ui["UI Components"]
  node_sidebar["Sidebar<br/>nav shell<br/>[sidebar.tsx]"]
  node_chart["Products chart<br/>client chart<br/>[products-chart.tsx]"]
  node_pagination["Pagination<br/>list control<br/>[pagination.tsx]"]
end

node_root -->|"renders within"| node_layout
node_layout -->|"uses"| node_sidebar
node_layout -->|"shows"| node_loading
node_layout -->|"routes to"| node_sign_in
node_sign_in -->|"auth UI"| node_stack_client
node_handler -->|"integrates"| node_lib_auth
node_lib_auth -->|"server side"| node_stack_server
node_lib_auth -->|"client side"| node_stack_client
node_dashboard -->|"visualizes"| node_chart
node_inventory_page -->|"paginates"| node_pagination
node_add_product -->|"submits to"| node_products_actions
node_dashboard -.->|"reads updates"| node_products_actions
node_inventory_page -.->|"reads updates"| node_products_actions
node_products_actions -->|"writes via"| node_prisma_client
node_prisma_client -->|"maps to"| node_schema
node_schema -->|"evolves through"| node_migrations
node_seed -.->|"seeds"| node_schema
node_dashboard -->|"navigates from"| node_sidebar
node_inventory_page -->|"navigates from"| node_sidebar
node_add_product -->|"navigates from"| node_sidebar
node_settings -->|"navigates from"| node_sidebar
node_dashboard -->|"reads from"| node_prisma_client
node_inventory_page -->|"reads from"| node_prisma_client

click node_root "https://github.com/machadop1407/nextjs-inventory-management-app/blob/main/app/page.tsx"
click node_layout "https://github.com/machadop1407/nextjs-inventory-management-app/blob/main/app/layout.tsx"
click node_loading "https://github.com/machadop1407/nextjs-inventory-management-app/blob/main/app/loading.tsx"
click node_sign_in "https://github.com/machadop1407/nextjs-inventory-management-app/blob/main/app/sign-in/page.tsx"
click node_handler "https://github.com/machadop1407/nextjs-inventory-management-app/blob/main/app/handler/[...stack]/page.tsx"
click node_lib_auth "https://github.com/machadop1407/nextjs-inventory-management-app/blob/main/lib/auth.ts"
click node_stack_client "https://github.com/machadop1407/nextjs-inventory-management-app/blob/main/stack/client.tsx"
click node_stack_server "https://github.com/machadop1407/nextjs-inventory-management-app/blob/main/stack/server.tsx"
click node_sidebar "https://github.com/machadop1407/nextjs-inventory-management-app/blob/main/components/sidebar.tsx"
click node_dashboard "https://github.com/machadop1407/nextjs-inventory-management-app/blob/main/app/dashboard/page.tsx"
click node_chart "https://github.com/machadop1407/nextjs-inventory-management-app/blob/main/components/products-chart.tsx"
click node_inventory_page "https://github.com/machadop1407/nextjs-inventory-management-app/blob/main/app/inventory/page.tsx"
click node_pagination "https://github.com/machadop1407/nextjs-inventory-management-app/blob/main/components/pagination.tsx"
click node_add_product "https://github.com/machadop1407/nextjs-inventory-management-app/blob/main/app/add-product/page.tsx"
click node_settings "https://github.com/machadop1407/nextjs-inventory-management-app/blob/main/app/settings/page.tsx"
click node_products_actions "https://github.com/machadop1407/nextjs-inventory-management-app/blob/main/lib/actions/products.ts"
click node_prisma_client "https://github.com/machadop1407/nextjs-inventory-management-app/blob/main/lib/prisma.ts"
click node_schema "https://github.com/machadop1407/nextjs-inventory-management-app/blob/main/prisma/schema.prisma"
click node_migrations "https://github.com/machadop1407/nextjs-inventory-management-app/blob/main/prisma/migrations/20250921232434_init/migration.sql"
click node_seed "https://github.com/machadop1407/nextjs-inventory-management-app/blob/main/prisma/seed.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_root,node_layout,node_loading toneBlue
class node_sign_in,node_handler,node_lib_auth,node_stack_client,node_stack_server toneAmber
class node_dashboard,node_inventory_page,node_add_product,node_settings,node_products_actions toneMint
class node_prisma_client,node_schema,node_migrations,node_seed toneRose
class node_sidebar,node_chart,node_pagination toneIndigo
```

## Components

### App Router

User-facing routes and shared Next.js shell.

- [Home](https://github.com/machadop1407/nextjs-inventory-management-app/blob/main/app/page.tsx): route entry · Root landing entry that routes users into the app. · `app/page.tsx`
- [Shell](https://github.com/machadop1407/nextjs-inventory-management-app/blob/main/app/layout.tsx): app shell · Shared application layout wrapping all routes. · `app/layout.tsx`
- [Loading](https://github.com/machadop1407/nextjs-inventory-management-app/blob/main/app/loading.tsx): route state · Global route-level loading UI. · `app/loading.tsx`

### Auth

Stack Auth integration and sign-in bridge.

- [Sign in](https://github.com/machadop1407/nextjs-inventory-management-app/blob/main/app/sign-in/page.tsx): public route · Unauthenticated entry point for login. · `app/sign-in/page.tsx`
- [Auth bridge](https://github.com/machadop1407/nextjs-inventory-management-app/blob/main/app/handler/[...stack]/page.tsx): callback route · Catch-all Stack Auth handler route. · `app/handler/[...stack]/page.tsx`
- [Auth config](https://github.com/machadop1407/nextjs-inventory-management-app/blob/main/lib/auth.ts): auth config · Central Stack Auth integration settings. · `lib/auth.ts`
- [Client auth](https://github.com/machadop1407/nextjs-inventory-management-app/blob/main/stack/client.tsx): stack client · Client-side Stack Auth wiring. · `stack/client.tsx`
- [Server auth](https://github.com/machadop1407/nextjs-inventory-management-app/blob/main/stack/server.tsx): stack server · Server-side Stack Auth wiring. · `stack/server.tsx`

### Inventory

Dashboard, list, and product editing flows.

- [Dashboard](https://github.com/machadop1407/nextjs-inventory-management-app/blob/main/app/dashboard/page.tsx): analytics page · Inventory overview and summary metrics. · `app/dashboard/page.tsx`
- [Inventory](https://github.com/machadop1407/nextjs-inventory-management-app/blob/main/app/inventory/page.tsx): list page · Main product browsing and management screen. · `app/inventory/page.tsx`
- [Add product](https://github.com/machadop1407/nextjs-inventory-management-app/blob/main/app/add-product/page.tsx): form page · Product creation and edit entry screen. · `app/add-product/page.tsx`
- [Settings](https://github.com/machadop1407/nextjs-inventory-management-app/blob/main/app/settings/page.tsx): account page · Application and account settings area. · `app/settings/page.tsx`
- [Product actions](https://github.com/machadop1407/nextjs-inventory-management-app/blob/main/lib/actions/products.ts): server actions · CRUD mutation layer for products. · `lib/actions/products.ts`

### Data Layer

Prisma schema, client, and seed data.

- [Prisma client](https://github.com/machadop1407/nextjs-inventory-management-app/blob/main/lib/prisma.ts): db client · Database access boundary used by app logic. · `lib/prisma.ts`
- [Schema](https://github.com/machadop1407/nextjs-inventory-management-app/blob/main/prisma/schema.prisma): data model · Inventory domain schema and relations. · `prisma/schema.prisma`
- [Migrations](https://github.com/machadop1407/nextjs-inventory-management-app/blob/main/prisma/migrations/20250921232434_init/migration.sql): db migrations · Database evolution history for the schema. · `prisma/migrations/20250921232434_init/migration.sql`
- [Seed data](https://github.com/machadop1407/nextjs-inventory-management-app/blob/main/prisma/seed.ts): bootstrap data · Initial/demo data for local setup. · `prisma/seed.ts`

### UI Components

Shared navigation, charts, and pagination.

- [Sidebar](https://github.com/machadop1407/nextjs-inventory-management-app/blob/main/components/sidebar.tsx): nav shell · Persistent navigation for authenticated views. · `components/sidebar.tsx`
- [Products chart](https://github.com/machadop1407/nextjs-inventory-management-app/blob/main/components/products-chart.tsx): client chart · Visual analytics for inventory trends. · `components/products-chart.tsx`
- [Pagination](https://github.com/machadop1407/nextjs-inventory-management-app/blob/main/components/pagination.tsx): list control · Paging controls for larger product sets. · `components/pagination.tsx`

## Connections

- Home → Shell: renders within · The home route is part of the shared app shell.
- Shell → Sidebar: uses · Authenticated navigation is composed into the layout.
- Shell → Loading: shows · Shared route loading state applies across the app.
- Shell → Sign in: routes to · Public auth entry is part of the app flow.
- Sign in → Client auth: auth UI · Sign-in uses client Stack Auth wiring.
- Auth bridge → Auth config: integrates · The auth handler is driven by shared auth config.
- Auth config → Server auth: server side · Auth configuration relies on server-side Stack integration.
- Auth config → Client auth: client side · Auth configuration also supports client-side integration.
- Dashboard → Products chart: visualizes · Dashboard metrics are presented with chart components.
- Inventory → Pagination: paginates · Inventory browsing is split across pages.
- Add product → Product actions: submits to · Form-driven product writes go through server actions.
- Dashboard → Product actions: reads updates · Dashboard data reflects product mutations.
- Inventory → Product actions: reads updates · Inventory list is driven by the product action/data flow.
- Product actions → Prisma client: writes via · Server actions persist through the Prisma boundary.
- Prisma client → Schema: maps to · Prisma client is generated from the database schema.
- Schema → Migrations: evolves through · Schema changes are tracked by migrations.
- Seed data → Schema: seeds · Seed data matches the inventory model.
- Dashboard → Sidebar: navigates from · Dashboard lives inside the shared authenticated shell.
- Inventory → Sidebar: navigates from · Inventory view is accessed through the persistent shell.
- Add product → Sidebar: navigates from · Product creation is part of the authenticated navigation flow.
- Settings → Sidebar: navigates from · Settings is accessed from the same shell.
- Dashboard → Prisma client: reads from · Dashboard aggregates data from the database layer.
- Inventory → Prisma client: reads from · Inventory listing pulls from the database layer.
