# kemezz/nadoharu-standalone architecture

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

- Interactive diagram: https://gitdiagram.com/kemezz/nadoharu-standalone
- Repository: https://github.com/kemezz/nadoharu-standalone

## Overview

##### Project type and purpose
- This is a full-stack social-network micro-blogging application built with Next.js (“app” directory) and TypeScript.
- It provides user authentication (login/register), post timelines, chat, notifications, user profiles, and friend requests.
- The backend logic (server-side actions, API routes) and the frontend views (React/TSX pages) live in the same Next.js codebase.
- Prisma is used as the ORM to persist data in a relational database; Iron Session handles session management.

##### File structure
- Top-level “app” directory follows Next.js’s App Router: nested folders for each route (auth/, tabs/, chat/, posts/, users/, me/).
- “components” holds reusable UI pieces, organized by domain (chat, post, comment, friendship, profile) and shared UI controls.
- “libs” contains shared utilities: db.ts (Prisma client), session.ts (Iron Session config), atoms/constants/utils.
- “prisma” directory defines the schema and migration history.
- Configuration files: next.config.ts, tsconfig.json, tailwind.config.ts, postcss.config.mjs.
- Middleware.ts likely enforces authentication checks or global request handling.

##### Key insights from README
- Next.js + Iron Session + Tailwind + Prisma deployed on Vercel.
- The app is the standalone web version of the NDHR social micro-blog, so real-time-ish chat, notifications, and timeline features are critical.

a. Main components
- Client (Browser/mobile web view)
- Next.js Server (Vercel Edge + Node Serverless Functions)
- Authentication Module (Iron Session middleware, auth server-actions)
- Business Logic Layer (server-actions & utilities in libs/)
- Prisma ORM Layer
- Relational Database (PostgreSQL or MySQL)
- Static Assets & CDN (public/, fonts, Vercel CDN)
- Optional External Services (OAuth providers, push notifications)
b. Relationships & interactions
- Client sends HTTP(S) requests to Next.js (SSR pages, API routes, server-actions).
- Next.js applies Middleware → session validation → routes to page or server-action.
- Server-action calls Business Logic → Prisma ORM → Database.
- Responses (HTML, JSON or redirects) return to Client.
- Static files and images served via CDN.
c. Architectural patterns / principles
- Monolithic full-stack architecture with a unified codebase.
- App Router pattern providing file-based routing, server and client components.
- Separation of concerns: UI components vs. domain logic vs. data persistence.
- Middleware pipeline for authentication/session.
- Reusable domain components (chat bubble, post timeline) to enforce UI consistency.
d. Relevant technologies
- Next.js (App Router, Server Components, Server Actions)
- React / JSX / TSX
- Iron Session for cookie-based sessions
- Prisma for DB access
- Tailwind CSS for styling
- Vercel for hosting (Serverless functions + CDN)
- Postgres (or another SQL DB) managed via Prisma

