# mitnichiter/inwa-website architecture

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

- Interactive diagram: https://gitdiagram.com/mitnichiter/inwa-website
- Repository: https://github.com/mitnichiter/inwa-website

## Overview

This repository is a Next.js App Router application with a clear split between:

1. a public-facing site,
2. an authenticated admin area,
3. a small set of backend endpoints and server actions,
4. a Prisma-backed local data store.

At a high level, it looks like a content/catalog site with products, home-page banners, and contact messages.

#### Main architectural shape

The app is organized around Next.js route segments under `src/app`:

- Public pages:
  - `/` home page
  - `/products`
  - `/contact`
  - `/login`
- Admin pages:
  - `/admin`
  - `/admin/products`
  - `/admin/banners`
  - `/admin/messages`
- API endpoints:
  - `/api/auth/[...nextauth]` for authentication
  - `/api/upload` for file uploads

The UI is mostly server-rendered pages with some client-side interactive components for forms, dialogs, image upload, carousel behavior, and admin management screens.

#### Core subsystems

##### 1) Public site presentation layer
Located primarily in `src/app` and `src/components`.

Important pieces:
- `src/app/page.tsx` – homepage
- `src/app/products/page.tsx` – product listing page
- `src/app/contact/page.tsx` and `ContactClient.tsx` – contact page with a client-side interactive form or submission flow
- `src/app/login/page.tsx` – authentication entry page
- `src/components/home/HeroCarousel.tsx` – homepage banner/carousel rendering
- `src/components/layout/Header.tsx` and `Footer.tsx` – shared site chrome
- `src/app/layout.tsx` and `src/app/globals.css` – root app shell and global styling

This layer is responsible for reading site data and rendering it for visitors.

##### 2) Admin console
Located under `src/app/admin` and `src/components/admin`.

Important pieces:
- `src/app/admin/page.tsx` – admin dashboard/home
- `src/app/admin/products/page.tsx` – product management
- `src/app/admin/banners/page.tsx` – banner management
- `src/app/admin/messages/page.tsx` – message inbox/review
- `src/app/admin/layout.tsx` – admin-specific shell/layout
- `src/components/admin/BannerManager.tsx`
- `src/components/admin/ImageUpload.tsx`

This is the operational back office for maintaining the site’s catalog, banners, and inbound messages.

##### 3) Business logic / server actions
Located in `src/lib/actions`.

Files:
- `auth.ts`
- `banners.ts`
- `messages.ts`
- `products.ts`
- `stats.ts`

These are the application’s main server-side business logic layer. They likely encapsulate create/read/update/delete operations, dashboard metrics, and submission workflows, and they sit between the UI and the database. This is a significant boundary in the architecture: pages and components do not appear to talk directly to the database; they go through action modules.

##### 4) Persistence layer
Centered on Prisma:

- `prisma/schema.prisma`
- `prisma/migrations/...`
- `prisma/dev.db`
- `src/lib/prisma.ts`

This indicates Prisma ORM is the data access layer, with a local SQLite development database committed in `prisma/dev.db`. The migration folder shows the schema is managed via migrations. The repository also includes:

- `prisma/seed.js` – initial data seeding
- `restore_products.js` – a maintenance/recovery script for product data

The implied domain entities are products, banners, messages, and likely users/accounts for admin auth.

##### 5) Authentication and access control
Authentication is handled with NextAuth:

- `src/auth.ts` – central auth configuration
- `src/app/api/auth/[...nextauth]/route.ts` – NextAuth handler
- `src/middleware.ts` – route protection / access control

The admin section is almost certainly protected via middleware, with login state supplied by NextAuth sessions. This is the main security boundary between public visitors and admins.

##### 6) File upload pipeline
Uploads are handled separately from normal CRUD:

- `src/app/api/upload/route.ts`
- `src/components/admin/ImageUpload.tsx`
- `public/uploads/`

The upload endpoint writes files into `public/uploads`, making them directly web-accessible. The admin UI uses the upload component to send files, probably for product images and banner assets. This is a distinct flow from database writes: the file is stored on disk first, then its public path is likely saved in the database by the product/banner logic.

##### 7) Validation and shared utilities
Supporting modules:
- `src/lib/validations.ts`
- `src/lib/utils.ts`

These provide shared input validation and helper functions. They form a boundary between untrusted user input and the business logic/data layer.

