# husanswe/klean architecture

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

- Interactive diagram: https://gitdiagram.com/husanswe/klean
- Repository: https://github.com/husanswe/klean

## Overview

This repository is a Laravel web application with blog publishing, comments, accounts and role administration, notifications, and language middleware. The main workflow enters through web routes, dispatches to controllers, reads or changes domain models, and returns Blade views or redirects. Post creation also dispatches an event and sends a notification. The graph follows the sampled controller and model code plus source-index references; several routes and subsystems are represented only at their documented directory or routing level because their implementations were not sampled.

Main entry points: [`app/Http/Controllers/PostController.php`](https://github.com/husanswe/klean/blob/main/app/Http/Controllers/PostController.php) (Post controller), [`routes/web.php`](https://github.com/husanswe/klean/blob/main/routes/web.php) (Web routes), [`app/Models/Post.php`](https://github.com/husanswe/klean/blob/main/app/Models/Post.php) (Posts), [`app/Models/User.php`](https://github.com/husanswe/klean/blob/main/app/Models/User.php) (Users)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Web entry and pages"]
  node_routes["Web routes<br/>[web.php]"]
  node_pages["Page controller<br/>[PageController.php]"]
  node_language["Language middleware"]
end

subgraph group_content["Publishing and discussion"]
  node_postctl["Post controller<br/>[PostController.php]"]
  node_postviews["Post views"]
  node_commentsctl["Comment controller"]
end

subgraph group_identity["Accounts and access"]
  node_authctl["Authentication<br/>[AuthController.php]"]
  node_userctl["User administration<br/>[UserController.php]"]
  node_ensure_role["Role middleware<br/>[EnsureRole.php]"]
end

subgraph group_messaging["Events and notifications"]
  node_post_event["Post-created event<br/>[PostCreated.php]"]
  node_listeners["Event listeners"]
  node_notification["Published-post notification"]
end

subgraph group_domain["Domain data"]
  node_post["Posts<br/>[Post.php]"]
  node_comment["Comments<br/>[Comment.php]"]
  node_category["Categories<br/>[Category.php]"]
  node_tag["Tags<br/>[Tag.php]"]
  node_user["Users<br/>[User.php]"]
  node_role["Roles<br/>[Role.php]"]
  node_store[("Application database")]
end

node_visitor(("Visitor"))

node_visitor -->|"sends request"| node_routes
node_routes -->|"routes to"| node_postctl
node_routes -->|"routes to"| node_commentsctl
node_routes -->|"routes to"| node_authctl
node_routes -->|"routes to"| node_userctl
node_routes -->|"routes to"| node_pages
node_postctl -->|"reads and writes"| node_post
node_postctl -->|"loads"| node_category
node_postctl -->|"loads and attaches"| node_tag
node_postctl -->|"queries users"| node_user
node_postctl -->|"returns views"| node_postviews
node_commentsctl -->|"creates and updates"| node_comment
node_commentsctl -->|"uses post model"| node_post
node_authctl -->|"creates and logs in"| node_user
node_authctl -->|"assigns reader role"| node_role
node_userctl -->|"loads and updates"| node_user
node_userctl -->|"loads roles"| node_role
node_routes -->|"middleware alias"| node_ensure_role
node_routes -->|"web middleware"| node_language
node_postctl -->|"dispatches"| node_post_event
node_postctl -->|"sends to users"| node_notification
node_post_event -->|"registered listeners"| node_listeners
node_post -->|"belongs to"| node_user
node_post -->|"belongs to"| node_category
node_post -->|"has many"| node_comment
node_post -->|"belongs to many"| node_tag
node_user -->|"belongs to many"| node_role
node_user -->|"has many"| node_post
node_user -->|"has many"| node_comment
node_postctl -.->|"persists records"| node_store
node_commentsctl -.->|"persists records"| node_store

click node_routes "https://github.com/husanswe/klean/blob/main/routes/web.php"
click node_pages "https://github.com/husanswe/klean/blob/main/app/Http/Controllers/PageController.php"
click node_language "https://github.com/husanswe/klean/blob/main/app/Http/Middleware/LanguageMiddleware.php"
click node_postctl "https://github.com/husanswe/klean/blob/main/app/Http/Controllers/PostController.php"
click node_postviews "https://github.com/husanswe/klean/tree/main/resources/views/posts"
click node_commentsctl "https://github.com/husanswe/klean/blob/main/app/Http/Controllers/CommentController.php"
click node_post "https://github.com/husanswe/klean/blob/main/app/Models/Post.php"
click node_comment "https://github.com/husanswe/klean/blob/main/app/Models/Comment.php"
click node_category "https://github.com/husanswe/klean/blob/main/app/Models/Category.php"
click node_tag "https://github.com/husanswe/klean/blob/main/app/Models/Tag.php"
click node_authctl "https://github.com/husanswe/klean/blob/main/app/Http/Controllers/AuthController.php"
click node_userctl "https://github.com/husanswe/klean/blob/main/app/Http/Controllers/UserController.php"
click node_user "https://github.com/husanswe/klean/blob/main/app/Models/User.php"
click node_role "https://github.com/husanswe/klean/blob/main/app/Models/Role.php"
click node_ensure_role "https://github.com/husanswe/klean/blob/main/app/Http/Middleware/EnsureRole.php"
click node_post_event "https://github.com/husanswe/klean/blob/main/app/Events/PostCreated.php"
click node_listeners "https://github.com/husanswe/klean/tree/main/app/Listeners"
click node_notification "https://github.com/husanswe/klean/blob/main/app/Notifications/NewPostPublished.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_routes,node_pages,node_language toneBlue
class node_postctl,node_postviews,node_commentsctl toneAmber
class node_authctl,node_userctl,node_ensure_role toneMint
class node_post_event,node_listeners,node_notification toneRose
class node_post,node_comment,node_category,node_tag,node_user,node_role,node_store,node_visitor toneIndigo
```

## Components

### Web entry and pages

- [Web routes](https://github.com/husanswe/klean/blob/main/routes/web.php): `routes/web.php`
- [Page controller](https://github.com/husanswe/klean/blob/main/app/Http/Controllers/PageController.php): `app/Http/Controllers/PageController.php`
- [Language middleware](https://github.com/husanswe/klean/blob/main/app/Http/Middleware/LanguageMiddleware.php): `app/Http/Middleware/LanguageMiddleware.php`

### Publishing and discussion

- [Post controller](https://github.com/husanswe/klean/blob/main/app/Http/Controllers/PostController.php): `app/Http/Controllers/PostController.php`
- [Post views](https://github.com/husanswe/klean/tree/main/resources/views/posts): `resources/views/posts`
- [Comment controller](https://github.com/husanswe/klean/blob/main/app/Http/Controllers/CommentController.php): `app/Http/Controllers/CommentController.php`

### Accounts and access

- [Authentication](https://github.com/husanswe/klean/blob/main/app/Http/Controllers/AuthController.php): `app/Http/Controllers/AuthController.php`
- [User administration](https://github.com/husanswe/klean/blob/main/app/Http/Controllers/UserController.php): `app/Http/Controllers/UserController.php`
- [Role middleware](https://github.com/husanswe/klean/blob/main/app/Http/Middleware/EnsureRole.php): `app/Http/Middleware/EnsureRole.php`

### Events and notifications

- [Post-created event](https://github.com/husanswe/klean/blob/main/app/Events/PostCreated.php): `app/Events/PostCreated.php`
- [Event listeners](https://github.com/husanswe/klean/tree/main/app/Listeners): `app/Listeners`
- [Published-post notification](https://github.com/husanswe/klean/blob/main/app/Notifications/NewPostPublished.php): `app/Notifications/NewPostPublished.php`

### Domain data

- [Posts](https://github.com/husanswe/klean/blob/main/app/Models/Post.php): `app/Models/Post.php`
- [Comments](https://github.com/husanswe/klean/blob/main/app/Models/Comment.php): `app/Models/Comment.php`
- [Categories](https://github.com/husanswe/klean/blob/main/app/Models/Category.php): `app/Models/Category.php`
- [Tags](https://github.com/husanswe/klean/blob/main/app/Models/Tag.php): `app/Models/Tag.php`
- [Users](https://github.com/husanswe/klean/blob/main/app/Models/User.php): `app/Models/User.php`
- [Roles](https://github.com/husanswe/klean/blob/main/app/Models/Role.php): `app/Models/Role.php`
- **Application database**

### Other components

- **Visitor**

## Connections

- Visitor → Web routes: sends request (evidence: `routes/web.php`)
- Web routes → Post controller: routes to (evidence: `routes/web.php`)
- Web routes → Comment controller: routes to (evidence: `routes/web.php`)
- Web routes → Authentication: routes to (evidence: `routes/web.php`)
- Web routes → User administration: routes to (evidence: `routes/web.php`)
- Web routes → Page controller: routes to (evidence: `routes/web.php`)
- Post controller → Posts: reads and writes (evidence: `app/Http/Controllers/PostController.php`)
- Post controller → Categories: loads (evidence: `app/Http/Controllers/PostController.php`)
- Post controller → Tags: loads and attaches (evidence: `app/Http/Controllers/PostController.php`)
- Post controller → Users: queries users (evidence: `app/Http/Controllers/PostController.php`)
- Post controller → Post views: returns views (evidence: `app/Http/Controllers/PostController.php`)
- Comment controller → Comments: creates and updates (evidence: `app/Http/Controllers/CommentController.php`)
- Comment controller → Posts: uses post model (evidence: `app/Http/Controllers/CommentController.php`)
- Authentication → Users: creates and logs in (evidence: `app/Http/Controllers/AuthController.php`)
- Authentication → Roles: assigns reader role (evidence: `app/Http/Controllers/AuthController.php`)
- User administration → Users: loads and updates (evidence: `app/Http/Controllers/UserController.php`)
- User administration → Roles: loads roles (evidence: `app/Http/Controllers/UserController.php`)
- Web routes → Role middleware: middleware alias
- Web routes → Language middleware: web middleware
- Post controller → Post-created event: dispatches (evidence: `app/Http/Controllers/PostController.php`)
- Post controller → Published-post notification: sends to users (evidence: `app/Http/Controllers/PostController.php`)
- Post-created event → Event listeners: registered listeners (evidence: `app/Providers/EventServiceProvider.php`)
- Posts → Users: belongs to (evidence: `app/Models/Post.php`)
- Posts → Categories: belongs to (evidence: `app/Models/Post.php`)
- Posts → Comments: has many (evidence: `app/Models/Post.php`)
- Posts → Tags: belongs to many (evidence: `app/Models/Post.php`)
- Users → Roles: belongs to many (evidence: `app/Models/User.php`)
- Users → Posts: has many (evidence: `app/Models/User.php`)
- Users → Comments: has many (evidence: `app/Models/User.php`)
- Post controller → Application database: persists records
- Comment controller → Application database: persists records
