create-ern-boilerplate 0.0.48 → 0.0.50
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/.claude/settings.local.json +9 -0
- package/package.json +1 -1
- package/templates/agent-generator/AI_GUIDE.md +69 -36
- package/templates/agent-generator/CUSTOMIZATION.md +33 -9
- package/templates/agent-generator/PATTERNS.md +95 -20
- package/templates/agent-generator/SERVER_GUIDE.md +97 -102
- package/templates/agent-generator/ai-context.json +2 -0
- package/templates/agent-generator/examples/services/mockApi/resource-advanced.mock.example.ts +132 -0
- package/templates/agent-generator/examples/services/mockApi/resource-basic.mock.example.ts +88 -0
- package/templates/agent-generator/examples/types/resource.types.example.ts +61 -0
- package/templates/agent-generator/server/db.json +0 -80
- package/templates/agent-generator/src/services/mockApi/index.ts +0 -26
- package/templates/agent-generator/src/services/mockApi/categories.mock.ts +0 -75
- package/templates/agent-generator/src/services/mockApi/products.mock.ts +0 -125
- package/templates/agent-generator/src/types/product.types.ts +0 -49
package/package.json
CHANGED
|
@@ -32,6 +32,24 @@ Each file has a specific purpose:
|
|
|
32
32
|
|
|
33
33
|
**Full details in respective files. This is just a quick reference.**
|
|
34
34
|
|
|
35
|
+
### 🔴 MOST IMPORTANT: Mock API Default (See SERVER_GUIDE.md)
|
|
36
|
+
|
|
37
|
+
**ALWAYS use Mock API unless user EXPLICITLY requests otherwise!**
|
|
38
|
+
|
|
39
|
+
- ✅ **DEFAULT BEHAVIOR: Use Mock API** - Always create mock API for any feature
|
|
40
|
+
- ✅ Use `service-with-mock.example.ts` pattern for services
|
|
41
|
+
- ✅ Add 2-4 sample items to `server/db.json`
|
|
42
|
+
- ✅ Create mock API file in `src/services/mockApi/`
|
|
43
|
+
- ❌ **NEVER connect to real API** unless user explicitly says:
|
|
44
|
+
- "use real API"
|
|
45
|
+
- "connect to actual backend"
|
|
46
|
+
- "no mock, use production API"
|
|
47
|
+
- ❌ **NEVER skip mock API** for online features
|
|
48
|
+
|
|
49
|
+
**Exception: Only skip Mock API if user requests:**
|
|
50
|
+
1. **Offline-only app** (use AsyncStorage - see `offline-service.example.ts`)
|
|
51
|
+
2. **Explicit real API request** ("connect to real API", "use production backend")
|
|
52
|
+
|
|
35
53
|
### Tech Stack (See PATTERNS.md)
|
|
36
54
|
- ⚠️ **NEVER add new dependencies** without permission
|
|
37
55
|
- ✅ Use only packages in package.json
|
|
@@ -43,11 +61,6 @@ Each file has a specific purpose:
|
|
|
43
61
|
- ✅ Support light/dark theme always
|
|
44
62
|
- ✅ Handle loading and error states
|
|
45
63
|
|
|
46
|
-
### Mock API (See SERVER_GUIDE.md)
|
|
47
|
-
- ✅ Add 2-4 sample items to `server/db.json`
|
|
48
|
-
- ✅ Match TypeScript interfaces exactly
|
|
49
|
-
- ✅ Create mock API file for new models
|
|
50
|
-
|
|
51
64
|
## 🎯 Quick Decision Guide
|
|
52
65
|
|
|
53
66
|
### Choose Your Template Variant
|
|
@@ -58,12 +71,20 @@ Each file has a specific purpose:
|
|
|
58
71
|
Does your app need user accounts?
|
|
59
72
|
├─ NO
|
|
60
73
|
│ ├─ Need API? → NO → Variant: Offline (examples/apps/todo-offline/)
|
|
74
|
+
│ │ ✅ Use: offline-service.example.ts
|
|
75
|
+
│ │
|
|
61
76
|
│ └─ Need API? → YES → Variant: Public Content (examples/apps/news-no-auth/)
|
|
77
|
+
│ ✅ DEFAULT: Use Mock API with service-with-mock.example.ts
|
|
78
|
+
│ ❌ NEVER use real API unless user explicitly requests it
|
|
62
79
|
│
|
|
63
80
|
└─ YES
|
|
64
81
|
└─ Need API? → YES → Variant: Protected (examples/apps/dashboard-with-auth/)
|
|
82
|
+
✅ DEFAULT: Use Mock API with service-with-mock.example.ts
|
|
83
|
+
❌ NEVER use real API unless user explicitly requests it
|
|
65
84
|
```
|
|
66
85
|
|
|
86
|
+
**🔴 IMPORTANT:** When user says "Need API", it means **Mock API by default**!
|
|
87
|
+
|
|
67
88
|
### Choose Your Examples
|
|
68
89
|
|
|
69
90
|
**See `examples/` folder. Quick reference:**
|
|
@@ -75,9 +96,9 @@ Does your app need user accounts?
|
|
|
75
96
|
- **Detail pages** → `detail-screen.example.tsx`
|
|
76
97
|
|
|
77
98
|
#### Service Patterns (`examples/services/`)
|
|
78
|
-
-
|
|
79
|
-
-
|
|
80
|
-
- **Offline storage** → `offline-service.example.ts`
|
|
99
|
+
- **✅ DEFAULT: API with mock** → `service-with-mock.example.ts` (Use this for any online feature)
|
|
100
|
+
- **❌ Direct API only** → `service-without-mock.example.ts` (Only if user explicitly requests real API)
|
|
101
|
+
- **Offline storage** → `offline-service.example.ts` (Only for offline-only apps)
|
|
81
102
|
|
|
82
103
|
#### Complete Apps (`examples/apps/`)
|
|
83
104
|
- **Offline app** → `todo-offline/README.md`
|
|
@@ -90,15 +111,19 @@ Does your app need user accounts?
|
|
|
90
111
|
|
|
91
112
|
### Quick Steps:
|
|
92
113
|
1. ✅ Understand user request
|
|
93
|
-
2. ✅
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
114
|
+
2. ✅ **Determine API strategy:**
|
|
115
|
+
- **DEFAULT: Use Mock API** (unless explicitly told otherwise)
|
|
116
|
+
- Only use offline storage if user says "offline-only app"
|
|
117
|
+
- Only skip mock if user says "use real API" or "connect to actual backend"
|
|
118
|
+
3. ✅ Check `examples/` for similar pattern
|
|
119
|
+
4. ✅ Check `CUSTOMIZATION.md` for variant
|
|
120
|
+
5. ✅ Create types in `src/types/`
|
|
121
|
+
6. ✅ **Add sample data to `server/db.json`** (if using Mock API - which is DEFAULT)
|
|
122
|
+
7. ✅ **Create mock API in `src/services/mockApi/`** (if using Mock API - which is DEFAULT)
|
|
123
|
+
8. ✅ Create service in `src/services/` (use `service-with-mock.example.ts` pattern by DEFAULT)
|
|
124
|
+
9. ✅ Create components in `src/components/`
|
|
125
|
+
10. ✅ Create screens in `app/(tabs)/`
|
|
126
|
+
11. ✅ Update navigation
|
|
102
127
|
|
|
103
128
|
## 📁 File Locations
|
|
104
129
|
|
|
@@ -106,26 +131,30 @@ Does your app need user accounts?
|
|
|
106
131
|
|
|
107
132
|
Quick reference:
|
|
108
133
|
```
|
|
109
|
-
app/(tabs)/
|
|
110
|
-
src/components/
|
|
111
|
-
src/hooks/
|
|
112
|
-
src/services/
|
|
113
|
-
src/services/mockApi/
|
|
114
|
-
src/store/
|
|
115
|
-
src/types/
|
|
116
|
-
server/db.json
|
|
117
|
-
examples/
|
|
134
|
+
app/(tabs)/ → Screens
|
|
135
|
+
src/components/ → Components
|
|
136
|
+
src/hooks/ → Custom hooks
|
|
137
|
+
src/services/ → API services
|
|
138
|
+
src/services/mockApi/ → Mock API implementations (auth, users only)
|
|
139
|
+
src/store/ → Zustand stores
|
|
140
|
+
src/types/ → TypeScript types
|
|
141
|
+
server/db.json → Mock data (users only by default)
|
|
142
|
+
examples/ → Code examples
|
|
143
|
+
examples/services/mockApi/ → Mock API pattern examples (basic & advanced CRUD)
|
|
144
|
+
examples/types/ → Type definition examples (generic resource types)
|
|
118
145
|
```
|
|
119
146
|
|
|
120
147
|
## ⚠️ Common Mistakes to Avoid
|
|
121
148
|
|
|
122
149
|
**Full list in `CONVENTIONS.md`. Quick reference:**
|
|
123
150
|
|
|
124
|
-
1. ❌ Don't
|
|
125
|
-
2. ❌ Don't
|
|
126
|
-
3. ❌ Don't
|
|
127
|
-
4. ❌ Don't
|
|
128
|
-
5. ❌ Don't
|
|
151
|
+
1. ❌ **Don't skip Mock API** - Always use mock API by default for online features
|
|
152
|
+
2. ❌ **Don't connect to real API** - Unless user explicitly requests it
|
|
153
|
+
3. ❌ Don't add new dependencies
|
|
154
|
+
4. ❌ Don't use relative imports (`../../`)
|
|
155
|
+
5. ❌ Don't skip theme support
|
|
156
|
+
6. ❌ Don't skip loading/error states
|
|
157
|
+
7. ❌ Don't ignore examples - always check first!
|
|
129
158
|
|
|
130
159
|
## 💡 Pro Tips
|
|
131
160
|
|
|
@@ -150,18 +179,24 @@ cat SERVER_GUIDE.md # Mock API guide
|
|
|
150
179
|
# Check examples
|
|
151
180
|
ls examples/screens/ # Screen patterns
|
|
152
181
|
ls examples/services/ # Service patterns
|
|
182
|
+
ls examples/services/mockApi/ # Mock API pattern examples
|
|
183
|
+
ls examples/types/ # Type definition examples
|
|
153
184
|
ls examples/apps/ # Complete app examples
|
|
154
185
|
|
|
155
186
|
# Check current structure
|
|
156
|
-
cat server/db.json # Mock data
|
|
157
|
-
ls src/types/ # Type definitions
|
|
158
|
-
ls src/services/mockApi/ #
|
|
187
|
+
cat server/db.json # Mock data (users only)
|
|
188
|
+
ls src/types/ # Type definitions (auth, user types)
|
|
189
|
+
ls src/services/mockApi/ # Active mock API files (auth, users)
|
|
159
190
|
```
|
|
160
191
|
|
|
161
192
|
## ✅ Success Checklist
|
|
162
193
|
|
|
163
194
|
Your generated code is good if:
|
|
164
195
|
|
|
196
|
+
- [ ] **Uses Mock API by default** (unless explicitly told to use real API or offline-only)
|
|
197
|
+
- [ ] Uses `service-with-mock.example.ts` pattern for services (DEFAULT)
|
|
198
|
+
- [ ] Dummy data (2-4 items) added to `server/db.json`
|
|
199
|
+
- [ ] Mock API file created in `src/services/mockApi/`
|
|
165
200
|
- [ ] Uses ONLY existing packages from package.json
|
|
166
201
|
- [ ] Follows examples/ patterns
|
|
167
202
|
- [ ] Uses TypeScript with proper types
|
|
@@ -170,8 +205,6 @@ Your generated code is good if:
|
|
|
170
205
|
- [ ] Handles loading/error states
|
|
171
206
|
- [ ] Uses NativeWind classes
|
|
172
207
|
- [ ] Follows naming conventions
|
|
173
|
-
- [ ] Dummy data matches TypeScript types (if using API)
|
|
174
|
-
- [ ] Mock API implemented for new models (if using API)
|
|
175
208
|
|
|
176
209
|
## 🎓 Learning Path
|
|
177
210
|
|
|
@@ -2,31 +2,55 @@
|
|
|
2
2
|
|
|
3
3
|
How to customize this template for different app types and requirements.
|
|
4
4
|
|
|
5
|
+
## 🔴 IMPORTANT: Mock API is DEFAULT
|
|
6
|
+
|
|
7
|
+
**This guide is for REMOVING features, not adding them!**
|
|
8
|
+
|
|
9
|
+
The template comes with Mock API **enabled by default**. This guide shows how to:
|
|
10
|
+
- Remove Mock API (only if connecting to real API)
|
|
11
|
+
- Remove API entirely (only for offline apps)
|
|
12
|
+
- Remove authentication (for public content apps)
|
|
13
|
+
|
|
14
|
+
**⚠️ For AI Agents: Unless user explicitly requests removal, KEEP and USE the Mock API!**
|
|
15
|
+
|
|
16
|
+
---
|
|
17
|
+
|
|
5
18
|
## 📋 Overview
|
|
6
19
|
|
|
7
|
-
This template is **intentionally general** and includes both auth and mock API infrastructure.
|
|
20
|
+
This template is **intentionally general** and includes both auth and mock API infrastructure. The mock API is the **default and recommended approach** for development.
|
|
21
|
+
|
|
22
|
+
Depending on your app needs, you may want to:
|
|
8
23
|
|
|
9
|
-
1. **
|
|
10
|
-
2. **Remove
|
|
11
|
-
3. **Remove API
|
|
12
|
-
4. **
|
|
24
|
+
1. **Keep Mock API (DEFAULT)** - Recommended for most apps
|
|
25
|
+
2. **Remove authentication** - For apps with public content only
|
|
26
|
+
3. **Remove mock API** - Only if user explicitly wants to connect directly to real API
|
|
27
|
+
4. **Remove API entirely** - Only for offline-only apps (AsyncStorage only)
|
|
13
28
|
|
|
14
29
|
## 🎯 Quick Decision Tree
|
|
15
30
|
|
|
31
|
+
**🔴 DEFAULT: Keep Mock API unless explicitly told otherwise!**
|
|
32
|
+
|
|
16
33
|
```
|
|
17
34
|
Does your app need user accounts?
|
|
18
35
|
├─ YES → Keep authentication
|
|
19
36
|
│ ├─ Does it need API?
|
|
20
|
-
│ │ ├─ YES → Keep
|
|
21
|
-
│ │
|
|
37
|
+
│ │ ├─ YES → ✅ DEFAULT: Keep Mock API (service-with-mock.example.ts)
|
|
38
|
+
│ │ │ ❌ Only remove if user says "use real API"
|
|
39
|
+
│ │ └─ NO → Remove API, use AsyncStorage (offline-service.example.ts)
|
|
22
40
|
│ └─ Continue to final setup
|
|
23
41
|
└─ NO → Remove authentication
|
|
24
42
|
├─ Does it need API?
|
|
25
|
-
│ ├─ YES →
|
|
26
|
-
│
|
|
43
|
+
│ ├─ YES → ✅ DEFAULT: Keep Mock API (service-with-mock.example.ts)
|
|
44
|
+
│ │ ❌ Only remove if user says "use real API"
|
|
45
|
+
│ └─ NO → Remove API, use AsyncStorage (offline-service.example.ts)
|
|
27
46
|
└─ Continue to final setup
|
|
28
47
|
```
|
|
29
48
|
|
|
49
|
+
**⚠️ IMPORTANT FOR AI AGENTS:**
|
|
50
|
+
- When user says "I need a news app" → Use Mock API (don't remove it!)
|
|
51
|
+
- When user says "create product management" → Use Mock API (don't remove it!)
|
|
52
|
+
- Only remove Mock API if user explicitly says: "connect to real API" or "use production backend"
|
|
53
|
+
|
|
30
54
|
## 📁 Template Variants
|
|
31
55
|
|
|
32
56
|
### Variant 1: Offline-Only App (No Auth, No API)
|
|
@@ -4,6 +4,51 @@ Guidelines for AI agents generating code for this project.
|
|
|
4
4
|
|
|
5
5
|
> **Note:** For coding standards, see `CONVENTIONS.md`. For navigation, see `AI_GUIDE.md`.
|
|
6
6
|
|
|
7
|
+
## 🔴 CRITICAL RULE #1: Mock API by Default
|
|
8
|
+
|
|
9
|
+
**ALWAYS use Mock API unless user EXPLICITLY requests otherwise!**
|
|
10
|
+
|
|
11
|
+
### The Rule:
|
|
12
|
+
```
|
|
13
|
+
DEFAULT BEHAVIOR = Mock API
|
|
14
|
+
↓
|
|
15
|
+
When user requests ANY feature with API/backend:
|
|
16
|
+
✅ Create Mock API (service-with-mock.example.ts pattern)
|
|
17
|
+
✅ Add 2-4 sample items to server/db.json
|
|
18
|
+
✅ Create mock API file in src/services/mockApi/
|
|
19
|
+
|
|
20
|
+
EXCEPTIONS (Only 2 cases to skip Mock API):
|
|
21
|
+
1. User explicitly says: "use real API" / "connect to actual backend" / "no mock"
|
|
22
|
+
2. User explicitly says: "offline-only app" (use AsyncStorage instead)
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
### Why This Matters:
|
|
26
|
+
- Mock API allows development without backend setup
|
|
27
|
+
- User can test features immediately with realistic data
|
|
28
|
+
- Easy to switch to real API later (just change API_CONFIG.MOCK_API flag)
|
|
29
|
+
- **If in doubt, USE MOCK API!**
|
|
30
|
+
|
|
31
|
+
### Examples of What User Might Say:
|
|
32
|
+
|
|
33
|
+
**✅ Use Mock API (DEFAULT for these requests):**
|
|
34
|
+
- "Create a news app" → Use Mock API
|
|
35
|
+
- "Add product management" → Use Mock API
|
|
36
|
+
- "Build a social feed" → Use Mock API
|
|
37
|
+
- "I need user profile feature" → Use Mock API
|
|
38
|
+
- "Create dashboard with charts" → Use Mock API
|
|
39
|
+
|
|
40
|
+
**❌ Only Skip Mock if User Says:**
|
|
41
|
+
- "Connect to my real API at https://api.example.com"
|
|
42
|
+
- "Use production backend, no mock"
|
|
43
|
+
- "I want offline-only app with AsyncStorage"
|
|
44
|
+
|
|
45
|
+
### When User is Silent About API:
|
|
46
|
+
If user doesn't mention API at all, but the feature needs data:
|
|
47
|
+
- **DEFAULT = Use Mock API**
|
|
48
|
+
- Never ask "do you want mock or real?" - just use mock!
|
|
49
|
+
|
|
50
|
+
---
|
|
51
|
+
|
|
7
52
|
## ⚠️ CRITICAL: Package Management & Tech Stack
|
|
8
53
|
|
|
9
54
|
### STRICT RULES - Dependencies
|
|
@@ -263,38 +308,64 @@ export function useData(): UseDataReturn {
|
|
|
263
308
|
|
|
264
309
|
**Location**: `src/services/`
|
|
265
310
|
|
|
266
|
-
|
|
311
|
+
**🔴 DEFAULT Pattern (With Mock API - Use This!):**
|
|
267
312
|
```typescript
|
|
268
|
-
import {
|
|
313
|
+
import { api } from '@/services/api';
|
|
314
|
+
import { mockApi } from '@/services/mockApi';
|
|
315
|
+
import { API_CONFIG } from '@/utils/constants';
|
|
269
316
|
|
|
270
317
|
interface Item {
|
|
271
318
|
id: string;
|
|
272
319
|
name: string;
|
|
273
320
|
}
|
|
274
321
|
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
322
|
+
class ItemService {
|
|
323
|
+
/**
|
|
324
|
+
* Get all items
|
|
325
|
+
* Switches between mock and real API automatically
|
|
326
|
+
*/
|
|
327
|
+
async getItems(): Promise<Item[]> {
|
|
328
|
+
if (API_CONFIG.MOCK_API) {
|
|
329
|
+
return await mockApi.get<Item[]>('/items');
|
|
330
|
+
}
|
|
331
|
+
return await api.get<Item[]>('/items');
|
|
332
|
+
}
|
|
280
333
|
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
334
|
+
async getItemById(id: string): Promise<Item> {
|
|
335
|
+
if (API_CONFIG.MOCK_API) {
|
|
336
|
+
return await mockApi.get<Item>(`/items/${id}`);
|
|
337
|
+
}
|
|
338
|
+
return await api.get<Item>(`/items/${id}`);
|
|
339
|
+
}
|
|
285
340
|
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
341
|
+
async createItem(data: Partial<Item>): Promise<Item> {
|
|
342
|
+
if (API_CONFIG.MOCK_API) {
|
|
343
|
+
return await mockApi.post<Item>('/items', data);
|
|
344
|
+
}
|
|
345
|
+
return await api.post<Item>('/items', data);
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
export const itemService = new ItemService();
|
|
350
|
+
```
|
|
351
|
+
|
|
352
|
+
**❌ Only Use This Pattern If User Explicitly Requests Real API:**
|
|
353
|
+
```typescript
|
|
354
|
+
// Direct API only (no mock) - RARELY USED!
|
|
355
|
+
import { api } from '@/services/api';
|
|
356
|
+
|
|
357
|
+
export const itemService = {
|
|
358
|
+
getItems: async () => await api.get('/items'),
|
|
290
359
|
};
|
|
291
360
|
```
|
|
292
361
|
|
|
293
362
|
**Requirements**:
|
|
294
|
-
-
|
|
295
|
-
-
|
|
296
|
-
-
|
|
297
|
-
-
|
|
363
|
+
- ✅ **DEFAULT: Use Mock API switching pattern** (first example)
|
|
364
|
+
- ✅ Check API_CONFIG.MOCK_API before every API call
|
|
365
|
+
- ✅ Export as singleton instance
|
|
366
|
+
- ✅ Async/await
|
|
367
|
+
- ✅ TypeScript types for all params and returns
|
|
368
|
+
- ✅ Follow `examples/services/service-with-mock.example.ts`
|
|
298
369
|
|
|
299
370
|
### Types (`src/types/`)
|
|
300
371
|
|
|
@@ -374,10 +445,14 @@ export const useMyStore = create<MyState>((set) => ({
|
|
|
374
445
|
|
|
375
446
|
Before generating code:
|
|
376
447
|
|
|
448
|
+
- [ ] 🔴 **MOST IMPORTANT: Use Mock API by default** (unless explicitly told otherwise)
|
|
449
|
+
- [ ] 🔴 Create service with Mock API switching (use `service-with-mock.example.ts`)
|
|
450
|
+
- [ ] 🔴 Add 2-4 sample items to `server/db.json`
|
|
451
|
+
- [ ] 🔴 Create mock API file in `src/services/mockApi/`
|
|
377
452
|
- [ ] Check `CUSTOMIZATION.md` - Choose template variant
|
|
378
453
|
- [ ] Check `examples/apps/` - See complete app example
|
|
379
454
|
- [ ] Check `examples/screens/` - Use appropriate screen pattern
|
|
380
|
-
- [ ] Check `examples/services/` -
|
|
455
|
+
- [ ] Check `examples/services/` - Confirm using mock API pattern
|
|
381
456
|
- [ ] Use ONLY existing packages from package.json
|
|
382
457
|
- [ ] Use TypeScript with proper types
|
|
383
458
|
- [ ] Use path aliases (`@/`)
|