# shatanshu3006/mydevblog architecture

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

- Interactive diagram: https://gitdiagram.com/shatanshu3006/mydevblog
- Repository: https://github.com/shatanshu3006/mydevblog

## Overview

##### Main Components
- Frontend Client (Next.js UI):
- Pages found under src/app (e.g., home, login, blog, posts, and write pages)
- Components folder subdivided into Menu, AuthLinks, Card, Featured, Navbar, Pagination, etc.
- CSS Modules and global styling files for styling
- API Routes (Next.js Backend Endpoints):
- Routes under src/app/api (grouped by auth, categories, posts, comments) – these endpoints perform CRUD operations.
- The auth routes (with [...nextauth]) indicate integration with NextAuth for authentication.
- Database & ORM Layer:
- The prisma directory which includes the Prisma schema file (defining models such as Post, Comment, Category, and User data relationships).
- Prisma Client is used as an interface between the API endpoints and the MongoDB database.
- From the README: emphasis on the Prisma Engine and some performance notes regarding join operations.
- External Dependencies and Services:
- NextAuth (as seen in the auth API) for secured authentication.
- Next.js built-in features for SSR (Server Side Rendering) and CSR (Client Side Rendering) to balance SEO and client interactions.

##### Relationships & Interactions
- The Client interacts with API Routes for CRUD operations. For example, when users interact with pages – like creating a post or retrieving comments – the Next.js route handlers in src/app/api/ are triggered.
- API endpoints then use Prisma (via src/utils/connect.js, src/utils/firebase.js might be auxiliary) to query/update the MongoDB database.
- Authentication is managed through NextAuth’s dynamic routing ([...nextauth]), ensuring that sensitive API routes are protected.

##### Architectural Patterns and Principles
- Next.js App Router – providing a file-system-based routing mechanism that cleanly separates pages and API.
- MVC-ish structure where:
- The “View” layer is represented by pages and components,
- The “Controller” layer is implicitly captured by the API routes,
- The “Model” is defined in the Prisma schema and managed via Prisma Client.
- Use of SSR/CSR strategies: URL-based pages using Server Side Rendering for SEO-critical content (like blogs) and Client Side Rendering where interactivity is key (e.g., login or dynamic components).
- Separation of Concerns: Distinct directories for API, components, context, and providers make it easier to distinguish the presentation layer from the business logic/data access layer.

## Diagram (Mermaid)

