# anze10/senzemo-app architecture

> Architecture diagram of the GitHub repository anze10/senzemo-app, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-26). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/anze10/senzemo-app
- Repository: https://github.com/anze10/senzemo-app

## Overview

##### Project type and purpose
- This is a full-stack Next.js application (App Router) with a React/TypeScript frontend and a Node.js server runtime.
- It uses Prisma as an ORM to interact with a relational database, Lucia for session-based authentication, and Google OAuth for SSO.
- The feature set includes an admin editing console, inventory management, order management, sales dashboards, sensor reading utilities, and developer utilities—all delivered from the same monolithic repo.

##### File structure
- Top-level framework/config: next.config.ts, tsconfig.json, bun.lockb, tailwind.config.ts, eslint.config.mjs, postcss.config.mjs.
- `prisma/schema.prisma`: ORM schema definition for production database.
- `src/app`: the App Router directory. Each subfolder under `src/app` (e.g., adminedit, inventory, orders, sales, sensors, dev, login/google…) is a separate route segment with its own React page.tsx and child components.
- `src/lib`, `src/providers.tsx`: shared utilities, context providers, base URL resolution.
- `src/server`: server-only modules (Google OAuth flows, Lucia session management, Prisma client instantiation, helper functions).
- `src/validators`: input or token validation logic.
- `public`: static assets.

##### README for additional insights
- Bootstrapped by Create-Next-App, deployed on Vercel.
- Uses next/font for optimized font loading.
- Standard npm scripts: `dev`, `build`, `start`.

##### Main components and their relationships
a. Frontend (Browser/Client)
- React components under `src/app/*` rendered via Next.js.
- Layouts (layout.tsx) supply shared navigation, styling via Tailwind.
- Client-side interactivity: hooks, sensors logic, button handlers, fetch calls to server actions.
b. Next.js Server (Node.js Runtime)
- Renders pages server-side and serves client bundles.
- Exposes server actions (`src/server/actions.ts`) and API routes (`src/app/login/google/route.ts`, callback routes).
- Middleware (`src/server/middleware.ts`) applies authentication guard.
c. Authentication & Session
- Google OAuth endpoints → obtains tokens → persisted via Lucia (`src/server/lucia.ts`, session.ts).
- `validate_session.ts` enforces access controls on protected pages.
d. Database (Prisma-backed)
- Prisma Client (`src/server/prisma.ts`) connects to underlying Postgres/MySQL/SQLite defined in schema.prisma.
- CRUD operations triggered by server actions or direct API handlers.
e. External Services
- Google OAuth 2.0 for sign-in.
- Potential file storage or printer server integrations under `src/app/dev/components/printer`.

##### Architectural patterns and design principles
- Full-stack monolithic architecture using Next.js App Router.
- Separation of concerns:
- UI layers under `src/app`.
- Business logic and auth flows under `src/server`.
- Data access layer via Prisma.
- Server actions for secure server-side mutations.
- Middleware for cross-cutting concerns (session validation).
- Route segment conventions for domain features (inventory, orders, sales, sensors).

- Client/browser
- Next.js Server (SSR + API Routes + Server Actions)
- Authentication subsystem (Google OAuth, Lucia)
- Database (Prisma ORM layer)
- External services (Google, printer service)
b. Interactions/data flow
- Next.js Server → Prisma Client → Database → returns data
- Next.js Server → OAuth endpoints → Google → returns user tokens
- Next.js Server → Lucia → session store
- Browser ← SSR HTML or JSON payloads
c. Technologies/Frameworks
- React/Next.js on Node.js
- TypeScript, Tailwind CSS
- Prisma ORM + relational DB
- Lucia for sessions
- Google OAuth
- Vercel (deployment)
d. Architectural patterns
- Monolithic modular feature routing
- App Router with nested layouts
- Server-side rendering and server actions
- Middleware pipeline for auth

