# beyondcode/laravel-comments architecture

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

- Interactive diagram: https://gitdiagram.com/beyondcode/laravel-comments
- Repository: https://github.com/beyondcode/laravel-comments

## Overview

This Laravel package adds polymorphic, nestable comments to Eloquent models. An application model using `HasComments` creates a comment, optionally on behalf of a user; the user’s `Commentator` policy determines its initial approval state. Comments can then be retrieved, filtered, approved, nested, or deleted, with add/delete events dispatched by the comment model. Laravel’s Eloquent database is the persistence layer, and the service provider exposes configuration and a migration for host applications. Relationships reflect the shown trait/model calls and documented capabilities; the migration’s schema was not sampled.

Main entry points: [`src/Comment.php`](https://github.com/beyondcode/laravel-comments/blob/master/src/Comment.php) (Comment model), [`src/Traits/HasComments.php`](https://github.com/beyondcode/laravel-comments/blob/master/src/Traits/HasComments.php) (Create and retrieve), [`database/migrations/create_comments_table.php.stub`](https://github.com/beyondcode/laravel-comments/blob/master/database/migrations/create_comments_table.php.stub) (Comments table), [`src/CommentsServiceProvider.php`](https://github.com/beyondcode/laravel-comments/blob/master/src/CommentsServiceProvider.php) (Service provider)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_comment_api["Comment API"]
  node_commentable_models["Commentable models<br/>[HasComments.php]"]
  node_comment_operations["Create and retrieve<br/>[HasComments.php]"]
  node_commentator_policy["Approval policy<br/>[Commentator.php]"]
end

subgraph group_comment_lifecycle["Comment lifecycle"]
  node_comment_model["Comment model<br/>[Comment.php]"]
  node_comment_storage[("Comments table")]
  node_added_event["Comment added event<br/>[CommentAdded.php]"]
  node_deleted_event["Comment deleted event<br/>[CommentDeleted.php]"]
end

subgraph group_laravel_setup["Laravel setup"]
  node_service_provider["Service provider"]
  node_package_config["Package configuration<br/>[config.php]"]
end

node_host_app(("Host application"))

node_host_app -->|"adds trait"| node_commentable_models
node_commentable_models -->|"exposes"| node_comment_operations
node_comment_operations -->|"checks approval"| node_commentator_policy
node_comment_operations -->|"creates and saves"| node_comment_model
node_comment_operations -.->|"persists via Eloquent"| node_comment_storage
node_comment_model -->|"supports nested replies"| node_comment_operations
node_comment_model -.->|"stores comment state"| node_comment_storage
node_comment_model -->|"dispatches on create"| node_added_event
node_comment_model -->|"dispatches on delete"| node_deleted_event
node_service_provider -->|"merges config"| node_package_config
node_service_provider -->|"publishes migration"| node_comment_storage

click node_commentable_models "https://github.com/beyondcode/laravel-comments/blob/master/src/Traits/HasComments.php"
click node_comment_operations "https://github.com/beyondcode/laravel-comments/blob/master/src/Traits/HasComments.php"
click node_commentator_policy "https://github.com/beyondcode/laravel-comments/blob/master/src/Contracts/Commentator.php"
click node_comment_model "https://github.com/beyondcode/laravel-comments/blob/master/src/Comment.php"
click node_comment_storage "https://github.com/beyondcode/laravel-comments/blob/master/database/migrations/create_comments_table.php.stub"
click node_added_event "https://github.com/beyondcode/laravel-comments/blob/master/src/Events/CommentAdded.php"
click node_deleted_event "https://github.com/beyondcode/laravel-comments/blob/master/src/Events/CommentDeleted.php"
click node_service_provider "https://github.com/beyondcode/laravel-comments/blob/master/src/CommentsServiceProvider.php"
click node_package_config "https://github.com/beyondcode/laravel-comments/blob/master/config/config.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_commentable_models,node_comment_operations,node_commentator_policy toneBlue
class node_comment_model,node_comment_storage,node_added_event,node_deleted_event toneAmber
class node_service_provider,node_package_config toneMint
class node_host_app toneIndigo
```

## Components

### Comment API

- [Commentable models](https://github.com/beyondcode/laravel-comments/blob/master/src/Traits/HasComments.php): `src/Traits/HasComments.php`
- [Create and retrieve](https://github.com/beyondcode/laravel-comments/blob/master/src/Traits/HasComments.php): `src/Traits/HasComments.php`
- [Approval policy](https://github.com/beyondcode/laravel-comments/blob/master/src/Contracts/Commentator.php): `src/Contracts/Commentator.php`

### Comment lifecycle

- [Comment model](https://github.com/beyondcode/laravel-comments/blob/master/src/Comment.php): `src/Comment.php`
- [Comments table](https://github.com/beyondcode/laravel-comments/blob/master/database/migrations/create_comments_table.php.stub): `database/migrations/create_comments_table.php.stub`
- [Comment added event](https://github.com/beyondcode/laravel-comments/blob/master/src/Events/CommentAdded.php): `src/Events/CommentAdded.php`
- [Comment deleted event](https://github.com/beyondcode/laravel-comments/blob/master/src/Events/CommentDeleted.php): `src/Events/CommentDeleted.php`

### Laravel setup

- [Service provider](https://github.com/beyondcode/laravel-comments/blob/master/src/CommentsServiceProvider.php): `src/CommentsServiceProvider.php`
- [Package configuration](https://github.com/beyondcode/laravel-comments/blob/master/config/config.php): `config/config.php`

### Other components

- **Host application**

## Connections

- Host application → Commentable models: adds trait (evidence: `README.md`)
- Commentable models → Create and retrieve: exposes (evidence: `src/Traits/HasComments.php`)
- Create and retrieve → Approval policy: checks approval (evidence: `src/Traits/HasComments.php`)
- Create and retrieve → Comment model: creates and saves (evidence: `src/Traits/HasComments.php`)
- Create and retrieve → Comments table: persists via Eloquent
- Comment model → Create and retrieve: supports nested replies (evidence: `README.md`)
- Comment model → Comments table: stores comment state
- Comment model → Comment added event: dispatches on create (evidence: `src/Comment.php`)
- Comment model → Comment deleted event: dispatches on delete (evidence: `src/Comment.php`)
- Service provider → Package configuration: merges config (evidence: `src/CommentsServiceProvider.php`)
- Service provider → Comments table: publishes migration (evidence: `src/CommentsServiceProvider.php`)