##### Detail
- Every major route group as a sub-module: Auth, Tabs, Chat, Posts, Users, Me.
- How shared components are imported by pages and how domain logic flows through server-actions.
- Don’t just lump “Next.js”—break it into Router, Middleware, Server-Actions, API-like handlers.
- Call out Prisma migrations as part of the deployment pipeline.
- Vercel hosting and CDN as the deployment layer.

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "Client-side"
        Browser["Browser"]:::client
    end

    subgraph "Next.js Server (Vercel)"
        subgraph "App Router (app/)"
            LoginPage["Login Page"]:::server
            RegisterPage["Register Page"]:::server
            TabsLayout["Tabs Layout"]:::server
            ChatTab["Chat Tab"]:::server
            MeTab["Me Tab"]:::server
            NotifTab["Notifications Tab"]:::server
            PostsTab["Posts Tab"]:::server
            ChatDynamic["Chat [id] Page"]:::server
            PostDetail["Post Detail Page"]:::server
            PostUpload["Post Upload Page"]:::server
            UserProfile["User Profile Page"]:::server
            MeRequested["Me Requested Page"]:::server
            MeSetting["Me Setting Page"]:::server
        end

        Middleware["Middleware"]:::server
        Session["Iron Session"]:::server

        AuthLoginAct["Login Action"]:::server
        AuthRegisterAct["Register Action"]:::server

        CommonAction["Common Server Action"]:::server
        Utils["Utils"]:::server
        UseActionHook["use-action-with-alert"]:::server

        DBClient["Prisma Client"]:::server
        PrismaSchema["schema.prisma"]:::db
        Migrations["prisma/migrations/"]:::db
    end

    subgraph "Database"
        SQLDB["SQL Database"]:::db
    end

    subgraph "CDN & Static Assets"
        CDN["Vercel CDN & public/"]:::ext
    end

    %% Connections
    Browser -->|"HTTP Request"| LoginPage
    Browser -->|"HTTP Request"| RegisterPage
    Browser -->|"HTTP Request"| TabsLayout
    Browser -->|"Static Asset Request"| CDN

    LoginPage -->|passes through| Middleware
    RegisterPage -->|passes through| Middleware
    TabsLayout -->|passes through| Middleware
    ChatTab -->|passes through| Middleware
    MeTab -->|passes through| Middleware
    NotifTab -->|passes through| Middleware
    PostsTab -->|passes through| Middleware
    ChatDynamic -->|passes through| Middleware
    PostDetail -->|passes through| Middleware
    PostUpload -->|passes through| Middleware
    UserProfile -->|passes through| Middleware
    MeRequested -->|passes through| Middleware
    MeSetting -->|passes through| Middleware

    Middleware -->|validates session| Session
    Session -->|invokes| AuthLoginAct
    Session -->|invokes| AuthRegisterAct
    Session -->|invokes| CommonAction

    AuthLoginAct -->|calls| CommonAction
    AuthRegisterAct -->|calls| CommonAction
    CommonAction -->|uses| Utils
    CommonAction -->|uses| UseActionHook

    CommonAction -->|connects to| DBClient
    DBClient -->|reads schema| PrismaSchema
    DBClient -->|runs migrations| Migrations
    DBClient -->|queries| SQLDB
    SQLDB -->|returns data| DBClient
    DBClient -->|returns results| CommonAction
    CommonAction -->|responds| Session
    Session -->|responds| Middleware
    Middleware -->|responds| LoginPage
    Middleware -->|responds| RegisterPage
    Middleware -->|responds| TabsLayout

    %% Click Events
    click LoginPage "https://github.com/kemezz/nadoharu-standalone/blob/main/app/(auth)/login/page.tsx"
    click RegisterPage "https://github.com/kemezz/nadoharu-standalone/blob/main/app/(auth)/register/page.tsx"
    click TabsLayout "https://github.com/kemezz/nadoharu-standalone/blob/main/app/(tabs)/layout.tsx"
    click ChatTab "https://github.com/kemezz/nadoharu-standalone/blob/main/app/(tabs)/chat/page.tsx"
    click MeTab "https://github.com/kemezz/nadoharu-standalone/blob/main/app/(tabs)/me/page.tsx"
    click NotifTab "https://github.com/kemezz/nadoharu-standalone/blob/main/app/(tabs)/notifications/page.tsx"
    click PostsTab "https://github.com/kemezz/nadoharu-standalone/blob/main/app/(tabs)/posts/page.tsx"
    click ChatDynamic "https://github.com/kemezz/nadoharu-standalone/blob/main/app/chat/[id]/page.tsx"
    click PostDetail "https://github.com/kemezz/nadoharu-standalone/blob/main/app/posts/[id]/page.tsx"
    click PostUpload "https://github.com/kemezz/nadoharu-standalone/blob/main/app/posts/upload/page.tsx"
    click UserProfile "https://github.com/kemezz/nadoharu-standalone/blob/main/app/users/[id]/page.tsx"
    click MeRequested "https://github.com/kemezz/nadoharu-standalone/blob/main/app/me/requested/page.tsx"
    click MeSetting "https://github.com/kemezz/nadoharu-standalone/blob/main/app/me/setting/page.tsx"

    click Middleware "https://github.com/kemezz/nadoharu-standalone/blob/main/middleware.ts"
    click Session "https://github.com/kemezz/nadoharu-standalone/blob/main/libs/session.ts"
    click AuthLoginAct "https://github.com/kemezz/nadoharu-standalone/blob/main/app/(auth)/login/action.ts"
    click AuthRegisterAct "https://github.com/kemezz/nadoharu-standalone/blob/main/app/(auth)/register/action.ts"

    click CommonAction "https://github.com/kemezz/nadoharu-standalone/blob/main/app/(common)/action.ts"
    click Utils "https://github.com/kemezz/nadoharu-standalone/blob/main/libs/utils.ts"
    click UseActionHook "https://github.com/kemezz/nadoharu-standalone/blob/main/hooks/use-action-with-alert.ts"

    click DBClient "https://github.com/kemezz/nadoharu-standalone/blob/main/libs/db.ts"
    click PrismaSchema "https://github.com/kemezz/nadoharu-standalone/blob/main/prisma/schema.prisma"
    click Migrations "https://github.com/kemezz/nadoharu-standalone/tree/main/prisma/migrations/"

    %% Styles
    classDef client fill:#e0f7fa,stroke:#006064;
    classDef server fill:#e8f5e9,stroke:#1b5e20;
    classDef db fill:#fff3e0,stroke:#ef6c00;
    classDef ext fill:#f3e5f5,stroke:#4a148c;
```
