@famgia/omnify-laravel 0.0.88 → 0.0.90
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-YVVAJA3T.js → chunk-2QSKZS63.js} +188 -12
- package/dist/chunk-2QSKZS63.js.map +1 -0
- package/dist/index.cjs +190 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +48 -1
- package/dist/index.d.ts +48 -1
- package/dist/index.js +5 -1
- package/dist/plugin.cjs +186 -11
- package/dist/plugin.cjs.map +1 -1
- package/dist/plugin.js +1 -1
- package/package.json +5 -5
- package/scripts/postinstall.js +29 -36
- package/stubs/ai-guides/README.md.stub +95 -0
- package/stubs/ai-guides/claude-agents/architect.md.stub +150 -0
- package/stubs/ai-guides/claude-agents/developer.md.stub +190 -0
- package/stubs/ai-guides/claude-agents/reviewer.md.stub +134 -0
- package/stubs/ai-guides/claude-agents/tester.md.stub +196 -0
- package/stubs/ai-guides/claude-checklists/backend.md.stub +112 -0
- package/stubs/ai-guides/claude-omnify/antdesign-guide.md.stub +401 -0
- package/stubs/ai-guides/claude-omnify/config-guide.md.stub +253 -0
- package/stubs/ai-guides/claude-omnify/japan-guide.md.stub +186 -0
- package/stubs/ai-guides/claude-omnify/laravel-guide.md.stub +61 -0
- package/stubs/ai-guides/claude-omnify/react-form-guide.md.stub +259 -0
- package/stubs/ai-guides/claude-omnify/schema-guide.md.stub +115 -0
- package/stubs/ai-guides/claude-omnify/typescript-guide.md.stub +310 -0
- package/stubs/ai-guides/claude-rules/naming.md.stub +364 -0
- package/stubs/ai-guides/claude-rules/performance.md.stub +251 -0
- package/stubs/ai-guides/claude-rules/security.md.stub +159 -0
- package/stubs/ai-guides/claude-workflows/bug-fix.md.stub +201 -0
- package/stubs/ai-guides/claude-workflows/code-review.md.stub +164 -0
- package/stubs/ai-guides/claude-workflows/new-feature.md.stub +327 -0
- package/stubs/ai-guides/cursor/laravel-controller.mdc.stub +391 -0
- package/stubs/ai-guides/cursor/laravel-request.mdc.stub +112 -0
- package/stubs/ai-guides/cursor/laravel-resource.mdc.stub +73 -0
- package/stubs/ai-guides/cursor/laravel-review.mdc.stub +69 -0
- package/stubs/ai-guides/cursor/laravel-testing.mdc.stub +138 -0
- package/stubs/ai-guides/cursor/laravel.mdc.stub +82 -0
- package/stubs/ai-guides/cursor/omnify.mdc.stub +58 -0
- package/stubs/ai-guides/laravel/README.md.stub +59 -0
- package/stubs/ai-guides/laravel/architecture.md.stub +424 -0
- package/stubs/ai-guides/laravel/controller.md.stub +484 -0
- package/stubs/ai-guides/laravel/datetime.md.stub +334 -0
- package/stubs/ai-guides/laravel/openapi.md.stub +369 -0
- package/stubs/ai-guides/laravel/request.md.stub +450 -0
- package/stubs/ai-guides/laravel/resource.md.stub +516 -0
- package/stubs/ai-guides/laravel/service.md.stub +503 -0
- package/stubs/ai-guides/laravel/testing.md.stub +1504 -0
- package/ai-guides/laravel-guide.md +0 -461
- package/dist/chunk-YVVAJA3T.js.map +0 -1
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: "PEST testing rules - 正常系/異常系, naming conventions"
|
|
3
|
+
globs: ["tests/**", "**/*Test.php"]
|
|
4
|
+
alwaysApply: false
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Testing Rules (PEST)
|
|
8
|
+
|
|
9
|
+
> **Agent:** Act as **@tester** agent
|
|
10
|
+
> - Read `.claude/guides/laravel/testing.md` for full guide
|
|
11
|
+
|
|
12
|
+
## How to Run Tests
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
# Run ALL tests (from project root - uses Docker wrapper)
|
|
16
|
+
./artisan test
|
|
17
|
+
|
|
18
|
+
# Run specific test file
|
|
19
|
+
./artisan test --filter=UserControllerTest
|
|
20
|
+
|
|
21
|
+
# Run specific test method
|
|
22
|
+
./artisan test --filter="creates user with valid data"
|
|
23
|
+
|
|
24
|
+
# Run with coverage (if xdebug installed)
|
|
25
|
+
./artisan test --coverage
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
> **Note:** The root `./artisan` script is a wrapper that runs commands inside Docker container.
|
|
29
|
+
|
|
30
|
+
## Testing Process
|
|
31
|
+
|
|
32
|
+
1. **Before writing tests:**
|
|
33
|
+
- Read the Controller to understand endpoints
|
|
34
|
+
- Read the Request to understand validation rules
|
|
35
|
+
- Read the Resource to understand response structure
|
|
36
|
+
|
|
37
|
+
2. **Write tests covering:**
|
|
38
|
+
- 正常系 (Normal cases) - success scenarios
|
|
39
|
+
- 異常系 (Abnormal cases) - failure scenarios
|
|
40
|
+
|
|
41
|
+
3. **Run tests to verify:**
|
|
42
|
+
```bash
|
|
43
|
+
cd backend && ./artisan test
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
4. **All tests must pass before committing**
|
|
47
|
+
|
|
48
|
+
## Critical Rules
|
|
49
|
+
|
|
50
|
+
1. **PEST Syntax** - Use `describe()` + `it()`, not PHPUnit
|
|
51
|
+
2. **正常系 + 異常系** - Cover both success and failure
|
|
52
|
+
3. **Naming** - Use `正常:` and `異常:` prefixes
|
|
53
|
+
4. **Coverage** - All endpoints, all validation rules
|
|
54
|
+
5. **RefreshDatabase** - MUST use for SQLite in-memory
|
|
55
|
+
|
|
56
|
+
## Database Trait - IMPORTANT
|
|
57
|
+
|
|
58
|
+
```php
|
|
59
|
+
// ✅ CORRECT - Use RefreshDatabase for SQLite in-memory
|
|
60
|
+
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
61
|
+
uses(RefreshDatabase::class);
|
|
62
|
+
|
|
63
|
+
// ❌ WRONG - DatabaseTransactions doesn't run migrations
|
|
64
|
+
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
|
65
|
+
uses(DatabaseTransactions::class); // Will fail with "no such table"
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
| Trait | When to Use | Notes |
|
|
69
|
+
| ---------------------- | --------------------------------- | ------------------------------- |
|
|
70
|
+
| `RefreshDatabase` | SQLite in-memory (default) | Runs migrations, then truncates |
|
|
71
|
+
| `DatabaseTransactions` | MySQL/PostgreSQL with existing DB | Only wraps in transaction |
|
|
72
|
+
|
|
73
|
+
## Test Naming
|
|
74
|
+
|
|
75
|
+
```php
|
|
76
|
+
// 正常系 (Normal) - success behavior
|
|
77
|
+
it('正常: returns paginated users')
|
|
78
|
+
it('正常: creates user with valid data')
|
|
79
|
+
it('正常: deletes user')
|
|
80
|
+
|
|
81
|
+
// 異常系 (Abnormal) - failure behavior
|
|
82
|
+
it('異常: fails to create user with missing email')
|
|
83
|
+
it('異常: fails to create user with invalid kana format')
|
|
84
|
+
it('異常: returns 404 when user not found')
|
|
85
|
+
it('異常: returns 401 when not authenticated')
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
## Coverage Matrix
|
|
89
|
+
|
|
90
|
+
| Endpoint | 正常系 | 異常系 |
|
|
91
|
+
| -------- | ------------------ | --------------------- |
|
|
92
|
+
| index | List, filter, sort | Empty, invalid params |
|
|
93
|
+
| store | Creates → 201 | 422 (each field) |
|
|
94
|
+
| show | Returns → 200 | 404 |
|
|
95
|
+
| update | Updates → 200 | 404, 422 |
|
|
96
|
+
| destroy | Deletes → 204 | 404 |
|
|
97
|
+
|
|
98
|
+
## Template
|
|
99
|
+
|
|
100
|
+
```php
|
|
101
|
+
describe('POST /api/users', function () {
|
|
102
|
+
// 正常系
|
|
103
|
+
it('正常: creates user with valid data', function () {
|
|
104
|
+
$response = $this->postJson('/api/users', validUserData());
|
|
105
|
+
|
|
106
|
+
$response->assertCreated();
|
|
107
|
+
$this->assertDatabaseHas('users', ['email' => 'test@example.com']);
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
// 異常系 - Required fields
|
|
111
|
+
it('異常: fails to create user with missing email', function () {
|
|
112
|
+
$data = validUserData();
|
|
113
|
+
unset($data['email']);
|
|
114
|
+
|
|
115
|
+
$this->postJson('/api/users', $data)
|
|
116
|
+
->assertUnprocessable()
|
|
117
|
+
->assertJsonValidationErrors(['email']);
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
// 異常系 - Format validation
|
|
121
|
+
it('異常: fails to create user with invalid email format', function () {
|
|
122
|
+
$this->postJson('/api/users', validUserData(['email' => 'invalid']))
|
|
123
|
+
->assertUnprocessable()
|
|
124
|
+
->assertJsonValidationErrors(['email']);
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
## Japanese Field Tests
|
|
130
|
+
|
|
131
|
+
```php
|
|
132
|
+
it('異常: fails with hiragana in kana field', function () {
|
|
133
|
+
$this->postJson('/api/users', validUserData([
|
|
134
|
+
'name_kana_lastname' => 'たなか' // hiragana - should fail
|
|
135
|
+
]))->assertUnprocessable()
|
|
136
|
+
->assertJsonValidationErrors(['name_kana_lastname']);
|
|
137
|
+
});
|
|
138
|
+
```
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: "Laravel backend development rules - security, performance, patterns"
|
|
3
|
+
globs: ["{{LARAVEL_BASE}}/**"]
|
|
4
|
+
alwaysApply: false
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Laravel Rules
|
|
8
|
+
|
|
9
|
+
> **Documentation:** `.claude/guides/laravel/`
|
|
10
|
+
> **Specific Rules:** See also `laravel-controller.mdc`, `laravel-resource.mdc`, `laravel-request.mdc`, `laravel-testing.mdc`
|
|
11
|
+
|
|
12
|
+
## Critical Rules
|
|
13
|
+
|
|
14
|
+
1. **Thin Controller** - Validate → Delegate → Respond (see `laravel-controller.mdc`)
|
|
15
|
+
2. **Schema-First** - Use Omnify schemas, don't create migrations manually
|
|
16
|
+
3. **Security** - Always use `$request->validated()`, never `$request->all()`
|
|
17
|
+
4. **Performance** - Use `with()` for relations, `paginate()` for lists
|
|
18
|
+
5. **Dates** - Store UTC, return `->toISOString()`
|
|
19
|
+
6. **Testing** - Write 正常系 + 異常系 tests (see `laravel-testing.mdc`)
|
|
20
|
+
7. **Imports** - Always `use` and short class names, never FQCN inline
|
|
21
|
+
|
|
22
|
+
## File-Specific Rules
|
|
23
|
+
|
|
24
|
+
| File Type | Rule File | Key Focus |
|
|
25
|
+
| ---------- | ----------------------- | ---------------------------- |
|
|
26
|
+
| Controller | `laravel-controller.mdc` | Thin, Query Builder, OpenAPI |
|
|
27
|
+
| Resource | `laravel-resource.mdc` | Schema matches output |
|
|
28
|
+
| Request | `laravel-request.mdc` | Schema matches validation |
|
|
29
|
+
| Test | `laravel-testing.mdc` | 正常系 + 異常系 coverage |
|
|
30
|
+
|
|
31
|
+
## Security Checklist
|
|
32
|
+
|
|
33
|
+
- [ ] `$fillable` defined in Model
|
|
34
|
+
- [ ] `$hidden` for sensitive fields
|
|
35
|
+
- [ ] `$request->validated()` not `$request->all()`
|
|
36
|
+
- [ ] No raw SQL with user input
|
|
37
|
+
- [ ] `with()` for eager loading
|
|
38
|
+
- [ ] `whenLoaded()` in Resources
|
|
39
|
+
- [ ] `paginate()` for list endpoints
|
|
40
|
+
|
|
41
|
+
## When to Use What
|
|
42
|
+
|
|
43
|
+
| Scenario | Solution |
|
|
44
|
+
| ---------------- | ------------------ |
|
|
45
|
+
| Simple CRUD | Controller + Model |
|
|
46
|
+
| Multi-step logic | Service |
|
|
47
|
+
| Reusable action | Action class |
|
|
48
|
+
| Async task | Job |
|
|
49
|
+
|
|
50
|
+
## Pre-Edit Checklist
|
|
51
|
+
|
|
52
|
+
**BEFORE editing any file, MUST:**
|
|
53
|
+
|
|
54
|
+
1. **Read the file first** - Check existing imports, patterns, style
|
|
55
|
+
2. **Check imports** - Add `use` if class not imported
|
|
56
|
+
3. **Follow existing style** - Match indentation, naming, patterns
|
|
57
|
+
4. **Never use FQCN inline** - Always import first
|
|
58
|
+
|
|
59
|
+
## Imports Rule
|
|
60
|
+
|
|
61
|
+
```php
|
|
62
|
+
// ❌ WRONG: Inline FQCN
|
|
63
|
+
public function store(): \Illuminate\Http\JsonResponse
|
|
64
|
+
|
|
65
|
+
// ✅ CORRECT: Import and use short name
|
|
66
|
+
use Illuminate\Http\JsonResponse;
|
|
67
|
+
public function store(): JsonResponse
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## Don't Over-Engineer
|
|
71
|
+
|
|
72
|
+
| ❌ DON'T | ✅ DO |
|
|
73
|
+
| ----------------------------------- | ------------------------- |
|
|
74
|
+
| Add workaround to hide bugs | Fix root cause or report |
|
|
75
|
+
| Repository for simple CRUD | Use Eloquent directly |
|
|
76
|
+
| Service that just wraps Model | Controller + Model |
|
|
77
|
+
| Interface with 1 implementation | Concrete class |
|
|
78
|
+
| Manual 404 check with route binding | Trust framework |
|
|
79
|
+
| "Improve" unrelated code | Change only what's needed |
|
|
80
|
+
| Build for future "just in case" | YAGNI - build when needed |
|
|
81
|
+
|
|
82
|
+
**Full examples:** `.claude/guides/laravel/architecture.md`
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: "Omnify schema-driven code generation rules"
|
|
3
|
+
globs: ["schemas/**/*.yaml", "omnify.config.ts"]
|
|
4
|
+
alwaysApply: false
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Omnify Schema Rules
|
|
8
|
+
|
|
9
|
+
This project uses Omnify for schema-driven code generation.
|
|
10
|
+
|
|
11
|
+
## Documentation
|
|
12
|
+
|
|
13
|
+
Read these files in `.claude/omnify/guides/omnify/`:
|
|
14
|
+
|
|
15
|
+
| File | Content |
|
|
16
|
+
| --------------------- | -------------------------------- |
|
|
17
|
+
| `schema-guide.md` | Base schema format |
|
|
18
|
+
| `config-guide.md` | Configuration (omnify.config.ts) |
|
|
19
|
+
| `laravel-guide.md` | Laravel generator |
|
|
20
|
+
| `typescript-guide.md` | TypeScript generator |
|
|
21
|
+
| `japan-guide.md` | Japanese field types |
|
|
22
|
+
|
|
23
|
+
## Commands
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
npx omnify generate # Generate code from schemas
|
|
27
|
+
npx omnify validate # Validate all schemas
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Important
|
|
31
|
+
|
|
32
|
+
- **DO NOT** manually edit files in `database/migrations/omnify/`
|
|
33
|
+
- **DO NOT** manually edit files in `resources/ts/omnify/schemas/base/`
|
|
34
|
+
- **DO NOT** manually edit files in `app/Models/OmnifyBase/`
|
|
35
|
+
- Schema changes → Run `npx omnify generate`
|
|
36
|
+
|
|
37
|
+
## Schema Quick Reference
|
|
38
|
+
|
|
39
|
+
```yaml
|
|
40
|
+
name: User
|
|
41
|
+
displayName:
|
|
42
|
+
ja: ユーザー
|
|
43
|
+
en: User
|
|
44
|
+
|
|
45
|
+
properties:
|
|
46
|
+
email:
|
|
47
|
+
type: Email
|
|
48
|
+
unique: true
|
|
49
|
+
name:
|
|
50
|
+
type: String
|
|
51
|
+
role:
|
|
52
|
+
type: EnumRef
|
|
53
|
+
target: UserRole
|
|
54
|
+
|
|
55
|
+
options:
|
|
56
|
+
timestamps: true
|
|
57
|
+
softDelete: true
|
|
58
|
+
```
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# Backend Guides
|
|
2
|
+
|
|
3
|
+
> Laravel 12, PHP 8.4, MySQL 8
|
|
4
|
+
|
|
5
|
+
## Quick Navigation
|
|
6
|
+
|
|
7
|
+
| Guide | Description |
|
|
8
|
+
| ------------------------------------ | --------------------------------------------- |
|
|
9
|
+
| [architecture.md](./architecture.md) | Design philosophy, when to use Service/Action |
|
|
10
|
+
| [controller.md](./controller.md) | Thin controller pattern, CRUD template |
|
|
11
|
+
| [request.md](./request.md) | Form validation, FormRequest |
|
|
12
|
+
| [resource.md](./resource.md) | API response format, dates |
|
|
13
|
+
| [service.md](./service.md) | When & how to use services |
|
|
14
|
+
| [testing.md](./testing.md) | PEST, 正常系/異常系 |
|
|
15
|
+
| [openapi.md](./openapi.md) | Swagger documentation |
|
|
16
|
+
| [datetime.md](./datetime.md) | Carbon, UTC handling |
|
|
17
|
+
|
|
18
|
+
## Related
|
|
19
|
+
|
|
20
|
+
| Topic | Location |
|
|
21
|
+
| ------------------------ | ----------------------------------------------------------- |
|
|
22
|
+
| **Security rules** | [/rules/security.md](../../rules/security.md) |
|
|
23
|
+
| **Performance rules** | [/rules/performance.md](../../rules/performance.md) |
|
|
24
|
+
| **Naming conventions** | [/rules/naming.md](../../rules/naming.md) |
|
|
25
|
+
| **Checklist** | [/checklists/backend.md](../../checklists/backend.md) |
|
|
26
|
+
| **New feature workflow** | [/workflows/new-feature.md](../../workflows/new-feature.md) |
|
|
27
|
+
|
|
28
|
+
## Quick Patterns
|
|
29
|
+
|
|
30
|
+
### Thin Controller
|
|
31
|
+
|
|
32
|
+
```php
|
|
33
|
+
public function store(UserStoreRequest $request): UserResource
|
|
34
|
+
{
|
|
35
|
+
return new UserResource(User::create($request->validated()));
|
|
36
|
+
}
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### Resource with Dates
|
|
40
|
+
|
|
41
|
+
```php
|
|
42
|
+
public function toArray($request): array
|
|
43
|
+
{
|
|
44
|
+
return [
|
|
45
|
+
'id' => $this->id,
|
|
46
|
+
'name' => $this->name,
|
|
47
|
+
'created_at' => $this->created_at?->toISOString(),
|
|
48
|
+
];
|
|
49
|
+
}
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### When to Use What
|
|
53
|
+
|
|
54
|
+
| Question | Answer |
|
|
55
|
+
| -------------------------- | --------------- |
|
|
56
|
+
| Simple CRUD? | Controller only |
|
|
57
|
+
| Multi-step business logic? | Service |
|
|
58
|
+
| Single reusable action? | Action class |
|
|
59
|
+
| Async task? | Job |
|