# muranyigyorgy/laravel-nayra architecture

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

- Interactive diagram: https://gitdiagram.com/muranyigyorgy/laravel-nayra
- Repository: https://github.com/muranyigyorgy/laravel-nayra

## Overview

##### Main Components
- Laravel Application Layer – This is the host application that will use the package. It includes web routes, controllers (or route closures), and blade templates for process interaction.
- Nayra BPMN Engine – The core engine implementation located in the src/Nayra directory. This includes the Engine, JobManager, CallActivity, FormalExpression, and ScriptTask components.
- Facade – The Nayra facade defined in src/Facades/Nayra, which provides a clean interface for starting processes, completing tasks, etc.
- Job Layer – Located in src/Jobs, there are timer-related and script-related jobs (CycleTimerJob, ScriptTaskJob, TimerJob) that facilitate asynchronous BPMN process handling via Laravel’s queue.
- Repositories – Implementations (in src/Repositories) of data access components including InstanceRepository, RequestRepository, and TokenRepository. Additionally, a Contract interface (in src/Contracts) defines the expected behavior.
- Models & Database – The Request model in src/Models along with the migrations in the database directory (e.g., create_requests_table.php) are responsible for persistent storage.

##### Relationships and Interactions
- The Laravel application (via defined web routes) invokes the Nayra facade.
- The facade routes the calls to the underlying BPMN engine (the Nayra classes and JobManager) to start, manage, and complete BPMN processes.
- When a process is started or a task is completed, the engine interacts with the Repositories to read/write process state to the database.
- The Job layer enqueues background processing tasks (like timer or script tasks) to the Laravel queue service.
- The BPMN process file (example.bpmn) acts as an external configuration that defines process flows, which the engine parses and executes.

##### Architectural Patterns and Design Principles
- Separation of Concerns – Splitting between the engine, data repositories, job processing, and Laravel integration.
- Facade Pattern – The Nayra facade abstracts away internal complexity, offering simple methods such as startProcess and completeTask.
- Dependency Injection – The ServiceProvider (src/Providers/PackageServiceProvider.php) likely binds implementations (Repositories, Engine, etc.) into the Laravel container.
- Asynchronous Processing – Use of Laravel’s queue system (handled by TimerJob, ScriptTaskJob, etc.) for process handling in the background.

##### Relevant Technologies, Frameworks, and Libraries
- Laravel framework (including its routing, service container, and queue features)
- Composer for package management (as indicated by composer.json)
- BPMN processing principles, with custom implementations in the package’s “Nayra” namespace.

- Laravel Web Routes/Controllers (the UI layer)
- Nayra Facade (a mediator between the web layer and engine)
- BPMN Engine (including core classes like Engine, JobManager)
- Job Processing Unit (depicting timer and script jobs)
- Data Access Layer (Repositories and Models)
- Database (which stores the process states via migrations)
- External BPMN File (e.g., the BPMN definition file)
- From the Web layer to the Facade (initiating actions such as starting a process)
- From the Facade to the Engine (executing process logic)
- From the Engine to the Job Processing Unit (enqueueing background jobs)
- From the Engine to the Repositories (interaction with the database storage)
- Control logic (e.g., engine and facade)
- Supporting infrastructure (e.g., jobs and repositories)
- External dependencies (e.g., the BPMN file and Laravel framework)
- Provide annotations where necessary to highlight:
- The dependency injection process (through the ServiceProvider)
- The asynchronous nature of jobs in the background queue service
- How the engine interprets BPMN definitions to manage process flows

- Every component is clearly labeled with its function.
- Double-check that each major layer (web, engine, data, jobs) is personal to this package’s integration within a Laravel project.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Laravel Application Layer
    subgraph "Laravel Application Layer"
        A1["Web Routes & Controllers"]:::laravel
        A2["Service Provider"]:::laravel
    end

    %% Facade Layer
    subgraph "Facade Layer"
        B1["Nayra Facade"]:::facade
    end

    %% BPMN Engine
    subgraph "BPMN Engine"
        C1["Nayra BPMN Engine"]:::engine
    end

    %% Job Processing Unit
    subgraph "Job Processing Unit"
        D1["Job Layer"]:::jobs
    end

    %% Data Access Layer
    subgraph "Data Access Layer"
        E2["Contracts"]:::data
        E1["Repositories"]:::data
        E3["Request Model"]:::data
        E4["Database"]:::data
    end

    %% External Configuration
    subgraph "External Configuration"
        F1["BPMN Process File"]:::external
    end

    %% Relationships
    A1 -->|"calls"| B1
    A2 -->|"injectsDependencies"| C1
    A2 -->|"bindsRepositories"| E1
    B1 -->|"routesCallTo"| C1
    C1 -->|"enqueueJob"| D1
    C1 -->|"updatesStateVia"| E1
    E1 -->|"persistsTo"| E4
    E2 -->|"implementedBy"| E1
    C1 -->|"parses"| F1

    %% Click Events
    click A2 "https://github.com/muranyigyorgy/laravel-nayra/blob/master/src/Providers/PackageServiceProvider.php"
    click C1 "https://github.com/muranyigyorgy/laravel-nayra/tree/master/src/Nayra"
    click B1 "https://github.com/muranyigyorgy/laravel-nayra/blob/master/src/Facades/Nayra.php"
    click D1 "https://github.com/muranyigyorgy/laravel-nayra/tree/master/src/Jobs"
    click E2 "https://github.com/muranyigyorgy/laravel-nayra/blob/master/src/Contracts/RequestRepositoryInterface.php"
    click E1 "https://github.com/muranyigyorgy/laravel-nayra/tree/master/src/Repositories"
    click E3 "https://github.com/muranyigyorgy/laravel-nayra/blob/master/src/Models/Request.php"
    click E4 "https://github.com/muranyigyorgy/laravel-nayra/blob/master/database/migrations/2019_06_01_000000_create_requests_table.php"
    click F1 "https://github.com/muranyigyorgy/laravel-nayra/blob/master/bpmn/example.bpmn"

    %% Styles
    classDef laravel fill:#FFDDCC,stroke:#333,stroke-width:2px;
    classDef facade fill:#CCFFCC,stroke:#333,stroke-width:2px;
    classDef engine fill:#DDEEFF,stroke:#333,stroke-width:2px;
    classDef jobs fill:#FFEEDD,stroke:#333,stroke-width:2px;
    classDef data fill:#EEFFDD,stroke:#333,stroke-width:2px;
    classDef external fill:#EEEEEE,stroke:#333,stroke-width:2px;
```
