# chiazhe/chatprofolio architecture

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

- Interactive diagram: https://gitdiagram.com/chiazhe/chatprofolio
- Repository: https://github.com/chiazhe/chatprofolio

## Overview

##### Project type and purpose
- This is a full-stack Next.js 13 application (using the App Router) that allows users to sign up/log in, customize their profile (basic info, education, experience, skills, projects, achievements, contact, layout preferences), and exposes an AI chat feature. It uses NextAuth for authentication, Prisma for database ORM, and server actions/API routes for CRUD operations on user data and chatbot records.

##### File structure
- Top-level “app” directory implements pages and layouts via React Server Components and Client Components under route segments like `(auth)`, `profile/[username]`, and `settings`.
- The “actions” directory contains Next.js Server Actions for create/update operations (e.g., `update-experience.ts`).
- “app/api” holds Next.js Route Handlers for auth (`[...nextauth]/route.ts`) and chat (`chat/route.ts`).
- “lib” contains utility code: `auth.ts` (NextAuth config), `db.ts` (Prisma client), validation schemas, and helper functions.
- “prisma” hosts the schema and migration history (defining User, Experience, Education, Skill, Project, Achievement, Contact, LayoutPreference, ChatbotRecords models).
- “components” and “app/_component” provide reusable UI (client) components.
- “context” and “lib/providers” provide React Context for theme and toasts.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Frontend Layer
    subgraph "Frontend" 
        direction TB
        Browser["Browser (User)"]:::ui
        ClientComponents["React Client Components"]:::ui
        GlobalUI["Global UI Library"]:::ui
        ServerComponents["React Server Components"]:::ui
    end

    %% Backend Layer
    subgraph "Backend" 
        direction TB
        subgraph "Next.js App Server" 
            direction TB
            AppRouter["App Router\n(Route Handlers & Server Actions)"]:::server

            subgraph "Authentication Module (NextAuth)"
                direction TB
                AuthAPI["API Route Handler\n[...nextauth]/route.ts"]:::server
                AuthConfig["NextAuth Config\nlib/auth.ts"]:::server
            end

            subgraph "Chat Module"
                direction TB
                ChatAPI["API Route Handler\napp/api/chat/route.ts"]:::server
                ChatAction["Server Action\nactions/create-chatbot-records.ts"]:::server
            end

            subgraph "Server Actions (CRUD)"
                direction TB
                UpdateBasic["update-basic-information.ts"]:::server
                UpdateEducation["update-education.ts"]:::server
                UpdateExperience["update-experience.ts"]:::server
                UpdateSkill["update-skill.ts"]:::server
                UpdateProject["update-project.ts"]:::server
                UpdateAchievement["update-achievement.ts"]:::server
                UpdateContact["update-contact.ts"]:::server
                UpdateLayout["create-update-layout-preference.ts"]:::server
                GetUser["get-user-by-username.ts"]:::server
                GetData["get-data.ts"]:::server
                SetUsername["set-username.ts"]:::server
                Logout["logout.ts"]:::server
            end

            subgraph "Validation Layer (Zod)"
                direction TB
                ZodBasic["basicInformation.ts"]:::server
                ZodEducation["education.ts"]:::server
                ZodExperience["experience.ts"]:::server
                ZodSkill["skill.ts"]:::server
                ZodProject["project.ts"]:::server
                ZodAchievement["achievement.ts"]:::server
                ZodContact["contact.ts"]:::server
                ZodLayout["layout-preference.ts"]:::server
                ZodUsername["username.ts"]:::server
            end

            subgraph "ORM / Database Client"
                direction TB
                PrismaClient["Prisma Client\nlib/db.ts"]:::data
                PrismaSchema["Prisma Schema\nprisma/schema.prisma"]:::data
            end

            subgraph "Utility / Helper Functions"
                direction TB
                Helper["lib/helper.ts"]:::server
                Utils["lib/utils.ts"]:::server
                Reusable["lib/reusableFunction.ts"]:::server
                LandingData["lib/landing-page-data.ts"]:::server
                LayoutData["lib/layout-data.ts"]:::server
            end

            subgraph "React Context Providers"
                direction TB
                ThemeProvider["Theme Context\ncontext/ThemeProvider.tsx"]:::server
                ToastProvider["Toast Notifications\nlib/providers/ReactToastProvider.tsx"]:::server
            end

            Middleware["Edge Middleware\napp/middleware.ts"]:::server
        end
    end

    %% Data and External Services
    DB["PostgreSQL Database\n(Prisma)"]:::data
    AI["OpenAI API"]:::external

    %% Relationships
    Browser -->|Requests / Navigation| AppRouter
    ClientComponents -->|Rendered by| AppRouter
    ServerComponents -->|Server-side Rendering| AppRouter

    AppRouter -->|CRUD Operations| UpdateBasic
    AppRouter --> UpdateEducation
    AppRouter --> UpdateExperience
    AppRouter --> UpdateSkill
    AppRouter --> UpdateProject
    AppRouter --> UpdateAchievement
    AppRouter --> UpdateContact
    AppRouter --> UpdateLayout
    AppRouter --> GetUser
    AppRouter --> GetData
    AppRouter --> SetUsername
    AppRouter --> Logout

    UpdateBasic --> PrismaClient
    UpdateEducation --> PrismaClient
    UpdateExperience --> PrismaClient
    UpdateSkill --> PrismaClient
    UpdateProject --> PrismaClient
    UpdateAchievement --> PrismaClient
    UpdateContact --> PrismaClient
    UpdateLayout --> PrismaClient
    SetUsername --> PrismaClient
    Logout --> PrismaClient
    GetUser --> PrismaClient
    GetData --> PrismaClient

    AuthAPI -->|Sessions / JWT| DB
    AuthConfig -->|Configures| AuthAPI

    ChatAPI -->|Send/Receive| AI
    ChatAction --> PrismaClient

    PrismaClient --> DB

    Middleware --> AppRouter

    %% Click Events
    click AuthAPI "https://github.com/chiazhe/chatprofolio/blob/main/app/api/auth/[...nextauth]/route.ts"
    click AuthConfig "https://github.com/chiazhe/chatprofolio/blob/main/lib/auth.ts"
    click ChatAPI "https://github.com/chiazhe/chatprofolio/blob/main/app/api/chat/route.ts"
    click ChatAction "https://github.com/chiazhe/chatprofolio/blob/main/actions/create-chatbot-records.ts"
    click UpdateBasic "https://github.com/chiazhe/chatprofolio/blob/main/actions/update-basic-information.ts"
    click UpdateEducation "https://github.com/chiazhe/chatprofolio/blob/main/actions/update-education.ts"
    click UpdateExperience "https://github.com/chiazhe/chatprofolio/blob/main/actions/update-experience.ts"
    click UpdateSkill "https://github.com/chiazhe/chatprofolio/blob/main/actions/update-skill.ts"
    click UpdateProject "https://github.com/chiazhe/chatprofolio/blob/main/actions/update-project.ts"
    click UpdateAchievement "https://github.com/chiazhe/chatprofolio/blob/main/actions/update-achievement.ts"
    click UpdateContact "https://github.com/chiazhe/chatprofolio/blob/main/actions/update-contact.ts"
    click UpdateLayout "https://github.com/chiazhe/chatprofolio/blob/main/actions/create-update-layout-preference.ts"
    click GetUser "https://github.com/chiazhe/chatprofolio/blob/main/actions/get-user-by-username.ts"
    click GetData "https://github.com/chiazhe/chatprofolio/blob/main/actions/get-data.ts"
    click SetUsername "https://github.com/chiazhe/chatprofolio/blob/main/actions/set-username.ts"
    click Logout "https://github.com/chiazhe/chatprofolio/blob/main/actions/logout.ts"
    click ZodBasic "https://github.com/chiazhe/chatprofolio/blob/main/lib/zodSchema/basicInformation.ts"
    click ZodEducation "https://github.com/chiazhe/chatprofolio/blob/main/lib/zodSchema/education.ts"
    click ZodExperience "https://github.com/chiazhe/chatprofolio/blob/main/lib/zodSchema/experience.ts"
    click ZodSkill "https://github.com/chiazhe/chatprofolio/blob/main/lib/zodSchema/skill.ts"
    click ZodProject "https://github.com/chiazhe/chatprofolio/blob/main/lib/zodSchema/project.ts"
    click ZodAchievement "https://github.com/chiazhe/chatprofolio/blob/main/lib/zodSchema/achievement.ts"
    click ZodContact "https://github.com/chiazhe/chatprofolio/blob/main/lib/zodSchema/contact.ts"
    click ZodLayout "https://github.com/chiazhe/chatprofolio/blob/main/lib/zodSchema/layout-preference.ts"
    click ZodUsername "https://github.com/chiazhe/chatprofolio/blob/main/lib/zodSchema/username.ts"
    click PrismaClient "https://github.com/chiazhe/chatprofolio/blob/main/lib/db.ts"
    click PrismaSchema "https://github.com/chiazhe/chatprofolio/blob/main/prisma/schema.prisma"
    click Helper "https://github.com/chiazhe/chatprofolio/blob/main/lib/helper.ts"
    click Utils "https://github.com/chiazhe/chatprofolio/blob/main/lib/utils.ts"
    click Reusable "https://github.com/chiazhe/chatprofolio/blob/main/lib/reusableFunction.ts"
    click LandingData "https://github.com/chiazhe/chatprofolio/blob/main/lib/landing-page-data.ts"
    click LayoutData "https://github.com/chiazhe/chatprofolio/blob/main/lib/layout-data.ts"
    click ThemeProvider "https://github.com/chiazhe/chatprofolio/blob/main/context/ThemeProvider.tsx"
    click ToastProvider "https://github.com/chiazhe/chatprofolio/blob/main/lib/providers/ReactToastProvider.tsx"
    click GlobalUI "https://github.com/chiazhe/chatprofolio/tree/main/components/ui"
    click ClientComponents "https://github.com/chiazhe/chatprofolio/tree/main/app/_component"
    click Middleware "https://github.com/chiazhe/chatprofolio/blob/main/app/middleware.ts"

    %% Styles
    classDef ui fill:#cce5ff,stroke:#0366d6,stroke-width:1px
    classDef server fill:#d4edda,stroke:#155724,stroke-width:1px
    classDef data fill:#fff3cd,stroke:#856404,stroke-width:1px
    classDef external fill:#e2e3e5,stroke:#6c757d,stroke-width:1px
```
