# adrianhajdin/project_next_14_ai_prompt_sharing architecture

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

- Interactive diagram: https://gitdiagram.com/adrianhajdin/project_next_14_ai_prompt_sharing
- Repository: https://github.com/adrianhajdin/project_next_14_ai_prompt_sharing

## Overview

##### Project type and purpose
- This is a full-stack Next.js 14 web application for sharing AI prompts.
- Frontend is built with Next.js App Router (React Server/Client Components) and TailwindCSS.
- Backend consists of Next.js API Routes, NextAuth for authentication, and MongoDB via Mongoose for data persistence.

##### File structure
- Top-level
- app/ – Next.js App Router directory (UI pages, layout.jsx, client/server components)
- app/api/ – Serverless API routes for auth (NextAuth), prompt CRUD, and user-post relationships
- components/ – Reusable UI components (Feed, Form, Nav, PromptCard, etc.)
- models/ – Mongoose schemas (prompt.js, user.js)
- utils/database.js – DB connection logic
- styles/*.css and tailwind.config.js – Global and utility styles
- Notice:
- api/auth uses NextAuth’s [...nextauth]/route.js for OAuth with Google
- api/prompt and api/users implement CRUD endpoints (GET, POST, PATCH, DELETE)
- app/pages for create, update, profile, feed functionality

##### Key insights from README
- Tech stack: Next.js, MongoDB, NextAuth, TailwindCSS
- Features: CRUD on prompts, profile pages, search by tag, copy to clipboard, responsive design
- Authentication: Google OAuth via NextAuth

##### Main components & interactions
a. Components
- Client Browser (React in Next.js)
- Next.js Server (App Router + API Routes)
- Authentication Service (NextAuth + Google OAuth)
- Database (MongoDB via Mongoose)
- External Services (Google Identity, optional CDN for public assets)
b. Relationships & Data Flows
1. User → Browser UI (React pages/components)
2. Browser → Next.js Server
– Page requests (SSR/SSG)
– API calls (fetch to /api/prompt, /api/users, /api/auth, etc.)
3. Next.js Server ↔ MongoDB
– connectToDB() establishes connection
– Mongoose operations on Prompt and User models
4. NextAuth flow:
– Browser → /api/auth/[...nextauth] → Google OAuth → NextAuth callback → Session stored
5. Browser receives JSON or rendered HTML/CSS (Tailwind)
c. Architectural patterns
- Serverless functions for API Routes (route.js)
- MVC-style separation: models/ for data, route files act as controllers, app/pages for views
- Next.js App Router pattern (layout, page, loading) with React Server/Client components
d. Key technologies
- Next.js (App Router, Server/Client Components, API Routes)
- NextAuth (OAuth, session management)
- MongoDB + Mongoose (connectToDB, schemas)
- TailwindCSS (utility-first CSS)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Browser Layer
    Browser["User Browser"]:::frontend

    %% Frontend Layer
    subgraph "Frontend (Next.js React UI)"
        direction TB
        Layout["layout.jsx"]:::frontend
        PageHome["page.jsx"]:::frontend
        PageCreate["create-prompt/page.jsx"]:::frontend
        PageUpdate["update-prompt/page.jsx"]:::frontend
        PageProfile["profile/page.jsx"]:::frontend
        PageProfileId["profile/[id]/page.jsx"]:::frontend
        PageLoading["profile/loading.jsx"]:::frontend

        FeedComp["Feed.jsx"]:::frontend
        FormComp["Form.jsx"]:::frontend
        NavComp["Nav.jsx"]:::frontend
        PromptCardComp["PromptCard.jsx"]:::frontend
        ProfileComp["Profile.jsx"]:::frontend
        ProviderComp["Provider.jsx"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend (API Routes + Auth + DB Connector)"
        direction TB
        AuthRoute["app/api/auth/[...nextauth]/route.js"]:::backend
        PromptRoute["app/api/prompt/route.js"]:::backend
        PromptIdRoute["app/api/prompt/[id]/route.js"]:::backend
        PromptNewRoute["app/api/prompt/new/route.js"]:::backend
        UsersPostsRoute["app/api/users/[id]/posts/route.js"]:::backend
        UserRoute["app/api/users/[id]/route.js"]:::backend
        DBConnector["utils/database.js"]:::backend
    end

    %% Data Layer
    Database[(MongoDB)]:::data

    %% External Services
    subgraph "External Services"
        direction TB
        GoogleOAuth(("Google OAuth")):::external
        CDN(("CDN / public assets")):::external
    end

    %% Relationships
    Browser -->|"loads pages"| PageHome
    Browser --> PageCreate
    Browser --> PageUpdate
    Browser --> PageProfile
    Browser --> PageProfileId

    PageHome --> Layout
    PageCreate --> Layout
    PageUpdate --> Layout
    PageProfile --> Layout
    PageProfileId --> Layout
    PageLoading --> Layout

    Layout --> FeedComp
    Layout --> FormComp
    Layout --> NavComp
    Layout --> PromptCardComp
    Layout --> ProfileComp
    Layout --> ProviderComp

    ProviderComp -->|uses NextAuth| AuthRoute
    AuthRoute -->|redirect to OAuth| GoogleOAuth
    GoogleOAuth -->|callback| AuthRoute
    AuthRoute -->|session| Browser

    FeedComp -->|fetch GET all| PromptRoute
    FormComp -->|POST new / PATCH| PromptNewRoute
    PromptCardComp -->|GET single / DELETE / PATCH| PromptIdRoute
    ProfileComp -->|GET user posts| UsersPostsRoute
    ProfileComp -->|GET user| UserRoute

    PromptRoute --> DBConnector
    PromptIdRoute --> DBConnector
    PromptNewRoute --> DBConnector
    UsersPostsRoute --> DBConnector
    UserRoute --> DBConnector
    AuthRoute --> DBConnector

    DBConnector --> Database

    CDN --> Layout
    CDN --> FeedComp
    CDN --> PromptCardComp

    %% Click Events - Frontend Pages
    click Layout "https://github.com/adrianhajdin/project_next_14_ai_prompt_sharing/blob/main/app/layout.jsx"
    click PageHome "https://github.com/adrianhajdin/project_next_14_ai_prompt_sharing/blob/main/app/page.jsx"
    click PageCreate "https://github.com/adrianhajdin/project_next_14_ai_prompt_sharing/blob/main/app/create-prompt/page.jsx"
    click PageUpdate "https://github.com/adrianhajdin/project_next_14_ai_prompt_sharing/blob/main/app/update-prompt/page.jsx"
    click PageProfile "https://github.com/adrianhajdin/project_next_14_ai_prompt_sharing/blob/main/app/profile/page.jsx"
    click PageProfileId "https://github.com/adrianhajdin/project_next_14_ai_prompt_sharing/blob/main/app/profile/[id]/page.jsx"
    click PageLoading "https://github.com/adrianhajdin/project_next_14_ai_prompt_sharing/blob/main/app/profile/loading.jsx"

    %% Click Events - UI Components
    click FeedComp "https://github.com/adrianhajdin/project_next_14_ai_prompt_sharing/blob/main/components/Feed.jsx"
    click FormComp "https://github.com/adrianhajdin/project_next_14_ai_prompt_sharing/blob/main/components/Form.jsx"
    click NavComp "https://github.com/adrianhajdin/project_next_14_ai_prompt_sharing/blob/main/components/Nav.jsx"
    click PromptCardComp "https://github.com/adrianhajdin/project_next_14_ai_prompt_sharing/blob/main/components/PromptCard.jsx"
    click ProfileComp "https://github.com/adrianhajdin/project_next_14_ai_prompt_sharing/blob/main/components/Profile.jsx"
    click ProviderComp "https://github.com/adrianhajdin/project_next_14_ai_prompt_sharing/blob/main/components/Provider.jsx"

    %% Click Events - API Routes
    click AuthRoute "https://github.com/adrianhajdin/project_next_14_ai_prompt_sharing/blob/main/app/api/auth/[...nextauth]/route.js"
    click PromptRoute "https://github.com/adrianhajdin/project_next_14_ai_prompt_sharing/blob/main/app/api/prompt/route.js"
    click PromptIdRoute "https://github.com/adrianhajdin/project_next_14_ai_prompt_sharing/blob/main/app/api/prompt/[id]/route.js"
    click PromptNewRoute "https://github.com/adrianhajdin/project_next_14_ai_prompt_sharing/blob/main/app/api/prompt/new/route.js"
    click UsersPostsRoute "https://github.com/adrianhajdin/project_next_14_ai_prompt_sharing/blob/main/app/api/users/[id]/posts/route.js"
    click UserRoute "https://github.com/adrianhajdin/project_next_14_ai_prompt_sharing/blob/main/app/api/users/[id]/route.js"

    %% Click Events - Database Connector and Models
    click DBConnector "https://github.com/adrianhajdin/project_next_14_ai_prompt_sharing/blob/main/utils/database.js"
    click Database "https://github.com/adrianhajdin/project_next_14_ai_prompt_sharing/blob/main/models/prompt.js"
    click Database "https://github.com/adrianhajdin/project_next_14_ai_prompt_sharing/blob/main/models/user.js"

    %% Click Events - Static Assets and Config
    click CDN "https://github.com/adrianhajdin/project_next_14_ai_prompt_sharing/tree/main/public/assets/icons"
    click CDN "https://github.com/adrianhajdin/project_next_14_ai_prompt_sharing/tree/main/public/assets/images"

    classDef frontend fill:#E3F2FD,stroke:#2196F3,stroke-width:2px
    classDef backend fill:#E8F5E9,stroke:#4CAF50,stroke-width:2px
    classDef data fill:#FFF3E0,stroke:#FB8C00,stroke-width:2px,stroke-dasharray: 5 2
    classDef external fill:#ECEFF1,stroke:#90A4AE,stroke-width:2px,stroke-dasharray: 2 2
```
