# eric-jy-park/bookmarket architecture

> Architecture diagram of the GitHub repository eric-jy-park/bookmarket, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-22). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/eric-jy-park/bookmarket
- Repository: https://github.com/eric-jy-park/bookmarket

## Overview

##### Main System Components

a) Client-Side (Frontend):
- Pages Layer (/(home), etc.)
- Components Layer (_components)
- State Management (React Query + Zustand)
- Hooks Layer (_hooks)

b) Server-Side:
- A "Server Components" section
- Database layer (Neon PostgreSQL)

c) External Services:
- Clerk Authentication
- URL Metadata Service

##### Component Relationships

**[Client Layer]**
- ↕
**[Next.js App Router]**
- ↕
**[API Layer] ←→ [External Services]**
- ↕
**[Database Layer]**

##### Detailed Component Breakdown

For each major section, include:

Frontend Components:
- BookmarkList
- BookmarkCard
- ContextMenu
- TopNavBar
- Common Components

State Management:
- Mutations (create, update, delete)
- Queries (bookmark fetching)
- Local State (bookmark store)

API Routes:
- /api/bookmarks (CRUD)
- /api/metadata (URL info)

##### Technical Details

- ORM Layer (Drizzle)
- Authentication Flow
- State Management Tools
- API Route Handlers

##### Document any assumptions

Remember to emphasize:
- The Next.js App Router architecture
- How server components interact with client components
- The role of React Query in data fetching
- How state is managed across the application
- Security boundaries and authentication flow

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        FE[Next.js Frontend]
        Pages["Pages Layer"]
        Components["Components Layer"]
        StateManagement["State Management"]
        Hooks["Hooks Layer"]
        
        FE --> Pages
        FE --> Components
        FE --> StateManagement
        FE --> Hooks
        
        subgraph Components
            BList["BookmarkList"]:::component
            BCard["BookmarkCard"]:::component
            CMenu["ContextMenu"]:::component
            TNav["TopNavBar"]:::component
        end
        
        subgraph StateManagement
            RQM["React Query Mutations"]:::state
            RQQ["React Query Queries"]:::state
            BStore["Bookmark Store"]:::state
        end
    end
    
    subgraph Server
        API["Next.js API Routes"]
        SC["Server Components"]
        
        subgraph APIRoutes
            BCRUD["/api/bookmarks"]:::api
            META["/api/metadata"]:::api
        end
        
        subgraph Database
            PG["Neon PostgreSQL"]:::db
            Schema["Database Schema"]:::db
            DBConfig["Database Config"]:::db
            BQueries["Bookmark Queries"]:::db
        end
    end
    
    subgraph ExternalServices
        Clerk["Clerk Authentication"]:::external
        URLMeta["URL Metadata Service"]:::external
    end
    
    subgraph Services
        BService["Bookmark Service"]:::service
        MService["Metadata Service"]:::service
    end
    
    subgraph Core
        QClient["Query Client"]:::util
        URLUtils["URL Utilities"]:::util
    end
    
    subgraph Providers
        GP["Global Provider"]:::provider
        SP["Server Prefetcher"]:::provider
    end
    
    MW["Middleware"]:::middleware
    
    %% Relationships
    Client --> API
    API --> Database
    API <--> ExternalServices
    SC <--> Database
    MW --> API
    
    %% Click Events
    click BList "https://github.com/eric-jy-park/bookmarket/blob/main/src/app/(pages)/(home)/_components/bookmark-list.tsx"
    click BCard "https://github.com/eric-jy-park/bookmarket/blob/main/src/app/(pages)/(home)/_components/bookmark-card.tsx"
    click CMenu "https://github.com/eric-jy-park/bookmarket/blob/main/src/app/_core/components/context-menu.tsx"
    click TNav "https://github.com/eric-jy-park/bookmarket/blob/main/src/app/_common/components/top-nav-bar.tsx"
    click RQM "https://github.com/eric-jy-park/bookmarket/tree/main/src/app/(pages)/(home)/_state/mutations/"
    click RQQ "https://github.com/eric-jy-park/bookmarket/blob/main/src/app/(pages)/(home)/_state/queries/bookmark-query.tsx"
    click BStore "https://github.com/eric-jy-park/bookmarket/blob/main/src/app/(pages)/(home)/_state/store/use-bookmark-store.ts"
    click BCRUD "https://github.com/eric-jy-park/bookmarket/tree/main/src/app/api/bookmarks/"
    click META "https://github.com/eric-jy-park/bookmarket/blob/main/src/app/api/metadata/route.ts"
    click Schema "https://github.com/eric-jy-park/bookmarket/blob/main/src/server/db/schema.ts"
    click DBConfig "https://github.com/eric-jy-park/bookmarket/blob/main/src/server/db/index.ts"
    click BQueries "https://github.com/eric-jy-park/bookmarket/blob/main/src/server/queries/bookmark.ts"
    click BService "https://github.com/eric-jy-park/bookmarket/blob/main/src/app/(pages)/(home)/services/bookmark-service.ts"
    click MService "https://github.com/eric-jy-park/bookmarket/blob/main/src/app/(pages)/(home)/services/metadata-service.ts"
    click QClient "https://github.com/eric-jy-park/bookmarket/blob/main/src/app/_core/utils/get-query-client.ts"
    click URLUtils "https://github.com/eric-jy-park/bookmarket/blob/main/src/app/_core/utils/url-to-domain.ts"
    click GP "https://github.com/eric-jy-park/bookmarket/blob/main/src/app/_common/providers/global-provider.tsx"
    click SP "https://github.com/eric-jy-park/bookmarket/blob/main/src/app/_common/providers/server-prefetcher.tsx"
    click MW "https://github.com/eric-jy-park/bookmarket/blob/main/src/middleware.ts"
    
    %% Styling
    classDef component fill:#2563eb,color:white
    classDef state fill:#4f46e5,color:white
    classDef api fill:#22c55e,color:white
    classDef db fill:#f97316,color:white
    classDef external fill:#a855f7,color:white
    classDef service fill:#06b6d4,color:white
    classDef util fill:#64748b,color:white
    classDef provider fill:#ec4899,color:white
    classDef middleware fill:#dc2626,color:white
    
    %% Legend
    subgraph Legend
        L1["Frontend Component"]:::component
        L2["State Management"]:::state
        L3["API Route"]:::api
        L4["Database"]:::db
        L5["External Service"]:::external
        L6["Internal Service"]:::service
        L7["Utility"]:::util
        L8["Provider"]:::provider
        L9["Middleware"]:::middleware
    end
```
