create-ern-boilerplate 0.0.34 → 0.0.36

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/create.js CHANGED
@@ -218,11 +218,15 @@ ${chalk.bold("\nšŸ“– READING ORDER (Urutan Baca yang Direkomendasikan):\n")}
218
218
  ${chalk.dim("# Pola pembuatan kode")}
219
219
  4. šŸ“ CONVENTIONS.md
220
220
  ${chalk.dim("# Standar coding")}
221
- 5. šŸ’” examples/
221
+ 5. šŸ“‹ SERVER_GUIDE.md
222
+ ${chalk.dim("# Mock API & dummy data guide")}
223
+ 6. šŸ’” examples/
222
224
  ${chalk.dim("# Contoh kode siap pakai")}
223
- 6. šŸ“– README.md
225
+ 7. šŸ“– README.md
224
226
  ${chalk.dim("# Gambaran umum project")}
225
227
 
228
+ ${chalk.bold("\nšŸ“– Pastikan untuk selalu menjaga stabilitas integrasi, skalabilitas arsitektur, maintainability, testability, konsistensi codebase, serta zero error.\n")}
229
+
226
230
  ${chalk.green("Happy coding! šŸ’»")}
227
231
  `);
228
232
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-ern-boilerplate",
3
- "version": "0.0.34",
3
+ "version": "0.0.36",
4
4
  "description": "Expo React Native boilerplate generator",
5
5
  "bin": {
6
6
  "create-ern-boilerplate": "./create.js",
@@ -0,0 +1,9 @@
1
+ {
2
+ "permissions": {
3
+ "allow": [
4
+ "Bash(tree:*)"
5
+ ],
6
+ "deny": [],
7
+ "ask": []
8
+ }
9
+ }
@@ -10,7 +10,8 @@ When you first enter this project, read these files in order:
10
10
  2. **`ai-context.json`** - Know where to generate each type of code
11
11
  3. **`GENERATE_RULES.md`** - āš ļø **READ THIS FIRST** - Tech stack & dependency rules
12
12
  4. **`CONVENTIONS.md`** - Understand coding standards
13
- 5. **`examples/`** - See actual working code patterns
13
+ 5. **`SERVER_GUIDE.md`** - āš ļø **Mock API & dummy data guide**
14
+ 6. **`examples/`** - See actual working code patterns
14
15
 
15
16
  ## 🚨 CRITICAL RULES - Read First!
16
17
 
@@ -60,11 +61,17 @@ Fixed Versions:
60
61
  "componentsPath": "src/components", // Components in src/components/common/ or /shared/
61
62
  "hooksPath": "src/hooks", // Custom hooks
62
63
  "servicesPath": "src/services", // API services
64
+ "mockApiPath": "src/services/mockApi", // Mock API implementations
63
65
  "storePath": "src/store", // Zustand stores
64
66
  "typesPath": "src/types", // TypeScript types
65
67
  "utilsPath": "src/utils", // Utility functions
66
68
  "themePath": "src/theme", // Theme configuration
67
- "examples": "examples" // Code examples - CHECK THIS FIRST!
69
+ "mockDataPath": "server/db.json", // Mock database (sample/starter data)
70
+ "examples": "examples", // Code examples - CHECK THIS FIRST!
71
+ "aiGuide": "AI_GUIDE.md", // AI agent guide
72
+ "serverGuide": "SERVER_GUIDE.md", // Mock API & server guide
73
+ "rules": "GENERATE_RULES.md", // Code generation rules
74
+ "conventions": "CONVENTIONS.md" // Coding conventions
68
75
  }
69
76
  ```
70
77
 
@@ -202,6 +209,73 @@ import { useNewsStore } from '@/store/newsStore';
202
209
  import { newsService } from '@/services/newsService';
