# pastemyst/pastemyst-v3 architecture

> Architecture diagram of the GitHub repository pastemyst/pastemyst-v3, 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/pastemyst/pastemyst-v3
- Repository: https://github.com/pastemyst/pastemyst-v3

## Overview

##### Project type and purpose
- This is a full-stack, open-source paste-sharing platform (“Pastemyst v3”), consisting of:
- A SvelteKit client (rich web UI, SSR/SPA)
- An ASP.NET Core Web API (REST endpoints, background jobs, OAuth)
- A MongoDB database
- A small CLI/documentation service and migrator
- Docker Compose orchestration

##### File structure
- Top-level directories:
- api/ – C# ASP.NET Core project (PasteMyst.Web), plus a Migrator project and unit tests
- client/ – SvelteKit application with components, routes, services, assets
- docs/ – Docusaurus-based documentation site
- compose.yml – Docker Compose definition tying together api, client, db, guesslang, etc.
- api/PasteMyst.Web:
- Controllers (HTTP endpoints), Middleware, Models (DTOs), Services (business logic, data access), Jobs (scheduled cleanup), Extensions, Utils
- Program.cs / Startup pipeline
- client/src:
- Routes (+page, +layout for SSR), lib/ (reusable components, API wrappers), static assets, configuration
- CI/CD: .github/workflows for build, test, doc deploy

##### README for additional insights
- API: ASP.NET Core, MongoDB, JWT, OAuth (GitHub/GitLab), Guesslang-bun for language autodetect
- Client: Node/NPM, env variables, dev server
- Docker: Entire stack launch via docker-compose

##### Main components and interactions
a. Frontend (SvelteKit client)
b. Backend API (ASP.NET Core)
c. Database (MongoDB)
d. External services:
- OAuth providers (GitHub, GitLab)
- guesslang-bun executable (language detection)
e. Supporting processes:
- Background jobs (expiration of pastes/tokens)
- Migrator (one-off DB migration utility)
- Documentation site (Docs)

##### Relationships and data flows
- Client → API: HTTP(S) REST calls to endpoints (PasteController, AuthController, etc.)
- API → MongoDB: CRUD operations via MongoService
- API → OAuth providers: OAuth code flow for login
- API → guesslang-bun: spawn process for language detection
- Jobs (ExpirePastesJob, ExpireAccessTokensJob) run within API container
- Migrator: CLI tool run manually or in CI, reads API config, writes to DB
- Docker Compose wires client, api, MongoDB, guesslang, optionally migrator

##### Architectural patterns & design principles
- Layered architecture in API: Controllers → Services → Data Access
- Middleware pipeline: Exception handling, encryption, user context
- Dependency injection for services/providers
- SvelteKit file-based routing & SSR
- Containerization & 12-factor app (env-based config, secrets via user-secrets or .env)

##### Technologies and frameworks
- Frontend: SvelteKit, Vite, TypeScript
- Backend: .NET 7+ (ASP.NET Core), C#, JWT, MongoDB
- CI/CD: GitHub Actions
- Containerization: Docker, Docker Compose
- Docs: Docusaurus

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Frontend Layer"
        SK["SvelteKit Client"]:::frontend
    end

    subgraph "Backend Layer"
        API["ASP.NET Core API"]:::backend
        subgraph "Controllers"
            Ctrl["Controllers"]:::backend
        end
        subgraph "Services"
            Serv["Services Layer"]:::backend
            OAuthSvc["OAuthService"]:::backend
            OAuthCfg["OAuthProviderConfig"]:::backend
        end
        subgraph "Models"
            Models["Data Models"]:::backend
        end
        subgraph "Middleware"
            MW["Middleware Pipeline"]:::backend
        end
        subgraph "Background Jobs"
            Job1["ExpirePastesJob"]:::job
            Job2["ExpireAccessTokensJob"]:::job
            Job3["ExpireSessionSettingsJob"]:::job
        end
        Migrator["Migrator CLI"]:::backend
    end

    DB[(MongoDB)]:::database

    cloudOAuth["OAuth Providers (GitHub/GitLab)"]:::external
    Guess["guesslang-bun"]:::external
    Docs["Documentation Site"]:::external
    Compose["Docker Compose"]:::util

    SK -->|"HTTPS JSON"| Ctrl
    Ctrl -->|"calls"| Serv
    Serv -->|"CRUD JSON"| DB
    Serv -->|"OAuth flow"| cloudOAuth
    Serv -->|"spawn process"| Guess
    OAuthSvc --> OAuthCfg
    API --> MW
    MW --> Serv
    Job1 --> DB
    Job2 --> DB
    Job3 --> DB
    Migrator --> DB
    Compose --> SK
    Compose --> API
    Compose --> DB
    Compose --> Guess
    Compose --> Migrator

    click SK "https://github.com/pastemyst/pastemyst-v3/tree/main/client/"
    click API "https://github.com/pastemyst/pastemyst-v3/tree/main/api/PasteMyst.Web/"
    click DB "https://github.com/pastemyst/pastemyst-v3/blob/main/compose.yml"
    click OAuthSvc "https://github.com/pastemyst/pastemyst-v3/blob/main/api/PasteMyst.Web/Services/OAuthService.cs"
    click OAuthCfg "https://github.com/pastemyst/pastemyst-v3/blob/main/api/PasteMyst.Web/Models/Auth/OAuthProviderConfig.cs"
    click Guess "https://github.com/pastemyst/pastemyst-v3/blob/main/compose.yml"
    click Job1 "https://github.com/pastemyst/pastemyst-v3/blob/main/api/PasteMyst.Web/Jobs/ExpirePastesJob.cs"
    click Job2 "https://github.com/pastemyst/pastemyst-v3/blob/main/api/PasteMyst.Web/Jobs/ExpireAccessTokensJob.cs"
    click Job3 "https://github.com/pastemyst/pastemyst-v3/blob/main/api/PasteMyst.Web/Jobs/ExpireSessionSettingsJob.cs"
    click Migrator "https://github.com/pastemyst/pastemyst-v3/blob/main/api/PasteMyst.Migrator/Program.cs"
    click Docs "https://github.com/pastemyst/pastemyst-v3/tree/main/docs/"
    click Compose "https://github.com/pastemyst/pastemyst-v3/blob/main/compose.yml"

    classDef frontend fill:#ADD8E6,stroke:#000;
    classDef backend fill:#90EE90,stroke:#000;
    classDef database fill:#FFE4B5,stroke:#000;
    classDef external fill:#F0E68C,stroke:#000;
    classDef job fill:#FFD700,stroke:#000;
    classDef util fill:#D3D3D3,stroke:#000;
```
