# ash-project/ash architecture

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

## Overview

##### Main Components

a. Core Framework Components:
- Resource Layer
- Attributes
- Relationships
- Actions (Create/Read/Update/Destroy)
- Calculations
- Validations
- Changes
- Domain Layer
- Data Layer
- Authorization Layer
- Notifier System
- Reactor System

b. Extension Points:
- Data Layer Implementations (ETS, Mnesia)
- Authentication Systems
- API Interfaces
- Notifiers

**┌─────────────────────────────────────────────┐**
- Client Applications            │
- ┘
- ↓
**┌─────────────────────────────────────────────┐**
- Extension Layer                │
- JSON:API  - GraphQL  - Phoenix  - Auth   │
- ┘
- ↓
**┌─────────────────────────────────────────────┐**
- Core Engine                  │
- ┌─────────────┐  ┌──────────┐ ┌──────────┐ │
- Resource   │  │  Domain  │ │ Reactor  │ │
- ┘  └──────────┘ └──────────┘ │
- ┌─────────────┐  ┌──────────┐ ┌──────────┐ │
- Policy    │  │ Notifier │ │  Action  │ │
- ┘  └──────────┘ └──────────┘ │
- ┘
- ↓
**┌─────────────────────────────────────────────┐**
- Data Layer                     │
- ETS  - Mnesia  - Postgres  - SQLite    │
- ┘

##### Key Relationships

- Resource to Data Layer connections
- Authorization flow through policies
- Action processing pipeline
- Extension point interfaces
- Notifier system event flow
- Reactor system workflow

##### Important Details

a. Resource Layer Details:
- Attribute management
- Relationship handling
- Action processing
- Validation pipeline

b. Security Components:
- Policy enforcement
- Authorization checks
- Actor system

c. Data Layer Interface:
- Data storage abstractions
- Query handling
- Transaction management

##### Implementation Notes

- Version information and compatibility notes

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Client["Client Applications"]
        API[API Consumers]
        WebApp[Web Applications]
        Mobile[Mobile Apps]
    end

    subgraph Extensions["Extension Layer"]
        JSONAPI["JSON:API"]
        GraphQL["GraphQL"]
        Phoenix["Phoenix"]
        Auth["Authentication"]
    end

    subgraph Core["Core Engine"]
        Resource["Resource Layer"]:::core
        Domain["Domain Layer"]:::core
        Reactor["Reactor System"]:::core
        Policy["Policy Layer"]:::core
        Notifier["Notifier System"]:::core
        Action["Action System"]:::core

        subgraph ResourceComponents["Resource Components"]
            Attributes["Attributes"]:::resource
            Relationships["Relationships"]:::resource
            Actions["Actions"]:::resource
            Calculations["Calculations"]:::resource
            Validations["Validations"]:::resource
            Changes["Changes"]:::resource
        end
    end

    subgraph DataLayer["Data Layer"]
        ETS["ETS Store"]:::data
        Mnesia["Mnesia"]:::data
        Postgres["Postgres"]:::data
        SQLite["SQLite"]:::data
    end

    %% Connections
    Client --> Extensions
    Extensions --> Core
    Core --> DataLayer

    %% Resource Layer Connections
    Resource --> ResourceComponents
    Resource --> Domain
    Domain --> DataLayer
    Policy --> Resource
    Notifier --> Resource
    Reactor --> Resource
    Action --> Resource

    %% Click Events
    click Resource "https://github.com/ash-project/ash/tree/main/lib/ash/resource/"
    click Domain "https://github.com/ash-project/ash/tree/main/lib/ash/domain/"
    click Reactor "https://github.com/ash-project/ash/tree/main/lib/ash/reactor/"
    click Policy "https://github.com/ash-project/ash/tree/main/lib/ash/policy/"
    click Notifier "https://github.com/ash-project/ash/tree/main/lib/ash/notifier/"
    click Attributes "https://github.com/ash-project/ash/blob/main/lib/ash/resource/attribute.ex"
    click Relationships "https://github.com/ash-project/ash/tree/main/lib/ash/resource/relationships/"
    click Actions "https://github.com/ash-project/ash/tree/main/lib/ash/resource/actions/"
    click Calculations "https://github.com/ash-project/ash/tree/main/lib/ash/resource/calculation/"
    click Validations "https://github.com/ash-project/ash/tree/main/lib/ash/resource/validation/"
    click Changes "https://github.com/ash-project/ash/tree/main/lib/ash/resource/change/"
    click ETS "https://github.com/ash-project/ash/tree/main/lib/ash/data_layer/ets/"
    click Mnesia "https://github.com/ash-project/ash/tree/main/lib/ash/data_layer/mnesia/"

    %% Styling
    classDef core fill:#2374ab,stroke:#000,stroke-width:2px,color:#fff
    classDef resource fill:#48a9a6,stroke:#000,stroke-width:1px,color:#fff
    classDef data fill:#d4af37,stroke:#000,stroke-width:1px,color:#fff
    
    %% Legend
    subgraph Legend
        CoreComp["Core Component"]:::core
        ResourceComp["Resource Component"]:::resource
        DataComp["Data Store"]:::data
    end
```
