# dejwid/marketplace architecture

> Architecture diagram of the GitHub repository dejwid/marketplace, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/dejwid/marketplace
- Repository: https://github.com/dejwid/marketplace

## Overview

##### Main System Components

a) Client Layer:
- Next.js Frontend (App Router)
- Client-side Components
- Server Components
- Client-side Actions

b) API Layer:
- Next.js API Routes
- Authentication System
- ImageKit Integration

c) Data Layer:
- Database (implied by the Ad model)
- External Services (ImageKit)

##### Detailed Component Breakdown

a) Frontend Architecture:
- Pages (`/`, `/new`, `/edit/[id]`, `/ad/[id]`, `/my-ads`)
- Components (organized by functionality):
- Form Components (AdForm, SearchForm)
- Media Components (Gallery, Uploader)
- Location Components (LocationMap, LocationPicker)
- UI Components (Header, SubmitButton)

b) API Routes Structure:
- Auth endpoints (`/api/auth/[...nextauth]`)
- Ad management endpoints (`/api/ads`)
- Media handling endpoints (`/api/imagekit`)

##### Data Flow Representation

- Client-Server interactions
- Authentication flow
- Data mutations (Create/Edit/Delete ads)
- Image upload flow

##### Specific Implementation Details

- Next.js App Router structure
- Server Actions implementation
- Authentication integration
- Image handling system

**┌─────────────────────────────────────────┐**
- Client Layer (Browser)                  │
- Pages                              │
- Components                         │
- ┤
- Server Layer (Next.js)                  │
- Server Components                   │
- API Routes                         │
- Server Actions                     │
- ┤
- External Services                       │
- Authentication                     │
- ImageKit                          │
- Database                          │
- ┘

##### Key Interactions to Highlight

- User authentication flow
- Ad creation/editing process
- Image upload and management
- Search and filtering functionality
- Location-based features

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Client["Client Layer (Browser)"]
        direction TB
        Pages["Pages"]
        Components["Components"]
        
        subgraph PagesDetail["Page Routes"]
            direction TB
            Home["Homepage"]:::page
            AdDetail["Ad Detail Page"]:::page
            NewAd["New Ad Page"]:::page
            EditAd["Edit Ad Page"]:::page
            MyAds["My Ads Page"]:::page
        end

        subgraph ComponentsDetail["Component Types"]
            direction TB
            FormComps["Form Components"]
            MediaComps["Media Components"]
            LocationComps["Location Components"]
            UIComps["UI Components"]

            subgraph Forms["Forms"]
                AdForm["Ad Form"]:::component
                SearchForm["Search Form"]:::component
            end

            subgraph Media["Media"]
                Gallery["Gallery"]:::component
                Uploader["Uploader"]:::component
                UploadArea["Upload Area"]:::component
                UploadThumb["Upload Thumbnail"]:::component
            end

            subgraph Location["Location"]
                LocMap["Location Map"]:::component
                LocPicker["Location Picker"]:::component
                DistPicker["Distance Picker"]:::component
            end

            subgraph UI["UI"]
                Header["Header"]:::component
                SubmitBtn["Submit Button"]:::component
                AdItem["Ad Item"]:::component
            end
        end
    end

    subgraph Server["Server Layer (Next.js)"]
        direction TB
        ServerComp["Server Components"]
        APIRoutes["API Routes"]
        ServerActions["Server Actions"]

        subgraph APIs["API Endpoints"]
            AuthAPI["Authentication API"]:::api
            AdsAPI["Ads API"]:::api
            ImageKitAPI["ImageKit API"]:::api
        end

        subgraph Actions["Actions"]
            AdActions["Ad Actions"]:::action
        end

        RootLayout["Root Layout"]:::layout
        AuthConfig["Auth Configuration"]:::config
        AdModel["Ad Model"]:::model
    end

    subgraph External["External Services"]
        direction TB
        Auth["Authentication"]
        ImageKit["ImageKit"]
        DB[(Database)]
    end

    %% Relationships
    Client --> Server
    Server --> External
    APIRoutes --> DB
    ServerActions --> DB
    MediaComps --> ImageKit
    FormComps --> ServerActions
    
    %% Styles
    classDef page fill:#2196F3,color:white
    classDef component fill:#42A5F5,color:white
    classDef api fill:#4CAF50,color:white
    classDef action fill:#8BC34A,color:white
    classDef layout fill:#9C27B0,color:white
    classDef config fill:#FF9800,color:white
    classDef model fill:#F44336,color:white

    %% Click Events
    click Home "https://github.com/dejwid/marketplace/blob/master/src/app/page.tsx"
    click AdDetail "https://github.com/dejwid/marketplace/blob/master/src/app/ad/[id]/page.tsx"
    click NewAd "https://github.com/dejwid/marketplace/blob/master/src/app/new/page.tsx"
    click EditAd "https://github.com/dejwid/marketplace/blob/master/src/app/edit/[id]/page.tsx"
    click MyAds "https://github.com/dejwid/marketplace/blob/master/src/app/my-ads/page.tsx"
    click AuthAPI "https://github.com/dejwid/marketplace/blob/master/src/app/api/auth/[...nextauth]/route.ts"
    click AdsAPI "https://github.com/dejwid/marketplace/blob/master/src/app/api/ads/route.ts"
    click ImageKitAPI "https://github.com/dejwid/marketplace/blob/master/src/app/api/imagekit/auth/route.ts"
    click AdForm "https://github.com/dejwid/marketplace/blob/master/src/components/AdForm.tsx"
    click SearchForm "https://github.com/dejwid/marketplace/blob/master/src/components/SearchForm.tsx"
    click Gallery "https://github.com/dejwid/marketplace/blob/master/src/components/Gallery.tsx"
    click Uploader "https://github.com/dejwid/marketplace/blob/master/src/components/Uploader.tsx"
    click UploadArea "https://github.com/dejwid/marketplace/blob/master/src/components/UploadArea.tsx"
    click UploadThumb "https://github.com/dejwid/marketplace/blob/master/src/components/UploadThumbnail.tsx"
    click LocMap "https://github.com/dejwid/marketplace/blob/master/src/components/LocationMap.tsx"
    click LocPicker "https://github.com/dejwid/marketplace/blob/master/src/components/LocationPicker.tsx"
    click DistPicker "https://github.com/dejwid/marketplace/blob/master/src/components/DistancePicker.tsx"
    click Header "https://github.com/dejwid/marketplace/blob/master/src/components/Header.tsx"
    click SubmitBtn "https://github.com/dejwid/marketplace/blob/master/src/components/SubmitButton.tsx"
    click AdItem "https://github.com/dejwid/marketplace/blob/master/src/components/AdItem.tsx"
    click AdModel "https://github.com/dejwid/marketplace/blob/master/src/models/Ad.ts"
    click AdActions "https://github.com/dejwid/marketplace/blob/master/src/app/actions/adActions.ts"
    click AuthConfig "https://github.com/dejwid/marketplace/blob/master/src/libs/authOptions.ts"
    click RootLayout "https://github.com/dejwid/marketplace/blob/master/src/app/layout.tsx"
```
