# refact0r/midnight-discord architecture

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

- Interactive diagram: https://gitdiagram.com/refact0r/midnight-discord
- Repository: https://github.com/refact0r/midnight-discord

## Overview

##### Project type and purpose
- This is an open-source, static asset “theme generator” for Discord (a CSS-based dark theme).
- It provides:
- A modular CSS source (in `/src`)
- A Node.js build/dev pipeline (`scripts/dev.js`)
- Pre-built and archived themes (`build/`, `themes/`, `archive/`)

##### File structure
- Top level:
- `scripts/` – dev script for watching/combining CSS
- `build/` – the compiled production CSS (`midnight.css`)
- `themes/` – distributable `.theme.css` files (main + flavors)
- `archive/` – historical theme versions and flavor experiments
- `assets/` – images used in README previews
- `package.json` & `scripts/dev.js` – Node.js-based watcher & bundler
- `.env` support for local dev output paths
- Patterns:
- Modular CSS → concatenation/build step
- Single build pipeline controlled by Node.js/`npm run dev`
- Flavor override files layering on top of core theme

##### Key components
a. Source layer
- CSS modules (`/src/*.css`)
- Core theme file (`themes/midnight.theme.css`)
- Flavor files (`themes/flavors/*.theme.css`)
b. Build pipeline
- `scripts/dev.js` watcher
- Node.js (npm) environment
- `.env` for DEV_OUTPUT_PATH
c. Output artifacts
- `/build/midnight.css` (compiled)
- `/themes/*.theme.css` (packaged for distribution)
- Local dev output to Discord theme folders
d. Consumers / Distribution
- Discord clients (BetterDiscord, Vencord, any CSS-importing client)
- GitHub Pages (hosting `https://refact0r.github.io/midnight-discord/build/midnight.css`)
- End users dragging `.theme.css` into theme folders

##### Relationships & data flow
1. Developer edits `/src` or core theme file
2. `scripts/dev.js` (Node.js) watches filesystem → on change, it:
- Merges modules → produces `/build/midnight.css`
- Injects output into local client path (if `.env` set)
3. Build artifact is committed or served via GH Pages
4. End user installs by:
- Downloading `.theme.css` from `themes/` or GH Pages
- Importing into Discord client theme directory
5. Flavor files apply variable overrides at runtime

##### Architectural patterns & principles
- Modular design: break theme into discrete CSS concerns
- Single responsibility: dev script only handles I/O and concatenation
- Extensibility: flavors layer on top of core; archive for fallback
- Zero-runtime overhead beyond static CSS (no JS in client)

##### Technologies & frameworks
- Node.js & npm (dev environment)
- Chokidar or fs.watch (inside `scripts/dev.js`)
- CSS variables for theming
- GitHub Pages (static hosting)
- Discord client theme import feature

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Developer Tools Layer
    subgraph "Developer Tools"
        direction TB
        Editor["Editor"]:::dev
        subgraph "Source Layer"
            direction TB
            SRC["SRC CSS Modules"]:::storage
            CoreTheme["Core Theme File (themes/midnight.theme.css)"]:::storage
            Flavors["Flavor Override Files (themes/flavors/)"]:::storage
        end
        NodeEnv["Node.js Environment (package.json & package-lock.json)"]:::dev
        BuildScript["Watch & Build Script (scripts/dev.js)"]:::dev
    end

    %% Artifacts & Distribution
    subgraph "Artifacts & Distribution"
        direction TB
        BuildOutput["Build Output (/build/midnight.css)"]:::artifacts
        ThemesDist["Themes Folder (/themes/*.theme.css)"]:::artifacts
        Archive["Archive (archive/)"]:::artifacts
    end

    %% Hosting
    Cloud["GitHub Pages"]:::external

    %% Assets & Tests
    subgraph "Assets & Tests"
        direction TB
        Assets["Assets (assets/)"]:::artifacts
        Tests["Test CSS Files (test/)"]:::artifacts
        Docs["Themes README (themes/README.md)"]:::artifacts
    end

    %% End User Flow
    subgraph "End User Flow"
        direction TB
        User["End User"]:::client
        DiscordClient["Discord Client"]:::client
    end

    %% Relationships
    Editor --> SRC
    Editor --> CoreTheme
    Editor --> Flavors
    SRC & CoreTheme & Flavors --> BuildScript
    NodeEnv --> BuildScript

    BuildScript --> BuildOutput
    BuildScript --> ThemesDist

    BuildOutput --> Cloud
    ThemesDist --> Cloud

    BuildOutput --> Assets
    BuildOutput --> Tests
    BuildOutput --> Docs

    Cloud -->|Hosted for Download| User
    User -->|Download .theme.css| ThemesDist
    User -->|Import| DiscordClient
    DiscordClient -->|Applies| BuildOutput
    DiscordClient -->|Applies| ThemesDist

    %% Click Events
    click SRC "https://github.com/refact0r/midnight-discord/tree/master/src/"
    click CoreTheme "https://github.com/refact0r/midnight-discord/blob/master/themes/midnight.theme.css"
    click Flavors "https://github.com/refact0r/midnight-discord/tree/master/themes/flavors/"
    click BuildScript "https://github.com/refact0r/midnight-discord/blob/master/scripts/dev.js"
    click NodeEnv "https://github.com/refact0r/midnight-discord/blob/master/package.json"
    click NodeEnv "https://github.com/refact0r/midnight-discord/blob/master/package-lock.json"
    click BuildOutput "https://github.com/refact0r/midnight-discord/blob/master/build/midnight.css"
    click ThemesDist "https://github.com/refact0r/midnight-discord/blob/master/themes/midnight.theme.css"
    click ThemesDist "https://github.com/refact0r/midnight-discord/tree/master/themes/flavors/"
    click Archive "https://github.com/refact0r/midnight-discord/tree/master/archive/"
    click Assets "https://github.com/refact0r/midnight-discord/tree/master/assets/"
    click Tests "https://github.com/refact0r/midnight-discord/tree/master/test/"
    click Docs "https://github.com/refact0r/midnight-discord/blob/master/themes/README.md"

    %% Styles
    classDef dev fill:#ADD8E6,stroke:#333,stroke-width:1px;
    classDef artifacts fill:#90EE90,stroke:#333,stroke-width:1px;
    classDef client fill:#FFA500,stroke:#333,stroke-width:1px;
    classDef external fill:#DDDDDD,stroke:#333,stroke-width:1px;
    classDef storage fill:#E0FFFF,stroke:#333,stroke-width:1px;
```
