# janfdev/recipe-jda-nextjs architecture

> Architecture diagram of the GitHub repository janfdev/recipe-jda-nextjs, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-08-11). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/janfdev/recipe-jda-nextjs
- Repository: https://github.com/janfdev/recipe-jda-nextjs

## Overview

##### Project Type and Purpose
- This is a full-stack, monolithic web application (“ReciVerse”) built on Next.js (App Router) that lets users browse, comment on, and manage recipes.
- It integrates user authentication (NextAuth.js), an admin dashboard for CRUD operations, a PostgreSQL database via Prisma, and Cloudinary for media storage.

##### File Structure
- **app/** holds both frontend routes (React server/client components) and backend endpoints (under app/api).
- **app/(auth)** and **middleware.ts** enforce protected routes via NextAuth sessions.
- **app/admin**, **app/recipes**, **app/user** are feature-driven folders under the App Router.
- **components/** houses presentational UI atoms, molecules, and domain-specific components (admin/UI, recipes/UI, dialogs).
- **hooks/** encapsulate client-side data-fetching logic (e.g., useRecipe, useComment).
- **lib/** contains shared utilities (axios instance, Prisma client, Cloudinary helpers, type definitions).
- **prisma/** manages schema, migrations, and seed logic.

##### README for Additional Insights
- Confirms tech stack: Next.js + Turbopack, Prisma/PostgreSQL, NextAuth, Tailwind CSS, shadcn/ui, Cloudinary, Vercel.
- Points out features: authentication flows, admin dashboard, image uploads, comment system, user profile management.

a. **Main Components**
- **Client/UI Layer**
- Next.js pages & React components (app/(auth), app/recipes, app/user, components/)
- Custom hooks (hooks/) for state and API calls
- **Server/API Layer**
- Next.js API routes (app/api/…) implemented as serverless functions on Vercel
- NextAuth.js auth handler (app/api/auth)
- Cloudinary upload endpoint (app/api/upload)
- **Business Logic / Data Access**
- Prisma client (lib/prisma.ts)
- Helpers (lib/cloudinary.ts, lib/auth.ts, lib/utils.ts)
- **Data Layer**
- PostgreSQL via Prisma ORM
- **External Services**
- Cloudinary for image storage
- Vercel serverless platform for hosting
b. **Relationships & Interactions**
- Browser → Next.js page (UI) → hook → API route
- API route → Prisma client → PostgreSQL
- API route → Cloudinary SDK → Cloudinary
- NextAuth.js ↔ Database (sessions, users)
- Middleware inspects NextAuth session to protect pages (admin/user)
c. **Architectural Patterns & Principles**
- **Feature-driven folder structure**: isolating auth, admin, recipes, user features
- **Layered architecture**: UI → API → ORM → DB
- **Serverless functions** for backend logic (scalable endpoints)
- **Domain-specific React components** and hooks for separation of concerns
d. **Key Technologies and Frameworks**
- Next.js App Router (server & client components)
- React + shadcn/ui + Tailwind CSS
- NextAuth.js for authentication
- Prisma ORM + PostgreSQL
- Cloudinary SDK
- Vercel (deployment environment)

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Client/UI Layer"
        Browser((Browser)):::external
        subgraph "Next.js Pages & React Components"
            AuthLogin["Login Page"]:::frontend
            AuthRegister["Register Page"]:::frontend
            AdminUI["Admin Dashboard"]:::frontend
            RecipeUI["Recipe Pages"]:::frontend
            UserUI["User Pages"]:::frontend
            Presentational["Presentational Components"]:::frontend
        end
        subgraph "Custom Hooks"
            Hooks["Hooks (use-recipe, use-comment, ...)"]:::frontend
        end
        Browser --> AuthLogin
        Browser --> AuthRegister
        Browser --> AdminUI
        Browser --> RecipeUI
        Browser --> UserUI
        AuthLogin --> Hooks
        AuthRegister --> Hooks
        AdminUI --> Hooks
        RecipeUI --> Hooks
        UserUI --> Hooks
        Presentational --> AuthLogin
        Presentational --> AuthRegister
        Presentational --> AdminUI
        Presentational --> RecipeUI
        Presentational --> UserUI
    end

    subgraph "Server/API Layer"
        APIAuth["NextAuth.js Auth Handler"]:::api
        APISignup["Signup Endpoint"]:::api
        APIAdminComments["Admin Comments API"]:::api
        APIRecipes["Recipe API Routes"]:::api
        APICategories["Category API Routes"]:::api
        APIUserComments["User Comments API"]:::api
        APIUpload["Media Upload API"]:::api
        APIUserProfile["User Profile API"]:::api
        Middleware["Middleware (Auth Guard)"]:::api
        Hooks --> Middleware
        Middleware --> APIAuth
        Middleware --> APISignup
        Middleware --> APIAdminComments
        Middleware --> APIRecipes
        Middleware --> APICategories
        Middleware --> APIUserComments
        Middleware --> APIUpload
        Middleware --> APIUserProfile
    end

    subgraph "Business Logic / Data Access"
        Prisma["Prisma Client"]:::data
        CloudinaryHelper["Cloudinary SDK Helper"]:::data
        AuthHelper["Auth Helpers"]:::data
        Utils["Shared Utilities"]:::data
        Axios["Axios Instance"]:::data
        Types["Type Definitions"]:::data
        APIAuth --> Prisma
        APISignup --> Prisma
        APIAdminComments --> Prisma
        APIRecipes --> Prisma
        APICategories --> Prisma
        APIUserComments --> Prisma
        APIUserProfile --> Prisma
        APIUpload --> CloudinaryHelper
        APIUpload --> Utils
        APIAuth --> AuthHelper
        APIAuth --> Utils
    end

    subgraph "Data Layer"
        DB[(PostgreSQL Database)]:::data
        Prisma --> DB
    end

    subgraph "External Services"
        Cloudinary(("Cloudinary")):::external
        Vercel(("Vercel")):::external
        CloudinaryHelper --> Cloudinary
        APIAuth --> Vercel
        APISignup --> Vercel
        APIAdminComments --> Vercel
        APIRecipes --> Vercel
        APICategories --> Vercel
        APIUserComments --> Vercel
        APIUpload --> Vercel
        APIUserProfile --> Vercel
    end

    click AuthLogin "https://github.com/janfdev/recipe-jda-nextjs/blob/main/app/(auth)/login/page.tsx"
    click AuthRegister "https://github.com/janfdev/recipe-jda-nextjs/blob/main/app/(auth)/register/page.tsx"
    click APIAuth "https://github.com/janfdev/recipe-jda-nextjs/blob/main/app/api/auth/[...nextauth]/route.ts"
    click APISignup "https://github.com/janfdev/recipe-jda-nextjs/blob/main/app/api/auth/signup/route.ts"
    click Middleware "https://github.com/janfdev/recipe-jda-nextjs/blob/main/middleware.ts"
    click AdminUI "https://github.com/janfdev/recipe-jda-nextjs/tree/main/app/admin/dashboard"
    click APIAdminComments "https://github.com/janfdev/recipe-jda-nextjs/blob/main/app/api/admin/comments/route.ts"
    click RecipeUI "https://github.com/janfdev/recipe-jda-nextjs/tree/main/app/recipes"
    click APIRecipes "https://github.com/janfdev/recipe-jda-nextjs/tree/main/app/api/recipes"
    click APICategories "https://github.com/janfdev/recipe-jda-nextjs/tree/main/app/api/categories"
    click APIUserComments "https://github.com/janfdev/recipe-jda-nextjs/tree/main/app/api/my-comments"
    click APIUpload "https://github.com/janfdev/recipe-jda-nextjs/blob/main/app/api/upload/route.ts"
    click APIUserProfile "https://github.com/janfdev/recipe-jda-nextjs/tree/main/app/api/user"
    click Prisma "https://github.com/janfdev/recipe-jda-nextjs/blob/main/lib/prisma.ts"
    click CloudinaryHelper "https://github.com/janfdev/recipe-jda-nextjs/blob/main/lib/cloudinary.ts"
    click AuthHelper "https://github.com/janfdev/recipe-jda-nextjs/blob/main/lib/auth.ts"
    click Utils "https://github.com/janfdev/recipe-jda-nextjs/blob/main/lib/utils.ts"
    click Axios "https://github.com/janfdev/recipe-jda-nextjs/blob/main/lib/axios.ts"
    click Types "https://github.com/janfdev/recipe-jda-nextjs/blob/main/lib/types/type.ts"
    click Hooks "https://github.com/janfdev/recipe-jda-nextjs/tree/main/hooks"
    click Presentational "https://github.com/janfdev/recipe-jda-nextjs/tree/main/components"

    classDef frontend fill:#ADD8E6,stroke:#000,stroke-width:1px
    classDef api fill:#90EE90,stroke:#000,stroke-width:1px
    classDef data fill:#FFA500,stroke:#000,stroke-width:1px
    classDef external fill:#D3D3D3,stroke:#000,stroke-width:1px
```