203
210
  ```
204
211
 
212
+ ## šŸ“¦ Mock API & Dummy Data
213
+
214
+ ### Understanding the Mock API System
215
+
216
+ This boilerplate includes a **mock API** that simulates a backend server:
217
+
218
+ - **Data source**: `server/db.json` (JSON file with dummy data)
219
+ - **Mock API files**: `src/services/mockApi/*.mock.ts` (simulates API endpoints)
220
+ - **Type safe**: All data must match TypeScript interfaces in `src/types/`
221
+
222
+ ### When Adding New Data Model
223
+
224
+ **IMPORTANT**: Follow this sequence exactly:
225
+
226
+ 1. **Create TypeScript interface** in `src/types/*.types.ts`
227
+ ```typescript
228
+ // src/types/news.types.ts
229
+ export interface News {
230
+ id: string;
231
+ title: string;
232
+ content: string;
233
+ createdAt: string;
234
+ }
235
+ ```
236
+
237
+ 2. **Add dummy data to `server/db.json`**
238
+ ```json
239
+ {
240
+ "users": [...],
241
+ "news": [
242
+ {
243
+ "id": "1",
244
+ "title": "Breaking News",
245
+ "content": "News content here",
246
+ "createdAt": "2024-11-18T00:00:00.000Z"
247
+ }
248
+ ]
249
+ }
250
+ ```
251
+
252
+ 3. **Create mock API file** in `src/services/mockApi/news.mock.ts`
253
+ - Import data: `import * as db from 'server/db.json'`
254
+ - Implement CRUD operations (get, post, put, del)
255
+ - Follow pattern in `products.mock.ts` or `users.mock.ts`
256
+
257
+ 4. **Create service** in `src/services/newsService.ts`
258
+ - Use `apiClient` from `./api`
259
+ - Service calls mock API in development
260
+
261
+ **See SERVER_GUIDE.md for complete mock API documentation!**
262
+
263
+ ### Dummy Data Rules
264
+
265
+ āœ… **DO:**
266
+ - Match TypeScript interfaces exactly
267
+ - Include ALL required fields
268
+ - Use realistic data (not "test", "example")
269
+ - Use ISO date format: `"2024-11-18T00:00:00.000Z"`
270
+ - Include edge cases (empty, low stock, inactive users, etc.)
271
+ - Maintain referential integrity (foreign keys must exist)
272
+
273
+ āŒ **DON'T:**
274
+ - Leave required fields empty
275
+ - Use wrong data types (string instead of number)
276
+ - Use fake/generic data
277
+ - Forget to update db.json when changing types
278
+
205
279
  ## šŸ“š Code Generation Workflow
206
280
 
207
281
  ### Step-by-Step Process
@@ -218,24 +292,34 @@ import { newsService } from '@/services/newsService';
218
292
  - Define data structures
219
293
  - Export all interfaces
220
294
 
221
- 4. **Create service** (`src/services/`)
295
+ 4. **Add dummy data to `server/db.json`**
296
+ - Create array matching your type
297
+ - Add 5-10 realistic items
298
+ - Include edge cases
299
+
300
+ 5. **Create mock API** (`src/services/mockApi/`)
301
+ - Import from db.json
302
+ - Implement CRUD operations
303
+ - Follow existing patterns
304
+
305
+ 6. **Create service** (`src/services/`)
222
306
  - API calls
223
307
  - Follow `examples/service.example.ts`
224
308
 
225
- 5. **Create hook if needed** (`src/hooks/`)
309
+ 7. **Create hook if needed** (`src/hooks/`)
226
310
  - Data fetching logic
227
311
  - Follow `examples/hook.example.ts`
228
312
 
229
- 6. **Create components** (`src/components/`)
313
+ 8. **Create components** (`src/components/`)
230
314
  - Reusable UI pieces
231
315
  - Follow `examples/component.example.tsx`
232
316
 
233
- 7. **Create screens** (`app/(tabs)/`)
317
+ 9. **Create screens** (`app/(tabs)/`)
234
318
  - Main screens
235
319
  - Follow `examples/screen.example.tsx`
236
320
 
237
- 8. **Update navigation**
238
- - Add tabs to `app/(tabs)/_layout.tsx`
321
+ 10. **Update navigation**
322
+ - Add tabs to `app/(tabs)/_layout.tsx`
239
323
 
240
324
  ## āš ļø Common Mistakes to Avoid
241
325
 
@@ -301,9 +385,12 @@ import { newsService } from '@/services/newsService';
301
385
  Before generating code:
302
386
  - [ ] āš ļø **Check package.json** - Only use existing packages!
303
387
  - [ ] āš ļø **NO new dependencies** - Use what's already installed
388
+ - [ ] āš ļø **Check server/db.json** - Ensure dummy data exists and matches types
304
389
  - [ ] Read examples/ folder
305
390
  - [ ] Check ai-context.json for paths
306
391
  - [ ] Use TypeScript types
392
+ - [ ] Add dummy data to server/db.json
393
+ - [ ] Create mock API file if needed
307
394
  - [ ] Use path aliases (@/)
308
395
  - [ ] Support theme (light/dark)
309
396
  - [ ] Handle loading state
@@ -330,17 +417,24 @@ cat README.md
330
417
  cat ai-context.json
331
418
  cat GENERATE_RULES.md
332
419
  cat CONVENTIONS.md
420
+ cat SERVER_GUIDE.md
333
421
 
334
422
  # Check examples
335
423
  ls examples/
336
424
  cat examples/screen.example.tsx
337
425
  cat examples/service.example.ts
338
426
 
427
+ # Check mock data & API
428
+ cat server/db.json
429
+ ls src/services/mockApi/
430
+ cat src/services/mockApi/products.mock.ts
431
+
339
432
  # Check existing structure
340
433
  ls app/(tabs)/
341
434
  ls src/components/
342
435
  ls src/services/
343
436
  ls src/store/
437
+ ls src/types/
344
438
  ```
345
439
 
346
440
  ## šŸŽÆ Success Criteria
@@ -349,6 +443,8 @@ Your generated code is good if:
349
443
  āœ… **Uses ONLY existing packages** from package.json
350
444
  āœ… **NO new dependencies** added
351
445
  āœ… **Expo SDK 54 compatible** only
446
+ āœ… **Dummy data in server/db.json** matches TypeScript types
447
+ āœ… **Mock API implemented** for new data models
352
448
  āœ… Follows examples/ patterns exactly
353
449
  āœ… Uses TypeScript properly
354
450
  āœ… Uses path aliases (@/)
@@ -21,7 +21,8 @@ This template is designed to work seamlessly with AI agents for rapid developmen
21
21
  2. **[ai-context.json](ai-context.json)** - Path mappings
22
22
  3. **[GENERATE_RULES.md](GENERATE_RULES.md)** - Code generation patterns
23
23
  4. **[CONVENTIONS.md](CONVENTIONS.md)** - Coding standards
24
- 5. **[examples/](examples/)** - Actual working code to copy
24
+ 5. **[SERVER_GUIDE.md](SERVER_GUIDE.md)** - Mock API & dummy data guide
25
+ 6. **[examples/](examples/)** - Actual working code to copy
25
26
 
26
27
  ## Quick Start
27
28
 
@@ -94,8 +95,15 @@ The `ai-context.json` tells AI where to generate code:
94
95
  "componentsPath": "src/components",
95
96
  "hooksPath": "src/hooks",
96
97
  "servicesPath": "src/services",
98
+ "mockApiPath": "src/services/mockApi",
99
+ "storePath": "src/store",
100
+ "typesPath": "src/types",
101
+ "mockDataPath": "server/db.json",
97
102
  "examples": "examples",
98
- "rules": "GENERATE_RULES.md"
103
+ "aiGuide": "AI_GUIDE.md",
104
+ "serverGuide": "SERVER_GUIDE.md",
105
+ "rules": "GENERATE_RULES.md",
106
+ "conventions": "CONVENTIONS.md"
99
107
  }
100
108
  ```
101
109
 
@@ -0,0 +1,731 @@
1
+ # Mock API Server Guide
2
+
3
+ Complete guide for working with mock API and dummy data in this boilerplate.
4
+
5
+ ## šŸ“¦ Overview
6
+
7
+ This boilerplate uses a **mock API system** that simulates a real backend server for development and testing purposes. The mock API reads data from `server/db.json` and provides full CRUD operations.
8
+
9
+ ### Why Mock API?
10
+
11
+ āœ… **No Backend Required** - Start developing immediately without setting up a server
12
+ āœ… **Realistic Data** - Work with actual data structures matching your TypeScript interfaces
13
+ āœ… **Full CRUD** - Complete Create, Read, Update, Delete operations
14
+ āœ… **Type Safe** - All mock data matches your TypeScript types
15
+ āœ… **Easy Testing** - Test your UI with controlled data
16
+
17
+ ### šŸ“Œ Important Note
18
+
19
+ The `server/db.json` file contains **minimal sample/starter data** for demonstration purposes only. This data is meant to:
20
+ - Show the correct structure and format
21
+ - Demonstrate edge cases (active/inactive users, low stock products)
22
+ - Serve as a template for AI agents
23
+
24
+ **This data will be replaced** when AI agents generate new features specific to your app. Think of it as a starting point, not production data.
25
+
26
+ ## šŸ—‚ļø File Structure
27
+
28
+ ```
29
+ templates/agent-generator/
30
+ ā”œā”€ā”€ server/
31
+ │ └── db.json # Mock database (dummy data)
32
+ │
33
+ ā”œā”€ā”€ src/
34
+ │ ā”œā”€ā”€ types/ # TypeScript interfaces
35
+ │ │ ā”œā”€ā”€ auth.types.ts # User & Auth types
36
+ │ │ ā”œā”€ā”€ user.types.ts # User data types
37
+ │ │ └── product.types.ts # Product & Category types
38
+ │ │
39
+ │ └── services/
40
+ │ ā”œā”€ā”€ mockApi/ # Mock API implementations
41
+ │ │ ā”œā”€ā”€ auth.mock.ts # Auth endpoints (login, register, etc)
42
+ │ │ ā”œā”€ā”€ users.mock.ts # User CRUD endpoints
43
+ │ │ ā”œā”€ā”€ products.mock.ts # Product CRUD endpoints
44
+ │ │ └── categories.mock.ts # Category CRUD endpoints
45
+ │ │
46
+ │ └── api.ts # API client (switches between mock/real)
47
+ ```
48
+
49
+ ## šŸ“‹ Understanding server/db.json
50
+
51
+ ### Structure
52
+
53
+ The `server/db.json` file is the **mock database** that contains sample/starter data. It must match your TypeScript interfaces exactly.
54
+
55
+ **Current Sample Data:**
56
+ - **3 users** (1 admin, 1 active user, 1 inactive user) - demonstrates different roles and statuses
57
+ - **3 categories** (Electronics, Food, Clothing) - shows category structure
58
+ - **4 products** (includes 1 low stock item) - demonstrates normal and edge cases
59
+
60
+ **Format:**
61
+ ```json
62
+ {
63
+ "users": [...], // Array of User objects (sample: 3 items)
64
+ "categories": [...], // Array of Category objects (sample: 3 items)
65
+ "products": [...] // Array of Product objects (sample: 4 items)
66
+ }
67
+ ```
68
+
69
+ **āš ļø This is minimal starter data!** When you add new features (e.g., News app, Todo app), you'll add new arrays or replace existing ones with data specific to your app.
70
+
71
+ ### Current Data Models
72
+
73
+ #### 1. Users
74
+
75
+ Based on `User` interface from `src/types/auth.types.ts`:
76
+
77
+ ```typescript
78
+ interface User {
79
+ id: string; // Required: Unique identifier
80
+ email: string; // Required: User email
81
+ password?: string; // Optional: For authentication (mock only)
82
+ name: string; // Required: User full name
83
+ role: 'admin' | 'user' | string; // Required: User role
84
+ status: 'active' | 'inactive' | string; // Required: Account status
85
+ avatar?: string; // Optional: Avatar URL
86
+ about?: string; // Optional: User bio
87
+ location?: string; // Optional: User location
88
+ phone?: string; // Optional: Phone number
89
+ createdAt: string; // Required: ISO date string
90
+ updatedAt: string; // Required: ISO date string
91
+ }
92
+ ```
93
+
94
+ **Example:**
95
+ ```json
96
+ {
97
+ "id": "1",
98
+ "email": "admin@example.com",
99
+ "password": "admin123",
100
+ "name": "Admin User",
101
+ "role": "admin",
102
+ "status": "active",
103
+ "avatar": "https://i.pravatar.cc/150?u=admin@example.com",
104
+ "about": "System administrator with full access",
105
+ "location": "Jakarta, Indonesia",
106
+ "phone": "+62812345678",
107
+ "createdAt": "2024-01-01T00:00:00.000Z",
108
+ "updatedAt": "2024-01-01T00:00:00.000Z"
109
+ }
110
+ ```
111
+
112
+ #### 2. Categories
113
+
114
+ Based on `Category` interface from `src/types/product.types.ts`:
115
+
116
+ ```typescript
117
+ interface Category {
118
+ id: string; // Required: Unique identifier
119
+ name: string; // Required: Category name
120
+ slug: string; // Required: URL-friendly name
121
+ description: string; // Required: Category description
122
+ icon: string; // Required: Emoji or icon
123
+ color: string; // Required: Hex color code
124
+ }
125
+ ```
126
+
127
+ **Example:**
128
+ ```json
129
+ {
130
+ "id": "1",
131
+ "name": "Electronics",
132
+ "slug": "electronics",
133
+ "description": "Electronic devices and accessories",
134
+ "icon": "šŸ“±",
135
+ "color": "#3b82f6"
136
+ }
137
+ ```
138
+
139
+ #### 3. Products
140
+
141
+ Based on `Product` interface from `src/types/product.types.ts`:
142
+
143
+ ```typescript
144
+ interface Product {
145
+ id: string; // Required: Unique identifier
146
+ name: string; // Required: Product name
147
+ categoryId: string; // Required: Foreign key to categories
148
+ unit: string; // Required: Unit of measurement (pcs, kg, liter, etc)
149
+ stockSystem: number; // Required: Stock in system
150
+ stockPhysical: number; // Required: Actual physical stock
151
+ minStock: number; // Required: Minimum stock threshold
152
+ price: number; // Required: Product price
153
+ description: string; // Required: Product description
154
+ createdAt: string; // Required: ISO date string
155
+ updatedAt: string; // Required: ISO date string
156
+ }
157
+ ```
158
+
159
+ **Example:**
160
+ ```json
161
+ {
162
+ "id": "1",
163
+ "name": "iPhone 15 Pro",
164
+ "categoryId": "1",
165
+ "unit": "pcs",
166
+ "stockSystem": 50,
167
+ "stockPhysical": 48,
168
+ "minStock": 10,
169
+ "price": 15000000,
170
+ "description": "Latest iPhone with A17 Pro chip",
171
+ "createdAt": "2024-01-10T00:00:00.000Z",
172
+ "updatedAt": "2024-01-10T00:00:00.000Z"
173
+ }
174
+ ```
175
+
176
+ ## šŸŽÆ How Mock API Works
177
+
178
+ ### 1. Data Import
179
+
180
+ Each mock file imports data from `server/db.json`:
181
+
182
+ ```typescript
183
+ // src/services/mockApi/products.mock.ts
184
+ import * as db from 'server/db.json';
185
+
186
+ let products: Product[] = [...db.products]; // Clone the data
187
+ ```
188
+
189
+ ### 2. CRUD Operations
190
+
191
+ Mock files provide functions that simulate API endpoints:
192
+
193
+ ```typescript
194
+ // GET /products
195
+ export async function get<T = any>(url: string): Promise<T> {
196
+ if (url === '/products') {
197
+ return products as unknown as T;
198
+ }
199
+ // ...
200
+ }
201
+
202
+ // POST /products
203
+ export async function post<T = any>(url: string, body: CreateProductData): Promise<T> {
204
+ const newProduct = {
205
+ id: String(Date.now()),
206
+ ...body,
207
+ createdAt: new Date().toISOString(),
208
+ updatedAt: new Date().toISOString(),
209
+ };
210
+ products.push(newProduct);
211
+ return newProduct as unknown as T;
212
+ }
213
+
214
+ // PUT /products/:id
215
+ export async function put<T = any>(url: string, body: UpdateProductData): Promise<T> {
216
+ const match = url.match(/\/products\/(\w+)/);
217
+ if (match) {
218
+ const id = match[1];
219
+ const index = products.findIndex(p => p.id === id);
220
+ products[index] = { ...products[index], ...body };
221
+ return products[index] as unknown as T;
222
+ }
223
+ }
224
+
225
+ // DELETE /products/:id
226
+ export async function del<T = any>(url: string): Promise<T> {
227
+ const match = url.match(/\/products\/(\w+)/);
228
+ if (match) {
229
+ products = products.filter(p => p.id !== match[1]);
230
+ return { message: 'Deleted' } as unknown as T;
231
+ }
232
+ }
233
+ ```
234
+
235
+ ### 3. API Client Integration
236
+
237
+ The API client (`src/services/api.ts`) switches between mock and real API:
238
+
239
+ ```typescript
240
+ // Development: Uses mock API
241
+ if (__DEV__) {
242
+ // Route requests to mock API
243
+ }
244
+ // Production: Uses real API
245
+ else {
246
+ // Route requests to actual backend
247
+ }
248
+ ```
249
+
250
+ ## šŸ”§ Adding New Data Models
251
+
252
+ When building a new feature (e.g., News app, Todo app), AI agents will:
253
+ 1. Create new TypeScript interfaces
254
+ 2. **Add or replace data** in `server/db.json` with data specific to your app
255
+ 3. Create corresponding mock API files
256
+ 4. Build the UI components and screens
257
+
258
+ ### How Much Data to Add?
259
+
260
+ **Keep it minimal!** Add only **2-4 sample items** per collection:
261
+ - āœ… **2-3 items minimum** - enough to test lists and UI
262
+ - āœ… **Include 1 edge case** - low stock, inactive, etc.
263
+ - āŒ **Don't add 10+ items** - it's just sample data, not production
264
+
265
+ **Example:** For a News app, add 3 news articles (1 recent, 1 older, 1 with long title for edge case).
266
+
267
+ ### Step 1: Create TypeScript Interface
268
+
269
+ Create a new type file in `src/types/`:
270
+
271
+ ```typescript
272
+ // src/types/news.types.ts
273
+ export interface News {
274
+ id: string;
275
+ title: string;
276
+ content: string;
277
+ author: string;
278
+ imageUrl: string;
279
+ publishedAt: string;
280
+ createdAt: string;
281
+ updatedAt: string;
282
+ }
283
+ ```
284
+
285
+ ### Step 2: Add Data to db.json
286
+
287
+ Add a new array to `server/db.json` with **2-4 sample items**:
288
+
289
+ ```json
290
+ {
291
+ "users": [...], // Keep existing if still relevant, or remove
292
+ "categories": [...], // Keep existing if still relevant, or remove
293
+ "products": [...], // Keep existing if still relevant, or remove
294
+ "news": [ // New array for news feature
295
+ {
296
+ "id": "1",
297
+ "title": "Breaking News: AI Revolution",
298
+ "content": "This is the news content...",
299
+ "author": "John Doe",
300
+ "imageUrl": "https://picsum.photos/400/300?random=1",
301
+ "publishedAt": "2024-11-18T10:00:00.000Z",
302
+ "createdAt": "2024-11-18T09:00:00.000Z",
303
+ "updatedAt": "2024-11-18T09:00:00.000Z"
304
+ },
305
+ {
306
+ "id": "2",
307
+ "title": "Technology Trends 2024",
308
+ "content": "Another news article...",
309
+ "author": "Jane Smith",
310
+ "imageUrl": "https://picsum.photos/400/300?random=2",
311
+ "publishedAt": "2024-11-17T14:00:00.000Z",
312
+ "createdAt": "2024-11-17T14:00:00.000Z",
313
+ "updatedAt": "2024-11-17T14:00:00.000Z"
314
+ },
315
+ {
316
+ "id": "3",
317
+ "title": "Edge Case: This is a Very Long Title That Might Break Your UI Layout If Not Handled Properly",
318
+ "content": "Testing edge cases...",
319
+ "author": "Test User",
320
+ "imageUrl": "https://picsum.photos/400/300?random=3",
321
+ "publishedAt": "2024-11-16T08:00:00.000Z",
322
+ "createdAt": "2024-11-16T08:00:00.000Z",
323
+ "updatedAt": "2024-11-16T08:00:00.000Z"
324
+ }
325
+ ]
326
+ }
327
+ ```
328
+
329
+ **Note:** You can remove `users`, `categories`, and `products` arrays if they're not needed for your specific app.
330
+
331
+ ### Step 3: Create Mock API File
332
+
333
+ Create `src/services/mockApi/news.mock.ts`:
334
+
335
+ ```typescript
336
+ import { News } from '@/types/news.types';
337
+ import * as db from 'server/db.json';
338
+
339
+ let news: News[] = [...db.news];
340
+
341
+ export async function get<T = any>(url: string): Promise<T> {
342
+ if (url === '/news') {
343
+ return news as unknown as T;
344
+ }
345
+
346
+ // Get single news by ID
347
+ const match = url.match(/\/news\/(\w+)/);
348
+ if (match) {
349
+ const item = news.find(n => n.id === match[1]);
350
+ if (!item) throw new Error('News not found');
351
+ return item as unknown as T;
352
+ }
353
+
354
+ throw new Error(`Unknown GET /news endpoint: ${url}`);
355
+ }
356
+
357
+ export async function post<T = any>(url: string, body: Partial<News>): Promise<T> {
358
+ if (url === '/news') {
359
+ const newNews: News = {
360
+ id: String(Date.now()),
361
+ title: body.title || '',
362
+ content: body.content || '',
363
+ author: body.author || '',
364
+ imageUrl: body.imageUrl || '',
365
+ publishedAt: new Date().toISOString(),
366
+ createdAt: new Date().toISOString(),
367
+ updatedAt: new Date().toISOString(),
368
+ };
369
+ news.push(newNews);
370
+ return newNews as unknown as T;
371
+ }
372
+ throw new Error(`Unknown POST /news endpoint: ${url}`);
373
+ }
374
+
375
+ // Add PUT and DELETE similarly...
376
+ ```
377
+
378
+ ### Step 4: Create Service
379
+
380
+ Create `src/services/newsService.ts`:
381
+
382
+ ```typescript
383
+ import { apiClient } from './api';
384
+ import { News } from '@/types/news.types';
385
+
386
+ export const newsService = {
387
+ getNews: async (): Promise<News[]> => {
388
+ const response = await apiClient.get('/news');
389
+ return response.data;
390
+ },
391
+
392
+ getNewsById: async (id: string): Promise<News> => {
393
+ const response = await apiClient.get(`/news/${id}`);
394
+ return response.data;
395
+ },
396
+
397
+ createNews: async (data: Partial<News>): Promise<News> => {
398
+ const response = await apiClient.post('/news', data);
399
+ return response.data;
400
+ },
401
+ };
402
+ ```
403
+
404
+ ## šŸ’” Best Practices
405
+
406
+ ### 1. Always Match TypeScript Interfaces
407
+
408
+ **āŒ Bad - Missing required fields:**
409
+ ```json
410
+ {
411
+ "id": "1",
412
+ "name": "Product"
413
+ // Missing: categoryId, unit, stockSystem, etc.
414
+ }
415
+ ```
416
+
417
+ **āœ… Good - All fields present:**
418
+ ```json
419
+ {
420
+ "id": "1",
421
+ "name": "Product",
422
+ "categoryId": "1",
423
+ "unit": "pcs",
424
+ "stockSystem": 100,
425
+ "stockPhysical": 98,
426
+ "minStock": 10,
427
+ "price": 50000,
428
+ "description": "Description here",
429
+ "createdAt": "2024-01-01T00:00:00.000Z",
430
+ "updatedAt": "2024-01-01T00:00:00.000Z"
431
+ }
432
+ ```
433
+
434
+ ### 2. Keep Data Minimal but Realistic
435
+
436
+ **āŒ Bad - Too many items or generic data:**
437
+ ```json
438
+ {
439
+ "products": [
440
+ { "id": "1", "name": "Test Product 1" },
441
+ { "id": "2", "name": "Test Product 2" },
442
+ { "id": "3", "name": "Test Product 3" },
443
+ // ... 20 more items (too much!)
444
+ ]
445
+ }
446
+ ```
447
+
448
+ **āœ… Good - Minimal (2-4 items) with realistic data:**
449
+ ```json
450
+ {
451
+ "products": [
452
+ {
453
+ "id": "1",
454
+ "name": "Smartphone",
455
+ "description": "Latest smartphone with advanced features"
456
+ },
457
+ {
458
+ "id": "2",
459
+ "name": "Wireless Earbuds (Low Stock)",
460
+ "description": "Bluetooth earbuds - edge case for testing"
461
+ }
462
+ ]
463
+ }
464
+ ```
465
+
466
+ ### 3. Include Edge Cases (But Keep It Minimal)
467
+
468
+ Add **1-2 edge cases** to test different scenarios:
469
+
470
+ ```json
471
+ {
472
+ "products": [
473
+ {
474
+ "id": "1",
475
+ "stockSystem": 50,
476
+ "minStock": 10
477
+ // Normal stock
478
+ },
479
+ {
480
+ "id": "2",
481
+ "stockSystem": 8,
482
+ "minStock": 15
483
+ // Edge case: Low stock (stockSystem < minStock)
484
+ }
485
+ ],
486
+ "users": [
487
+ {
488
+ "id": "1",
489
+ "status": "active"
490
+ // Normal active user
491
+ },
492
+ {
493
+ "id": "2",
494
+ "status": "inactive"
495
+ // Edge case: Inactive user
496
+ }
497
+ ]
498
+ }
499
+ ```
500
+
501
+ **Remember:** Don't add every possible edge case. Just 1-2 is enough for testing!
502
+
503
+ ### 4. Use Proper Date Formats
504
+
505
+ Always use ISO 8601 format:
506
+
507
+ ```json
508
+ {
509
+ "createdAt": "2024-11-18T10:30:00.000Z",
510
+ "updatedAt": "2024-11-18T10:30:00.000Z"
511
+ }
512
+ ```
513
+
514
+ ### 5. Maintain Referential Integrity
515
+
516
+ Ensure foreign keys reference existing data:
517
+
518
+ ```json
519
+ {
520
+ "categories": [
521
+ { "id": "1", "name": "Electronics" }
522
+ ],
523
+ "products": [
524
+ {
525
+ "id": "1",
526
+ "categoryId": "1" // āœ… References existing category
527
+ },
528
+ {
529
+ "id": "2",
530
+ "categoryId": "999" // āŒ Category doesn't exist
531
+ }
532
+ ]
533
+ }
534
+ ```
535
+
536
+ ## šŸŽ“ For AI Agents
537
+
538
+ When generating code that needs data:
539
+
540
+ ### 1. Check Existing Types First
541
+
542
+ ```bash
543
+ # Read the type definition
544
+ cat src/types/product.types.ts
545
+ ```
546
+
547
+ ### 2. Check db.json Structure
548
+
549
+ ```bash
550
+ # See what data is available
551
+ cat server/db.json
552
+ ```
553
+
554
+ ### 3. Follow the Pattern
555
+
556
+ Copy existing mock API patterns:
557
+ - Read `src/services/mockApi/products.mock.ts`
558
+ - Copy the CRUD structure
559
+ - Adapt for your new data model
560
+
561
+ ### 4. Ensure Data Matches Types
562
+
563
+ **Steps:**
564
+ 1. Read TypeScript interface from `src/types/*.types.ts`
565
+ 2. Create **2-4 sample items** in `server/db.json` matching ALL required fields
566
+ 3. Include 1 edge case if applicable
567
+ 4. Create mock API file in `src/services/mockApi/`
568
+ 5. Create service in `src/services/`
569
+
570
+ **Important:** Keep data minimal! This is sample data, not production data.
571
+
572
+ ### Example Workflow
573
+
574
+ ```typescript
575
+ // 1. Type (src/types/todo.types.ts)
576
+ export interface Todo {
577
+ id: string;
578
+ title: string;
579
+ completed: boolean;
580
+ createdAt: string;
581
+ }
582
+
583
+ // 2. Data (server/db.json) - Add 2-3 minimal items
584
+ {
585
+ "todos": [
586
+ {
587
+ "id": "1",
588
+ "title": "Learn React Native",
589
+ "completed": false,
590
+ "createdAt": "2024-11-18T00:00:00.000Z"
591
+ },
592
+ {
593
+ "id": "2",
594
+ "title": "Build Todo App",
595
+ "completed": true,
596
+ "createdAt": "2024-11-17T00:00:00.000Z"
597
+ },
598
+ {
599
+ "id": "3",
600
+ "title": "Edge Case: Very Long Todo Title That Might Break UI Layout",
601
+ "completed": false,
602
+ "createdAt": "2024-11-16T00:00:00.000Z"
603
+ }
604
+ ]
605
+ }
606
+
607
+ // 3. Mock API (src/services/mockApi/todos.mock.ts)
608
+ import * as db from 'server/db.json';
609
+ let todos: Todo[] = [...db.todos];
610
+ export async function get<T = any>(url: string): Promise<T> {
611
+ if (url === '/todos') return todos as unknown as T;
612
+ // ...
613
+ }
614
+
615
+ // 4. Service (src/services/todoService.ts)
616
+ export const todoService = {
617
+ getTodos: async () => {
618
+ const response = await apiClient.get('/todos');
619
+ return response.data;
620
+ }
621
+ };
622
+ ```
623
+
624
+ ## āš ļø Common Mistakes
625
+
626
+ ### 1. Missing Fields
627
+
628
+ ```json
629
+ // āŒ Missing required fields
630
+ {
631
+ "id": "1",
632
+ "name": "Product"
633
+ }
634
+
635
+ // āœ… All required fields present
636
+ {
637
+ "id": "1",
638
+ "name": "Product",
639
+ "categoryId": "1",
640
+ "unit": "pcs",
641
+ "stockSystem": 10,
642
+ "stockPhysical": 10,
643
+ "minStock": 5,
644
+ "price": 100000,
645
+ "description": "Description",
646
+ "createdAt": "2024-01-01T00:00:00.000Z",
647
+ "updatedAt": "2024-01-01T00:00:00.000Z"
648
+ }
649
+ ```
650
+
651
+ ### 2. Wrong Data Types
652
+
653
+ ```json
654
+ // āŒ Wrong types
655
+ {
656
+ "price": "100000", // Should be number
657
+ "stockSystem": "10", // Should be number
658
+ "createdAt": 1234567890 // Should be ISO string
659
+ }
660
+
661
+ // āœ… Correct types
662
+ {
663
+ "price": 100000,
664
+ "stockSystem": 10,
665
+ "createdAt": "2024-01-01T00:00:00.000Z"
666
+ }
667
+ ```
668
+
669
+ ### 3. Too Many or Too Few Items
670
+
671
+ ```json
672
+ // āŒ Empty - can't test UI
673
+ {
674
+ "products": []
675
+ }
676
+
677
+ // āŒ Too many - unnecessary
678
+ {
679
+ "products": [
680
+ { /* 20+ items - overkill! */ }
681
+ ]
682
+ }
683
+
684
+ // āœ… Minimal sample data (2-4 items)
685
+ {
686
+ "products": [
687
+ { "id": "1", "name": "Product 1" },
688
+ { "id": "2", "name": "Product 2 (edge case)" }
689
+ ]
690
+ }
691
+ ```
692
+
693
+ ## šŸš€ Quick Reference
694
+
695
+ ### File Checklist
696
+
697
+ When adding new data model:
698
+
699
+ - [ ] Create TypeScript interface in `src/types/*.types.ts`
700
+ - [ ] Add dummy data array to `server/db.json`
701
+ - [ ] Create mock API file in `src/services/mockApi/*.mock.ts`
702
+ - [ ] Create service file in `src/services/*Service.ts`
703
+ - [ ] Test with a screen/component
704
+
705
+ ### Data Checklist
706
+
707
+ For db.json:
708
+
709
+ - [ ] **Keep it minimal** - Only 2-4 items per collection
710
+ - [ ] All required fields from TypeScript interface
711
+ - [ ] Correct data types (string, number, boolean)
712
+ - [ ] ISO date format for dates
713
+ - [ ] Valid foreign keys (if applicable)
714
+ - [ ] Realistic data (not just "test", "example")
715
+ - [ ] Include 1-2 edge cases (low stock, inactive, long text, etc.)
716
+
717
+ ## šŸ“ž Need Help?
718
+
719
+ Check these files for examples:
720
+ - `server/db.json` - Current dummy data
721
+ - `src/types/*.types.ts` - All type definitions
722
+ - `src/services/mockApi/*.mock.ts` - Mock API implementations
723
+ - `examples/service.example.ts` - Service pattern
724
+
725
+ ---
726
+
727
+ **Remember:**
728
+ - Keep `server/db.json` **minimal** (2-4 items per collection)
729
+ - This is **sample/starter data**, not production data
730
+ - Data will be replaced when AI generates new features
731
+ - Mock API should feel like a real API - keep data realistic and type-safe!
@@ -3,12 +3,15 @@
3
3
  "componentsPath": "src/components",
4
4
  "hooksPath": "src/hooks",
5
5
  "servicesPath": "src/services",
6
+ "mockApiPath": "src/services/mockApi",
6
7
  "storePath": "src/store",
7
8
  "typesPath": "src/types",
8
9
  "utilsPath": "src/utils",
9
10
  "themePath": "src/theme",
11
+ "mockDataPath": "server/db.json",
10
12
  "examples": "examples",
11
13
  "aiGuide": "AI_GUIDE.md",
14
+ "serverGuide": "SERVER_GUIDE.md",
12
15
  "rules": "GENERATE_RULES.md",
13
16
  "conventions": "CONVENTIONS.md"
14
17
  }
@@ -0,0 +1,120 @@
1
+ {
2
+ "users": [
3
+ {
4
+ "id": "1",
5
+ "email": "admin@example.com",
6
+ "password": "admin123",
7
+ "name": "Admin User",
8
+ "role": "admin",
9
+ "status": "active",
10
+ "avatar": "https://i.pravatar.cc/150?u=admin@example.com",
11
+ "about": "System administrator",
12
+ "location": "Jakarta, Indonesia",
13
+ "phone": "+62812345678",
14
+ "createdAt": "2024-01-01T00:00:00.000Z",
15
+ "updatedAt": "2024-01-01T00:00:00.000Z"
16
+ },
17
+ {
18
+ "id": "2",
19
+ "email": "user@example.com",
20
+ "password": "user123",
21
+ "name": "John Doe",
22
+ "role": "user",
23
+ "status": "active",
24
+ "avatar": "https://i.pravatar.cc/150?u=user@example.com",
25
+ "createdAt": "2024-01-15T10:30:00.000Z",
26
+ "updatedAt": "2024-01-15T10:30:00.000Z"
27
+ },
28
+ {
29
+ "id": "3",
30
+ "email": "inactive@example.com",
31
+ "password": "user123",
32
+ "name": "Jane Smith",
33
+ "role": "user",
34
+ "status": "inactive",
35
+ "avatar": "https://i.pravatar.cc/150?u=inactive@example.com",
36
+ "createdAt": "2024-02-01T08:00:00.000Z",
37
+ "updatedAt": "2024-02-01T08:00:00.000Z"
38
+ }
39
+ ],
40
+ "categories": [
41
+ {
42
+ "id": "1",
43
+ "name": "Electronics",
44
+ "slug": "electronics",
45
+ "description": "Electronic devices and accessories",
46
+ "icon": "šŸ“±",
47
+ "color": "#3b82f6"
48
+ },
49
+ {
50
+ "id": "2",
51
+ "name": "Food & Beverage",
52
+ "slug": "food-beverage",
53
+ "description": "Food items and beverages",
54
+ "icon": "šŸ”",
55
+ "color": "#ef4444"
56
+ },
57
+ {
58
+ "id": "3",
59
+ "name": "Clothing",
60
+ "slug": "clothing",
61
+ "description": "Clothing and fashion items",
62
+ "icon": "šŸ‘•",
63
+ "color": "#8b5cf6"
64
+ }
65
+ ],
66
+ "products": [
67
+ {
68
+ "id": "1",
69
+ "name": "Smartphone",
70
+ "categoryId": "1",
71
+ "unit": "pcs",
72
+ "stockSystem": 50,
73
+ "stockPhysical": 48,
74
+ "minStock": 10,
75
+ "price": 5000000,
76
+ "description": "Latest smartphone with advanced features",
77
+ "createdAt": "2024-01-10T00:00:00.000Z",
78
+ "updatedAt": "2024-01-10T00:00:00.000Z"
79
+ },
80
+ {
81
+ "id": "2",
82
+ "name": "Wireless Earbuds",
83
+ "categoryId": "1",
84
+ "unit": "pcs",
85
+ "stockSystem": 8,
86
+ "stockPhysical": 8,
87
+ "minStock": 15,
88
+ "price": 500000,
89
+ "description": "Bluetooth earbuds with noise cancellation (Low Stock)",
90
+ "createdAt": "2024-01-15T00:00:00.000Z",
91
+ "updatedAt": "2024-01-15T00:00:00.000Z"
92
+ },
93
+ {
94
+ "id": "3",
95
+ "name": "Mineral Water",
96
+ "categoryId": "2",
97
+ "unit": "bottle",
98
+ "stockSystem": 200,
99
+ "stockPhysical": 195,
100
+ "minStock": 50,
101
+ "price": 5000,
102
+ "description": "Pure mineral water 600ml",
103
+ "createdAt": "2024-01-20T00:00:00.000Z",
104
+ "updatedAt": "2024-01-20T00:00:00.000Z"
105
+ },
106
+ {
107
+ "id": "4",
108
+ "name": "T-Shirt",
109
+ "categoryId": "3",
110
+ "unit": "pcs",
111
+ "stockSystem": 100,
112
+ "stockPhysical": 98,
113
+ "minStock": 20,
114
+ "price": 150000,
115
+ "description": "Cotton t-shirt, various colors",
116
+ "createdAt": "2024-01-25T00:00:00.000Z",
117
+ "updatedAt": "2024-01-25T00:00:00.000Z"
118
+ }
119
+ ]
120
+ }