```mermaid
graph TD
  %% Frontend UI
  subgraph "Frontend UI"
    subgraph "Next.js Pages"
      Homepage["Homepage (Next.js Page)"]:::frontend
      BlogPage["Blog Page (Next.js Page)"]:::frontend
      LoginPage["Login Page (Next.js Page)"]:::frontend
      PostDetail["Post Detail Page (Next.js Page)"]:::frontend
      WritePage["Write Page (Next.js Page)"]:::frontend
    end
    subgraph "Components and Styling"
      Menu["Menu Component"]:::components
      AuthLinks["AuthLinks Component"]:::components
      Card["Card Component"]:::components
      Featured["Featured Component"]:::components
      Navbar["Navbar Component"]:::components
      Pagination["Pagination Component"]:::components
      Others["Other Components (CategoryList, Comments, Footer, etc.)"]:::components
    end
  end

  %% API Endpoints
  subgraph "API Endpoints"
    AuthAPI["Auth API ([...nextauth])"]:::api
    CategoriesAPI["Categories API"]:::api
    CommentsAPI["Comments API"]:::api
    PostsAPIGeneral["Posts API (General)"]:::api
    PostsAPIDynamic["Posts API (Dynamic)"]:::api
  end

  %% Database and ORM Layer
  subgraph "Database & ORM"
    Prisma["Prisma Schema & Client"]:::orm
    Connect["Prisma Connection (connect.js)"]:::orm
    DB["MongoDB/PlanetScale Database"]:::db
  end
  
  %% External Services & Utilities
  subgraph "External Services"
    NextAuthService["NextAuth Service"]:::external
    FirebaseUtil["Firebase Utility"]:::external
    AuthUtil["Auth Utilities"]:::external
  end

  %% Providers & Context
  subgraph "Providers & Context"
    AuthProvider["Auth Provider"]:::providers
    ThemeProvider["Theme Provider"]:::providers
    ThemeContext["Theme Context"]:::providers
  end

  %% Relationships from Next.js Pages to API Endpoints
  Homepage -->|"HTTP_Request"| PostsAPIGeneral
  BlogPage  -->|"HTTP_Request"| PostsAPIGeneral
  LoginPage -->|"HTTP_Request"| AuthAPI
  PostDetail -->|"HTTP_Request"| PostsAPIDynamic
  WritePage  -->|"HTTP_Request"| PostsAPIGeneral
  
  %% API Endpoints to Database & ORM
  AuthAPI         -->|"DB_Query"| Connect
  CategoriesAPI   -->|"DB_Query"| Connect
  CommentsAPI     -->|"DB_Query"| Connect
  PostsAPIGeneral-->|"DB_Query"| Connect
  PostsAPIDynamic-->|"DB_Query"| Connect
  
  Connect -->|"Uses"| Prisma
  Prisma  -->|"Executes"| DB
  DB      -->|"Returns"| Prisma
  
  %% API Endpoints to External Services
  AuthAPI -->|"NextAuth"| NextAuthService
  AuthAPI -->|"Uses"| AuthUtil
  PostsAPIGeneral -->|"Optional"| FirebaseUtil
  
  %% Providers & Context support Frontend UI
  AuthProvider   -->|"Provides_State"| LoginPage
  ThemeProvider  -->|"Provides_Theme"| Homepage
  ThemeContext   -->|"Provides_Context"| Homepage

  %% Styling Classes
  classDef frontend fill:#CFE2F3,stroke:#0B5394,stroke-width:2px;
  classDef components fill:#D9EAD3,stroke:#274E13,stroke-width:2px;
  classDef api fill:#FFF2CC,stroke:#BF9000,stroke-width:2px;
  classDef orm fill:#EAD1DC,stroke:#6D1338,stroke-width:2px;
  classDef db fill:#F4CCCC,stroke:#990000,stroke-width:2px,stroke-dasharray: 5 5;
  classDef external fill:#D0E0E3,stroke:#115B69,stroke-width:2px;
  classDef providers fill:#E2EFDA,stroke:#38761D,stroke-width:2px;

  %% Click Events for Frontend Pages
  click Homepage "https://github.com/shatanshu3006/mydevblog/blob/starter/src/app/page.jsx"
  click BlogPage "https://github.com/shatanshu3006/mydevblog/blob/starter/src/app/blog/page.jsx"
  click LoginPage "https://github.com/shatanshu3006/mydevblog/blob/starter/src/app/login/page.jsx"
  click PostDetail "https://github.com/shatanshu3006/mydevblog/blob/starter/src/app/posts/[slug]/page.jsx"
  click WritePage "https://github.com/shatanshu3006/mydevblog/blob/starter/src/app/write/page.jsx"

  %% Click Events for Frontend Components
  click Menu "https://github.com/shatanshu3006/mydevblog/blob/starter/src/components/Menu/Menu.jsx"
  click AuthLinks "https://github.com/shatanshu3006/mydevblog/blob/starter/src/components/authLinks/AuthLinks.jsx"
  click Card "https://github.com/shatanshu3006/mydevblog/blob/starter/src/components/card/Card.jsx"
  click Featured "https://github.com/shatanshu3006/mydevblog/blob/starter/src/components/featured/Featured.jsx"
  click Navbar "https://github.com/shatanshu3006/mydevblog/blob/starter/src/components/navbar/Navbar.jsx"
  click Pagination "https://github.com/shatanshu3006/mydevblog/blob/starter/src/components/pagination/Pagination.jsx"

  %% Click Events for API Endpoints
  click AuthAPI "https://github.com/shatanshu3006/mydevblog/blob/starter/src/app/api/auth/[...nextauth]/route.js"
  click CategoriesAPI "https://github.com/shatanshu3006/mydevblog/blob/starter/src/app/api/categories/route.js"
  click CommentsAPI "https://github.com/shatanshu3006/mydevblog/blob/starter/src/app/api/comments/route.js"
  click PostsAPIGeneral "https://github.com/shatanshu3006/mydevblog/blob/starter/src/app/api/posts/route.js"
  click PostsAPIDynamic "https://github.com/shatanshu3006/mydevblog/blob/starter/src/app/api/posts/[slug]/route.js"

  %% Click Events for Database & ORM Layer
  click Prisma "https://github.com/shatanshu3006/mydevblog/blob/starter/prisma/schema.prisma"
  click Connect "https://github.com/shatanshu3006/mydevblog/blob/starter/src/utils/connect.js"

  %% Click Events for External Services
  click NextAuthService "https://github.com/shatanshu3006/mydevblog/blob/starter/src/app/api/auth/[...nextauth]/route.js"
  click FirebaseUtil "https://github.com/shatanshu3006/mydevblog/blob/starter/src/utils/firebase.js"
  click AuthUtil "https://github.com/shatanshu3006/mydevblog/blob/starter/src/utils/auth.js"

  %% Click Events for Providers & Context
  click AuthProvider "https://github.com/shatanshu3006/mydevblog/blob/starter/src/providers/AuthProvider.jsx"
  click ThemeProvider "https://github.com/shatanshu3006/mydevblog/blob/starter/src/providers/ThemeProvider.jsx"
  click ThemeContext "https://github.com/shatanshu3006/mydevblog/blob/starter/src/context/ThemeContext.jsx"
```
