# dbrizov/naughtyattributes architecture

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

- Interactive diagram: https://gitdiagram.com/dbrizov/naughtyattributes
- Repository: https://github.com/dbrizov/naughtyattributes

## Overview

##### Project Type and Purpose
- This is a Unity Editor/Runtime extension (plugin) called “NaughtyAttributes” that augments Unity’s built-in Inspector with custom attributes, property drawers, validation, and meta-attributes.
- It is distributed as a Unity Package (via OpenUPM, Git URL, Asset Store) and includes runtime code (Core), editor-only code (Editor), sample scenes, and automated tests.

##### Main Components
a. Unity Host
- Unity Editor – the IDE hosting the Inspector UI and Editor APIs
- Unity Runtime – the engine runtime that executes MonoBehaviours, serializes/deserializes fields
b. NaughtyAttributes Assemblies
- Core Assembly (NaughtyAttributes.Core.asmdef)
– Defines attribute classes (DrawerAttributes, MetaAttributes, ValidatorAttributes), utilities, and interfaces (INaughtyAttribute).
– Runs both in Editor & Play mode to mark up MonoBehaviour fields.
- Editor Assembly (NaughtyAttributes.Editor.asmdef)
– Contains CustomPropertyDrawer implementations, decorator drawers, property validators, and the NaughtyInspector class hooking into UnityEditor.
– Only compiles in the Editor.
- Test Assembly (NaughtyAttributes.Test.asmdef)
– Unit/integration tests for attributes and drawers, run via Unity Test Runner in CI.
c. Samples Directory
- DemoScene & TestAssets under `Assets/NaughtyAttributes/Samples` to showcase each attribute in action.
d. Packaging & CI
- package.json (Asset manifest for UPM)
- GitHub Actions (ci.yml) orchestrates Unity Test Runner, linting, packaging validations.

##### Relationships and Interactions
- At design time, Core attribute classes are applied to user MonoBehaviour/scriptable-object fields.
- When the Inspector renders, UnityEditor invokes the Editor Assembly’s CustomPropertyDrawers, which use reflection to read attribute metadata from the Core classes.
- Drawer logic formats the UI (dropdowns, sliders, buttons, etc.), optionally invoking callbacks or validations defined in Core.
- ValidatorAttributes provide runtime/check-in-Inspector feedback, clamping or error-highlighting fields.
- CI pipeline checks that all tests in the Test Assembly pass, ensuring attribute/drawer consistency across Unity versions.

##### Architectural Patterns and Principles
- Separation of Concerns:
- Core defines “what” each attribute means (metadata).
- Editor defines “how” each attribute is drawn/validated (presentation).
- Attribute-Driven Design: Behavior injected via metadata and reflection rather than manual editor code per class.
- Assembly Definition Files (.asmdef): Enforce clear module boundaries and faster compilation.
- Public Package Distribution: package.json enables OpenUPM/Git/Asset Store integration.

##### Essential Elements
- Call out package.json and .github/workflows for distribution and CI.
- Samples as demonstration assets, not part of core execution.

## Diagram (Mermaid)

```mermaid
graph TB
    %% Unity Host
    subgraph "Unity Host"
        UE["Unity Editor"]:::editor
        UR["Unity Runtime"]:::runtime
    end

    %% NaughtyAttributes Assemblies
    subgraph "NaughtyAttributes Assemblies"
        Core["Core Assembly\n(NaughtyAttributes.Core)"]:::runtime
        EditorAsm["Editor Assembly\n(NaughtyAttributes.Editor)"]:::editor
        TestAsm["Test Assembly\n(NaughtyAttributes.Test)"]:::samples
    end

    %% Samples
    Samples["Samples Directory\n(Assets/NaughtyAttributes/Samples)"]:::samples

    %% External & CI
    subgraph "External & CI"
        Registry["External Registry\n(Git/OpenUPM/Asset Store)"]:::external
        CI["CI Pipeline\n(.github/workflows/ci.yml)"]:::external
        PackageLock["Packages Lock\n(Packages/manifest.json\nPackages/packages-lock.json)"]:::external
    end

    %% Package Manifest
    PackageJSON["UPM Manifest\n(Assets/NaughtyAttributes/package.json)"]:::external

    %% Relationships
    UR -->|"Serializes/Deserializes fields"| Core
    UE -->|"Invokes CustomPropertyDrawer.Draw\nvia UnityEditor API"| EditorAsm
    Core -->|"Metadata via Reflection"| EditorAsm
    EditorAsm -->|"Draws UI in Inspector"| UE
    CI -->|"Runs Unity Test Runner on"| TestAsm
    TestAsm -->|"Validates Core & Editor Assemblies"| Core
    TestAsm -->|"Validates Core & Editor Assemblies"| EditorAsm
    Registry -->|"Installs via UPM"| PackageJSON
    PackageJSON -->|"Defines Core & Editor Assemblies"| Core
    PackageJSON -->|"Defines Core & Editor Assemblies"| EditorAsm
    PackageLock -->|"Locks package versions"| Core
    PackageLock -->|"Locks package versions"| EditorAsm
    Samples -->|"Demonstrates attributes in"| UE

    %% Click Events
    click Core "https://github.com/dbrizov/naughtyattributes/blob/master/Assets/NaughtyAttributes/Scripts/Core/NaughtyAttributes.Core.asmdef"
    click Core "https://github.com/dbrizov/naughtyattributes/tree/master/Assets/NaughtyAttributes/Scripts/Core"
    click EditorAsm "https://github.com/dbrizov/naughtyattributes/blob/master/Assets/NaughtyAttributes/Scripts/Editor/NaughtyAttributes.Editor.asmdef"
    click EditorAsm "https://github.com/dbrizov/naughtyattributes/tree/master/Assets/NaughtyAttributes/Scripts/Editor"
    click TestAsm "https://github.com/dbrizov/naughtyattributes/blob/master/Assets/NaughtyAttributes/Scripts/Test/NaughtyAttributes.Test.asmdef"
    click TestAsm "https://github.com/dbrizov/naughtyattributes/tree/master/Assets/NaughtyAttributes/Scripts/Test"
    click Samples "https://github.com/dbrizov/naughtyattributes/tree/master/Assets/NaughtyAttributes/Samples"
    click PackageJSON "https://github.com/dbrizov/naughtyattributes/blob/master/Assets/NaughtyAttributes/package.json"
    click CI "https://github.com/dbrizov/naughtyattributes/blob/master/.github/workflows/ci.yml"
    click PackageLock "https://github.com/dbrizov/naughtyattributes/blob/master/Packages/manifest.json"
    click PackageLock "https://github.com/dbrizov/naughtyattributes/blob/master/Packages/packages-lock.json"

    %% Styles
    classDef runtime fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef editor fill:#98FB98,stroke:#333,stroke-width:1px
    classDef external fill:#D3D3D3,stroke:#333,stroke-width:1px
    classDef samples fill:#FFFFE0,stroke:#333,stroke-width:1px
```
