Skip to content

Commit 73eb6cf

Browse files
gubakareemcursoragent
authored andcommitted
Document design patterns, package updates, and Workspace UI install.
Sync CHANGELOG with GoF generators and expand getting-started for presets, update commands, and dashboard requirements. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 96d6e70 commit 73eb6cf

6 files changed

Lines changed: 445 additions & 8 deletions

File tree

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Documentation
11+
12+
- Expanded [getting started](docs/getting-started.md): all architecture presets, GoF patterns, package update commands, and Architecture Workspace (UI) install / requirements / update.
13+
- New [design patterns & examples](docs/examples/design-patterns.md): Strategy, State, Singleton, Abstract Factory, DDD, CQRS, Pipeline, Actions/ADR with usage snippets.
14+
- CHANGELOG brought in line with GoF generators shipped before 1.5.0 (documented under 1.5.0 below).
15+
1016
## [1.5.1] - 2026-07-23
1117

1218
### Fixed
@@ -22,6 +28,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2228
- **Architecture Brief** (Phase 16) — living transferable understanding with Audience (`developer` / `architect` / `contributor`); not static documentation.
2329
- **Architecture Context** (Phase 17) — “What should I know before I touch this?” composition from identity, decisions, evolution, and guidance.
2430
- **ArchitectureContextEnvelope v1.0** — stable pre-AI boundary for UI · IDE · PR · AI; `can_explain` / `can_modify`; typed `allowed_questions`.
31+
- **GoF pattern generators** (add with `--patterns=…`, distinct from Eloquent `factory`):
32+
- `strategy` — interface + default/alternative strategies + context
33+
- `state` — draft / published / archived states + context
34+
- `singleton``{Model}Registry` singleton scaffold
35+
- `abstract-factory` — Standard/Premium factory family (notifier + serializer) + client
2536
- CLI: `architect:ask`, `architect:workspace` enhancements; Ask is read-only.
2637
- Product constitution: [VISION.md](VISION.md), [philosophy](docs/philosophy.md), [roadmap](docs/roadmap.md), [Architecture Moment Map](docs/architecture/moments.md) (Phase 18 discovery — evidence before surfaces).
2738
- [ADR-0008](docs/adr/0008-visualize-architecture-assistant-ux.md): Architecture Workspace UX boundary.

README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,38 @@ php artisan vendor:publish --tag=lara-architect-stubs
9292

9393
Published stubs live in `stubs/lara-architect/` and always win over the package defaults.
9494