##### 8) UI primitives and component system
The repo includes a local component library under `src/components/ui` plus `components.json`, which strongly suggests a shadcn/ui-style setup.

Components include:
- dialog, sheet, table, button, input, textarea, card, label, alert-dialog

These are the building blocks used across the public site and admin UI.

#### Data flows

##### Public browsing flow
1. A visitor requests a page like `/`, `/products`, or `/contact`.
2. Next.js renders the route from `src/app/...`.
3. Page components pull required data via server actions or Prisma-backed helpers.
4. The UI is composed with shared layout/header/footer components.
5. Dynamic content like homepage banners and product listings is pulled from the database.

##### Admin content management flow
1. An authenticated user accesses `/admin/*`.
2. `middleware.ts` checks access and redirects unauthenticated users to login if needed.
3. Admin pages load current data via the action layer.
4. The admin interface creates/updates/deletes products, banners, or messages through `src/lib/actions/*`.
5. Changes are persisted through Prisma into the SQLite database.

##### Upload flow
1. Admin uses `ImageUpload` in the UI.
2. The browser posts the file to `/api/upload`.
3. The route stores the file under `public/uploads`.
4. The returned file reference is used in product/banner records.

##### Contact/message flow
1. A visitor submits the contact form on `/contact`.
2. The form likely uses a client component (`ContactClient.tsx`) plus a server action in `src/lib/actions/messages.ts`.
3. The message is persisted to the database.
4. Admins review incoming messages on `/admin/messages`.

##### Dashboard/statistics flow
1. `/admin` likely loads aggregate counts and summary metrics.
2. `src/lib/actions/stats.ts` computes data from the database.
3. The dashboard presents operational totals for products, banners, messages, or similar site metrics.

#### Important boundaries

##### Public vs authenticated
This is the most important boundary in the repo:
- public pages are open,
- admin routes are protected,
- auth is centralized through NextAuth and middleware.

##### File storage vs database storage
There are two persistence surfaces:
- SQLite/Prisma for structured records,
- `public/uploads` for binary asset files.

The app appears to store metadata in the database and the actual uploaded file on disk.

##### UI vs server logic
The repo cleanly separates:
- route/page components for rendering,
- `src/lib/actions` for server-side business rules,
- `src/lib/prisma.ts` for DB access,
- `src/lib/validations.ts` for input guarding.

This separation is important for diagramming because most data mutation does not originate directly inside the route files.

#### Technologies that materially affect architecture

- Next.js App Router
- React server/client component split
- NextAuth for authentication
- Prisma ORM
- SQLite in development (`prisma/dev.db`)
- Route handlers under `src/app/api`
- Local file serving from `public/uploads`
- Tailwind-based styling is likely present, given `postcss.config.mjs` and the shadcn-style UI setup

#### Supporting/operational files

- `prisma/migrations` – schema evolution
- `prisma/seed.js` – bootstrap data
- `restore_products.js` – recovery/admin utility
- `public/google50ef8a11987e95a4.html` – Google site verification
- `src/app/robots.ts` and `src/app/sitemap.ts` – SEO/indexing support

#### Suggested diagram mental model

If you draw this architecture, a good representation is:

- Browser / visitor and admin browser as the two client entry points
- Next.js app routes in the middle, divided into public and admin areas
- NextAuth + middleware as the access-control layer
- Server actions as the business logic layer
- Prisma as the data-access layer
- SQLite database plus uploaded files in `public/uploads` as the persistence layer
- Upload API as a separate file-ingestion path

Overall, this is a monolithic Next.js application with a fairly clean separation between presentation, auth-gated admin operations, server-side business logic, and Prisma-managed persistence.

