# scs0209/3d-blog architecture

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

- Interactive diagram: https://gitdiagram.com/scs0209/3d-blog
- Repository: https://github.com/scs0209/3d-blog

## Overview

##### Main Components
- Frontend (UI): The Next.js “app” directory holds the pages. Note the segmentation into “(public)” (e.g., login, sign-up, 3d pages) and “(protect)” (admin/dashboard pages). This separation suggests public-facing and secured/admin interfaces.
- Database: The “prisma” folder (with the schema.prisma and migration files) clearly indicates a relational database layer managed by Prisma. Entities defined in “src/entities” (like post, category, tag, user, and home) should be visualized as part of this persistence layer.
- Domain/Business Logic: The “src/features”, “src/shared”, and “src/widgets” directories encapsulate specific business logic, UI components, and even custom hooks/utilities. These modules often interact with or wrap the API calls and represent the domain-specific logic of the application.
- Authentication: The integration with NextAuth (via files like “app/api/auth/[...nextauth]” and relevant source files in “src/features/auth”) should be highlighted as a cross-cutting security component.
- Testing/Utilities: Though not central to runtime architecture, testing directories (like __test__ and jest configs) and utility scripts emphasize quality assurance and development workflow.

##### Relationships and Interactions
- The API endpoints then interact with the database (Prisma-managed) and domain entities (from “src/entities”).
- Authentication flows (using NextAuth) will intercept or protect routes using middleware (as seen from the middleware.ts file) and will be linked between the UI’s secured sections and the auth API endpoints.
- Shared libraries and utilities (in “src/shared” and “src/shadcn-ui”) act as supportive functions that many UI components and modules depend on.

##### Architectural Patterns and Design Principles
- Modular / Feature-based Architecture: Core domains like posts, categories, tags, and users are separated into features and entities, which makes the architecture extensible and maintainable.
- Separation of concerns: Clear division between public-facing pages, protected admin routes, API endpoints, database models, and shared UI components.
- Next.js App Directory Structure: Emphasize Next.js’s routing conventions, such as dynamic routes (e.g., [id], [slug]) and layout grouping (using layout.tsx files).

## Diagram (Mermaid)

```mermaid
flowchart TD

    subgraph "Frontend UI (Next.js Pages)"
        FPublic["\"Public Pages\""]:::frontend
        FProtected["\"Protected Pages\""]:::frontend
    end

    subgraph "Backend/API Endpoints"
        API["\"API Routes\""]:::backend
        AAuth["\"Auth API\""]:::backend
        ACategory["\"Category API\""]:::backend
        APosts["\"Posts API\""]:::backend
        ARegister["\"Register API\""]:::backend
        ATags["\"Tags API\""]:::backend
        ADocs["\"API Docs\""]:::backend
        ASwagger["\"Swagger\""]:::backend
    end

    subgraph "Database (Prisma ORM)"
        DB["\"Prisma & Migrations\""]:::db
    end

    subgraph "Domain & Business Logic"
        DEntities["\"Entities\""]:::domain
        DFeatures["\"Features\""]:::domain
        DWidgets["\"Widgets\""]:::domain
        DShared["\"Shared Utilities\""]:::domain
    end

    AUTH["\"NextAuth Integration\""]:::auth

    TTest["\"Tests & Configs\""]:::testing

    %% Connections
    FPublic -->|"HTTP_Request"| API
    FProtected -->|"Secured_Request"| API
    FProtected -->|"Auth_Validation"| AUTH

    API -->|"DB_Query"| DB
    API -->|"DomainAccess"| DEntities
    API --> DFeatures
    API -->|"Uses_Shared"| DShared

    AAuth ---|"AuthEndpoint"| AUTH

    %% Styles will help grouping vertical layout; placement of subgraphs ensures verticality.

    %% Click Events
    click FPublic "https://github.com/scs0209/3d-blog/tree/main/app/(public)"
    click FProtected "https://github.com/scs0209/3d-blog/tree/main/app/(protect)"
    
    click API "https://github.com/scs0209/3d-blog/tree/main/app/api"
    click AAuth "https://github.com/scs0209/3d-blog/tree/main/app/api/auth"
    click ACategory "https://github.com/scs0209/3d-blog/tree/main/app/api/category"
    click APosts "https://github.com/scs0209/3d-blog/tree/main/app/api/posts"
    click ARegister "https://github.com/scs0209/3d-blog/tree/main/app/api/register"
    click ATags "https://github.com/scs0209/3d-blog/tree/main/app/api/tags"
    click ADocs "https://github.com/scs0209/3d-blog/tree/main/app/api/api-docs"
    click ASwagger "https://github.com/scs0209/3d-blog/tree/main/app/swagger"
    
    click DB "https://github.com/scs0209/3d-blog/tree/main/prisma"
    
    click DEntities "https://github.com/scs0209/3d-blog/tree/main/src/entities"
    click DFeatures "https://github.com/scs0209/3d-blog/tree/main/src/features"
    click DWidgets "https://github.com/scs0209/3d-blog/tree/main/src/widgets"
    click DShared "https://github.com/scs0209/3d-blog/tree/main/src/shared"
    
    click AUTH "https://github.com/scs0209/3d-blog/blob/main/app/api/auth/[...nextauth]"
    
    click TTest "https://github.com/scs0209/3d-blog/tree/main/__test__"

    %% Class Definitions for Colors
    classDef frontend fill:#AED6F1,stroke:#2E86C1,stroke-width:2px;
    classDef backend fill:#ABEBC6,stroke:#28B463,stroke-width:2px;
    classDef db fill:#F9E79F,stroke:#F1C40F,stroke-width:2px;
    classDef domain fill:#FAD7A0,stroke:#E67E22,stroke-width:2px;
    classDef auth fill:#D2B4DE,stroke:#8E44AD,stroke-width:2px;
    classDef testing fill:#F5B7B1,stroke:#C0392B,stroke-width:2px;
```
