# ahmadalabed/full-stack-blog-application architecture

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

- Interactive diagram: https://gitdiagram.com/ahmadalabed/full-stack-blog-application
- Repository: https://github.com/ahmadalabed/full-stack-blog-application

## Overview

##### Main Components Identification

a) Client Layer:
- Next.js Frontend (Server and Client Components)
- Authentication UI (/auth directory)
- Blog Management UI (/blog directory)
- Reusable Components (/components directory)

b) Server Layer:
- API Routes (/api directory)
- Server Actions (/actions directory)
- Authentication Handlers
- Database Integration

c) Data Layer:
- MongoDB Database
- Mongoose Models (User and Blog)

**[Client Layer]**
- ↕
**[Server Layer]**
- ↕
**[Data Layer]**

##### Detailed Component Breakdown

Client Layer (Top):
- Auth Pages (Sign In/Sign Up)
- Blog Pages (List/Single/My Posts)
- Shared Components
- Providers (AuthProvider, ToastProvider) as wrapping containers

Server Layer (Middle):
- Create sections for:
- API Routes (auth, blogs)
- Server Actions
- NextAuth.js Integration
- Validation Layer (Zod schemas)
- Middleware as a gateway between Client and Server layers

Data Layer (Bottom):
- MongoDB Connection
- Mongoose Models (User, Blog)

##### Connection and Flow Representation

- Client-Server Communication:
→ Server Actions (direct calls)
→ API Routes (REST endpoints)
- Authentication Flow:
→ Social Auth Providers
→ Credential Auth
- Data Flow:
→ Database Operations
→ Response Handling

##### Technical Details

Annotations for:
- Authentication Strategies (OAuth, Credentials)
- Validation Layers (Zod Schemas)
- Server Actions Implementation
- Database Model Relationships

##### Implementation Notes

- Next.js 13+ App Router Structure
- Server Components Architecture
- API Route Organization
- Authentication Flow
- Database Integration

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        UI[Next.js Frontend]
        AuthUI[Authentication UI]
        BlogUI[Blog Management UI]
        Components[Reusable Components]
        Providers{Client Providers}
    end

    subgraph Server
        API[API Routes]
        Actions[Server Actions]
        Auth[Authentication System]
        Middleware[Middleware Layer]
        Validation[Validation Layer]
    end

    subgraph Database
        MongoDB[(MongoDB)]
        Models[Data Models]
        UserModel[User Model]
        BlogModel[Blog Model]
    end

    %% Client Layer Relationships
    UI --> AuthUI
    UI --> BlogUI
    UI --> Components
    Providers --> UI

    %% Server Layer Relationships
    Middleware --> API
    Middleware --> Actions
    API --> Auth
    API --> Validation
    Actions --> Validation

    %% Database Layer Relationships
    Models --> UserModel
    Models --> BlogModel
    Auth --> MongoDB
    API --> MongoDB
    Actions --> MongoDB

    %% Cross-Layer Communication
    UI --> Middleware
    AuthUI --> Auth
    BlogUI --> API

    %% Styling
    classDef default fill:#f9f9f9,stroke:#333,stroke-width:2px
    classDef database fill:#f5f5dc,stroke:#333
    classDef auth fill:#e6ffe6,stroke:#333
    classDef api fill:#e6f3ff,stroke:#333
    classDef component fill:#ffe6e6,stroke:#333

    class MongoDB database
    class Auth,AuthUI auth
    class API,Actions api
    class Components,Providers component

    %% Click Events
    click AuthUI "https://github.com/AhmadAlabed/full-stack-blog-application/tree/main/src/app/auth/"
    click BlogUI "https://github.com/AhmadAlabed/full-stack-blog-application/tree/main/src/app/blog/"
    click Components "https://github.com/AhmadAlabed/full-stack-blog-application/tree/main/src/components/"
    click API "https://github.com/AhmadAlabed/full-stack-blog-application/tree/main/src/app/api/"
    click Actions "https://github.com/AhmadAlabed/full-stack-blog-application/tree/main/src/actions/"
    click Auth "https://github.com/AhmadAlabed/full-stack-blog-application/tree/main/src/app/api/auth/"
    click MongoDB "https://github.com/AhmadAlabed/full-stack-blog-application/blob/main/src/lib/mongodb.ts"
    click Models "https://github.com/AhmadAlabed/full-stack-blog-application/tree/main/src/models/"
    click Validation "https://github.com/AhmadAlabed/full-stack-blog-application/tree/main/src/validations/"
    click Providers "https://github.com/AhmadAlabed/full-stack-blog-application/blob/main/src/providers/AuthProvider.tsx"
    click Middleware "https://github.com/AhmadAlabed/full-stack-blog-application/blob/main/src/middleware.ts"
    click BlogModel "https://github.com/AhmadAlabed/full-stack-blog-application/blob/main/src/models/blog.ts"
    click UserModel "https://github.com/AhmadAlabed/full-stack-blog-application/blob/main/src/models/user.ts"

    %% Legend
    subgraph Legend
        L1[Client Component]:::component
        L2[Server Component]:::api
        L3[Auth Component]:::auth
        L4[(Database)]:::database
    end
```
