# 1d0u/nextjs-blog-project architecture

> Architecture diagram of the GitHub repository 1d0u/nextjs-blog-project, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/1d0u/nextjs-blog-project
- Repository: https://github.com/1d0u/nextjs-blog-project

## Overview

##### Main Components
- Frontend: Built primarily with Next.js, the frontend resides in the src/app directory. It includes pages (e.g., home, post pages, category pages, profile, dashboard, signin/signup) as well as layout and global styling components (e.g., globals.css, Header, Footer).
- Backend/API: The server-side API endpoints are located under src/app/api. These endpoints handle authentication (with NextAuth.js under auth and register directories), posts, categories, dashboard statistics, and profile actions. They encapsulate the business logic of the blog platform.
- Database Layer: The project uses Prisma (see lib/prisma.ts, prisma/schema.prisma, and prisma/seed.ts) which connects to a MongoDB database. This layer manages data models for users, posts, categories, and bookmarks.
- External Services: Notice the integration points for:
- Cloudinary for image uploads (details provided in the README’s environment variables).
- NextAuth.js for user authentication.
- TipTap for rich text editing.
- UI Components and Data Modules: The src/components directory contains reusable UI components (buttons, forms, modals, etc.) and other UI elements (e.g., bookmarks, category badges) that are assembled together into the application pages.

##### Relationships and Interactions
- The Frontend (UI) interacts with the Backend API endpoints—each API route is designed to manage CRUD operations on blog posts, authenticate users, manage profiles, and support user dashboard functionalities.
- User interactions (such as creating a new post, signing in, or updating profiles) trigger calls to the respective API endpoints. For example, the authentication endpoints (located within src/app/api/auth) direct requests to NextAuth.js configurations, while blog-related operations interface with the database via Prisma.
- The Database (MongoDB via Prisma) serves as the central data repository. API endpoints in the application perform database operations using utilities from src/lib/db.ts and Prisma integrations.
- External service integrations (Cloudinary for media uploads and TipTap for text editing) are accessed from both the UI and API layers as needed.

##### Architectural Patterns
- Separation of Concerns: There’s a clear separation between the UI (frontend components in src/app and src/components), the backend logic (organized in src/app/api), and the database access (Prisma in prisma and lib directories).
- Modular and Component-Based Design: The codebase makes heavy use of components (React/Next.js) and separate API routes for different functionalities (e.g., posts, categories, dashboard) to ensure modularity and scalability.
- API-Driven Communication: The frontend relies on consistent API endpoints (under src/app/api) for user data, blog content, and interactions, making the client-server communication straightforward.
- Environment-Driven Configuration: Database URLs, authentication secrets, and Cloudinary credentials are managed using environment variables, promoting a secure and flexible deployment setup.

