# d7omdev/gallery architecture

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

- Interactive diagram: https://gitdiagram.com/d7omdev/gallery
- Repository: https://github.com/d7omdev/gallery

## Overview

##### Main System Components

a) Client Layer:
- Next.js Frontend (src/app directory)
- UI Components (src/components)
- Analytics Provider
- Authentication Layer (Clerk)

b) API Layer:
- Next.js API Routes (src/app/api)
- Upload Handling (UploadThing integration)
- Rate Limiting Service

c) Database Layer:
- Database Schema (src/server/db)
- Query Layer (src/server/queries.ts)

d) External Services:
- Clerk Authentication
- UploadThing
- Sentry Error Tracking

##### Component Relationships

a) Frontend to Backend:
- API routes connections for:
- Album management (/api/albums)
- Image handling (/api/image)
- Upload functionality (/api/uploadthing)

b) Data Flow:
- User authentication flow through Clerk
- Image upload flow through UploadThing
- Database interactions for albums and images

##### Specific Implementation Details

Architectural patterns:

a) Next.js App Router Structure:
- Route hierarchy from src/app
- Dynamic routes ([albumId], [userId], [imageId])

b) Component Architecture:
- UI Components layer (src/components)
- Shared components and their relationships
- Integration with shadcn/ui

**┌─ Client Layer ─────────────────────┐**
- Next.js Pages                    │
- UI Components                    │
- Authentication Interface         │
- ┬─┘
- ↕                   │
**┌─ API Layer ──────────────────────┤**
- Album Management              │
- Image Processing             │
- Upload Handling              │
- ┬─┘
- ↕              │
**┌─ Service Layer ─────────────┤**
- Authentication          │
- Storage                │
- Error Tracking         │
- ┘

##### Important Notes

- App router architecture of Next.js 13+
- Clear separation between server and client components
- Real-time aspects of image management
- Error handling flow with Sentry
- Rate limiting implementation
- Demonstrate the album-image relationship in the database schema

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        Frontend["Next.js Frontend"]
        UIComponents["UI Components"]
        Analytics["Analytics Provider"]
        AuthUI["Authentication Interface"]
        
        subgraph CoreFeatures
            Albums["Album Management"]
            Gallery["Image Gallery"]
            Favorites["Favorites System"]
            Sharing["Sharing System"]
        end
        
        subgraph UIElements
            Nav["Navigation Components"]
            ImageComps["Image Components"]
            ActionBtns["Action Buttons"]
        end
    end
    
    subgraph APILayer
        AlbumAPI["Album Management API"]
        ImageAPI["Image Handling API"]
        UploadAPI["Upload Handling API"]
        RateLimit["Rate Limiting Service"]
    end
    
    subgraph Database
        Schema["Database Schema"]
        DBConfig["Database Configuration"]
        Queries["Query Layer"]
    end
    
    subgraph ExternalServices
        Clerk["Clerk Authentication"]
        UploadThing["UploadThing Storage"]
        Sentry["Sentry Error Tracking"]
    end
    
    %% Relationships
    Frontend --> APILayer
    UIComponents --> Frontend
    Analytics --> Frontend
    AuthUI --> Clerk
    
    APILayer --> Database
    APILayer --> ExternalServices
    
    %% Core Features Connections
    Albums --> AlbumAPI
    Gallery --> ImageAPI
    Favorites --> AlbumAPI
    Sharing --> AlbumAPI
    
    %% External Service Connections
    UploadAPI --> UploadThing
    APILayer --> Sentry
    
    %% Click Events
    click Frontend "https://github.com/d7omdev/gallery/tree/main/src/app"
    click UIComponents "https://github.com/d7omdev/gallery/tree/main/src/components"
    click Analytics "https://github.com/d7omdev/gallery/blob/main/src/app/_analytics/provider.tsx"
    click AlbumAPI "https://github.com/d7omdev/gallery/tree/main/src/app/api/albums"
    click ImageAPI "https://github.com/d7omdev/gallery/tree/main/src/app/api/image"
    click UploadAPI "https://github.com/d7omdev/gallery/tree/main/src/app/api/uploadthing"
    click RateLimit "https://github.com/d7omdev/gallery/blob/main/src/server/ratelimit.ts"
    click Schema "https://github.com/d7omdev/gallery/blob/main/src/server/db/schema.ts"
    click DBConfig "https://github.com/d7omdev/gallery/blob/main/src/server/db/index.ts"
    click Queries "https://github.com/d7omdev/gallery/blob/main/src/server/queries.ts"
    click Sentry "https://github.com/d7omdev/gallery/blob/main/sentry.client.config.ts"
    click UploadThing "https://github.com/d7omdev/gallery/blob/main/src/utils/uploadthing.ts"
    click Albums "https://github.com/d7omdev/gallery/tree/main/src/app/albums"
    click Gallery "https://github.com/d7omdev/gallery/blob/main/src/components/image-grid.tsx"
    click Favorites "https://github.com/d7omdev/gallery/tree/main/src/app/favorites"
    click Sharing "https://github.com/d7omdev/gallery/tree/main/src/app/share"
    click Nav "https://github.com/d7omdev/gallery/blob/main/src/components/sidenav.tsx"
    click ImageComps "https://github.com/d7omdev/gallery/blob/main/src/components/image.tsx"
    click ActionBtns "https://github.com/d7omdev/gallery/blob/main/src/components/create-album-button.tsx"
    
    classDef frontend fill:#a8d1ff,stroke:#333
    classDef api fill:#90EE90,stroke:#333
    classDef database fill:#DDA0DD,stroke:#333
    classDef external fill:#FFD700,stroke:#333
    
    class Frontend,UIComponents,Analytics,AuthUI,CoreFeatures,UIElements frontend
    class AlbumAPI,ImageAPI,UploadAPI,RateLimit api
    class Schema,DBConfig,Queries database
    class Clerk,UploadThing,Sentry external
    
    %% Legend
    subgraph Legend
        Frontend_L["Frontend Components"]:::frontend
        API_L["API Services"]:::api
        DB_L["Database Layer"]:::database
        Ext_L["External Services"]:::external
    end
```
