Darkxx91 commited on
Commit
bbad7d8
·
verified ·
1 Parent(s): b420ea0

"Create a modular HTML application using the Module Pattern with IIFE (Immediately Invoked Function Expressions) to simulate a component-based architecture. Include a service layer, state management using closures, and event-driven communication between modules. Structure: App.init() → ModuleA.init() → ModuleB.init() with dependency injection." - Initial Deployment

Browse files
Files changed (2) hide show
  1. README.md +6 -4
  2. index.html +574 -19
README.md CHANGED
@@ -1,10 +1,12 @@
1
  ---
2
- title: Modular Component Architecture
3
- emoji: 🔥
4
  colorFrom: gray
5
- colorTo: pink
6
  sdk: static
7
  pinned: false
 
 
8
  ---
9
 
10
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
  ---
2
+ title: modular-component-architecture
3
+ emoji: 🐳
4
  colorFrom: gray
5
+ colorTo: gray
6
  sdk: static
7
  pinned: false
8
+ tags:
9
+ - deepsite
10
  ---
11
 
12
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
index.html CHANGED
@@ -1,19 +1,574 @@
1
- <!doctype html>
2
- <html>
3
- <head>
4
- <meta charset="utf-8" />
5
- <meta name="viewport" content="width=device-width" />
6
- <title>My static Space</title>
7
- <link rel="stylesheet" href="style.css" />
8
- </head>
9
- <body>
10
- <div class="card">
11
- <h1>Welcome to your static Space!</h1>
12
- <p>You can modify this app directly by editing <i>index.html</i> in the Files and versions tab.</p>
13
- <p>
14
- Also don't forget to check the
15
- <a href="https://huggingface.co/docs/hub/spaces" target="_blank">Spaces documentation</a>.
16
- </p>
17
- </div>
18
- </body>
19
- </html>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>Modular Component Architecture</title>
7
+ <script src="https://cdn.tailwindcss.com"></script>
8
+ <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
9
+ <script>
10
+ tailwind.config = {
11
+ theme: {
12
+ extend: {
13
+ colors: {
14
+ primary: '#6366f1',
15
+ secondary: '#8b5cf6',
16
+ dark: '#1e293b',
17
+ light: '#f8fafc'
18
+ }
19
+ }
20
+ }
21
+ }
22
+ </script>
23
+ <style>
24
+ .module-card {
25
+ transition: all 0.3s ease;
26
+ box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
27
+ }
28
+ .module-card:hover {
29
+ transform: translateY(-5px);
30
+ box-shadow: 0 10px 15px rgba(0, 0, 0, 0.1);
31
+ }
32
+ .event-log {
33
+ max-height: 300px;
34
+ overflow-y: auto;
35
+ }
36
+ .event-item {
37
+ animation: fadeIn 0.3s ease;
38
+ }
39
+ @keyframes fadeIn {
40
+ from { opacity: 0; transform: translateY(10px); }
41
+ to { opacity: 1; transform: translateY(0); }
42
+ }
43
+ .state-badge {
44
+ transition: all 0.3s ease;
45
+ }
46
+ </style>
47
+ </head>
48
+ <body class="bg-gradient-to-br from-indigo-50 to-purple-100 min-h-screen">
49
+ <div class="container mx-auto px-4 py-8">
50
+ <!-- Header -->
51
+ <header class="text-center mb-12">
52
+ <h1 class="text-4xl font-bold text-dark mb-2">Modular Component Architecture</h1>
53
+ <p class="text-lg text-gray-600 max-w-2xl mx-auto">
54
+ Demonstrating IIFE modules, dependency injection, service layer, and event-driven communication
55
+ </p>
56
+ </header>
57
+
58
+ <!-- Main App Container -->
59
+ <div class="grid grid-cols-1 lg:grid-cols-3 gap-8">
60
+ <!-- Modules Panel -->
61
+ <div class="lg:col-span-2">
62
+ <div class="bg-white rounded-xl shadow-lg p-6 mb-8">
63
+ <h2 class="text-2xl font-bold text-dark mb-6 flex items-center">
64
+ <i class="fas fa-cubes mr-2 text-primary"></i> Application Modules
65
+ </h2>
66
+
67
+ <div class="grid grid-cols-1 md:grid-cols-2 gap-6">
68
+ <!-- App Module -->
69
+ <div class="module-card bg-gradient-to-br from-indigo-50 to-purple-50 rounded-xl p-6 border border-indigo-100">
70
+ <div class="flex items-start mb-4">
71
+ <div class="bg-primary rounded-lg p-3 mr-4">
72
+ <i class="fas fa-rocket text-white text-xl"></i>
73
+ </div>
74
+ <div>
75
+ <h3 class="text-xl font-bold text-dark">App Module</h3>
76
+ <p class="text-gray-600 text-sm">Main application controller</p>
77
+ </div>
78
+ </div>
79
+ <div class="mb-4">
80
+ <div class="flex items-center mb-2">
81
+ <span class="text-sm font-medium text-gray-600 mr-2">State:</span>
82
+ <span id="app-state" class="state-badge bg-indigo-100 text-indigo-800 text-xs px-2 py-1 rounded-full">Initialized</span>
83
+ </div>
84
+ <div class="flex items-center">
85
+ <span class="text-sm font-medium text-gray-600 mr-2">Dependencies:</span>
86
+ <span class="bg-gray-100 text-gray-800 text-xs px-2 py-1 rounded-full">EventBus</span>
87
+ <span class="bg-gray-100 text-gray-800 text-xs px-2 py-1 rounded-full ml-1">StateManager</span>
88
+ </div>
89
+ </div>
90
+ <button id="init-app" class="w-full bg-primary hover:bg-indigo-600 text-white font-medium py-2 px-4 rounded-lg transition">
91
+ Initialize App
92
+ </button>
93
+ </div>
94
+
95
+ <!-- Module A -->
96
+ <div class="module-card bg-gradient-to-br from-blue-50 to-cyan-50 rounded-xl p-6 border border-blue-100">
97
+ <div class="flex items-start mb-4">
98
+ <div class="bg-blue-500 rounded-lg p-3 mr-4">
99
+ <i class="fas fa-cog text-white text-xl"></i>
100
+ </div>
101
+ <div>
102
+ <h3 class="text-xl font-bold text-dark">Module A</h3>
103
+ <p class="text-gray-600 text-sm">Service consumer</p>
104
+ </div>
105
+ </div>
106
+ <div class="mb-4">
107
+ <div class="flex items-center mb-2">
108
+ <span class="text-sm font-medium text-gray-600 mr-2">State:</span>
109
+ <span id="moduleA-state" class="state-badge bg-blue-100 text-blue-800 text-xs px-2 py-1 rounded-full">Not Initialized</span>
110
+ </div>
111
+ <div class="flex items-center">
112
+ <span class="text-sm font-medium text-gray-600 mr-2">Dependencies:</span>
113
+ <span class="bg-gray-100 text-gray-800 text-xs px-2 py-1 rounded-full">DataService</span>
114
+ <span class="bg-gray-100 text-gray-800 text-xs px-2 py-1 rounded-full ml-1">EventBus</span>
115
+ </div>
116
+ </div>
117
+ <button id="fetch-data" class="w-full bg-blue-500 hover:bg-blue-600 text-white font-medium py-2 px-4 rounded-lg transition disabled:opacity-50" disabled>
118
+ Fetch Data
119
+ </button>
120
+ </div>
121
+
122
+ <!-- Module B -->
123
+ <div class="module-card bg-gradient-to-br from-purple-50 to-pink-50 rounded-xl p-6 border border-purple-100">
124
+ <div class="flex items-start mb-4">
125
+ <div class="bg-secondary rounded-lg p-3 mr-4">
126
+ <i class="fas fa-chart-bar text-white text-xl"></i>
127
+ </div>
128
+ <div>
129
+ <h3 class="text-xl font-bold text-dark">Module B</h3>
130
+ <p class="text-gray-600 text-sm">Data processor</p>
131
+ </div>
132
+ </div>
133
+ <div class="mb-4">
134
+ <div class="flex items-center mb-2">
135
+ <span class="text-sm font-medium text-gray-600 mr-2">State:</span>
136
+ <span id="moduleB-state" class="state-badge bg-purple-100 text-purple-800 text-xs px-2 py-1 rounded-full">Not Initialized</span>
137
+ </div>
138
+ <div class="flex items-center">
139
+ <span class="text-sm font-medium text-gray-600 mr-2">Dependencies:</span>
140
+ <span class="bg-gray-100 text-gray-800 text-xs px-2 py-1 rounded-full">DataService</span>
141
+ <span class="bg-gray-100 text-gray-800 text-xs px-2 py-1 rounded-full ml-1">EventBus</span>
142
+ </div>
143
+ </div>
144
+ <button id="process-data" class="w-full bg-secondary hover:bg-purple-600 text-white font-medium py-2 px-4 rounded-lg transition disabled:opacity-50" disabled>
145
+ Process Data
146
+ </button>
147
+ </div>
148
+
149
+ <!-- Service Module -->
150
+ <div class="module-card bg-gradient-to-br from-green-50 to-emerald-50 rounded-xl p-6 border border-green-100">
151
+ <div class="flex items-start mb-4">
152
+ <div class="bg-green-500 rounded-lg p-3 mr-4">
153
+ <i class="fas fa-database text-white text-xl"></i>
154
+ </div>
155
+ <div>
156
+ <h3 class="text-xl font-bold text-dark">Data Service</h3>
157
+ <p class="text-gray-600 text-sm">Central data provider</p>
158
+ </div>
159
+ </div>
160
+ <div class="mb-4">
161
+ <div class="flex items-center mb-2">
162
+ <span class="text-sm font-medium text-gray-600 mr-2">State:</span>
163
+ <span id="service-state" class="state-badge bg-green-100 text-green-800 text-xs px-2 py-1 rounded-full">Not Initialized</span>
164
+ </div>
165
+ <div class="flex items-center">
166
+ <span class="text-sm font-medium text-gray-600 mr-2">Methods:</span>
167
+ <span class="bg-gray-100 text-gray-800 text-xs px-2 py-1 rounded-full">fetchData()</span>
168
+ <span class="bg-gray-100 text-gray-800 text-xs px-2 py-1 rounded-full ml-1">processData()</span>
169
+ </div>
170
+ </div>
171
+ <div class="text-sm text-gray-600">
172
+ <i class="fas fa-info-circle mr-1"></i> Initialized by App module
173
+ </div>
174
+ </div>
175
+ </div>
176
+ </div>
177
+
178
+ <!-- Data Display -->
179
+ <div class="bg-white rounded-xl shadow-lg p-6">
180
+ <h2 class="text-2xl font-bold text-dark mb-4 flex items-center">
181
+ <i class="fas fa-table mr-2 text-primary"></i> Data Output
182
+ </h2>
183
+ <div id="data-output" class="bg-gray-50 rounded-lg p-4 min-h-[200px]">
184
+ <p class="text-gray-500 text-center py-8">No data available. Initialize the app and fetch data to see results.</p>
185
+ </div>
186
+ </div>
187
+ </div>
188
+
189
+ <!-- Event Log -->
190
+ <div class="lg:col-span-1">
191
+ <div class="bg-white rounded-xl shadow-lg p-6 sticky top-4">
192
+ <h2 class="text-2xl font-bold text-dark mb-4 flex items-center">
193
+ <i class="fas fa-bolt mr-2 text-yellow-500"></i> Event Log
194
+ </h2>
195
+ <div class="text-sm text-gray-600 mb-4">
196
+ Shows event-driven communication between modules
197
+ </div>
198
+ <div id="event-log" class="event-log bg-gray-50 rounded-lg p-4">
199
+ <div class="event-item bg-blue-50 border-l-4 border-blue-500 p-3 mb-2 rounded">
200
+ <div class="font-medium text-blue-800">System: Application loaded</div>
201
+ <div class="text-xs text-gray-600">Waiting for initialization...</div>
202
+ </div>
203
+ </div>
204
+
205
+ <div class="mt-8">
206
+ <h3 class="text-lg font-bold text-dark mb-3">Architecture Flow</h3>
207
+ <div class="space-y-4">
208
+ <div class="flex items-start">
209
+ <div class="bg-primary rounded-full w-8 h-8 flex items-center justify-center mr-3 flex-shrink-0">
210
+ <span class="text-white font-bold">1</span>
211
+ </div>
212
+ <div>
213
+ <h4 class="font-medium text-dark">App Initialization</h4>
214
+ <p class="text-sm text-gray-600">App module initializes services and other modules</p>
215
+ </div>
216
+ </div>
217
+ <div class="flex items-start">
218
+ <div class="bg-blue-500 rounded-full w-8 h-8 flex items-center justify-center mr-3 flex-shrink-0">
219
+ <span class="text-white font-bold">2</span>
220
+ </div>
221
+ <div>
222
+ <h4 class="font-medium text-dark">Module A Initialization</h4>
223
+ <p class="text-sm text-gray-600">Module A receives dependencies from App</p>
224
+ </div>
225
+ </div>
226
+ <div class="flex items-start">
227
+ <div class="bg-secondary rounded-full w-8 h-8 flex items-center justify-center mr-3 flex-shrink-0">
228
+ <span class="text-white font-bold">3</span>
229
+ </div>
230
+ <div>
231
+ <h4 class="font-medium text-dark">Module B Initialization</h4>
232
+ <p class="text-sm text-gray-600">Module B receives dependencies from App</p>
233
+ </div>
234
+ </div>
235
+ <div class="flex items-start">
236
+ <div class="bg-green-500 rounded-full w-8 h-8 flex items-center justify-center mr-3 flex-shrink-0">
237
+ <span class="text-white font-bold">4</span>
238
+ </div>
239
+ <div>
240
+ <h4 class="font-medium text-dark">Event Communication</h4>
241
+ <p class="text-sm text-gray-600">Modules communicate through events</p>
242
+ </div>
243
+ </div>
244
+ </div>
245
+ </div>
246
+ </div>
247
+ </div>
248
+ </div>
249
+ </div>
250
+
251
+ <script>
252
+ // =====================
253
+ // MODULE DEFINITIONS
254
+ // =====================
255
+
256
+ // Event Bus Module (IIFE)
257
+ const EventBus = (function() {
258
+ const events = {};
259
+
260
+ function on(event, callback) {
261
+ if (!events[event]) events[event] = [];
262
+ events[event].push(callback);
263
+ }
264
+
265
+ function emit(event, data) {
266
+ if (events[event]) {
267
+ events[event].forEach(callback => callback(data));
268
+ }
269
+ }
270
+
271
+ return { on, emit };
272
+ })();
273
+
274
+ // State Manager Module (IIFE)
275
+ const StateManager = (function() {
276
+ let state = {
277
+ appInitialized: false,
278
+ moduleAInitialized: false,
279
+ moduleBInitialized: false,
280
+ serviceInitialized: false,
281
+ data: null,
282
+ processedData: null
283
+ };
284
+
285
+ function getState() {
286
+ return {...state};
287
+ }
288
+
289
+ function setState(newState) {
290
+ state = {...state, ...newState};
291
+ // Emit state change event
292
+ EventBus.emit('stateChanged', state);
293
+ }
294
+
295
+ return { getState, setState };
296
+ })();
297
+
298
+ // Data Service Module (IIFE)
299
+ const DataService = (function(eventBus, stateManager) {
300
+ function init() {
301
+ stateManager.setState({ serviceInitialized: true });
302
+ logEvent('DataService initialized', 'service');
303
+ }
304
+
305
+ function fetchData() {
306
+ logEvent('Fetching data from API...', 'service');
307
+
308
+ // Simulate API call
309
+ setTimeout(() => {
310
+ const mockData = [
311
+ { id: 1, name: 'Product A', value: 125, category: 'Electronics' },
312
+ { id: 2, name: 'Product B', value: 89, category: 'Home' },
313
+ { id: 3, name: 'Product C', value: 210, category: 'Electronics' },
314
+ { id: 4, name: 'Product D', value: 55, category: 'Office' },
315
+ { id: 5, name: 'Product E', value: 175, category: 'Home' }
316
+ ];
317
+
318
+ stateManager.setState({ data: mockData });
319
+ eventBus.emit('dataFetched', mockData);
320
+ logEvent('Data fetched successfully', 'service');
321
+ }, 1500);
322
+ }
323
+
324
+ function processData() {
325
+ logEvent('Processing data...', 'service');
326
+
327
+ const state = stateManager.getState();
328
+ if (!state.data) {
329
+ logEvent('No data to process', 'service', 'error');
330
+ return;
331
+ }
332
+
333
+ // Simulate data processing
334
+ setTimeout(() => {
335
+ const processed = state.data.map(item => ({
336
+ ...item,
337
+ tax: Math.round(item.value * 0.1),
338
+ total: Math.round(item.value * 1.1)
339
+ }));
340
+
341
+ stateManager.setState({ processedData: processed });
342
+ eventBus.emit('dataProcessed', processed);
343
+ logEvent('Data processed successfully', 'service');
344
+ }, 1000);
345
+ }
346
+
347
+ return { init, fetchData, processData };
348
+ })(EventBus, StateManager);
349
+
350
+ // Module A (IIFE)
351
+ const ModuleA = (function(eventBus, dataService) {
352
+ function init() {
353
+ logEvent('ModuleA initialized', 'moduleA');
354
+ StateManager.setState({ moduleAInitialized: true });
355
+
356
+ // Enable fetch button
357
+ document.getElementById('fetch-data').disabled = false;
358
+
359
+ // Listen for data processing events
360
+ eventBus.on('dataProcessed', (data) => {
361
+ logEvent('Received processed data from ModuleB', 'moduleA');
362
+ });
363
+ }
364
+
365
+ function fetchDataHandler() {
366
+ logEvent('ModuleA requesting data', 'moduleA');
367
+ dataService.fetchData();
368
+ }
369
+
370
+ return { init, fetchDataHandler };
371
+ })(EventBus, DataService);
372
+
373
+ // Module B (IIFE)
374
+ const ModuleB = (function(eventBus, dataService) {
375
+ function init() {
376
+ logEvent('ModuleB initialized', 'moduleB');
377
+ StateManager.setState({ moduleBInitialized: true });
378
+
379
+ // Enable process button
380
+ document.getElementById('process-data').disabled = false;
381
+
382
+ // Listen for data fetching events
383
+ eventBus.on('dataFetched', (data) => {
384
+ logEvent('Received raw data from DataService', 'moduleB');
385
+ renderData(data);
386
+ });
387
+
388
+ // Listen for data processing events
389
+ eventBus.on('dataProcessed', (data) => {
390
+ logEvent('Rendering processed data', 'moduleB');
391
+ renderProcessedData(data);
392
+ });
393
+ }
394
+
395
+ function processDataHandler() {
396
+ logEvent('ModuleB processing data', 'moduleB');
397
+ dataService.processData();
398
+ }
399
+
400
+ function renderData(data) {
401
+ const output = document.getElementById('data-output');
402
+ output.innerHTML = `
403
+ <div class="mb-4">
404
+ <h3 class="text-lg font-bold text-dark mb-2">Raw Data</h3>
405
+ <div class="text-sm text-gray-600 mb-3">Received by ModuleB from DataService</div>
406
+ </div>
407
+ <div class="overflow-x-auto">
408
+ <table class="min-w-full bg-white">
409
+ <thead>
410
+ <tr class="bg-gray-100">
411
+ <th class="py-2 px-4 border-b text-left">ID</th>
412
+ <th class="py-2 px-4 border-b text-left">Name</th>
413
+ <th class="py-2 px-4 border-b text-left">Value</th>
414
+ <th class="py-2 px-4 border-b text-left">Category</th>
415
+ </tr>
416
+ </thead>
417
+ <tbody>
418
+ ${data.map(item => `
419
+ <tr class="hover:bg-gray-50">
420
+ <td class="py-2 px-4 border-b">${item.id}</td>
421
+ <td class="py-2 px-4 border-b">${item.name}</td>
422
+ <td class="py-2 px-4 border-b">$${item.value}</td>
423
+ <td class="py-2 px-4 border-b">${item.category}</td>
424
+ </tr>
425
+ `).join('')}
426
+ </tbody>
427
+ </table>
428
+ </div>
429
+ `;
430
+ }
431
+
432
+ function renderProcessedData(data) {
433
+ const output = document.getElementById('data-output');
434
+ output.innerHTML = `
435
+ <div class="mb-4">
436
+ <h3 class="text-lg font-bold text-dark mb-2">Processed Data</h3>
437
+ <div class="text-sm text-gray-600 mb-3">With tax calculations applied</div>
438
+ </div>
439
+ <div class="overflow-x-auto">
440
+ <table class="min-w-full bg-white">
441
+ <thead>
442
+ <tr class="bg-gray-100">
443
+ <th class="py-2 px-4 border-b text-left">ID</th>
444
+ <th class="py-2 px-4 border-b text-left">Name</th>
445
+ <th class="py-2 px-4 border-b text-left">Value</th>
446
+ <th class="py-2 px-4 border-b text-left">Tax (10%)</th>
447
+ <th class="py-2 px-4 border-b text-left">Total</th>
448
+ </tr>
449
+ </thead>
450
+ <tbody>
451
+ ${data.map(item => `
452
+ <tr class="hover:bg-gray-50">
453
+ <td class="py-2 px-4 border-b">${item.id}</td>
454
+ <td class="py-2 px-4 border-b">${item.name}</td>
455
+ <td class="py-2 px-4 border-b">$${item.value}</td>
456
+ <td class="py-2 px-4 border-b">$${item.tax}</td>
457
+ <td class="py-2 px-4 border-b font-medium">$${item.total}</td>
458
+ </tr>
459
+ `).join('')}
460
+ </tbody>
461
+ </table>
462
+ </div>
463
+ `;
464
+ }
465
+
466
+ return { init, processDataHandler };
467
+ })(EventBus, DataService);
468
+
469
+ // App Module (IIFE)
470
+ const App = (function(eventBus, stateManager, dataService, moduleA, moduleB) {
471
+ function init() {
472
+ logEvent('App initialization started', 'app');
473
+
474
+ // Initialize services
475
+ dataService.init();
476
+
477
+ // Initialize modules with dependencies
478
+ moduleA.init();
479
+ moduleB.init();
480
+
481
+ // Update state
482
+ stateManager.setState({ appInitialized: true });
483
+
484
+ logEvent('App fully initialized', 'app');
485
+
486
+ // Update UI
487
+ document.getElementById('init-app').disabled = true;
488
+ document.getElementById('init-app').textContent = 'App Initialized';
489
+ document.getElementById('init-app').classList.remove('bg-primary', 'hover:bg-indigo-600');
490
+ document.getElementById('init-app').classList.add('bg-green-500', 'hover:bg-green-600');
491
+ }
492
+
493
+ return { init };
494
+ })(EventBus, StateManager, DataService, ModuleA, ModuleB);
495
+
496
+ // =====================
497
+ // UTILITY FUNCTIONS
498
+ // =====================
499
+
500
+ function logEvent(message, module, type = 'info') {
501
+ const eventLog = document.getElementById('event-log');
502
+ const colors = {
503
+ app: 'indigo',
504
+ moduleA: 'blue',
505
+ moduleB: 'purple',
506
+ service: 'green',
507
+ error: 'red'
508
+ };
509
+
510
+ const color = colors[module] || (type === 'error' ? 'red' : 'gray');
511
+
512
+ const eventItem = document.createElement('div');
513
+ eventItem.className = `event-item bg-${color}-50 border-l-4 border-${color}-500 p-3 mb-2 rounded`;
514
+ eventItem.innerHTML = `
515
+ <div class="font-medium text-${color}-800">${module}: ${message}</div>
516
+ <div class="text-xs text-gray-600">${new Date().toLocaleTimeString()}</div>
517
+ `;
518
+
519
+ eventLog.prepend(eventItem);
520
+
521
+ // Update module state badges
522
+ updateStateBadges();
523
+ }
524
+
525
+ function updateStateBadges() {
526
+ const state = StateManager.getState();
527
+
528
+ document.getElementById('app-state').textContent = state.appInitialized ? 'Initialized' : 'Not Initialized';
529
+ document.getElementById('app-state').className = state.appInitialized ?
530
+ 'state-badge bg-green-100 text-green-800 text-xs px-2 py-1 rounded-full' :
531
+ 'state-badge bg-indigo-100 text-indigo-800 text-xs px-2 py-1 rounded-full';
532
+
533
+ document.getElementById('moduleA-state').textContent = state.moduleAInitialized ? 'Initialized' : 'Not Initialized';
534
+ document.getElementById('moduleA-state').className = state.moduleAInitialized ?
535
+ 'state-badge bg-green-100 text-green-800 text-xs px-2 py-1 rounded-full' :
536
+ 'state-badge bg-blue-100 text-blue-800 text-xs px-2 py-1 rounded-full';
537
+
538
+ document.getElementById('moduleB-state').textContent = state.moduleBInitialized ? 'Initialized' : 'Not Initialized';
539
+ document.getElementById('moduleB-state').className = state.moduleBInitialized ?
540
+ 'state-badge bg-green-100 text-green-800 text-xs px-2 py-1 rounded-full' :
541
+ 'state-badge bg-purple-100 text-purple-800 text-xs px-2 py-1 rounded-full';
542
+
543
+ document.getElementById('service-state').textContent = state.serviceInitialized ? 'Initialized' : 'Not Initialized';
544
+ document.getElementById('service-state').className = state.serviceInitialized ?
545
+ 'state-badge bg-green-100 text-green-800 text-xs px-2 py-1 rounded-full' :
546
+ 'state-badge bg-green-100 text-green-800 text-xs px-2 py-1 rounded-full';
547
+ }
548
+
549
+ // =====================
550
+ // EVENT LISTENERS
551
+ // =====================
552
+
553
+ document.getElementById('init-app').addEventListener('click', () => {
554
+ App.init();
555
+ });
556
+
557
+ document.getElementById('fetch-data').addEventListener('click', () => {
558
+ ModuleA.fetchDataHandler();
559
+ });
560
+
561
+ document.getElementById('process-data').addEventListener('click', () => {
562
+ ModuleB.processDataHandler();
563
+ });
564
+
565
+ // Listen for state changes to update UI
566
+ EventBus.on('stateChanged', (state) => {
567
+ updateStateBadges();
568
+ });
569
+
570
+ // Initial state update
571
+ updateStateBadges();
572
+ </script>
573
+ <p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=Darkxx91/modular-component-architecture" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
574
+ </html>