# samcbdev/mailnotifier architecture

> Architecture diagram of the GitHub repository samcbdev/mailnotifier, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-12). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/samcbdev/mailnotifier
- Repository: https://github.com/samcbdev/mailnotifier

## Overview

#### Purpose and Integration

`mailnotifier` is a Laravel package for storing email templates in the database, substituting `{{placeholder}}` values, and sending the resulting email. It is consumed by a host Laravel application through Composer and package discovery/service registration.

Primary package entry points:
- `src/NotifyMailServiceProvider.php`
- `src/Notifymail.php`
- `src/Facades/NotifyMailFacade.php`

#### Package Bootstrapping

`NotifyMailServiceProvider` is the Laravel integration boundary. It registers package services and exposes publishable configuration and migration assets for the host application. The host publishes these assets, runs its migration process, and supplies mail configuration through Laravel’s normal environment/configuration.

Relevant paths:
- `src/NotifyMailServiceProvider.php`
- `src/config/notifymail.php`
- `src/database/migrations/create_email_notifications_table.php`

#### Template Persistence

Email notification templates are persisted in a configurable database table created by the package migration. A template is identified by a unique template ID and contains at least subject/content intended for dynamic replacement.

The model is the persistence-facing component; table naming and related defaults are controlled by package configuration.

Relevant paths:
- `src/Models/NotifyMail.php`
- `src/database/migrations/create_email_notifications_table.php`
- `src/config/notifymail.php`

#### Public Mail Generation API

`Notifymail` is the main application-facing service API, surfaced through `NotifyMailFacade`. Callers provide a template identifier plus ordered replacement arrays for template content and subject. The service retrieves the stored template, identifies replacement fields, and generates a mail-details payload.

Key operations described by the package API:
- inspect available dynamic fields;
- generate substituted subject/content records;
- send a generated mail payload.

Relevant paths:
- `src/Notifymail.php`
- `src/Facades/NotifyMailFacade.php`
- `src/Models/NotifyMail.php`

#### Dynamic Template Processing

Templates use `{{key}}` markers. The generation layer parses these markers and replaces them using caller-provided values. Replacement arrays are position-sensitive: callers must provide values for every discovered variable and in the same order as the field inspection result.

This is a significant boundary: template structure comes from the database, while replacement values and delivery metadata come from the host application.

Relevant paths:
- `src/Notifymail.php`
- `src/Models/NotifyMail.php`

#### Delivery Pipeline

After generation, the host application enriches the returned details with recipient, sender, optional comma-separated CC/BCC recipients, and optional attachment data. The package dispatches delivery through Laravel’s mail system, represented by a Mailable and potentially an asynchronous job/controller path.

Relevant paths:
- `src/Mail/NotifyMail.php`
- `src/Jobs/NotifyMailJob.php`
- `src/Http/Controllers/NotifyMailController.php`

#### Rendering, Runtime, and External Boundaries

The package runs inside PHP/Laravel and depends on Laravel’s database, migration, Blade view rendering, mail transport, and optionally queue infrastructure. Email body rendering is handled through a Blade template, while actual SMTP/API delivery is delegated to the host application’s configured Laravel mail driver.

Relevant paths:
- `src/resources/views/temp.blade.php`
- `src/Mail/NotifyMail.php`
- `src/Jobs/NotifyMailJob.php`

