# codemyst/pastemyst architecture

> Architecture diagram of the GitHub repository codemyst/pastemyst, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-14). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/codemyst/pastemyst
- Repository: https://github.com/codemyst/pastemyst

## Overview

##### Project type and purpose
- This is a full-stack web application (“Pastemyst”), written in the D language, that provides a beautiful, multi-file pastebin with user accounts, encryption, history, tagging, and a REST API.
- It also ships a first-party CLI tool (“pastry-cli”) that interacts with the same REST API.

##### File structure
- Root contains Dockerfile, docker-compose, Makefile, config templates, Dub (DUB) manifest, submodules, CI workflows.
- “views/” contains server-side Diet templates (.dt) for dynamic HTML rendering (pages, components, API docs).
- “source/” implements the backend in D, organized into:
- pastemyst/web → HTTP routes & page controllers
- pastemyst/rest → REST API endpoints (v1)
- pastemyst/auth → OAuth services (GitHub, GitLab, sessions)
- pastemyst/paste, data, db → business logic and data‐access layer for pastes, users, zips, avatars
- util, conv, encoding, time → supporting utilities (ID gen, diffs, encoding, expirations)
- “data/” holds JSON reference data (languages, expiration options).
- “lib/” vendored native libraries (scrypt for Windows, linguist metadata).
- Configuration and environment defined via config-example.yml, environment variables, Docker.

##### README for additional insights
- Uses MongoDB as the primary datastore (two databases: production/test).
- Depends on libssl, libscrypt, diff & patch for history.
- Built/run via `dmd` + `dub run`, or with Docker Compose.
- OAuth integrations with GitHub and GitLab.
- Emphasizes a simple REST API (v1) plus full web interface.

##### Detail is key
- Docker container boundary, showing that everything from the HTTP server down to MongoDB client runs inside the container, while MongoDB itself may be external or in another container.
- Configuration inputs (config.yaml) feeding into the server at startup.

## Diagram (Mermaid)

```mermaid
graph TD
  subgraph "Clients"
    Browser["Web Browser"]:::frontend
    CLI["pastry-cli (CLI)"]:::frontend
  end

  subgraph "Docker Container"
    direction TB
    subgraph "HTTP Server (Vibe.d)"
      Static["Static Asset Server"]:::backend
      Router["HTTP Router & Controllers"]:::backend
      Template["Template Engine (Diet)"]:::backend
      API["REST API Layer (v1)"]:::backend
    end

    subgraph "Business Logic Services"
      PasteSvc["Paste Service"]:::backend
      UserSvc["User Service"]:::backend
      AuthSvc["Auth Service"]:::backend
      EncryptSvc["Encryption Service"]:::backend
      HistSvc["History & Diff Service"]:::backend
      UtilSvc["Utilities & ID Generation"]:::backend
    end

    subgraph "Data Access Layer"
      DBLayer["MongoDB Abstractions"]:::data
      JSONLoader["JSON Reference Loader"]:::data
    end

    Config["Infrastructure & Config"]:::infra
  end

  subgraph "External Services"
    GitHub["GitHub OAuth"]:::external
    GitLab["GitLab OAuth"]:::external
    MongoDB["MongoDB"]:::data
  end

  Browser -->|"GET assets"| Static
  Static -->|"HTML/CSS/JS"| Browser
  Browser -->|"XHR/Fetch"| API
  CLI -->|"HTTPS API"| API

  Router -->|"routes UI pages"| Template
  Router -->|"routes API requests"| API

  API -->|"calls"| PasteSvc
  API -->|"calls"| UserSvc
  API -->|"calls"| AuthSvc
  API -->|"calls"| EncryptSvc
  API -->|"calls"| HistSvc
  API -->|"calls"| UtilSvc

  PasteSvc -->|"queries"| DBLayer
  UserSvc -->|"queries"| DBLayer
  AuthSvc -->|"queries"| DBLayer
  EncryptSvc -->|"uses"| UtilSvc
  HistSvc -->|"uses"| UtilSvc
  UtilSvc -->|"loads ref data"| JSONLoader
  JSONLoader -->|"loaded at startup"| Config

  DBLayer -->|"reads/writes"| MongoDB
  AuthSvc -->|"OAuth handshake"| GitHub
  AuthSvc -->|"OAuth handshake"| GitLab
  Config -->|"env + YAML"| HTTP

  click Static "https://github.com/codemyst/pastemyst/tree/main/public/"
  click Template "https://github.com/codemyst/pastemyst/tree/main/views/"
  click Router "https://github.com/codemyst/pastemyst/tree/main/source/pastemyst/web/"
  click API "https://github.com/codemyst/pastemyst/tree/main/source/pastemyst/rest/"
  click AuthSvc "https://github.com/codemyst/pastemyst/tree/main/source/pastemyst/auth/"
  click PasteSvc "https://github.com/codemyst/pastemyst/tree/main/source/pastemyst/paste/"
  click UserSvc "https://github.com/codemyst/pastemyst/blob/main/source/pastemyst/data/user.d"
  click EncryptSvc "https://github.com/codemyst/pastemyst/blob/main/scrypt.d"
  click EncryptSvc "https://github.com/codemyst/pastemyst/blob/main/lib/windows/scrypt.lib"
  click HistSvc "https://github.com/codemyst/pastemyst/blob/main/source/pastemyst/util/diff.d"
  click UtilSvc "https://github.com/codemyst/pastemyst/tree/main/source/pastemyst/util/"
  click UtilSvc "https://github.com/codemyst/pastemyst/tree/main/source/pastemyst/encoding/"
  click DBLayer "https://github.com/codemyst/pastemyst/tree/main/source/pastemyst/db/"
  click JSONLoader "https://github.com/codemyst/pastemyst/blob/main/data/languages.json"
  click JSONLoader "https://github.com/codemyst/pastemyst/blob/main/data/expireOptions.json"
  click Config "https://github.com/codemyst/pastemyst/blob/main/config-example.yml"
  click CLI "https://github.com/codemyst/pastemyst/blob/main/pastry.md"

  classDef frontend fill:#D0E8FF,stroke:#0366D6,color:#0366D6
  classDef backend fill:#E6FFEA,stroke:#28A745,color:#22863A
  classDef data fill:#FFF5B1,stroke:#DBAB09,color:#735C0F
  classDef external fill:#FBEFF1,stroke:#D73A49,color:#CB2431
  classDef infra fill:#F0F0F0,stroke:#6A737D,color:#24292E
```
