# lucasadrianof/personal-blog-nextjs architecture

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

- Interactive diagram: https://gitdiagram.com/lucasadrianof/personal-blog-nextjs
- Repository: https://github.com/lucasadrianof/personal-blog-nextjs

## Overview

##### Project Type & Purpose
- The project is a personal website built with Next.js and Tailwind CSS.
- It serves static content (homepage, about me, contact) and dynamic blog pages. Blog content is sourced from Sanity CMS with caching (SSG/ISR) and revalidation via webhooks.
- It also includes integration with analytics (PostHog), commenting (Commento++), and performance/animation libraries (AOS).

##### File Structure to Identify Main Components
- Top-Level Configuration & Deployment:
- .env.sample, next.config.mjs, tailwind.config.ts, postcss.config.mjs: Configuration and build settings.
- .github/workflows: GitHub Actions workflows for CI/CD (linting and production deployment to Vercel).
- Application Layer (src/app):
- Route groups (i.e., (blog) route group) split into static pages and dynamic blog pages.
- Dynamic routes under /blog and API routes for cache revalidation and sitemap generation.
- The /studio folder under /app suggests an administrative or editing interface, likely for Sanity Studio.
- Components:
- Organized in “src/components” with sub-folders for UI elements like Blog components, Header, Footer, Hero, etc.
- There are specialized components for integrating third-party services (Commento, PostHog) and content rendering (PortableText).
- Libraries and Hooks:
- “src/lib/sanity” and “src/hooks” indicate custom libraries for interfacing with Sanity CMS and managing front-end behavior.
- Sanity Configuration:

##### Identifying Key Relationships & Interactions
- Frontend – Next.js App:
- Responsible for both static (SSG) and dynamic rendering.
- Implements routing via the Next.js app directory structure with dynamic blog pages integrated with Sanity.
- Backend / API Routes:
- API endpoints for cache revalidation (triggered by Sanity webhooks) and sitemap generation.
- External Services:
- Sanity CMS as the content backend.
- Vercel for hosting and deployment.
- GitHub Actions for CI/CD pipelines (build, lint, deploy).
- Third-party integrations such as Commento++ for comments and PostHog for analytics.
- UI Components:
- Modularized UI components across various aspects of the site (blog, header, footer, social, etc.) that render dynamic content and static sections.

##### Architectural Patterns & Design Principles
- Separation of Concerns:
- Clear division between static pages and dynamic blog routes.
- A modular component structure that keeps UI, hooks, libraries, and API routes separate.
- Dynamic Data Fetching & Caching:
- The use of Next.js SSG/ISR for serving content cached on the server, with revalidation triggered by CMS actions.
- CI/CD and Deployment Pipeline:
- GitHub Actions workflows ensure automated testing, linting, and production deployment on Vercel.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Next.js Frontend"
        SP["Static Pages (src/app/(blog))"]:::frontend
        DB["Dynamic Blog (src/app/(blog)/blog/[slug])"]:::frontend
        SS["Sanity Studio (src/app/studio)"]:::frontend
    end

    subgraph "API Endpoints"
        CR["Cache Revalidation API (src/app/api/cache-revalidate/route.ts)"]:::backend
        SG["Sitemap Generation API (src/app/sitemap-blog.xml/route.ts)"]:::backend
    end

    subgraph "External Services and CI/CD"
        SC["Sanity CMS Integration (sanity.cli.ts, sanity.config.ts, src/sanity, src/lib/sanity)"]:::cms
        Vercel["Vercel Hosting"]:::external
        GHA["GitHub Actions CI/CD (.github/workflows)"]:::external
        Conf["Project Configuration Files (.env.sample, next.config.mjs, tailwind.config.ts, postcss.config.mjs, next-sitemap.config.js)"]:::config
    end

    subgraph "UI and Integrations"
        UI["UI Components (src/components)"]:::ui
        PH["PostHog Analytics (src/components/PostHog)"]:::integration
        COM["Commento++ (src/components/Commento/Commento.tsx)"]:::integration
        AOS["AOS Animations (src/components/AOS/AOSInit.tsx)"]:::integration
        Hooks["Custom Hooks (src/hooks)"]:::util
        Utils["Utility Functions (src/utils)"]:::util
    end

    %% Connections between Frontend and External Systems
    DB -->|"fetchesContent"| SC
    DB -->|"triggersRevalidation"| CR
    CR -->|"updatesContent"| DB
    SP -->|"rendersVia"| UI
    SS -->|"managesContent"| SC

    %% Connections involving API and External Services
    GHA -->|"deploysTo"| Vercel
    GHA -->|"triggersConfig"| Conf
    SC -->|"webhookTriggers"| CR
    SC -->|"updatesSitemap"| SG

    %% UI and Integration connections
    UI -->|"integratesWith"| PH
    UI -->|"integratesWith"| COM
    UI -->|"integratesWith"| AOS
    UI -->|"enhancedBy"| Hooks
    UI -->|"enhancedBy"| Utils

    %% Click Events
    click SP "https://github.com/lucasadrianof/personal-blog-nextjs/tree/main/src/app/(blog)"
    click DB "https://github.com/lucasadrianof/personal-blog-nextjs/tree/main/src/app/(blog)/blog/[slug]"
    click SS "https://github.com/lucasadrianof/personal-blog-nextjs/tree/main/src/app/studio"
    click CR "https://github.com/lucasadrianof/personal-blog-nextjs/blob/main/src/app/api/cache-revalidate/route.ts"
    click SG "https://github.com/lucasadrianof/personal-blog-nextjs/blob/main/src/app/sitemap-blog.xml/route.ts"
    click UI "https://github.com/lucasadrianof/personal-blog-nextjs/tree/main/src/components"
    click PH "https://github.com/lucasadrianof/personal-blog-nextjs/tree/main/src/components/PostHog"
    click COM "https://github.com/lucasadrianof/personal-blog-nextjs/blob/main/src/components/Commento/Commento.tsx"
    click AOS "https://github.com/lucasadrianof/personal-blog-nextjs/blob/main/src/components/AOS/AOSInit.tsx"
    click GHA "https://github.com/lucasadrianof/personal-blog-nextjs/tree/main/.github/workflows"
    click Hooks "https://github.com/lucasadrianof/personal-blog-nextjs/tree/main/src/hooks"
    click Utils "https://github.com/lucasadrianof/personal-blog-nextjs/tree/main/src/utils"
    click SC "https://github.com/lucasadrianof/personal-blog-nextjs/blob/main/sanity.cli.ts"
    click Conf "https://github.com/lucasadrianof/personal-blog-nextjs/blob/main/.env.sample"

    %% Styles
    classDef frontend fill:#cce5ff,stroke:#000,stroke-width:1px;
    classDef backend fill:#d5f5e3,stroke:#000,stroke-width:1px;
    classDef cms fill:#f9e79f,stroke:#000,stroke-width:1px;
    classDef external fill:#fadbd8,stroke:#000,stroke-width:1px;
    classDef ui fill:#d6eaf8,stroke:#000,stroke-width:1px;
    classDef integration fill:#f5b7b1,stroke:#000,stroke-width:1px;
    classDef util fill:#e8daef,stroke:#000,stroke-width:1px;
    classDef config fill:#f0b27a,stroke:#000,stroke-width:1px;
```