Main entry points: [`src/Notifymail.php`](https://github.com/samcbdev/mailnotifier/blob/main/src/Notifymail.php) (Notifymail), [`src/Mail/NotifyMail.php`](https://github.com/samcbdev/mailnotifier/blob/main/src/Mail/NotifyMail.php) (NotifyMail mailable), [`src/Jobs/NotifyMailJob.php`](https://github.com/samcbdev/mailnotifier/blob/main/src/Jobs/NotifyMailJob.php) (NotifyMailJob), [`src/Models/NotifyMail.php`](https://github.com/samcbdev/mailnotifier/blob/main/src/Models/NotifyMail.php) (NotifyMail model)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_host["Host Laravel App"]
  node_host_callers["Application callers<br/>host code"]
  node_host_assets["Published assets<br/>config and migration"]
end

subgraph group_package["mailnotifier Package"]
  node_provider["NotifyMailServiceProvider<br/>service provider"]
  node_facade["NotifyMailFacade<br/>Laravel facade"]
  node_service["Notifymail<br/>template service<br/>[Notifymail.php]"]
  node_model["NotifyMail model<br/>Eloquent model<br/>[NotifyMail.php]"]
  node_package_config["notifymail config<br/>package config<br/>[notifymail.php]"]
  node_migration["Template table migration"]
  node_mail_controller["NotifyMailController<br/>delivery controller"]
  node_mail_job["NotifyMailJob<br/>queue job<br/>[NotifyMailJob.php]"]
  node_mailable["NotifyMail mailable<br/>Laravel mailable<br/>[NotifyMail.php]"]
  node_blade_view["Email body view<br/>Blade template<br/>[temp.blade.php]"]
end

subgraph group_runtime["Laravel Runtime"]
  node_template_db[("Email templates<br/>database table")]
  node_laravel_container{{"Laravel container<br/>framework container"}}
  node_queue["Queue infrastructure<br/>Laravel queue"]
  node_mail_transport["Mail driver / SMTP API<br/>external delivery"]
end

node_host_callers -->|"uses API"| node_facade
node_facade -->|"resolves"| node_service
node_provider -->|"registers services"| node_laravel_container
node_provider -->|"publishes"| node_host_assets
node_host_assets -.->|"runs copy of"| node_migration
node_migration -->|"creates"| node_template_db
node_package_config -->|"configures table"| node_model
node_service -->|"loads template by ID"| node_model
node_model -->|"queries"| node_template_db
node_host_callers -->|"replacement values and metadata"| node_service
node_service -->|"generated mail details"| node_mailable
node_mail_controller -->|"optional send path"| node_service
node_mail_controller -.->|"may dispatch"| node_mail_job
node_mail_job -->|"executes on"| node_queue
node_mail_job -->|"creates"| node_mailable
node_mailable -->|"renders body"| node_blade_view
node_mailable -->|"sends through"| node_mail_transport

click node_provider "https://github.com/samcbdev/mailnotifier/blob/main/src/NotifyMailServiceProvider.php"
click node_facade "https://github.com/samcbdev/mailnotifier/blob/main/src/Facades/NotifyMailFacade.php"
click node_service "https://github.com/samcbdev/mailnotifier/blob/main/src/Notifymail.php"
click node_model "https://github.com/samcbdev/mailnotifier/blob/main/src/Models/NotifyMail.php"
click node_package_config "https://github.com/samcbdev/mailnotifier/blob/main/src/config/notifymail.php"
click node_migration "https://github.com/samcbdev/mailnotifier/blob/main/src/database/migrations/create_email_notifications_table.php"
click node_mail_controller "https://github.com/samcbdev/mailnotifier/blob/main/src/Http/Controllers/NotifyMailController.php"
click node_mail_job "https://github.com/samcbdev/mailnotifier/blob/main/src/Jobs/NotifyMailJob.php"
click node_mailable "https://github.com/samcbdev/mailnotifier/blob/main/src/Mail/NotifyMail.php"
click node_blade_view "https://github.com/samcbdev/mailnotifier/blob/main/src/resources/views/temp.blade.php"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_host_callers,node_host_assets toneBlue
class node_provider,node_facade,node_service,node_model,node_package_config,node_migration,node_mail_controller,node_mail_job,node_mailable,node_blade_view toneAmber
class node_template_db,node_laravel_container,node_queue,node_mail_transport toneMint
```

## Components

### Host Laravel App

Consumes the package and supplies delivery data.

- **Application callers**: host code · Provide template IDs, replacements, and delivery metadata.
- **Published assets**: config and migration · Configuration and migration are published into the host application.

### mailnotifier Package

- [NotifyMailServiceProvider](https://github.com/samcbdev/mailnotifier/blob/main/src/NotifyMailServiceProvider.php): service provider · Registers package services and publishable assets. · `src/NotifyMailServiceProvider.php`
- [NotifyMailFacade](https://github.com/samcbdev/mailnotifier/blob/main/src/Facades/NotifyMailFacade.php): Laravel facade · Public static-style API surface. · `src/Facades/NotifyMailFacade.php`
- [Notifymail](https://github.com/samcbdev/mailnotifier/blob/main/src/Notifymail.php): template service · Inspects fields, generates payloads, and initiates sending. · `src/Notifymail.php`
- [NotifyMail model](https://github.com/samcbdev/mailnotifier/blob/main/src/Models/NotifyMail.php): Eloquent model · Reads stored notification templates. · `src/Models/NotifyMail.php`
- [notifymail config](https://github.com/samcbdev/mailnotifier/blob/main/src/config/notifymail.php): package config · Controls table naming and defaults. · `src/config/notifymail.php`
- [Template table migration](https://github.com/samcbdev/mailnotifier/blob/main/src/database/migrations/create_email_notifications_table.php): migration · Creates persistent email notification templates. · `src/database/migrations/create_email_notifications_table.php`
- [NotifyMailController](https://github.com/samcbdev/mailnotifier/blob/main/src/Http/Controllers/NotifyMailController.php): delivery controller · Optional HTTP-oriented delivery path. · `src/Http/Controllers/NotifyMailController.php`
- [NotifyMailJob](https://github.com/samcbdev/mailnotifier/blob/main/src/Jobs/NotifyMailJob.php): queue job · Optional asynchronous delivery path. · `src/Jobs/NotifyMailJob.php`
- [NotifyMail mailable](https://github.com/samcbdev/mailnotifier/blob/main/src/Mail/NotifyMail.php): Laravel mailable · Builds the outgoing message from generated details. · `src/Mail/NotifyMail.php`
- [Email body view](https://github.com/samcbdev/mailnotifier/blob/main/src/resources/views/temp.blade.php): Blade template · Renders the generated email body. · `src/resources/views/temp.blade.php`

### Laravel Runtime

Host-configured framework services and infrastructure.

- **Email templates**: database table · Stores template IDs, subjects, and bodies containing markers.
- **Laravel container**: framework container
- **Queue infrastructure**: Laravel queue · Runs queued mail jobs when enabled.
- **Mail driver / SMTP API**: external delivery · Configured by the host Laravel application.

## Connections

- Application callers → NotifyMailFacade: uses API
- NotifyMailFacade → Notifymail: resolves
- NotifyMailServiceProvider → Laravel container: registers services
- NotifyMailServiceProvider → Published assets: publishes
- Published assets → Template table migration: runs copy of
- Template table migration → Email templates: creates
- notifymail config → NotifyMail model: configures table
- Notifymail → NotifyMail model: loads template by ID
- NotifyMail model → Email templates: queries
- Application callers → Notifymail: replacement values and metadata
- Notifymail → NotifyMail mailable: generated mail details
- NotifyMailController → Notifymail: optional send path
- NotifyMailController → NotifyMailJob: may dispatch
- NotifyMailJob → Queue infrastructure: executes on
- NotifyMailJob → NotifyMail mailable: creates
- NotifyMail mailable → Email body view: renders body
- NotifyMail mailable → Mail driver / SMTP API: sends through
