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.
@@ -0,0 +1,9 @@
1
+ {
2
+ "permissions": {
3
+ "allow": [
4
+ "Bash(cat:*)"
5
+ ],
6
+ "deny": [],
7
+ "ask": []
8
+ }
9
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-ern-boilerplate",
3
- "version": "0.0.48",
3
+ "version": "0.0.50",
4
4
  "description": "Expo React Native boilerplate generator",
5
5
  "bin": {
6
6
  "create-ern-boilerplate": "./create.js",
@@ -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
- - **API with mock** → `service-with-mock.example.ts`
79
- - **Direct API only** → `service-without-mock.example.ts`
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. ✅ Check `examples/` for similar pattern
94
- 3. Check `CUSTOMIZATION.md` for variant
95
- 4. Create types in `src/types/`
96
- 5. Add sample data to `server/db.json` (if using API)
97
- 6. ✅ Create mock API in `src/services/mockApi/` (if using API)
98
- 7. ✅ Create service in `src/services/`
99
- 8. ✅ Create components in `src/components/`
100
- 9. ✅ Create screens in `app/(tabs)/`
101
- 10. ✅ Update navigation
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)/ → Screens
110
- src/components/ → Components
111
- src/hooks/ → Custom hooks
112
- src/services/ → API services
113
- src/services/mockApi/ → Mock API implementations
114
- src/store/ → Zustand stores
115
- src/types/ → TypeScript types
116
- server/db.json → Mock data
117
- examples/ → Code 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 add new dependencies
125
- 2. ❌ Don't use relative imports (`../../`)
126
- 3. ❌ Don't skip theme support
127
- 4. ❌ Don't skip loading/error states
128
- 5. ❌ Don't ignore examples - always check first!
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/ # Mock API files
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. Depending on your app needs, you may want to:
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. **Remove authentication** - For apps with public content
10
- 2. **Remove mock API** - For apps connecting directly to real API
11
- 3. **Remove API entirely** - For offline-only apps
12
- 4. **Keep everything** - For full-featured apps with auth and API
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 mock API for development
21
- │ │ └─ NO Remove API, use local storage
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 → Remove auth, keep API
26
- └─ NO Remove both auth and API
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
- **Pattern**:
311
+ **🔴 DEFAULT Pattern (With Mock API - Use This!):**
267
312
  ```typescript
268
- import { apiClient } from './api';
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
- export const itemService = {
276
- getItems: async (): Promise<Item[]> => {
277
- const response = await apiClient.get('/items');
278
- return response.data;
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
- getItemById: async (id: string): Promise<Item> => {
282
- const response = await apiClient.get(`/items/${id}`);
283
- return response.data;
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
- createItem: async (data: Partial<Item>): Promise<Item> => {
287
- const response = await apiClient.post('/items', data);
288
- return response.data;
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
- - Export as const object
295
- - Use apiClient from `./api`
296
- - Async/await
297
- - TypeScript types for all params and returns
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/` - Use appropriate service pattern
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 (`@/`)