appiq-solution 1.4.2 → 1.4.4

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.
Files changed (94) hide show
  1. package/#Tools/APPIQ-METHOD/.cursor/commands/analyze.md +1 -1
  2. package/#Tools/APPIQ-METHOD/.cursor/commands/appiq.md +1 -1
  3. package/#Tools/APPIQ-METHOD/.cursor/commands/help.md +1 -1
  4. package/#Tools/APPIQ-METHOD/.cursor/commands/story.md +1 -1
  5. package/#Tools/APPIQ-METHOD/bmad-core/agents/init-flow-po.md +219 -0
  6. package/#Tools/APPIQ-METHOD/commands/analyze.md +1 -1
  7. package/#Tools/APPIQ-METHOD/commands/appiq.md +1 -1
  8. package/#Tools/APPIQ-METHOD/commands/help.md +1 -1
  9. package/#Tools/APPIQ-METHOD/commands/story.md +1 -1
  10. package/#Tools/APPIQ-METHOD/package.json +1 -1
  11. package/#Tools/APPIQ-METHOD/tools/appiq-installer.js +196 -104
  12. package/#Tools/APPIQ-METHOD/tools/cli.js +1 -1
  13. package/#Tools/APPIQ-METHOD/tools/setup-ide-commands.js +40 -37
  14. package/#Tools/APPIQ-METHOD/tools/smart-installer.js +16 -13
  15. package/bmad-core/agent-teams/team-all.yaml +14 -0
  16. package/bmad-core/agent-teams/team-flutter-mobile.yaml +114 -0
  17. package/bmad-core/agent-teams/team-fullstack.yaml +28 -0
  18. package/bmad-core/agent-teams/team-ide-minimal.yaml +10 -0
  19. package/bmad-core/agent-teams/team-no-ui.yaml +13 -0
  20. package/bmad-core/agents/analyst.md +85 -0
  21. package/bmad-core/agents/architect.md +90 -0
  22. package/bmad-core/agents/bmad-master.md +108 -0
  23. package/bmad-core/agents/bmad-orchestrator.md +150 -0
  24. package/bmad-core/agents/bmad-smart-launcher.md +170 -0
  25. package/bmad-core/agents/dev.md +95 -0
  26. package/bmad-core/agents/init-flow-po.md +219 -0
  27. package/bmad-core/agents/pm.md +85 -0
  28. package/bmad-core/agents/po.md +76 -0
  29. package/bmad-core/agents/qa.md +86 -0
  30. package/bmad-core/agents/sm.md +67 -0
  31. package/bmad-core/agents/ux-expert.md +71 -0
  32. package/bmad-core/bmad-core/user-guide.md +0 -0
  33. package/bmad-core/checklists/architect-checklist.md +443 -0
  34. package/bmad-core/checklists/change-checklist.md +182 -0
  35. package/bmad-core/checklists/pm-checklist.md +375 -0
  36. package/bmad-core/checklists/po-master-checklist.md +441 -0
  37. package/bmad-core/checklists/security-validation-checklist.md +332 -0
  38. package/bmad-core/checklists/story-dod-checklist.md +101 -0
  39. package/bmad-core/checklists/story-draft-checklist.md +156 -0
  40. package/bmad-core/core-config.yaml +20 -0
  41. package/bmad-core/core-config.yaml.bak +20 -0
  42. package/bmad-core/data/backend-services-integration.md +686 -0
  43. package/bmad-core/data/bmad-kb.md +803 -0
  44. package/bmad-core/data/brainstorming-techniques.md +36 -0
  45. package/bmad-core/data/elicitation-methods.md +134 -0
  46. package/bmad-core/data/shadcn-ui-integration.md +388 -0
  47. package/bmad-core/data/technical-preferences.md +149 -0
  48. package/bmad-core/enhanced-ide-development-workflow.md +43 -0
  49. package/bmad-core/tasks/advanced-elicitation.md +117 -0
  50. package/bmad-core/tasks/brownfield-create-epic.md +160 -0
  51. package/bmad-core/tasks/brownfield-create-story.md +147 -0
  52. package/bmad-core/tasks/correct-course.md +70 -0
  53. package/bmad-core/tasks/create-brownfield-story.md +304 -0
  54. package/bmad-core/tasks/create-deep-research-prompt.md +289 -0
  55. package/bmad-core/tasks/create-flutter-story.md +197 -0
  56. package/bmad-core/tasks/create-next-story.md +112 -0
  57. package/bmad-core/tasks/document-project.md +341 -0
  58. package/bmad-core/tasks/facilitate-brainstorming-session.md +136 -0
  59. package/bmad-core/tasks/generate-ai-frontend-prompt.md +51 -0
  60. package/bmad-core/tasks/index-docs.md +179 -0
  61. package/bmad-core/tasks/intelligent-epic-creation.md +234 -0
  62. package/bmad-core/tasks/kb-mode-interaction.md +75 -0
  63. package/bmad-core/tasks/review-story.md +145 -0
  64. package/bmad-core/tasks/shard-doc.md +187 -0
  65. package/bmad-core/tasks/smart-project-analysis.md +289 -0
  66. package/bmad-core/tasks/validate-next-story.md +134 -0
  67. package/bmad-core/templates/architecture-tmpl.yaml +650 -0
  68. package/bmad-core/templates/brainstorming-output-tmpl.yaml +156 -0
  69. package/bmad-core/templates/brownfield-architecture-tmpl.yaml +476 -0
  70. package/bmad-core/templates/brownfield-prd-tmpl.yaml +280 -0
  71. package/bmad-core/templates/competitor-analysis-tmpl.yaml +293 -0
  72. package/bmad-core/templates/flutter-mobile-prd-tmpl.yaml +330 -0
  73. package/bmad-core/templates/flutter-story-tmpl.yaml +376 -0
  74. package/bmad-core/templates/flutter-ui-spec-tmpl.yaml +415 -0
  75. package/bmad-core/templates/front-end-architecture-tmpl.yaml +206 -0
  76. package/bmad-core/templates/front-end-spec-tmpl.yaml +349 -0
  77. package/bmad-core/templates/fullstack-architecture-tmpl.yaml +812 -0
  78. package/bmad-core/templates/market-research-tmpl.yaml +252 -0
  79. package/bmad-core/templates/prd-tmpl.yaml +202 -0
  80. package/bmad-core/templates/project-brief-tmpl.yaml +221 -0
  81. package/bmad-core/templates/story-tmpl.yaml +137 -0
  82. package/bmad-core/user-guide.md +251 -0
  83. package/bmad-core/workflows/brownfield-fullstack.yaml +311 -0
  84. package/bmad-core/workflows/brownfield-service.yaml +187 -0
  85. package/bmad-core/workflows/brownfield-ui.yaml +197 -0
  86. package/bmad-core/workflows/greenfield-fullstack.yaml +284 -0
  87. package/bmad-core/workflows/greenfield-service.yaml +206 -0
  88. package/bmad-core/workflows/greenfield-ui.yaml +235 -0
  89. package/bmad-core/working-in-the-brownfield.md +373 -0
  90. package/package.json +1 -1
  91. package/tools/appiq-installer.js +196 -104
  92. package/tools/cli.js +1 -1
  93. package/tools/setup-ide-commands.js +40 -37
  94. package/tools/smart-installer.js +16 -13