95+
### Update the core package
96+
97+
```bash
98+
composer update karim-ashraf/lara-architect
99+
```
100+
101+
After upgrading, skim [CHANGELOG.md](CHANGELOG.md). Published config is deep-merged with package defaults (since 1.4.2), so newer generators keep working without a full re-publish.
102+
103+
### Architecture Workspace UI (optional)
104+
105+
Install beside core for the Workspace at `/architect/workspace`.
106+
107+
| Requirement | Detail |
108+
| --- | --- |
109+
| Core | `karim-ashraf/lara-architect` already installed |
110+
| PHP / Laravel | Same as core (^8.2, Laravel 11–13) |
111+
| Node.js | **18+** (npm) to build React assets once |
112+
113+
```bash
114+
composer require karim-ashraf/lara-architect-ui
115+
# path / local install: see lara-architect-ui README
116+
117+
cd vendor/karim-ashraf/lara-architect-ui && npm install && npm run build
118+
php artisan vendor:publish --tag=lara-architect-ui-assets
119+
```
120+
121+
```text
122+
/architect/workspace?context=ProductController&context_type=file
123+
```
124+
125+
Update UI later with `composer update karim-ashraf/lara-architect-ui`, rebuild assets, and re-publish `--tag=lara-architect-ui-assets`. Step-by-step: [Getting started](docs/getting-started.md#install-the-architecture-workspace-ui--dashboard) · [UI README](../lara-architect-ui/README.md).
126+
95127
## Quick start: your first CRUD in five steps
96128

97129
> The full walkthrough with explanations lives in [docs/getting-started.md](docs/getting-started.md).
@@ -177,6 +209,8 @@ GoF patterns (add with `--patterns=…`, not Eloquent `factory`):
177209
php artisan make:module Order --patterns=model,strategy,state,singleton,abstract-factory
178210
```
179211

212+
Usage examples (Strategy, State, Singleton, Abstract Factory, DDD, CQRS, Pipeline): [docs/examples/design-patterns.md](docs/examples/design-patterns.md).
213+
180214
```php
181215
'architectures' => [
182216
'service-repository' => [/* … */],

docs/examples/README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# Examples
22

3-
Practical walkthroughs and sample layouts. Start with the package getting-started guide:
3+
Practical walkthroughs and sample layouts:
44

5-
- [Getting started](../getting-started.md)
5+
- [Getting started](../getting-started.md) — install, update, Workspace UI, first CRUD
6+
- [Design patterns & architecture presets](design-patterns.md) — Strategy, State, Singleton, Abstract Factory, DDD, CQRS, Pipeline, Actions/ADR
67

7-
More Workspace / engine examples will land here as Integration and Visualize milestones ship.
8+
More Workspace / engine examples will land here as Integration milestones ship.

docs/examples/design-patterns.md

Lines changed: 234 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,234 @@
1+
# Design patterns & architecture presets
2+
3+
Lara Architect generates **architecture presets** (named stacks) and **individual patterns** you can mix with `--patterns=…`.
4+
5+
List everything registered in your app:
6+
7+
```bash
8+
php artisan architect:patterns
9+
```
10+
11+
> **Note:** Pattern `factory` is the Eloquent model factory (`Database\Factories`). The GoF **Abstract Factory** is `abstract-factory` — a different generator.
12+
13+
---
14+
15+
## Architecture presets
16+
17+
| Preset | Intent | Patterns included |
18+
| --- | --- | --- |
19+
| `service-repository` (default) | Classic layered CRUD | model, migration, factory, enum, repository, service, filter, requests, resource, controller |
20+
| `actions` | One class per use-case + DTO | model, migration, factory, enum, dto, actions, filter, requests, resource, controller |
21+
| `adr` | Action–Domain–Responder | Same scaffold as `actions` |
22+
| `ddd` | Domain folders under `App\Domain\{Module}` | model, migration, factory, enum, dto, repository, service, filter, requests, resource, controller (+ namespace overlays) |
23+
| `cqrs` | Separate writes (commands) and reads (queries) | model, migration, factory, enum, dto, query, command, filter, requests, resource, controller |
24+
| `pipeline` | Illuminate Pipeline pipes | model, migration, factory, enum, pipeline, requests, resource, controller |
25+
| `lean` | Minimal scaffold | model, migration, requests, resource, controller |
26+
27+
```bash
28+
php artisan make:module Product --architecture=service-repository --fields="name:string, price:decimal"
29+
php artisan make:module Order --architecture=actions --fields="total:decimal, status:enum"
30+
php artisan make:module Invoice --architecture=ddd --fields="total:decimal"
31+
php artisan make:module Report --architecture=cqrs --fields="title:string"
32+
php artisan make:module Checkout --architecture=pipeline --fields="total:decimal"
33+
php artisan make:module Tag --architecture=lean --fields="name:string:unique"
34+
```
35+
36+
Set a project default:
37+
38+
```env
39+
LARA_ARCHITECT_ARCHITECTURE=ddd
40+
```
41+
42+
---
43+
44+
## GoF / behavioral & creational patterns
45+
46+
Add with `--patterns=…` (alone or on top of a preset via hand-picked lists):
47+
48+
| Pattern | Generates | Default namespace |
49+
| --- | --- | --- |
50+
| `strategy` | Interface + default/alternative strategies + context | `App\Strategies` |
51+
| `state` | Interface + draft / published / archived states + context | `App\States` |
52+
| `singleton` | `{Model}Registry` (classic singleton) | `App\Singletons` |
53+
| `abstract-factory` | Family of factories + notifier/serializer products + client | `App\Factories` |
54+
55+
```bash
56+
php artisan make:module Order \
57+
--patterns=model,migration,strategy,state,singleton,abstract-factory \
58+
--fields="total:decimal, status:string"
59+
```
60+
61+
### Strategy — interchangeable algorithms
62+
63+
```php
64+
use App\Strategies\DefaultOrderStrategy;
65+
use App\Strategies\AlternativeOrderStrategy;
66+
use App\Strategies\OrderStrategyContext;
67+
68+
$context = new OrderStrategyContext(new DefaultOrderStrategy());
69+
$context->execute($order, ['total' => 99.5]);
70+
71+
$context->use(new AlternativeOrderStrategy());
72+
$context->execute($order, ['total' => 120]);
73+
74+
// or by registered name:
75+
$context->use('alternative');
76+
```
77+
78+
**When to use:** shipping calculators, pricing rules, export formats — same interface, swap behaviour.
79+
80+
### State — lifecycle transitions
81+
82+
```php
83+
use App\States\DraftOrderState;
84+
use App\States\OrderStateContext;
85+
86+
$context = new OrderStateContext(new DraftOrderState());
87+
$context->name(); // 'draft'
88+
$context->publish(); // → PublishedOrderState
89+
$context->archive(); // → ArchivedOrderState
90+
```
91+
92+
**When to use:** draft → published → archived workflows; gate actions by current state.
93+
94+
### Singleton — one shared registry
95+
96+
```php
97+
use App\Singletons\OrderRegistry;
98+
99+
$registry = OrderRegistry::getInstance();
100+
$registry->set('last_id', $order->id);
101+
$registry->get('last_id');
102+
103+
OrderRegistry::reset(); // tests / CLI only
104+
```
105+
106+
In Laravel apps prefer the container when you can:
107+
108+
```php
109+
$this->app->singleton(OrderRegistry::class);
110+
```
111+
112+
The generated class is for **explicit Singleton semantics** (teaching, libraries, CLI).
113+
114+
### Abstract Factory — families of related objects
115+
116+
Not the Eloquent `factory` pattern. Generates Standard/Premium factories, notifiers, serializers, and a client that depends only on the abstract factory:
117+
118+
```php
119+
use App\Factories\Orders\OrderComponentClient;
120+
use App\Factories\Orders\StandardOrderComponentFactory;
121+
use App\Factories\Orders\PremiumOrderComponentFactory;
122+
123+
$client = new OrderComponentClient(new StandardOrderComponentFactory());
124+
$client->dispatch(['id' => 1, 'total' => 50]);
125+
126+
// swap the whole product family:
127+
$client = new OrderComponentClient(new PremiumOrderComponentFactory());
128+
$client->dispatch(['id' => 1, 'total' => 50]);
129+
```
130+
131+
**When to use:** themed/partner integrations where notifier + serializer must stay consistent as a set.
132+
133+
---
134+
135+
## DDD preset — domain layout
136+
137+
```bash
138+
php artisan make:module Invoice --architecture=ddd --fields="total:decimal, status:enum"
139+
```
140+
141+
Typical layout (namespaces from `architecture_namespaces.ddd`):
142+
143+
```
144+
app/
145+
├── Domain/Invoice/
146+
│ ├── Models/Invoice.php
147+
│ ├── Services/InvoiceService.php
148+
│ ├── Data/InvoiceData.php
149+
│ ├── Enums/InvoiceStatus.php
150+
│ └── Filters/InvoiceFilter.php
151+
└── Infrastructure/Invoice/InvoiceRepository.php
152+
```
153+
154+
Use the service the same way as service-repository; only the folders change.
155+
156+
---
157+
158+
## CQRS preset — commands & queries
159+
160+
```bash
161+
php artisan make:module Report --architecture=cqrs --fields="title:string, body:text"
162+
```
163+
164+
```
165+
app/
166+
├── Commands/Reports/CreateReportCommand.php
167+
├── Commands/Reports/UpdateReportCommand.php
168+
├── Commands/Reports/DeleteReportCommand.php
169+
├── Queries/Reports/ListReportsQuery.php
170+
├── Queries/Reports/GetReportQuery.php
171+
└── DTOs/ReportData.php
172+
```
173+
174+
```php
175+
// writes
176+
CreateReportCommand::run(ReportData::fromRequest($request));
177+
178+
// reads
179+
$reports = ListReportsQuery::run($filter);
180+
$report = GetReportQuery::run($id);
181+
```
182+
183+
---
184+
185+
## Pipeline preset
186+
187+
```bash
188+
php artisan make:module Checkout --architecture=pipeline --fields="total:decimal"
189+
```
190+
191+
```php
192+
use App\Pipelines\Checkouts\CheckoutPipeline;
193+
194+
$result = app(CheckoutPipeline::class)->send([
195+
'total' => 149.99,
196+
// …
197+
]);
198+
```
199+
200+
Pipes default to validate → persist; add your own pipes in `through([...])`.
201+
202+
---
203+
204+
## Actions / ADR
205+
206+
```bash
207+
php artisan make:module Order --architecture=actions --fields="total:decimal, status:enum"
208+
# same scaffold:
209+
php artisan make:module Order --architecture=adr --fields="total:decimal, status:enum"
210+
```
211+
212+
```php
213+
CreateOrder::run(OrderData::fromRequest($request));
214+
UpdateOrder::run($order, OrderData::fromRequest($request));
215+
DeleteOrder::run($order);
216+
```
217+
218+
---
219+
220+
## Compose your own
221+
222+
```bash
223+
# Model + service, no repository
224+
php artisan make:module Invoice \
225+
--patterns=model,migration,service,requests,resource,controller \
226+
--fields="number:string:unique, total:decimal"
227+
228+
# CRUD + Strategy + State
229+
php artisan make:module Ticket \
230+
--patterns=model,migration,factory,service,repository,filter,requests,resource,controller,strategy,state \
231+
--fields="title:string, status:enum"
232+
```
233+
234+
Register custom presets under `architectures` in `config/lara-architect.php` — see [Getting started §6.5](../getting-started.md#65-project-default-and-custom-presets).

0 commit comments

Comments
 (0)