How mitnichiter/inwa-website works
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: products.ts Server actions · admin/layout.tsx Admin shell · app/layout.tsx App shell · page.tsx Home
Components 22
Public site
Visitor-facing pages and shared chrome
- App shell · Root layout and global styling for the application
src/app/layout.tsx - Home · Public landing page
src/app/page.tsx - Products · Public product listing page
src/app/products/page.tsx - Contact · Public contact page and submission entry
src/app/contact/page.tsx - Login · Authentication entry page
src/app/login/page.tsx - Contact form · Interactive contact form behavior
src/app/contact/ContactClient.tsx
Admin console
Authenticated content management area
- Admin shell · Authenticated admin area layout
src/app/admin/layout.tsx - Dashboard · Operational summary and admin landing page
src/app/admin/page.tsx - Product admin · Product management interface
src/app/admin/products/page.tsx - Banner admin · Banner management interface
src/app/admin/banners/page.tsx - Message inbox · Inbound contact message review
src/app/admin/messages/page.tsx
Backend
Auth, actions, and route handlers
- Auth core · Central authentication configuration
src/auth.ts - Access guard · Route protection and admin access control
src/middleware.ts - Server actions · CRUD and workflow logic for auth, products, banners, messages, and stats
src/lib/actions/products.ts - Upload API · File ingestion endpoint used by admin uploads
src/app/api/upload/route.ts
Data
ORM, database, uploads, and persistence assets
- Prisma client · Shared database client wrapper
src/lib/prisma.ts - Schema · Data model and migrations source
prisma/schema.prisma - SQLite DB · Committed development database file
prisma/dev.db - Uploads · Publicly served uploaded assets
public/uploads
Shared UI
Reusable components and validation helpers
- Site chrome · Shared header, footer, and homepage carousel
src/components/layout/Header.tsx - Validation · Input validation and helper utilities
src/lib/validations.ts - Admin widgets · Banner manager and image upload UI
src/components/admin/BannerManager.tsx
Connections 30
- 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