# thanhhoan-v2/piz architecture

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

- Interactive diagram: https://gitdiagram.com/thanhhoan-v2/piz
- Repository: https://github.com/thanhhoan-v2/piz

## Overview

##### Main Components
- Frontend (Next.js App): Highlight the “app” directory which contains the core pages and route handlers such as login, authentication callbacks, protected routes, and the main page. Indicate how the App Router, middleware (middleware.ts), and global styling (app/globals.css) tie together.
- UI and Component Library: Show a component layer that encompasses “components” and “components/ui”. This part includes reusable UI pieces (buttons, inputs, dialogs, sidebar components, etc.) and theme management.
- Authentication Module: Emphasize the authentication-related code in “app/auth”, “components/auth” and the related Supabase client logic. Note how both the frontend login pages and static UI elements integrate authentication actions.
- Supabase Integration: Represent the “utils/supabase” directory containing client, middleware, and server code. This part is critical for Supabase Auth (supabase-ssr) and for establishing the connection with the Supabase backend (e.g., using environment variables for SECRET/ANON keys).
- Static Assets and Configurations: Indicate directories such as “assets” (for fonts) and configuration files like tailwind.config.ts, postcss.config.js, tsconfig.json, and next.config.mjs. These establish toolchain and styling conventions.

##### Relationships and Interactions
- Middleware at the appropriate layer (middleware.ts and utils/supabase/middleware.ts) to indicate request intercession for authentication and session management.

##### Architectural Patterns and Design Principles
- The separation of Concerns: Clearly separate UI (visual components), business logic (authentication flows, routing) and data access (Supabase utilities).
- Component Reusability: Emphasize the usage of modular, reusable components in the “components” directory, which help maintain a clean and scalable architecture.
- Full-Stack Integrated Approach: Showcase the interaction between client-side components (Next.js pages/route handlers) and server-side utilities (Supabase integration) which is a common pattern in Next.js applications.

##### Relevant Technologies and Tools
- Next.js (both App and Pages router, middleware, and route handlers)
- Supabase (for authentication and possibly database interactions)
- Tailwind CSS (for the styling found in app/globals.css and Tailwind configuration files)
- TypeScript (as indicated by tsconfig.json, .tsx files, and type usage)
- Vercel Deployment: Note that the project supports direct deployment with Vercel, so you might add a note that the environment variables and deployment configuration are crucial parts of the architecture.

- Client with the Next.js routes; when a user interacts (e.g., clicking the auth-button), the action goes through the Next.js handler, which then reaches the Supabase backend—depicted as an external module/service.

## Diagram (Mermaid)

```mermaid
graph TD
    UB("User Browser"):::client

    subgraph "Server (Next.js Application)"
        APP("Next.js App Router"):::backend
        AUTHP("Auth Pages & Handlers"):::auth
        UI("UI & Component Library"):::ui
        AUTHC("Authentication Components"):::auth
        MW("Middleware"):::middleware
        SUPA("Supabase Integration Utils"):::integration
    end

    SUBSUP("Supabase Service"):::external

    subgraph "Styling & Configuration"
        GS("Global Styling"):::config
        TW("Tailwind Config"):::config
        PC("PostCSS Config"):::config
        TS("TypeScript Config"):::config
        NC("Next Config"):::config
        AS("Assets"):::config
    end

    UB -->|"navigatesTo"| APP
    APP -->|"routesTo"| AUTHP
    APP -->|"renders"| UI
    AUTHP -->|"invokes"| AUTHC
    APP -->|"interceptedBy"| MW
    MW -->|"calls"| SUPA
    AUTHC -->|"calls"| SUPA
    SUPA -->|"connectsTo"| SUBSUP
    UI -->|"integratesWith"| AUTHC

    GS --- UI
    GS --- APP

    %% Click Events
    click APP "https://github.com/thanhhoan-v2/piz/tree/main/app"
    click AUTHP "https://github.com/thanhhoan-v2/piz/tree/main/app/auth"
    click UI "https://github.com/thanhhoan-v2/piz/tree/main/components"
    click AUTHC "https://github.com/thanhhoan-v2/piz/tree/main/components/auth"
    click SUPA "https://github.com/thanhhoan-v2/piz/tree/main/utils/supabase"
    click MW "https://github.com/thanhhoan-v2/piz/blob/main/middleware.ts"
    click GS "https://github.com/thanhhoan-v2/piz/blob/main/app/globals.css"
    click TW "https://github.com/thanhhoan-v2/piz/blob/main/tailwind.config.ts"
    click PC "https://github.com/thanhhoan-v2/piz/blob/main/postcss.config.js"
    click TS "https://github.com/thanhhoan-v2/piz/blob/main/tsconfig.json"
    click NC "https://github.com/thanhhoan-v2/piz/blob/main/next.config.mjs"
    click AS "https://github.com/thanhhoan-v2/piz/tree/main/assets"

    %% Style definitions
    classDef client fill:#f9c,stroke:#333,stroke-width:2px;
    classDef backend fill:#cce,stroke:#000,stroke-width:2px;
    classDef auth fill:#fdd,stroke:#c00,stroke-width:2px;
    classDef ui fill:#dfd,stroke:#080,stroke-width:2px;
    classDef middleware fill:#fed,stroke:#aa0,stroke-width:2px;
    classDef integration fill:#bbf,stroke:#00f,stroke-width:2px;
    classDef external fill:#ddd,stroke:#555,stroke-width:2px;
    classDef config fill:#ff9,stroke:#990,stroke-width:2px;
```
