# mletrone/power-events architecture

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

## Overview

##### Project Type Identification
This is an open-source Python library focused on event routing and handling, similar in style to FastAPI but for event management. The project is a standalone library rather than a full-stack application.

##### Main Components

A. Core Components:
- EventResolver (Central Component)
- Condition System
- Value Handler
- Route Registry

B. Flow Components:
- Event Input
- Condition Evaluation Pipeline
- Handler Execution
- Result Collection

**Top Layer: Client Integration**

**Middle Layer: Core Components**

**Bottom Layer: Event Handling Infrastructure**

##### Specific Component Details

- It as the main orchestrator

b) Condition System (Left Side):
- Different condition types:
- Basic conditions (equals, one_of)
- Complex conditions (Value-based)
- Logical operators (AND, OR, NEG)

c) Route Registry (Right Side):
- Handler registration
- Route matching system
- Handler execution pipeline

##### Flow Representation

**Event Input → EventResolver**
**↓**
**Condition Evaluation**
**↓**
**Route Matching**
**↓**
**Handler Execution**
**↓**
**Result Collection**

##### Important Elements to Highlight

a) Decorator System:
- How @app.equal and @app.when connect to the core
- Condition registration flow

b) Condition Evaluation:
- Hierarchical nature of conditions
- How nested conditions are processed

c) Value Resolution:
- Demonstrate dot notation path resolution
- How deep object traversal works

##### Technical Details

- Python ≥3.9 compatibility
- Type hint system integration
- Error handling pathways
- Condition combination mechanisms

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Legend
        L1[Core Component]:::core
        L2[Condition System]:::condition
        L3[Route Component]:::route
        L4[Infrastructure]:::infra
        L5[Error Handling]:::error
        
        style Legend fill:#f5f5f5,stroke:#333
    end

    subgraph "Client Integration Layer"
        CI[Client Code]:::infra
        DEC["@app Decorators"]:::infra
    end

    subgraph "Core Layer"
        ER[EventResolver]:::core
        click ER "https://github.com/mletrone/power-events/blob/main/power_events/resolver.py"
        
        subgraph "Condition System"
            CS["Condition System"]:::condition
            click CS "https://github.com/mletrone/power-events/tree/main/power_events/conditions/"
            VH["Value Handler"]:::condition
            click VH "https://github.com/mletrone/power-events/blob/main/power_events/conditions/value.py"
            CL["Core Condition Logic"]:::condition
            click CL "https://github.com/mletrone/power-events/blob/main/power_events/conditions/condition.py"
        end

        subgraph "Route Registry"
            RR["Route Registry"]:::route
            HE["Handler Execution"]:::route
            RM["Route Matching"]:::route
        end
    end

    subgraph "Event Handling Infrastructure"
        EI["Event Input"]:::infra
        RC["Result Collection"]:::infra
        EH["Exception Handler"]:::error
        click EH "https://github.com/mletrone/power-events/blob/main/power_events/exceptions.py"
    end

    %% Flow Connections
    CI --> DEC
    DEC --> ER
    EI --> ER
    ER --> CS
    CS --> VH
    CS --> CL
    ER --> RR
    RR --> RM
    RM --> HE
    HE --> RC
    
    %% Error Handling Paths
    ER -.-> EH
    CS -.-> EH
    HE -.-> EH

    classDef core fill:#3498db,stroke:#2980b9,color:white
    classDef condition fill:#2ecc71,stroke:#27ae60,color:white
    classDef route fill:#e67e22,stroke:#d35400,color:white
    classDef infra fill:#95a5a6,stroke:#7f8c8d,color:white
    classDef error fill:#e74c3c,stroke:#c0392b,color:white
```
