# marseventh/cloudflare-imgbed architecture

> Architecture diagram of the GitHub repository marseventh/cloudflare-imgbed, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-25). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/marseventh/cloudflare-imgbed
- Repository: https://github.com/marseventh/cloudflare-imgbed

## Overview

CloudFlare ImgBed is a self-hosted file-hosting and management hub. Users upload files through the upload API, which applies configuration, authentication and content review, then records file metadata; they can retrieve and manage files through file, REST-style management and WebDAV interfaces. Supporting capabilities include sessions, directory and tag organization, random-image selection, and multiple storage backends. The graph follows the documented product scope and sampled calls; some route and provider wiring was not sampled, so uncertain links are omitted.

Main entry points: [`functions/upload/index.js`](https://github.com/marseventh/cloudflare-imgbed/blob/main/functions/upload/index.js) (Upload API), [`functions/random/index.js`](https://github.com/marseventh/cloudflare-imgbed/blob/main/functions/random/index.js) (Random images), [`functions/utils/databaseAdapter.js`](https://github.com/marseventh/cloudflare-imgbed/blob/main/functions/utils/databaseAdapter.js) (Database adapter), [`functions/api/manage`](https://github.com/marseventh/cloudflare-imgbed/tree/main/functions/api/manage) (Management API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_access["Access and API"]
  node_login["Authentication API<br/>[login.js]"]
  node_sessions["Session manager<br/>[sessionManager.js]"]
  node_dav["WebDAV interface<br/>[&#91;&#91;path&#93;&#93;.js]"]
  node_publiclist["Public gallery<br/>[list.js]"]
end

subgraph group_files["File workflows"]
  node_upload["Upload API<br/>[index.js]"]
  node_uploadtools["Upload tools<br/>[uploadTools.js]"]
  node_chunkupload["Chunk upload<br/>[chunkUpload.js]"]
  node_filedelivery["File delivery<br/>[&#91;&#91;path&#93;&#93;.js]"]
  node_imaging["Image transforms<br/>[imageTransform.js]"]
  node_random["Random images<br/>[index.js]"]
  node_adaptive["Adaptive selection<br/>[adaptive.js]"]
end

subgraph group_management["Management"]
  node_manageapi["Management API"]
  node_moderation["Content moderation<br/>[uploadTools.js]"]
  node_index["File index<br/>[indexManager.js]"]
  node_tags["Tags and metadata<br/>[tagHelpers.js]"]
  node_configuration["System configuration<br/>[sysConfig.js]"]
end

subgraph group_platform["Persistence and storage"]
  node_adapter["Database adapter<br/>[databaseAdapter.js]"]
  node_d1[("D1 database<br/>[d1Database.js]")]
  node_server["Local server runtime<br/>[index.js]"]
  node_localr2[("Local R2 adapter<br/>[r2Storage.js]")]
  node_telegram["Telegram storage<br/>[telegramAPI.js]"]
  node_discord["Discord storage<br/>[discordAPI.js]"]
  node_huggingface["Hugging Face storage<br/>[huggingfaceAPI.js]"]
  node_webdavstorage["WebDAV storage<br/>[webdavAPI.js]"]
end

node_visitor(("Visitor / client"))
node_admin(("Administrator"))
node_r2service[("Cloudflare R2")]
node_externalstores["External storage services"]

node_visitor -->|"uploads files"| node_upload
node_upload -->|"loads settings"| node_configuration
node_upload -->|"prepares and reviews"| node_uploadtools
node_upload -->|"dispatches large files"| node_chunkupload
node_visitor -->|"requests files"| node_filedelivery
node_filedelivery -->|"transforms images"| node_imaging
node_visitor -->|"requests random image"| node_random
node_random -->|"reads options"| node_configuration
node_random -->|"reads file records"| node_index
node_random -->|"selects by device"| node_adaptive
node_visitor -->|"signs in"| node_login
node_login -->|"manages session"| node_sessions
node_admin -->|"manages files and settings"| node_manageapi
node_manageapi -->|"uses file index"| node_index
node_manageapi -->|"manages tags"| node_tags
node_visitor -->|"browses files"| node_publiclist
node_visitor -->|"uses WebDAV"| node_dav
node_upload -->|"records metadata"| node_adapter
node_index -->|"stores index chunks"| node_adapter
node_sessions -->|"stores sessions"| node_adapter
node_adapter -->|"adapts D1"| node_d1
node_server -->|"initializes local storage"| node_localr2
node_upload -.->|"uploads to"| node_telegram
node_upload -.->|"uploads to"| node_discord
node_upload -.->|"uploads to"| node_huggingface
node_upload -.->|"uploads to"| node_webdavstorage
node_telegram -.->|"transfers files"| node_externalstores
node_discord -.->|"transfers files"| node_externalstores
node_huggingface -.->|"transfers files"| node_externalstores
node_webdavstorage -.->|"transfers files"| node_externalstores

click node_upload "https://github.com/marseventh/cloudflare-imgbed/blob/main/functions/upload/index.js"
click node_uploadtools "https://github.com/marseventh/cloudflare-imgbed/blob/main/functions/upload/uploadTools.js"
click node_chunkupload "https://github.com/marseventh/cloudflare-imgbed/blob/main/functions/upload/chunkUpload.js"
click node_filedelivery "https://github.com/marseventh/cloudflare-imgbed/blob/main/functions/file/%5B%5Bpath%5D%5D.js"
click node_imaging "https://github.com/marseventh/cloudflare-imgbed/blob/main/functions/file/imageTransform.js"
click node_random "https://github.com/marseventh/cloudflare-imgbed/blob/main/functions/random/index.js"
click node_adaptive "https://github.com/marseventh/cloudflare-imgbed/blob/main/functions/random/adaptive.js"
click node_login "https://github.com/marseventh/cloudflare-imgbed/blob/main/functions/api/auth/login.js"
click node_sessions "https://github.com/marseventh/cloudflare-imgbed/blob/main/functions/utils/auth/sessionManager.js"
click node_manageapi "https://github.com/marseventh/cloudflare-imgbed/tree/main/functions/api/manage"
click node_dav "https://github.com/marseventh/cloudflare-imgbed/blob/main/functions/dav/%5B%5Bpath%5D%5D.js"
click node_publiclist "https://github.com/marseventh/cloudflare-imgbed/blob/main/functions/api/public/list.js"
click node_moderation "https://github.com/marseventh/cloudflare-imgbed/blob/main/functions/upload/uploadTools.js"
click node_index "https://github.com/marseventh/cloudflare-imgbed/blob/main/functions/utils/indexManager.js"
click node_tags "https://github.com/marseventh/cloudflare-imgbed/blob/main/functions/utils/tagHelpers.js"
click node_configuration "https://github.com/marseventh/cloudflare-imgbed/blob/main/functions/utils/sysConfig.js"
click node_adapter "https://github.com/marseventh/cloudflare-imgbed/blob/main/functions/utils/databaseAdapter.js"
click node_d1 "https://github.com/marseventh/cloudflare-imgbed/blob/main/functions/utils/d1Database.js"
click node_server "https://github.com/marseventh/cloudflare-imgbed/blob/main/deploy/server/index.js"
click node_localr2 "https://github.com/marseventh/cloudflare-imgbed/blob/main/deploy/server/r2Storage.js"
click node_telegram "https://github.com/marseventh/cloudflare-imgbed/blob/main/functions/utils/storage/telegramAPI.js"
click node_discord "https://github.com/marseventh/cloudflare-imgbed/blob/main/functions/utils/storage/discordAPI.js"
click node_huggingface "https://github.com/marseventh/cloudflare-imgbed/blob/main/functions/utils/storage/huggingfaceAPI.js"
click node_webdavstorage "https://github.com/marseventh/cloudflare-imgbed/blob/main/functions/utils/storage/webdavAPI.js"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_login,node_sessions,node_dav,node_publiclist,node_visitor toneBlue
class node_upload,node_uploadtools,node_chunkupload,node_filedelivery,node_imaging,node_random,node_adaptive,node_r2service,node_externalstores toneAmber
class node_manageapi,node_moderation,node_index,node_tags,node_configuration toneMint
class node_adapter,node_d1,node_server,node_localr2,node_telegram,node_discord,node_huggingface,node_webdavstorage toneRose
class node_admin toneIndigo
```

## Components

### Access and API

- [Authentication API](https://github.com/marseventh/cloudflare-imgbed/blob/main/functions/api/auth/login.js): `functions/api/auth/login.js`
- [Session manager](https://github.com/marseventh/cloudflare-imgbed/blob/main/functions/utils/auth/sessionManager.js): `functions/utils/auth/sessionManager.js`
- [WebDAV interface](https://github.com/marseventh/cloudflare-imgbed/blob/main/functions/dav/%5B%5Bpath%5D%5D.js): `functions/dav/[[path]].js`
- [Public gallery](https://github.com/marseventh/cloudflare-imgbed/blob/main/functions/api/public/list.js): `functions/api/public/list.js`

### File workflows

- [Upload API](https://github.com/marseventh/cloudflare-imgbed/blob/main/functions/upload/index.js): `functions/upload/index.js`
- [Upload tools](https://github.com/marseventh/cloudflare-imgbed/blob/main/functions/upload/uploadTools.js): `functions/upload/uploadTools.js`
- [Chunk upload](https://github.com/marseventh/cloudflare-imgbed/blob/main/functions/upload/chunkUpload.js): `functions/upload/chunkUpload.js`
- [File delivery](https://github.com/marseventh/cloudflare-imgbed/blob/main/functions/file/%5B%5Bpath%5D%5D.js): `functions/file/[[path]].js`
- [Image transforms](https://github.com/marseventh/cloudflare-imgbed/blob/main/functions/file/imageTransform.js): `functions/file/imageTransform.js`
- [Random images](https://github.com/marseventh/cloudflare-imgbed/blob/main/functions/random/index.js): `functions/random/index.js`
- [Adaptive selection](https://github.com/marseventh/cloudflare-imgbed/blob/main/functions/random/adaptive.js): `functions/random/adaptive.js`

### Management

- [Management API](https://github.com/marseventh/cloudflare-imgbed/tree/main/functions/api/manage): `functions/api/manage`
- [Content moderation](https://github.com/marseventh/cloudflare-imgbed/blob/main/functions/upload/uploadTools.js): `functions/upload/uploadTools.js`
- [File index](https://github.com/marseventh/cloudflare-imgbed/blob/main/functions/utils/indexManager.js): `functions/utils/indexManager.js`
- [Tags and metadata](https://github.com/marseventh/cloudflare-imgbed/blob/main/functions/utils/tagHelpers.js): `functions/utils/tagHelpers.js`
- [System configuration](https://github.com/marseventh/cloudflare-imgbed/blob/main/functions/utils/sysConfig.js): `functions/utils/sysConfig.js`

### Persistence and storage

- [Database adapter](https://github.com/marseventh/cloudflare-imgbed/blob/main/functions/utils/databaseAdapter.js): `functions/utils/databaseAdapter.js`
- [D1 database](https://github.com/marseventh/cloudflare-imgbed/blob/main/functions/utils/d1Database.js): `functions/utils/d1Database.js`
- [Local server runtime](https://github.com/marseventh/cloudflare-imgbed/blob/main/deploy/server/index.js): `deploy/server/index.js`
- [Local R2 adapter](https://github.com/marseventh/cloudflare-imgbed/blob/main/deploy/server/r2Storage.js): `deploy/server/r2Storage.js`
- [Telegram storage](https://github.com/marseventh/cloudflare-imgbed/blob/main/functions/utils/storage/telegramAPI.js): `functions/utils/storage/telegramAPI.js`
- [Discord storage](https://github.com/marseventh/cloudflare-imgbed/blob/main/functions/utils/storage/discordAPI.js): `functions/utils/storage/discordAPI.js`
- [Hugging Face storage](https://github.com/marseventh/cloudflare-imgbed/blob/main/functions/utils/storage/huggingfaceAPI.js): `functions/utils/storage/huggingfaceAPI.js`
- [WebDAV storage](https://github.com/marseventh/cloudflare-imgbed/blob/main/functions/utils/storage/webdavAPI.js): `functions/utils/storage/webdavAPI.js`

### Other components

- **Visitor / client**
- **Administrator**
- **Cloudflare R2**
- **External storage services**

## Connections

- Visitor / client → Upload API: uploads files
- Upload API → System configuration: loads settings
- Upload API → Upload tools: prepares and reviews
- Upload API → Chunk upload: dispatches large files
- Visitor / client → File delivery: requests files
- File delivery → Image transforms: transforms images
- Visitor / client → Random images: requests random image
- Random images → System configuration: reads options
- Random images → File index: reads file records
- Random images → Adaptive selection: selects by device
- Visitor / client → Authentication API: signs in
- Authentication API → Session manager: manages session
- Administrator → Management API: manages files and settings
- Management API → File index: uses file index
- Management API → Tags and metadata: manages tags
- Visitor / client → Public gallery: browses files
- Visitor / client → WebDAV interface: uses WebDAV
- Upload API → Database adapter: records metadata
- File index → Database adapter: stores index chunks
- Session manager → Database adapter: stores sessions
- Database adapter → D1 database: adapts D1
- Local server runtime → Local R2 adapter: initializes local storage
- Upload API → Telegram storage: uploads to
- Upload API → Discord storage: uploads to
- Upload API → Hugging Face storage: uploads to
- Upload API → WebDAV storage: uploads to
- Telegram storage → External storage services: transfers files
- Discord storage → External storage services: transfers files
- Hugging Face storage → External storage services: transfers files
- WebDAV storage → External storage services: transfers files