##### Detail
- How global providers (`src/providers.tsx`) and global CSS (`globals.css`) fit into page layouts.
- Middleware ordering: auth middleware runs before serving protected routes.

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "Browser (Client)"
        Client["Browser (React/Next.js Client)"]:::frontend
    end

    subgraph "Frontend Routes (Next.js App Router)"
        AppRouter["Next.js App Router"]:::frontend
        Admin["Admin Editing Console"]:::frontend
        Inventory["Inventory Management"]:::frontend
        Orders["Order Management"]:::frontend
        Sales["Sales Dashboards"]:::frontend
        Sensors["Sensor Reading Utilities"]:::frontend
        Dev["Developer Utilities"]:::frontend
        SharedUI["Shared Components & Utilities"]:::frontend
        GlobalLayout["Global Layout & Styling"]:::frontend
    end

    subgraph "Next.js Server (Node.js Runtime)"
        Routing["Routing & SSR"]:::server
        Middleware["Authentication Middleware"]:::server
        API["Server Actions & API Routes"]:::server
        Auth["Authentication & Session Management"]:::server
        Utils["Server Utilities"]:::server
        DataAccess["Prisma Client (Data Access)"]:::server
    end

    subgraph "Database & ORM"
        Schema["Prisma Schema"]:::database
        DB["Relational Database"]:::database
    end

    subgraph "External Services"
        Google["Google OAuth 2.0"]:::external
        Printer["Printer Service"]:::external
    end

    Client -->|"HTTP(S) Requests"| AppRouter
    AppRouter --> Admin
    AppRouter --> Inventory
    AppRouter --> Orders
    AppRouter --> Sales
    AppRouter --> Sensors
    AppRouter --> Dev
    AppRouter --> SharedUI
    AppRouter --> GlobalLayout

    AppRouter --> Routing
    Routing --> Middleware
    Middleware --> API
    API --> Auth
    API --> Utils
    API --> DataAccess

    DataAccess --> Schema
    DataAccess --> DB
    Schema --- DB

    Auth --> Google
    Dev --> Printer

    classDef frontend fill:#E3F2FD,stroke:#2196F3
    classDef server fill:#E8F5E9,stroke:#4CAF50
    classDef database fill:#FFF3E0,stroke:#FB8C00
    classDef external fill:#ECEFF1,stroke:#78909C

    click AppRouter "https://github.com/anze10/senzemo-app/tree/main/src/app"
    click Admin "https://github.com/anze10/senzemo-app/tree/main/src/app/adminedit"
    click Inventory "https://github.com/anze10/senzemo-app/tree/main/src/app/inventory"
    click Orders "https://github.com/anze10/senzemo-app/tree/main/src/app/orders"
    click Sales "https://github.com/anze10/senzemo-app/tree/main/src/app/sales"
    click Sensors "https://github.com/anze10/senzemo-app/tree/main/src/app/sensors"
    click Dev "https://github.com/anze10/senzemo-app/tree/main/src/app/dev"
    click SharedUI "https://github.com/anze10/senzemo-app/tree/main/src/app/components"
    click GlobalLayout "https://github.com/anze10/senzemo-app/blob/main/src/app/layout.tsx"
    click Routing "https://github.com/anze10/senzemo-app/blob/main/src/app/route.ts"
    click Middleware "https://github.com/anze10/senzemo-app/blob/main/src/server/middleware.ts"
    click API "https://github.com/anze10/senzemo-app/blob/main/src/server/actions.ts"
    click Auth "https://github.com/anze10/senzemo-app/blob/main/src/server/lucia.ts"
    click Utils "https://github.com/anze10/senzemo-app/blob/main/src/server/utils.ts"
    click DataAccess "https://github.com/anze10/senzemo-app/blob/main/src/server/prisma.ts"
    click Schema "https://github.com/anze10/senzemo-app/blob/main/prisma/schema.prisma"
```
