# bufferhead-code/nightowl architecture

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

- Interactive diagram: https://gitdiagram.com/bufferhead-code/nightowl
- Repository: https://github.com/bufferhead-code/nightowl

## Overview

##### Project Type Analysis
This is a frontend-focused JavaScript/TypeScript library that provides a simple dark mode implementation using CSS filters. The project is relatively small but serves a specific purpose.

##### Main Components

A. Core Components:
- Nightowl Library Core (main.ts)
- Counter Module (counter.ts)
- Configuration Handler

B. Integration Methods:
- CDN Distribution
- NPM Package

C. External Interfaces:
- User's Website DOM
- System Dark Mode Preferences
- User Preferences Storage

**[Top Layer - Integration Points]**

- CDN Integration
- nightowl.js (bundled)

- NPM Integration
- @bufferhead/nightowl package

**[Middle Layer - Core Framework]**

- Configuration Handler
- defaultMode setting
- toggleButtonMode setting

- Main Module (main.ts)
- createNightowl function
- DOM manipulation logic
- CSS filter application

- Counter Module (counter.ts)
- State management

**[Bottom Layer - Integration Points]**

- Browser APIs
- DOM Interface
- LocalStorage (preferences)
- System Dark Mode Detection

- User's Website
- DOM Elements

##### Important Flows to Highlight

a. Initialization Flow:
- NPM/CDN → createNightowl() → Configuration → DOM Manipulation

b. Runtime Flow:
- User Interaction → Toggle Button → State Change → CSS Filter Application

##### Technical Details

- Build process (Vite)
- TypeScript compilation flow
- Distribution packaging
- CSS filter application mechanism

##### The preference persistence mechanism

This will give other developers a clear understanding of how the library works internally while also showing how simple it is to integrate.

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Integration
        CDN["CDN Integration"]
        NPM["NPM Package"]:::npm
    end

    subgraph Core["Core Framework"]
        direction TB
        Main["Main Module"]:::main
        Counter["Counter Module"]:::counter
        Config["Configuration Handler"]
        
        subgraph ConfigOptions["Configuration Options"]
            DefaultMode["Default Mode Setting"]
            ToggleMode["Toggle Button Mode"]
        end
        
        Main --> Counter
        Config --> Main
        ConfigOptions --> Config
    end

    subgraph Build["Build System"]
        direction TB
        Vite["Vite Build"]:::vite
        TSConfig["TypeScript Config"]:::tsconfig
        PostCSS["PostCSS Config"]:::postcss
        NPMConfig["Package Config"]:::package
    end

    subgraph Browser["Browser Environment"]
        DOM["DOM Interface"]
        Storage["LocalStorage"]
        SystemPref["System Dark Mode"]
    end

    Integration --> Core
    Core --> Browser
    Build --> Integration

    subgraph CI["CI/CD Pipeline"]
        Format["Format Check"]:::format
        Lint["Lint Check"]:::lint
        Publish["Publish Process"]:::publish
    end

    CI --> Build

    %% Click Events
    click Main "https://github.com/bufferhead-code/nightowl/blob/main/src/main.ts"
    click Counter "https://github.com/bufferhead-code/nightowl/blob/main/src/counter.ts"
    click TSConfig "https://github.com/bufferhead-code/nightowl/blob/main/tsconfig.json"
    click Vite "https://github.com/bufferhead-code/nightowl/blob/main/vite.config.js"
    click NPMConfig "https://github.com/bufferhead-code/nightowl/blob/main/package.json"
    click Format "https://github.com/bufferhead-code/nightowl/blob/main/.github/workflows/format.yml"
    click Lint "https://github.com/bufferhead-code/nightowl/blob/main/.github/workflows/lint.yml"
    click Publish "https://github.com/bufferhead-code/nightowl/blob/main/.github/workflows/publish.yml"
    click PostCSS "https://github.com/bufferhead-code/nightowl/blob/main/postcss.config.js"

    %% Styling
    classDef main fill:#a8d5ff
    classDef counter fill:#a8d5ff
    classDef npm fill:#c2e0c6
    classDef format fill:#d4c5f9
    classDef lint fill:#d4c5f9
    classDef publish fill:#d4c5f9
    classDef vite fill:#fff5b1
    classDef tsconfig fill:#fff5b1
    classDef postcss fill:#fff5b1
    classDef package fill:#fff5b1

    %% Legend
    subgraph Legend
        L1["Core Components"]:::main
        L2["Integration Points"]:::npm
        L3["Build Configuration"]:::vite
        L4["CI/CD Components"]:::format
    end
```
