# toxic-lmao/nextblog architecture

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

- Interactive diagram: https://gitdiagram.com/toxic-lmao/nextblog
- Repository: https://github.com/toxic-lmao/nextblog

## Overview

##### Overall Architecture – Identify Major Components
- Frontend/UI Layer:
- Represented by the /app folder (with pages, layouts, and server components) and /components directory.
- Includes areas for authentication (signin, signup, resetpassword), user pages (like profile, about, blog details), and admin dashboard.
- Backend/API & Server Actions:
- The /actions folder (e.g., handleAuth, handleBlog, handleContact, handleUser) encapsulates server-side operations.
- The /api routes inside the app (‘app/api/auth’) help expose endpoints for authentication and possibly other interactions.
- Business Logic & Utility Modules:
- /lib contains essential services (authentication helpers, Cloudinary integrations, and database connectors).
- /utils provides helper functions (slug generation, nudity/profanity checks, email senders, etc.).
- Database Layer:
- Represented by the /prisma folder, which defines the database schema (using Prisma ORM targeting PostgreSQL) along with the connection configurations.
- External Services & Integrations:
- Cloudinary for image storage (integrated via /lib/cloudinary).
- BetterAuth for authentication.
- External APIs for email (SendGrid) and content moderation (SightEngine).

- User requests hitting the React-driven frontend.
- Frontend pages calling API endpoints (e.g., for auth, blog CRUD operations).
- The API layer invoking server actions (in /actions) and util functions (/utils).
- The server actions interacting with the database via Prisma (/prisma/schema.prisma) and external services (Cloudinary, SendGrid, SightEngine).
- Distinguish client-side (rendered pages in the browser) and server-side components (API routes and server actions).

##### Architectural Patterns & Design Principles
- Separation between presentation (React components and pages) and business logic (server actions in /actions & /lib).
- Role-based authorization flow (User vs. Admin access in app/admin).

##### Technologies and Frameworks
- Next.js (App Router and React Server Components) for page routing and server rendering.
- TypeScript for type safety across the project.
- Tailwind CSS for styling.
- Prisma as the ORM connecting to a PostgreSQL database.
- Cloudinary, BetterAuth, SendGrid, and other external integrations that are pivotal to the architecture.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client
    Client["Browser(User)"]:::client

    %% Frontend/UI Layer
    subgraph "Frontend Layer (Next.js UI Components)"
        direction TB
        App["/app"]:::frontend
        Components["/components"]:::frontend
    end

    %% Backend/API & Server Actions
    subgraph "Backend API & Server Actions"
        direction TB
        API["/app/api"]:::backend
        Actions["/actions"]:::backend
    end

    %% Business Logic & Utilities
    subgraph "Business Logic & Utilities"
        direction TB
        Lib["/lib"]:::logic
        Utils["/utils"]:::logic
    end

    %% Database Layer
    subgraph "Database Layer"
        direction TB
        DB["PostgreSQL (via Prisma)"]:::database
        Prisma["/prisma/schema.prisma"]:::database
    end

    %% External Services & Integrations
    subgraph "External Services"
        direction TB
        Cloudinary["Cloudinary"]:::external
        BetterAuth["BetterAuth"]:::external
        SendGrid["SendGrid"]:::external
        SightEngine["SightEngine"]:::external
    end

    %% System Flow Connections
    Client -->|"Requests"| App
    Client -->|"Loads assets"| Components
    App -->|"Calls API"| API
    App -->|"Invokes Server Components"| Actions
    API -->|"Executes server actions"| Actions
    API -->|"Utilizes logic"| Lib
    API -->|"Utilizes utilities"| Utils
    Actions -->|"Uses utils"| Lib
    Actions -->|"Uses utils"| Utils
    Actions -->|"DB operations"| Prisma
    Lib -->|"Connects to"| DB
    Lib -->|"Integrates"| Cloudinary
    Lib -->|"Handles Auth"| BetterAuth
    Lib -->|"Sends Emails"| SendGrid
    Lib -->|"Moderation"| SightEngine
    API -->|"External API calls"| SendGrid

    %% ER Diagram Inset for Database Schema
    subgraph "ER Diagram"
        direction TB
        User["User\n(id, username, email, hashed_password, role, profileImage)"]:::entity
        BlogPost["BlogPost\n(id, title, content, slug, createdAt, updatedAt, published)"]:::entity
        Comment["Comment\n(id, content, userId, blogPostId, createdAt)"]:::entity
        Category["Category\n(id, name, slug)"]:::entity
        Like["Like\n(userId, blogPostId)"]:::entity

        User -->|"1-to-many"| BlogPost
        BlogPost -->|"1-to-many"| Comment
        BlogPost -->|"many-to-many"| Category
        BlogPost -->|"many-to-many"| Like
        User -->|"many-to-many"| Like
    end

    %% Click Events
    click App "https://github.com/toxic-lmao/nextblog/tree/master//app"
    click Components "https://github.com/toxic-lmao/nextblog/tree/master//components"
    click API "https://github.com/toxic-lmao/nextblog/tree/master//app/api"
    click Actions "https://github.com/toxic-lmao/nextblog/tree/master//actions"
    click Lib "https://github.com/toxic-lmao/nextblog/tree/master//lib"
    click Utils "https://github.com/toxic-lmao/nextblog/tree/master//utils"
    click Prisma "https://github.com/toxic-lmao/nextblog/blob/master//prisma/schema.prisma"
    click Cloudinary "https://github.com/toxic-lmao/nextblog/blob/master//lib/cloudinary.ts"

    %% Styles
    classDef frontend fill:#cce5ff,stroke:#004085,stroke-width:2px;
    classDef backend fill:#d4edda,stroke:#155724,stroke-width:2px;
    classDef logic fill:#fff3cd,stroke:#856404,stroke-width:2px;
    classDef database fill:#f8d7da,stroke:#721c24,stroke-width:2px;
    classDef external fill:#e2e3e5,stroke:#6c757d,stroke-width:2px;
    classDef client fill:#d1ecf1,stroke:#0c5460,stroke-width:2px;
    classDef entity fill:#ffffff,stroke:#000000,stroke-width:1px,stroke-dasharray: 5 5;
```
