# mbaharip/next-gdrive-index architecture

> Architecture diagram of the GitHub repository mbaharip/next-gdrive-index, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-07-25). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/mbaharip/next-gdrive-index
- Repository: https://github.com/mbaharip/next-gdrive-index

## Overview

##### Project type and purpose
- This is a full-stack, monolithic Next.js 13 application (App Router) whose purpose is to provide a Google Drive directory index with file preview, download proxy, simple ACL (password protection), and an embedded configurator UI.

##### File structure
- Top-level: next.config.js, tsconfig.json, package.json, .env example, config files, public assets
- src/app: page.tsx, layout, loading/error handlers, nested routes, and app/api directory containing all serverless API endpoints
- src/actions: “server actions” modules (configuration.ts, files.ts, token.ts, etc.) that encapsulate calls to Google Drive
- src/components: React components grouped by concern (explorer UI, preview UI, layout, global, UI primitives, internal configurator pages)
- src/lib: utility functions and helpers (configurationHelper, previewHelper)
- Configuration: .env or downloaded .env with service-account credentials, encryption key parameters

##### README insights
- Uses Google Drive REST API under the hood
- Runs entirely in Next.js environment (SSR + serverless functions)
- Features: folder listing, file preview (image, video, audio, document, code, manga), direct download proxy, raw links, thumbnail generation, OG image generation

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Layer
    Browser["Browser / Client"]:::frontend

    %% Next.js Application Boundary
    subgraph "Next.js Application"
        direction TB

        subgraph "UI Layer"
            direction TB
            SSR["SSR Pages & Server Components"]:::frontend
            CLIENT["Client Components & Hooks"]:::frontend
        end

        subgraph "Server Layer"
            direction TB
            ACTIONS["Data Access & Business Logic"]:::action
            CONFIG["Configuration & Encryption Module"]:::config
        end

        subgraph "Serverless API Endpoints"
            direction TB
            API_DOWNLOAD["/api/download/[...rest]"]:::api
            API_RAW["/api/raw/[...rest]"]:::api
            API_THUMB["/api/thumb/[encryptedId]"]:::api
            API_PREVIEW["/api/preview/[encryptedId]"]:::api
            subgraph "Internal Endpoints"
                direction TB
                API_CHECK["/api/internal/check"]:::api
                API_ENCRYPT["/api/internal/encrypt"]:::api
            end
            API_OG["/api/og/[encryptedId]"]:::api
        end
    end

    %% External Service
    Google["Google Drive API"]:::external

    %% Connections: Browser to UI and APIs
    Browser -->|renders SSR pages| SSR
    Browser -->|hydrates React| CLIENT
    Browser -->|requests download| API_DOWNLOAD
    Browser -->|requests raw file| API_RAW
    Browser -->|requests thumbnail| API_THUMB
    Browser -->|requests preview| API_PREVIEW
    Browser -->|checks ACL| API_CHECK
    Browser -->|encrypts ID| API_ENCRYPT
    Browser -->|generates OG image| API_OG

    %% UI and API to Business Logic
    SSR -->|calls actions| ACTIONS
    API_DOWNLOAD -->|calls actions| ACTIONS
    API_RAW -->|calls actions| ACTIONS
    API_THUMB -->|calls actions| ACTIONS
    API_PREVIEW -->|calls actions| ACTIONS
    API_CHECK -->|calls actions| ACTIONS
    API_ENCRYPT -->|calls actions| ACTIONS
    API_OG -->|calls actions| ACTIONS

    %% All server-side to config
    SSR -->|uses config| CONFIG
    ACTIONS -->|uses config| CONFIG
    API_DOWNLOAD -->|uses config| CONFIG
    API_RAW -->|uses config| CONFIG
    API_THUMB -->|uses config| CONFIG
    API_PREVIEW -->|uses config| CONFIG
    API_CHECK -->|uses config| CONFIG
    API_ENCRYPT -->|uses config| CONFIG
    API_OG -->|uses config| CONFIG

    %% Business Logic to external
    ACTIONS -->|REST calls| Google
    API_DOWNLOAD -->|REST calls| Google
    API_RAW -->|REST calls| Google
    API_THUMB -->|REST calls| Google
    API_PREVIEW -->|REST calls| Google
    API_CHECK -->|REST calls| Google
    API_ENCRYPT -->|REST calls| Google
    API_OG -->|REST calls| Google

    %% Click events
    click SSR "https://github.com/mbaharip/next-gdrive-index/blob/main/src/app/[...rest]/page.tsx"
    click CLIENT "https://github.com/mbaharip/next-gdrive-index/tree/main/src/components"
    click API_DOWNLOAD "https://github.com/mbaharip/next-gdrive-index/blob/main/src/app/api/download/[...rest]/route.ts"
    click API_RAW "https://github.com/mbaharip/next-gdrive-index/blob/main/src/app/api/raw/[...rest]/route.ts"
    click API_THUMB "https://github.com/mbaharip/next-gdrive-index/blob/main/src/app/api/thumb/[encryptedId]/route.ts"
    click API_PREVIEW "https://github.com/mbaharip/next-gdrive-index/blob/main/src/app/api/preview/[encryptedId]/route.ts"
    click API_CHECK "https://github.com/mbaharip/next-gdrive-index/blob/main/src/app/api/internal/check/route.ts"
    click API_ENCRYPT "https://github.com/mbaharip/next-gdrive-index/blob/main/src/app/api/internal/encrypt/route.ts"
    click API_OG "https://github.com/mbaharip/next-gdrive-index/blob/main/src/app/api/og/[encryptedId]/route.ts"
    click CONFIG "https://github.com/mbaharip/next-gdrive-index/blob/main/src/lib/configurationHelper.ts"
    click ACTIONS "https://github.com/mbaharip/next-gdrive-index/blob/main/src/actions/configuration.ts"

    %% Styles
    classDef frontend fill:#E8F0FE,stroke:#4376E8
    classDef server fill:#E6EEFE,stroke:#2345A1
    classDef api fill:#FEF3E8,stroke:#E67A00
    classDef action fill:#E8FEEC,stroke:#39A044
    classDef config fill:#F3E8FE,stroke:#8E39A0
    classDef external fill:#E8F8FE,stroke:#1AAFC1
```