Main entry points: [`src/lib/actions/products.ts`](https://github.com/mitnichiter/inwa-website/blob/HEAD/src/lib/actions/products.ts) (Server actions), [`src/app/admin/layout.tsx`](https://github.com/mitnichiter/inwa-website/blob/HEAD/src/app/admin/layout.tsx) (Admin shell), [`src/app/layout.tsx`](https://github.com/mitnichiter/inwa-website/blob/HEAD/src/app/layout.tsx) (App shell), [`src/app/page.tsx`](https://github.com/mitnichiter/inwa-website/blob/HEAD/src/app/page.tsx) (Home)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph "Public site"
  n_root["App shell<br/>Next.js App Router<br/>[layout.tsx]"]
  n_public_home["Home<br/>route page<br/>[page.tsx]"]
  n_public_products["Products<br/>route page<br/>[page.tsx]"]
  n_public_contact["Contact<br/>route page<br/>[page.tsx]"]
  n_public_login["Login<br/>route page<br/>[page.tsx]"]
  n_contact_client["Contact form<br/>client component<br/>[ContactClient.tsx]"]
end

subgraph "Admin console"
  n_admin_shell["Admin shell<br/>admin layout<br/>[layout.tsx]"]
  n_admin_dashboard["Dashboard<br/>admin page<br/>[page.tsx]"]
  n_admin_products["Product admin<br/>admin page<br/>[page.tsx]"]
  n_admin_banners["Banner admin<br/>admin page<br/>[page.tsx]"]
  n_admin_messages["Message inbox<br/>admin page<br/>[page.tsx]"]
end

subgraph "Backend"
  n_auth["Auth core<br/>NextAuth config<br/>[auth.ts]"]
  n_middleware["Access guard<br/>middleware<br/>[middleware.ts]"]
  n_actions["Server actions<br/>business logic<br/>[products.ts]"]
  n_upload_api["Upload API<br/>route handler<br/>[route.ts]"]
end

subgraph "Data"
  n_prisma[("Prisma client<br/>ORM access<br/>[prisma.ts]")]
  n_schema["Schema<br/>[schema.prisma]"]
  n_db[("SQLite DB<br/>local datastore<br/>[dev.db]")]
  n_uploads["Uploads<br/>file storage"]
end

subgraph "Shared UI"
  n_public_chrome["Site chrome<br/>layout components<br/>[Header.tsx]"]
  n_validations["Validation<br/>shared utilities<br/>[validations.ts]"]
  n_admin_widgets["Admin widgets<br/>ui components<br/>[BannerManager.tsx]"]
end

n_root -->|"renders"| n_public_home
n_root -->|"renders"| n_public_products
n_root -->|"renders"| n_public_contact
n_root -->|"renders"| n_public_login
n_public_home -->|"uses"| n_public_chrome
n_public_products -->|"uses"| n_public_chrome
n_public_contact -->|"includes"| n_contact_client
n_public_contact -->|"submits to"| n_actions
n_public_home -->|"loads data"| n_actions
n_public_products -->|"loads data"| n_actions
n_admin_shell -->|"renders"| n_admin_dashboard
n_admin_shell -->|"renders"| n_admin_products
n_admin_shell -->|"renders"| n_admin_banners
n_admin_shell -->|"renders"| n_admin_messages
n_admin_dashboard -->|"reads stats"| n_actions
n_admin_products -->|"mutates"| n_actions
n_admin_banners -->|"uses"| n_admin_widgets
n_admin_banners -->|"mutates"| n_actions
n_admin_messages -->|"reads"| n_actions
n_admin_widgets -->|"uploads files"| n_upload_api
n_upload_api -->|"stores"| n_uploads
n_actions -->|"queries"| n_prisma
n_prisma -->|"driven by"| n_schema
n_prisma -->|"persists to"| n_db
n_actions -->|"validates"| n_validations
n_auth -->|"auth context"| n_actions
n_middleware -->|"protects"| n_auth
n_middleware -->|"guards"| n_admin_shell
n_public_login -->|"signs in"| n_auth
n_admin_widgets -->|"writes metadata"| n_actions

click n_root "https://github.com/mitnichiter/inwa-website/blob/master/src/app/layout.tsx"
click n_public_home "https://github.com/mitnichiter/inwa-website/blob/master/src/app/page.tsx"
click n_public_products "https://github.com/mitnichiter/inwa-website/blob/master/src/app/products/page.tsx"
click n_public_contact "https://github.com/mitnichiter/inwa-website/blob/master/src/app/contact/page.tsx"
click n_public_login "https://github.com/mitnichiter/inwa-website/blob/master/src/app/login/page.tsx"
click n_public_chrome "https://github.com/mitnichiter/inwa-website/blob/master/src/components/layout/Header.tsx"
click n_contact_client "https://github.com/mitnichiter/inwa-website/blob/master/src/app/contact/ContactClient.tsx"
click n_admin_shell "https://github.com/mitnichiter/inwa-website/blob/master/src/app/admin/layout.tsx"
click n_admin_dashboard "https://github.com/mitnichiter/inwa-website/blob/master/src/app/admin/page.tsx"
click n_admin_products "https://github.com/mitnichiter/inwa-website/blob/master/src/app/admin/products/page.tsx"
click n_admin_banners "https://github.com/mitnichiter/inwa-website/blob/master/src/app/admin/banners/page.tsx"
click n_admin_messages "https://github.com/mitnichiter/inwa-website/blob/master/src/app/admin/messages/page.tsx"
click n_auth "https://github.com/mitnichiter/inwa-website/blob/master/src/auth.ts"
click n_middleware "https://github.com/mitnichiter/inwa-website/blob/master/src/middleware.ts"
click n_actions "https://github.com/mitnichiter/inwa-website/blob/master/src/lib/actions/products.ts"
click n_upload_api "https://github.com/mitnichiter/inwa-website/blob/master/src/app/api/upload/route.ts"
click n_prisma "https://github.com/mitnichiter/inwa-website/blob/master/src/lib/prisma.ts"
click n_schema "https://github.com/mitnichiter/inwa-website/blob/master/prisma/schema.prisma"
click n_db "https://github.com/mitnichiter/inwa-website/blob/master/prisma/dev.db"
click n_uploads "https://github.com/mitnichiter/inwa-website/tree/master/public/uploads"
click n_validations "https://github.com/mitnichiter/inwa-website/blob/master/src/lib/validations.ts"
click n_admin_widgets "https://github.com/mitnichiter/inwa-website/blob/master/src/components/admin/BannerManager.tsx"

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 n_root,n_public_home,n_public_products,n_public_contact,n_public_login,n_contact_client toneBlue
class n_admin_shell,n_admin_dashboard,n_admin_products,n_admin_banners,n_admin_messages toneAmber
class n_auth,n_middleware,n_actions,n_upload_api toneMint
class n_prisma,n_schema,n_db,n_uploads toneRose
class n_public_chrome,n_validations,n_admin_widgets toneIndigo
```

## Components

### Public site

Visitor-facing pages and shared chrome

- [App shell](https://github.com/mitnichiter/inwa-website/blob/HEAD/src/app/layout.tsx): Next.js App Router · Root layout and global styling for the application · `src/app/layout.tsx`
- [Home](https://github.com/mitnichiter/inwa-website/blob/HEAD/src/app/page.tsx): route page · Public landing page · `src/app/page.tsx`
- [Products](https://github.com/mitnichiter/inwa-website/blob/HEAD/src/app/products/page.tsx): route page · Public product listing page · `src/app/products/page.tsx`
- [Contact](https://github.com/mitnichiter/inwa-website/blob/HEAD/src/app/contact/page.tsx): route page · Public contact page and submission entry · `src/app/contact/page.tsx`
- [Login](https://github.com/mitnichiter/inwa-website/blob/HEAD/src/app/login/page.tsx): route page · Authentication entry page · `src/app/login/page.tsx`
- [Contact form](https://github.com/mitnichiter/inwa-website/blob/HEAD/src/app/contact/ContactClient.tsx): client component · Interactive contact form behavior · `src/app/contact/ContactClient.tsx`

### Admin console

Authenticated content management area

- [Admin shell](https://github.com/mitnichiter/inwa-website/blob/HEAD/src/app/admin/layout.tsx): admin layout · Authenticated admin area layout · `src/app/admin/layout.tsx`
- [Dashboard](https://github.com/mitnichiter/inwa-website/blob/HEAD/src/app/admin/page.tsx): admin page · Operational summary and admin landing page · `src/app/admin/page.tsx`
- [Product admin](https://github.com/mitnichiter/inwa-website/blob/HEAD/src/app/admin/products/page.tsx): admin page · Product management interface · `src/app/admin/products/page.tsx`
- [Banner admin](https://github.com/mitnichiter/inwa-website/blob/HEAD/src/app/admin/banners/page.tsx): admin page · Banner management interface · `src/app/admin/banners/page.tsx`
- [Message inbox](https://github.com/mitnichiter/inwa-website/blob/HEAD/src/app/admin/messages/page.tsx): admin page · Inbound contact message review · `src/app/admin/messages/page.tsx`

### Backend

Auth, actions, and route handlers

- [Auth core](https://github.com/mitnichiter/inwa-website/blob/HEAD/src/auth.ts): NextAuth config · Central authentication configuration · `src/auth.ts`
- [Access guard](https://github.com/mitnichiter/inwa-website/blob/HEAD/src/middleware.ts): middleware · Route protection and admin access control · `src/middleware.ts`
- [Server actions](https://github.com/mitnichiter/inwa-website/blob/HEAD/src/lib/actions/products.ts): business logic · CRUD and workflow logic for auth, products, banners, messages, and stats · `src/lib/actions/products.ts`
- [Upload API](https://github.com/mitnichiter/inwa-website/blob/HEAD/src/app/api/upload/route.ts): route handler · File ingestion endpoint used by admin uploads · `src/app/api/upload/route.ts`

### Data

ORM, database, uploads, and persistence assets

- [Prisma client](https://github.com/mitnichiter/inwa-website/blob/HEAD/src/lib/prisma.ts): ORM access · Shared database client wrapper · `src/lib/prisma.ts`
- [Schema](https://github.com/mitnichiter/inwa-website/blob/HEAD/prisma/schema.prisma): prisma schema · Data model and migrations source · `prisma/schema.prisma`
- [SQLite DB](https://github.com/mitnichiter/inwa-website/blob/HEAD/prisma/dev.db): local datastore · Committed development database file · `prisma/dev.db`
- [Uploads](https://github.com/mitnichiter/inwa-website/tree/HEAD/public/uploads): file storage · Publicly served uploaded assets · `public/uploads`

### Shared UI

Reusable components and validation helpers

- [Site chrome](https://github.com/mitnichiter/inwa-website/blob/HEAD/src/components/layout/Header.tsx): layout components · Shared header, footer, and homepage carousel · `src/components/layout/Header.tsx`
- [Validation](https://github.com/mitnichiter/inwa-website/blob/HEAD/src/lib/validations.ts): shared utilities · Input validation and helper utilities · `src/lib/validations.ts`
- [Admin widgets](https://github.com/mitnichiter/inwa-website/blob/HEAD/src/components/admin/BannerManager.tsx): ui components · Banner manager and image upload UI · `src/components/admin/BannerManager.tsx`

## Connections

- App shell → Home: renders · App shell hosts the public landing page
- App shell → Products: renders · App shell hosts the product listing
- App shell → Contact: renders · App shell hosts the contact page
- App shell → Login: renders · App shell hosts the login page
- Home → Site chrome: uses · Home page shares header/footer/carousel UI
- Products → Site chrome: uses · Products page shares site chrome
- Contact → Contact form: includes · Contact page delegates interactive form behavior
- Contact → Server actions: submits to · Contact submissions are handled in server logic
- Home → Server actions: loads data · Homepage pulls site content via server actions
- Products → Server actions: loads data · Product listings are sourced from server actions
- Admin shell → Dashboard: renders · Admin layout hosts the dashboard page
- Admin shell → Product admin: renders · Admin layout hosts product management
- Admin shell → Banner admin: renders · Admin layout hosts banner management
- Admin shell → Message inbox: renders · Admin layout hosts message inbox
- Dashboard → Server actions: reads stats · Dashboard summary comes from stats actions
- Product admin → Server actions: mutates · Product CRUD flows through server actions
- Banner admin → Admin widgets: uses · Banner management uses reusable admin widgets
- Banner admin → Server actions: mutates · Banner CRUD flows through server actions
- Message inbox → Server actions: reads · Inbox data is loaded through server actions
- Admin widgets → Upload API: uploads files · Image upload component posts to upload endpoint
- Upload API → Uploads: stores · Uploaded files are written into public uploads
- Server actions → Prisma client: queries · Business logic accesses the shared Prisma client
- Prisma client → Schema: driven by · Client is backed by the Prisma schema and migrations
- Prisma client → SQLite DB: persists to · Development data is stored in local SQLite
- Server actions → Validation: validates · Server actions guard inputs with shared validation
- Auth core → Server actions: auth context · Authentication logic supports server-side operations
- Access guard → Auth core: protects · Middleware enforces authenticated admin access
- Access guard → Admin shell: guards · Admin routes are protected at the boundary
- Login → Auth core: signs in · Login page initiates authentication flow
- Admin widgets → Server actions: writes metadata · Admin widgets feed content metadata into actions