##### Relevant Technologies and Frameworks
- Next.js 13 (with App Router for routing and layout composition)
- TypeScript (the type definitions are found under src/types)
- TailwindCSS (styling through tailwind.config.js and globals.css)
- MongoDB and Prisma (schema definitions located in prisma/schema.prisma and access utilities in lib folders)
- NextAuth.js (authentication endpoints and configuration files within src/app/api/auth)
- TipTap Editor (implemented in the rich text editor page; referenced in the README)
- Cloudinary (used for image uploads via API calls)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend Layer"
        A["Next.js App (src/app)"]:::frontend
        A1["Home Page (page.tsx)"]:::frontend
        A2["Layout (layout.tsx)"]:::frontend
        A3["Global Styles (globals.css)"]:::frontend
    end

    %% UI Components
    subgraph "UI Components"
        B["Components (src/components)"]:::component
        B1["Header (Header.tsx)"]:::component
        B2["Footer (Footer.tsx)"]:::component
        B3["Layout Component (Layout.tsx)"]:::component
        B4["Post Card (PostCard.tsx)"]:::component
        B5["New Post Form (NewPostForm.tsx)"]:::component
        B6["Sign In Form (SignInForm.tsx)"]:::component
        B7["Sign Up Form (SignUpForm.tsx)"]:::component
    end

    %% Backend API
    subgraph "Backend API"
        C["API Endpoints (src/app/api)"]:::backend
        subgraph "Authentication"
            C1["Auth API (src/app/api/auth)"]:::backend
            C1A["NextAuth Route ([...nextauth]/route.ts)"]:::backend
            C1B["NextAuth Options ([...nextauth]/options.ts)"]:::backend
        end
        C2["Posts API (src/app/api/posts)"]:::backend
        C3["Categories API (src/app/api/categories)"]:::backend
        C4["Dashboard API (src/app/api/dashboard)"]:::backend
        C5["Profile API (profile/route.ts)"]:::backend
    end

    %% Database Layer
    subgraph "Database Layer"
        D["Prisma Schema (prisma/schema.prisma)"]:::database
        D1["Seed File (prisma/seed.ts)"]:::database
        D2["Prisma Client (lib/prisma.ts / src/lib/prisma.ts)"]:::database
        D3["Database Utility (src/lib/db.ts)"]:::database
    end

    %% External Services
    subgraph "External Services"
        E["Cloudinary"]:::external
        E1["NextAuth.js"]:::external
        E2["TipTap Editor"]:::external
    end

    %% Rich Text / New Post Feature
    subgraph "Rich Text / New Post"
        F["New Post Page (src/app/new-post/page.tsx)"]:::richtext
    end

    %% Connections between components
    A -->|"userAction"| C
    A -->|"renders"| B
    C -->|"authenticates"| C1
    C1 -->|"configures"| E1
    C2 -->|"manages posts"| D2
    C3 -->|"manages categories"| D2
    C4 -->|"dashboard stats"| D2
    C5 -->|"profile ops"| D2
    C2 -->|"uploads images"| E
    C -->|"DB queries"| D2
    F -->|"richText editing"| E2
    B5 -->|"integrates"| F

    %% Click Events for Frontend
    click A "https://github.com/1d0u/nextjs-blog-project/tree/main/src/app"
    click A1 "https://github.com/1d0u/nextjs-blog-project/blob/main/src/app/page.tsx"
    click A2 "https://github.com/1d0u/nextjs-blog-project/blob/main/src/app/layout.tsx"
    click A3 "https://github.com/1d0u/nextjs-blog-project/blob/main/src/app/globals.css"

    %% Click Events for UI Components
    click B "https://github.com/1d0u/nextjs-blog-project/tree/main/src/components"
    click B1 "https://github.com/1d0u/nextjs-blog-project/blob/main/src/components/layout/Header.tsx"
    click B2 "https://github.com/1d0u/nextjs-blog-project/blob/main/src/components/layout/Footer.tsx"
    click B3 "https://github.com/1d0u/nextjs-blog-project/blob/main/src/components/layout/Layout.tsx"
    click B4 "https://github.com/1d0u/nextjs-blog-project/blob/main/src/components/blog/PostCard.tsx"
    click B5 "https://github.com/1d0u/nextjs-blog-project/blob/main/src/components/post/NewPostForm.tsx"
    click B6 "https://github.com/1d0u/nextjs-blog-project/blob/main/src/components/auth/SignInForm.tsx"
    click B7 "https://github.com/1d0u/nextjs-blog-project/blob/main/src/components/auth/SignUpForm.tsx"

    %% Click Events for Backend/API Endpoints
    click C "https://github.com/1d0u/nextjs-blog-project/tree/main/src/app/api"
    click C1 "https://github.com/1d0u/nextjs-blog-project/tree/main/src/app/api/auth"
    click C1A "https://github.com/1d0u/nextjs-blog-project/blob/main/src/app/api/auth/[...nextauth]/route.ts"
    click C1B "https://github.com/1d0u/nextjs-blog-project/blob/main/src/app/api/auth/[...nextauth]/options.ts"
    click C2 "https://github.com/1d0u/nextjs-blog-project/tree/main/src/app/api/posts"
    click C3 "https://github.com/1d0u/nextjs-blog-project/tree/main/src/app/api/categories"
    click C4 "https://github.com/1d0u/nextjs-blog-project/tree/main/src/app/api/dashboard"
    click C5 "https://github.com/1d0u/nextjs-blog-project/blob/main/src/app/api/profile/route.ts"

    %% Click Events for Database Layer
    click D "https://github.com/1d0u/nextjs-blog-project/blob/main/prisma/schema.prisma"
    click D1 "https://github.com/1d0u/nextjs-blog-project/blob/main/prisma/seed.ts"
    click D2 "https://github.com/1d0u/nextjs-blog-project/blob/main/src/lib/prisma.ts"
    click D3 "https://github.com/1d0u/nextjs-blog-project/blob/main/src/lib/db.ts"

    %% Click Event for Rich Text / New Post
    click F "https://github.com/1d0u/nextjs-blog-project/blob/main/src/app/new-post/page.tsx"

    %% Styles
    classDef frontend fill:#C9E9FF,stroke:#333,stroke-width:2px;
    classDef component fill:#FFE4B5,stroke:#333,stroke-width:2px;
    classDef backend fill:#FFCCCB,stroke:#333,stroke-width:2px;
    classDef database fill:#C1FFC1,stroke:#333,stroke-width:2px;
    classDef external fill:#F0E68C,stroke:#333,stroke-width:2px;
    classDef richtext fill:#D8BFD8,stroke:#333,stroke-width:2px;
```
