# enderz420/nextjs_auth architecture

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

- Interactive diagram: https://gitdiagram.com/enderz420/nextjs_auth
- Repository: https://github.com/enderz420/nextjs_auth

## Overview

##### Project type and purpose
- This is a full-stack Next.js application whose primary function is to provide user authentication (login, register, session management) using NextAuth, React, and Prisma.
- Written in TypeScript, it includes both UI pages (public and protected) and API routes that back the auth flows.

##### File structure
- **app/**
- Top-level Next.js App Router directory, subdivided into:
– `(protected)` (client, server, dashboard) – UI regions that require an active session
– `auth/login` & `auth/register` – pages for user sign-in and sign-up
– `api/auth/[...nextauth]` – catch-all NextAuth route handling sign-in/out and callbacks
– `layout.tsx`, `globals.css`, other shared assets
- **actions/**: TypeScript functions (`login.ts`, `register.ts`) encapsulating client-side calls to the API.
- **components/**: UI component library (buttons, cards, form controls, navbar, footer).
- **lib/db.ts** and **prisma/schema.prisma**: Prisma ORM setup and database schema.
- **middleware.ts**: Next.js middleware enforcing auth on protected routes.
- **schemas/** & **types/**: Validation schemas and TypeScript type definitions.
- **tailwind.config.ts**, **postcss.config.mjs**, **eslint.config.mjs**: styling and linting configuration.
- **next.config.ts**, **tsconfig.json**: Next.js and TypeScript project settings.

##### README
- Confirms it is a “simple login app with authentication using NextJS and React”

## Diagram (Mermaid)

```mermaid
graph TB
    %% Client Side
    subgraph "Browser UI"
        Home["Home Page"]:::ui
        Login["Login Page"]:::ui
        Register["Register Page"]:::ui
        ProtectedClient["Protected Client UI"]:::ui
        ProtectedDashboard["Protected Dashboard UI"]:::ui
        ProtectedServer["Protected Server Component UI"]:::ui
    end

    %% Server/API Layer
    subgraph "Server/API Layer"
        AppRouter["Next.js App Router"]:::api
        Middleware["Auth Middleware"]:::api
        NextAuthRoute["NextAuth API Route [...nextauth]"]:::api
        NextAuthConfig["NextAuth Configuration"]:::api
        AuthWrapper["NextAuth Wrapper"]:::api
        LoginAction["Login Action"]:::api
        RegisterAction["Register Action"]:::api
        Utils["Shared Utils"]:::api
    end

    %% Database Layer
    Database["Database (Prisma ORM)"]:::db

    %% Connections
    Home --> AppRouter
    Login --> AppRouter
    Register --> AppRouter
    ProtectedClient --> AppRouter
    ProtectedDashboard --> AppRouter
    ProtectedServer --> AppRouter

    AppRouter --> Middleware
    Middleware --> AppRouter

    AppRouter --> NextAuthRoute

    Login --> LoginAction
    LoginAction --> NextAuthRoute

    Register --> RegisterAction
    RegisterAction --> NextAuthRoute

    NextAuthRoute --> AuthWrapper
    AuthWrapper --> Utils

    NextAuthRoute -.-> Database
    AuthWrapper -.-> Database

    %% Click Events
    click Home "https://github.com/enderz420/nextjs_auth/blob/main/nextjs_auth/app/page.tsx"
    click Login "https://github.com/enderz420/nextjs_auth/blob/main/nextjs_auth/app/auth/login/page.tsx"
    click Register "https://github.com/enderz420/nextjs_auth/blob/main/nextjs_auth/app/auth/register/page.tsx"
    click ProtectedClient "https://github.com/enderz420/nextjs_auth/blob/main/nextjs_auth/app/(protected)/client/page.tsx"
    click ProtectedDashboard "https://github.com/enderz420/nextjs_auth/blob/main/nextjs_auth/app/(protected)/dashboard/page.tsx"
    click ProtectedServer "https://github.com/enderz420/nextjs_auth/blob/main/nextjs_auth/app/(protected)/server/page.tsx"
    click AppRouter "https://github.com/enderz420/nextjs_auth/tree/main/nextjs_auth/app/"
    click NextAuthRoute "https://github.com/enderz420/nextjs_auth/blob/main/nextjs_auth/app/api/auth/[...nextauth]/route.ts"
    click NextAuthConfig "https://github.com/enderz420/nextjs_auth/blob/main/nextjs_auth/auth.config.ts"
    click AuthWrapper "https://github.com/enderz420/nextjs_auth/blob/main/nextjs_auth/auth.ts"
    click LoginAction "https://github.com/enderz420/nextjs_auth/blob/main/nextjs_auth/actions/login.ts"
    click RegisterAction "https://github.com/enderz420/nextjs_auth/blob/main/nextjs_auth/actions/register.ts"
    click Utils "https://github.com/enderz420/nextjs_auth/blob/main/nextjs_auth/lib/utils.ts"
    click Database "https://github.com/enderz420/nextjs_auth/blob/main/nextjs_auth/lib/db.ts"
    click Database "https://github.com/enderz420/nextjs_auth/blob/main/nextjs_auth/prisma/schema.prisma"

    %% Styles
    classDef ui fill:#AEDFF7,stroke:#333,stroke-width:1px
    classDef api fill:#C8FACC,stroke:#333,stroke-width:1px
    classDef db fill:#FFD699,stroke:#333,stroke-width:1px
```