@@ -0,0 +1,686 @@
1
+ # Backend Services Integration Guide
2
+
3
+ ## 📋 Overview
4
+
5
+ This guide provides comprehensive integration instructions for modern backend services including Firebase, Supabase, and traditional backend solutions with MCP tool integration for enhanced development workflows.
6
+
7
+ ## 🔥 Firebase Integration
8
+
9
+ ### Firebase Services Overview
10
+
11
+ Firebase provides a comprehensive suite of backend services:
12
+ - **Authentication**: Multi-provider authentication system
13
+ - **Firestore**: NoSQL document database with real-time updates
14
+ - **Realtime Database**: Real-time synchronized database
15
+ - **Storage**: File storage and management
16
+ - **Functions**: Serverless backend logic
17
+ - **Hosting**: Web application hosting
18
+ - **Analytics**: User behavior analytics
19
+ - **Crashlytics**: Crash reporting and analysis
20
+
21
+ ### Firebase Setup
22
+
23
+ #### 1. Project Configuration
24
+ ```javascript
25
+ // firebase.config.js
26
+ import { initializeApp } from 'firebase/app';
27
+ import { getAuth } from 'firebase/auth';
28
+ import { getFirestore } from 'firebase/firestore';
29
+ import { getStorage } from 'firebase/storage';
30
+ import { getFunctions } from 'firebase/functions';
31
+
32
+ const firebaseConfig = {
33
+ apiKey: process.env.NEXT_PUBLIC_FIREBASE_API_KEY,
34
+ authDomain: process.env.NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN,
35
+ projectId: process.env.NEXT_PUBLIC_FIREBASE_PROJECT_ID,
36
+ storageBucket: process.env.NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET,
37
+ messagingSenderId: process.env.NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID,
38
+ appId: process.env.NEXT_PUBLIC_FIREBASE_APP_ID
39
+ };
40
+
41
+ // Initialize Firebase
42
+ const app = initializeApp(firebaseConfig);
43
+
44
+ // Initialize Firebase services
45
+ export const auth = getAuth(app);
46
+ export const db = getFirestore(app);
47
+ export const storage = getStorage(app);
48
+ export const functions = getFunctions(app);
49
+
50
+ export default app;
51
+ ```
52
+
53
+ #### 2. Authentication Service
54
+ ```typescript
55
+ // services/firebase-auth.service.ts
56
+ import {
57
+ signInWithEmailAndPassword,
58
+ createUserWithEmailAndPassword,
59
+ signOut,
60
+ onAuthStateChanged,
61
+ GoogleAuthProvider,
62
+ signInWithPopup
63
+ } from 'firebase/auth';
64
+ import { auth } from '../config/firebase.config';
65
+
66
+ export class FirebaseAuthService {
67
+ // Email/Password Authentication
68
+ async signInWithEmail(email: string, password: string) {
69
+ try {
70
+ const userCredential = await signInWithEmailAndPassword(auth, email, password);
71
+ return { user: userCredential.user, error: null };
72
+ } catch (error) {
73
+ return { user: null, error: error.message };
74
+ }
75
+ }
76
+
77
+ async signUpWithEmail(email: string, password: string) {
78
+ try {
79
+ const userCredential = await createUserWithEmailAndPassword(auth, email, password);
80
+ return { user: userCredential.user, error: null };
81
+ } catch (error) {
82
+ return { user: null, error: error.message };
83
+ }
84
+ }
85
+
86
+ // Google Authentication
87
+ async signInWithGoogle() {
88
+ try {
89
+ const provider = new GoogleAuthProvider();
90
+ const userCredential = await signInWithPopup(auth, provider);
91
+ return { user: userCredential.user, error: null };
92
+ } catch (error) {
93
+ return { user: null, error: error.message };
94
+ }
95
+ }
96
+
97
+ // Sign Out
98
+ async signOut() {
99
+ try {
100
+ await signOut(auth);
101
+ return { success: true, error: null };
102
+ } catch (error) {
103
+ return { success: false, error: error.message };
104
+ }
105
+ }
106
+
107
+ // Auth State Observer
108
+ onAuthStateChange(callback: (user: any) => void) {
109
+ return onAuthStateChanged(auth, callback);
110
+ }
111
+ }
112
+ ```
113
+
114
+ #### 3. Firestore Database Service
115
+ ```typescript
116
+ // services/firebase-firestore.service.ts
117
+ import {
118
+ collection,
119
+ doc,
120
+ getDocs,
121
+ getDoc,
122
+ addDoc,
123
+ updateDoc,
124
+ deleteDoc,
125
+ query,
126
+ where,
127
+ orderBy,
128
+ limit,
129
+ onSnapshot
130
+ } from 'firebase/firestore';
131
+ import { db } from '../config/firebase.config';
132
+
133
+ export class FirestoreService<T> {
134
+ constructor(private collectionName: string) {}
135
+
136
+ // Create document
137
+ async create(data: Omit<T, 'id'>): Promise<string> {
138
+ try {
139
+ const docRef = await addDoc(collection(db, this.collectionName), data);
140
+ return docRef.id;
141
+ } catch (error) {
142
+ throw new Error(`Failed to create document: ${error.message}`);
143
+ }
144
+ }
145
+
146
+ // Get all documents
147
+ async getAll(): Promise<T[]> {
148
+ try {
149
+ const querySnapshot = await getDocs(collection(db, this.collectionName));
150
+ return querySnapshot.docs.map(doc => ({
151
+ id: doc.id,
152
+ ...doc.data()
153
+ } as T));
154
+ } catch (error) {
155
+ throw new Error(`Failed to get documents: ${error.message}`);
156
+ }
157
+ }
158
+
159
+ // Get document by ID
160
+ async getById(id: string): Promise<T | null> {
161
+ try {
162
+ const docRef = doc(db, this.collectionName, id);
163
+ const docSnap = await getDoc(docRef);
164
+
165
+ if (docSnap.exists()) {
166
+ return { id: docSnap.id, ...docSnap.data() } as T;
167
+ }
168
+ return null;
169
+ } catch (error) {
170
+ throw new Error(`Failed to get document: ${error.message}`);
171
+ }
172
+ }
173
+
174
+ // Update document
175
+ async update(id: string, data: Partial<T>): Promise<void> {
176
+ try {
177
+ const docRef = doc(db, this.collectionName, id);
178
+ await updateDoc(docRef, data);
179
+ } catch (error) {
180
+ throw new Error(`Failed to update document: ${error.message}`);
181
+ }
182
+ }
183
+
184
+ // Delete document
185
+ async delete(id: string): Promise<void> {
186
+ try {
187
+ const docRef = doc(db, this.collectionName, id);
188
+ await deleteDoc(docRef);
189
+ } catch (error) {
190
+ throw new Error(`Failed to delete document: ${error.message}`);
191
+ }
192
+ }
193
+
194
+ // Real-time listener
195
+ onSnapshot(callback: (data: T[]) => void) {
196
+ const q = collection(db, this.collectionName);
197
+ return onSnapshot(q, (querySnapshot) => {
198
+ const data = querySnapshot.docs.map(doc => ({
199
+ id: doc.id,
200
+ ...doc.data()
201
+ } as T));
202
+ callback(data);
203
+ });
204
+ }
205
+
206
+ // Query with filters
207
+ async query(filters: { field: string; operator: any; value: any }[]): Promise<T[]> {
208
+ try {
209
+ let q = collection(db, this.collectionName);
210
+
211
+ filters.forEach(filter => {
212
+ q = query(q, where(filter.field, filter.operator, filter.value));
213
+ });
214
+
215
+ const querySnapshot = await getDocs(q);
216
+ return querySnapshot.docs.map(doc => ({
217
+ id: doc.id,
218
+ ...doc.data()
219
+ } as T));
220
+ } catch (error) {
221
+ throw new Error(`Failed to query documents: ${error.message}`);
222
+ }
223
+ }
224
+ }
225
+ ```
226
+
227
+ ### Firebase MCP Integration
228
+
229
+ ```typescript
230
+ // MCP Firebase integration
231
+ interface FirebaseMCPIntegration {
232
+ // Firebase project management
233
+ createProject(config: FirebaseConfig): Promise<ProjectResult>;
234
+ deployFunctions(functions: CloudFunction[]): Promise<DeploymentResult>;
235
+ configureFirestore(rules: FirestoreRules): Promise<ConfigResult>;
236
+ setupAuthentication(providers: AuthProvider[]): Promise<AuthSetupResult>;
237
+
238
+ // Development helpers
239
+ generateFirebaseConfig(): Promise<ConfigCode>;
240
+ createServiceBoilerplate(service: FirebaseService): Promise<ServiceCode>;
241
+ optimizeFirestoreQueries(queries: FirestoreQuery[]): Promise<OptimizationSuggestions>;
242
+ }
243
+ ```
244
+
245
+ ## 🚀 Supabase Integration
246
+
247
+ ### Supabase Services Overview
248
+
249
+ Supabase provides an open-source Firebase alternative:
250
+ - **Database**: PostgreSQL with Row Level Security (RLS)
251
+ - **Authentication**: Multi-provider auth with JWT tokens
252
+ - **Storage**: File storage with CDN
253
+ - **Edge Functions**: Deno-based serverless functions
254
+ - **Real-time**: Real-time subscriptions
255
+ - **API**: Auto-generated REST and GraphQL APIs
256
+
257
+ ### Supabase Setup
258
+
259
+ #### 1. Project Configuration
260
+ ```typescript
261
+ // supabase.config.ts
262
+ import { createClient } from '@supabase/supabase-js';
263
+
264
+ const supabaseUrl = process.env.NEXT_PUBLIC_SUPABASE_URL!;
265
+ const supabaseAnonKey = process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!;
266
+
267
+ export const supabase = createClient(supabaseUrl, supabaseAnonKey, {
268
+ auth: {
269
+ autoRefreshToken: true,
270
+ persistSession: true,
271
+ detectSessionInUrl: true
272
+ }
273
+ });
274
+
275
+ // Type-safe database interface
276
+ export type Database = {
277
+ public: {
278
+ Tables: {
279
+ users: {
280
+ Row: {
281
+ id: string;
282
+ email: string;
283
+ name: string;
284
+ created_at: string;
285
+ updated_at: string;
286
+ };
287
+ Insert: {
288
+ id?: string;
289
+ email: string;
290
+ name: string;
291
+ created_at?: string;
292
+ updated_at?: string;
293
+ };
294
+ Update: {
295
+ id?: string;
296
+ email?: string;
297
+ name?: string;
298
+ updated_at?: string;
299
+ };
300
+ };
301
+ };
302
+ };
303
+ };
304
+ ```
305
+
306
+ #### 2. Authentication Service
307
+ ```typescript
308
+ // services/supabase-auth.service.ts
309
+ import { supabase } from '../config/supabase.config';
310
+
311
+ export class SupabaseAuthService {
312
+ // Email/Password Authentication
313
+ async signInWithEmail(email: string, password: string) {
314
+ try {
315
+ const { data, error } = await supabase.auth.signInWithPassword({
316
+ email,
317
+ password
318
+ });
319
+ return { user: data.user, session: data.session, error };
320
+ } catch (error) {
321
+ return { user: null, session: null, error: error.message };
322
+ }
323
+ }
324
+
325
+ async signUpWithEmail(email: string, password: string) {
326
+ try {
327
+ const { data, error } = await supabase.auth.signUp({
328
+ email,
329
+ password
330
+ });
331
+ return { user: data.user, session: data.session, error };
332
+ } catch (error) {
333
+ return { user: null, session: null, error: error.message };
334
+ }
335
+ }
336
+
337
+ // OAuth Authentication
338
+ async signInWithProvider(provider: 'google' | 'github' | 'discord') {
339
+ try {
340
+ const { data, error } = await supabase.auth.signInWithOAuth({
341
+ provider,
342
+ options: {
343
+ redirectTo: `${window.location.origin}/auth/callback`
344
+ }
345
+ });
346
+ return { data, error };
347
+ } catch (error) {
348
+ return { data: null, error: error.message };
349
+ }
350
+ }
351
+
352
+ // Sign Out
353
+ async signOut() {
354
+ try {
355
+ const { error } = await supabase.auth.signOut();
356
+ return { success: !error, error };
357
+ } catch (error) {
358
+ return { success: false, error: error.message };
359
+ }
360
+ }
361
+
362
+ // Get current session
363
+ async getSession() {
364
+ try {
365
+ const { data: { session }, error } = await supabase.auth.getSession();
366
+ return { session, error };
367
+ } catch (error) {
368
+ return { session: null, error: error.message };
369
+ }
370
+ }
371
+
372
+ // Auth state change listener
373
+ onAuthStateChange(callback: (event: string, session: any) => void) {
374
+ return supabase.auth.onAuthStateChange(callback);
375
+ }
376
+ }
377
+ ```
378
+
379
+ #### 3. Database Service
380
+ ```typescript
381
+ // services/supabase-database.service.ts
382
+ import { supabase } from '../config/supabase.config';
383
+ import type { Database } from '../config/supabase.config';
384
+
385
+ type Tables = Database['public']['Tables'];
386
+
387
+ export class SupabaseService<T extends keyof Tables> {
388
+ constructor(private tableName: T) {}
389
+
390
+ // Create record
391
+ async create(data: Tables[T]['Insert']) {
392
+ try {
393
+ const { data: result, error } = await supabase
394
+ .from(this.tableName)
395
+ .insert(data)
396
+ .select()
397
+ .single();
398
+
399
+ if (error) throw error;
400
+ return { data: result, error: null };
401
+ } catch (error) {
402
+ return { data: null, error: error.message };
403
+ }
404
+ }
405
+
406
+ // Get all records
407
+ async getAll() {
408
+ try {
409
+ const { data, error } = await supabase
410
+ .from(this.tableName)
411
+ .select('*');
412
+
413
+ if (error) throw error;
414
+ return { data, error: null };
415
+ } catch (error) {
416
+ return { data: null, error: error.message };
417
+ }
418
+ }
419
+
420
+ // Get record by ID
421
+ async getById(id: string) {
422
+ try {
423
+ const { data, error } = await supabase
424
+ .from(this.tableName)
425
+ .select('*')
426
+ .eq('id', id)
427
+ .single();
428
+
429
+ if (error) throw error;
430
+ return { data, error: null };
431
+ } catch (error) {
432
+ return { data: null, error: error.message };
433
+ }
434
+ }
435
+
436
+ // Update record
437
+ async update(id: string, data: Tables[T]['Update']) {
438
+ try {
439
+ const { data: result, error } = await supabase
440
+ .from(this.tableName)
441
+ .update(data)
442
+ .eq('id', id)
443
+ .select()
444
+ .single();
445
+
446
+ if (error) throw error;
447
+ return { data: result, error: null };
448
+ } catch (error) {
449
+ return { data: null, error: error.message };
450
+ }
451
+ }
452
+
453
+ // Delete record
454
+ async delete(id: string) {
455
+ try {
456
+ const { error } = await supabase
457
+ .from(this.tableName)
458
+ .delete()
459
+ .eq('id', id);
460
+
461
+ if (error) throw error;
462
+ return { success: true, error: null };
463
+ } catch (error) {
464
+ return { success: false, error: error.message };
465
+ }
466
+ }
467
+
468
+ // Real-time subscription
469
+ subscribe(callback: (payload: any) => void) {
470
+ return supabase
471
+ .channel(`public:${this.tableName}`)
472
+ .on('postgres_changes',
473
+ { event: '*', schema: 'public', table: this.tableName },
474
+ callback
475
+ )
476
+ .subscribe();
477
+ }
478
+
479
+ // Query with filters
480
+ async query(filters: { column: string; operator: string; value: any }[]) {
481
+ try {
482
+ let query = supabase.from(this.tableName).select('*');
483
+
484
+ filters.forEach(filter => {
485
+ query = query.filter(filter.column, filter.operator, filter.value);
486
+ });
487
+
488
+ const { data, error } = await query;
489
+ if (error) throw error;
490
+ return { data, error: null };
491
+ } catch (error) {
492
+ return { data: null, error: error.message };
493
+ }
494
+ }
495
+ }
496
+ ```
497
+
498
+ ### Supabase MCP Integration
499
+
500
+ ```typescript
501
+ // MCP Supabase integration
502
+ interface SupabaseMCPIntegration {
503
+ // Project management
504
+ createProject(config: SupabaseConfig): Promise<ProjectResult>;
505
+ generateTypes(databaseUrl: string): Promise<TypeDefinitions>;
506
+ setupRLS(policies: RLSPolicy[]): Promise<PolicyResult>;
507
+ deployEdgeFunctions(functions: EdgeFunction[]): Promise<DeploymentResult>;
508
+
509
+ // Development helpers
510
+ generateSupabaseClient(): Promise<ClientCode>;
511
+ createServiceBoilerplate(table: string): Promise<ServiceCode>;
512
+ optimizeQueries(queries: SupabaseQuery[]): Promise<OptimizationSuggestions>;
513
+ }
514
+ ```
515
+
516
+ ## 🏗️ Traditional Backend Integration
517
+
518
+ ### Node.js + Express Setup
519
+
520
+ ```typescript
521
+ // server.ts
522
+ import express from 'express';
523
+ import cors from 'cors';
524
+ import helmet from 'helmet';
525
+ import rateLimit from 'express-rate-limit';
526
+ import { authRouter } from './routes/auth.routes';
527
+ import { userRouter } from './routes/user.routes';
528
+
529
+ const app = express();
530
+
531
+ // Security middleware
532
+ app.use(helmet());
533
+ app.use(cors({
534
+ origin: process.env.FRONTEND_URL,
535
+ credentials: true
536
+ }));
537
+
538
+ // Rate limiting
539
+ const limiter = rateLimit({
540
+ windowMs: 15 * 60 * 1000, // 15 minutes
541
+ max: 100 // limit each IP to 100 requests per windowMs
542
+ });
543
+ app.use(limiter);
544
+
545
+ // Body parsing
546
+ app.use(express.json({ limit: '10mb' }));
547
+ app.use(express.urlencoded({ extended: true }));
548
+
549
+ // Routes
550
+ app.use('/api/auth', authRouter);
551
+ app.use('/api/users', userRouter);
552
+
553
+ // Error handling middleware
554
+ app.use((err: any, req: any, res: any, next: any) => {
555
+ console.error(err.stack);
556
+ res.status(500).json({ error: 'Something went wrong!' });
557
+ });
558
+
559
+ const PORT = process.env.PORT || 3001;
560
+ app.listen(PORT, () => {
561
+ console.log(`Server running on port ${PORT}`);
562
+ });
563
+ ```
564
+
565
+ ### Database Integration (PostgreSQL)
566
+
567
+ ```typescript
568
+ // database/connection.ts
569
+ import { Pool } from 'pg';
570
+
571
+ const pool = new Pool({
572
+ user: process.env.DB_USER,
573
+ host: process.env.DB_HOST,
574
+ database: process.env.DB_NAME,
575
+ password: process.env.DB_PASSWORD,
576
+ port: parseInt(process.env.DB_PORT || '5432'),
577
+ ssl: process.env.NODE_ENV === 'production' ? { rejectUnauthorized: false } : false
578
+ });
579
+
580
+ export class DatabaseService {
581
+ async query(text: string, params?: any[]) {
582
+ const client = await pool.connect();
583
+ try {
584
+ const result = await client.query(text, params);
585
+ return result;
586
+ } finally {
587
+ client.release();
588
+ }
589
+ }
590
+
591
+ async transaction(queries: { text: string; params?: any[] }[]) {
592
+ const client = await pool.connect();
593
+ try {
594
+ await client.query('BEGIN');
595
+ const results = [];
596
+
597
+ for (const query of queries) {
598
+ const result = await client.query(query.text, query.params);
599
+ results.push(result);
600
+ }
601
+
602
+ await client.query('COMMIT');
603
+ return results;
604
+ } catch (error) {
605
+ await client.query('ROLLBACK');
606
+ throw error;
607
+ } finally {
608
+ client.release();
609
+ }
610
+ }
611
+ }
612
+ ```
613
+
614
+ ## 🔧 MCP Tool Integration
615
+
616
+ ### Backend Service Selection
617
+
618
+ ```typescript
619
+ // MCP integration for backend service selection
620
+ interface BackendServiceMCP {
621
+ analyzeRequirements(requirements: ProjectRequirements): Promise<ServiceRecommendation>;
622
+ compareServices(services: BackendService[]): Promise<ComparisonMatrix>;
623
+ generateIntegration(service: BackendService): Promise<IntegrationCode>;
624
+ optimizeConfiguration(config: ServiceConfig): Promise<OptimizedConfig>;
625
+ }
626
+
627
+ // Usage example
628
+ const mcp = new BackendServiceMCP();
629
+
630
+ const recommendation = await mcp.analyzeRequirements({
631
+ scalability: 'high',
632
+ realtime: true,
633
+ authentication: 'multi-provider',
634
+ database: 'relational',
635
+ budget: 'medium'
636
+ });
637
+
638
+ // Recommendation might suggest Supabase for this combination
639
+ ```
640
+
641
+ ### Code Generation
642
+
643
+ ```typescript
644
+ // Automated service integration code generation
645
+ interface CodeGenerationMCP {
646
+ generateAuthService(provider: AuthProvider): Promise<ServiceCode>;
647
+ generateDatabaseService(schema: DatabaseSchema): Promise<ServiceCode>;
648
+ generateAPIRoutes(endpoints: APIEndpoint[]): Promise<RouteCode>;
649
+ generateMigrations(changes: SchemaChange[]): Promise<MigrationCode>;
650
+ }
651
+ ```
652
+
653
+ ## 📋 Best Practices
654
+
655
+ ### Security
656
+ - **Environment Variables**: Store sensitive data in environment variables
657
+ - **Authentication**: Implement proper JWT token management
658
+ - **Authorization**: Use Row Level Security (RLS) for database access
659
+ - **Input Validation**: Validate all inputs on both client and server
660
+ - **Rate Limiting**: Implement rate limiting to prevent abuse
661
+ - **HTTPS**: Always use HTTPS in production
662
+ - **CORS**: Configure CORS properly for your domain
663
+
664
+ ### Performance
665
+ - **Caching**: Implement caching strategies for frequently accessed data
666
+ - **Database Indexing**: Create proper database indexes
667
+ - **Connection Pooling**: Use connection pooling for database connections
668
+ - **CDN**: Use CDN for static assets
669
+ - **Compression**: Enable gzip compression
670
+ - **Monitoring**: Implement proper monitoring and logging
671
+
672
+ ### Development Workflow
673
+ - **Type Safety**: Use TypeScript for type safety
674
+ - **Error Handling**: Implement comprehensive error handling
675
+ - **Testing**: Write unit and integration tests
676
+ - **Documentation**: Document APIs with OpenAPI/Swagger
677
+ - **Version Control**: Use semantic versioning for APIs
678
+ - **CI/CD**: Implement automated testing and deployment
679
+
680
+ ### Cost Optimization
681
+ - **Resource Monitoring**: Monitor resource usage and costs
682
+ - **Auto-scaling**: Implement auto-scaling for variable loads
683
+ - **Cleanup**: Regular cleanup of unused resources
684
+ - **Optimization**: Regular performance and cost optimization reviews
685
+
686
+ This comprehensive guide ensures proper integration of modern backend services with the BMAD framework, providing developers with the tools and knowledge needed to build scalable, secure, and maintainable applications.