Index: view-database.js
===================================================================
--- view-database.js	(revision 69f2a41cff81a4c7825abb68eb0f0eff6818e4e5)
+++ view-database.js	(revision 33517cc23b4f63a19074ebcdcf7ef56c65850f09)
@@ -3,5 +3,10 @@
 
 const dbPath = path.join(__dirname, 'database', 'handcraft.db');
-const db = new sqlite3.Database(dbPath);
+const db = new sqlite3.Database(dbPath, (err) => {
+    if (err) {
+        console.error('Error opening database:', err.message);
+        process.exit(1);
+    }
+});
 
 console.log('\n🎨 HANDCRAFT MARKETPLACE - DATABASE CONTENTS\n');
@@ -25,43 +30,82 @@
 }
 
+// Main execution chain
+function executeChecks() {
+    let currentCheck = 0;
+
+    const checks = [
+        { name: 'clients', func: checkClients },
+        { name: 'personal', func: checkPersonal },
+        { name: 'store', func: checkStore },
+        { name: 'product', func: checkProduct },
+        { name: 'category', func: checkCategory },
+        { name: 'works_in_store', func: checkWorksInStore },
+        { name: 'permissions', func: checkPermissions },
+        { name: 'employees', func: checkEmployees },
+        { name: 'boss', func: checkBoss },
+        { name: 'order', func: checkOrder },
+        { name: 'report', func: checkReport },
+        { name: 'refund', func: checkRefund },
+        { name: 'image', func: checkImage },
+        { name: 'color', func: checkColor }
+    ];
+
+    function next() {
+        currentCheck++;
+        if (currentCheck < checks.length) {
+            checks[currentCheck].func(next);
+        } else {
+            finish();
+        }
+    }
+
+    // Start with first check
+    checks[0].func(next);
+}
+
 // Display CLIENTS table
-console.log('\n👤 CLIENTS TABLE:');
-console.log('================================================================================');
-tableExists('client', (exists) => {
-    if (!exists) {
-        console.log('Table does not exist');
-        checkNext();
-        return;
-    }
-
-    db.all('SELECT * FROM client', [], (err, rows) => {
-        if (err) {
-            console.log(`Error: ${err.message}`);
-            checkNext();
-            return;
-        }
-
-        if (!rows || rows.length === 0) {
-            console.log('No clients found');
-        } else {
-            console.log(`Total: ${rows.length} clients\n`);
-            rows.forEach((client, index) => {
-                console.log(`ID: ${client.client_id} | Name: ${client.first_name || ''} ${client.last_name || ''}`);
-                console.log(`Email: ${client.email || 'N/A'}`);
-                if (index < rows.length - 1) console.log('-'.repeat(80));
-            });
-        }
-        checkNext();
-    });
-});
+function checkClients(next) {
+    console.log('\n👤 CLIENTS TABLE:');
+    console.log('================================================================================');
+
+    tableExists('client', (exists) => {
+        if (!exists) {
+            console.log('Table does not exist\n');
+            if (next) next();
+            return;
+        }
+
+        db.all('SELECT * FROM client', [], (err, rows) => {
+            if (err) {
+                console.log(`Error: ${err.message}\n`);
+                if (next) next();
+                return;
+            }
+
+            if (!rows || rows.length === 0) {
+                console.log('No clients found\n');
+            } else {
+                console.log(`Total: ${rows.length} clients\n`);
+                rows.forEach((client, index) => {
+                    console.log(`ID: ${client.client_id} | Name: ${client.first_name || ''} ${client.last_name || ''}`);
+                    console.log(`Email: ${client.email || 'N/A'}`);
+                    if (index < rows.length - 1) console.log('-'.repeat(80));
+                });
+                console.log(); // Add blank line after table
+            }
+            if (next) next();
+        });
+    });
+}
 
 // Display PERSONAL table
-function checkPersonal() {
+function checkPersonal(next) {
     console.log('\n👔 PERSONAL TABLE (STORE OWNERS/EMPLOYEES):');
     console.log('================================================================================');
+
     tableExists('personal', (exists) => {
         if (!exists) {
-            console.log('Table does not exist');
-            checkStore();
+            console.log('Table does not exist\n');
+            if (next) next();
             return;
         }
@@ -77,11 +121,11 @@
         `, [], (err, rows) => {
             if (err) {
-                console.log(`Error: ${err.message}`);
-                checkStore();
-                return;
-            }
-
-            if (!rows || rows.length === 0) {
-                console.log('No personal records found');
+                console.log(`Error: ${err.message}\n`);
+                if (next) next();
+                return;
+            }
+
+            if (!rows || rows.length === 0) {
+                console.log('No personal records found\n');
             } else {
                 console.log(`Total: ${rows.length} personal records\n`);
@@ -91,6 +135,7 @@
                     if (index < rows.length - 1) console.log('-'.repeat(80));
                 });
-            }
-            checkStore();
+                console.log();
+            }
+            if (next) next();
         });
     });
@@ -98,11 +143,12 @@
 
 // Display STORE table
-function checkStore() {
+function checkStore(next) {
     console.log('\n🏪 STORE TABLE:');
     console.log('================================================================================');
+
     tableExists('store', (exists) => {
         if (!exists) {
-            console.log('Table does not exist');
-            checkProduct();
+            console.log('Table does not exist\n');
+            if (next) next();
             return;
         }
@@ -110,11 +156,11 @@
         db.all('SELECT * FROM store', [], (err, rows) => {
             if (err) {
-                console.log(`Error: ${err.message}`);
-                checkProduct();
-                return;
-            }
-
-            if (!rows || rows.length === 0) {
-                console.log('No stores found');
+                console.log(`Error: ${err.message}\n`);
+                if (next) next();
+                return;
+            }
+
+            if (!rows || rows.length === 0) {
+                console.log('No stores found\n');
             } else {
                 console.log(`Total: ${rows.length} stores\n`);
@@ -126,6 +172,7 @@
                     if (index < rows.length - 1) console.log('-'.repeat(80));
                 });
-            }
-            checkProduct();
+                console.log();
+            }
+            if (next) next();
         });
     });
@@ -133,11 +180,12 @@
 
 // Display PRODUCT table
-function checkProduct() {
+function checkProduct(next) {
     console.log('\n🛍️ PRODUCT TABLE:');
     console.log('================================================================================');
+
     tableExists('product', (exists) => {
         if (!exists) {
-            console.log('Table does not exist');
-            checkCategory();
+            console.log('Table does not exist\n');
+            if (next) next();
             return;
         }
@@ -149,11 +197,11 @@
         `, [], (err, rows) => {
             if (err) {
-                console.log(`Error: ${err.message}`);
-                checkCategory();
-                return;
-            }
-
-            if (!rows || rows.length === 0) {
-                console.log('No products found');
+                console.log(`Error: ${err.message}\n`);
+                if (next) next();
+                return;
+            }
+
+            if (!rows || rows.length === 0) {
+                console.log('No products found\n');
             } else {
                 console.log(`Total: ${rows.length} products\n`);
@@ -165,6 +213,7 @@
                     if (index < rows.length - 1) console.log('-'.repeat(80));
                 });
-            }
-            checkCategory();
+                console.log();
+            }
+            if (next) next();
         });
     });
@@ -172,11 +221,12 @@
 
 // Display CATEGORY table
-function checkCategory() {
+function checkCategory(next) {
     console.log('\n📁 CATEGORY TABLE:');
     console.log('================================================================================');
+
     tableExists('category', (exists) => {
         if (!exists) {
-            console.log('Table does not exist');
-            checkWorksInStore();
+            console.log('Table does not exist\n');
+            if (next) next();
             return;
         }
@@ -188,11 +238,11 @@
         `, [], (err, rows) => {
             if (err) {
-                console.log(`Error: ${err.message}`);
-                checkWorksInStore();
-                return;
-            }
-
-            if (!rows || rows.length === 0) {
-                console.log('No categories found');
+                console.log(`Error: ${err.message}\n`);
+                if (next) next();
+                return;
+            }
+
+            if (!rows || rows.length === 0) {
+                console.log('No categories found\n');
             } else {
                 console.log(`Total: ${rows.length} categories\n`);
@@ -203,6 +253,7 @@
                     if (index < rows.length - 1) console.log('-'.repeat(80));
                 });
-            }
-            checkWorksInStore();
+                console.log();
+            }
+            if (next) next();
         });
     });
@@ -210,11 +261,12 @@
 
 // Display WORKS_IN_STORE table
-function checkWorksInStore() {
+function checkWorksInStore(next) {
     console.log('\n🔗 WORKS_IN_STORE TABLE:');
     console.log('================================================================================');
+
     tableExists('works_in_store', (exists) => {
         if (!exists) {
-            console.log('Table does not exist');
-            checkPermissions();
+            console.log('Table does not exist\n');
+            if (next) next();
             return;
         }
@@ -227,11 +279,11 @@
         `, [], (err, rows) => {
             if (err) {
-                console.log(`Error: ${err.message}`);
-                checkPermissions();
-                return;
-            }
-
-            if (!rows || rows.length === 0) {
-                console.log('No assignments found');
+                console.log(`Error: ${err.message}\n`);
+                if (next) next();
+                return;
+            }
+
+            if (!rows || rows.length === 0) {
+                console.log('No assignments found\n');
             } else {
                 console.log(`Total: ${rows.length} assignments\n`);
@@ -241,6 +293,7 @@
                     if (index < rows.length - 1) console.log('-'.repeat(80));
                 });
-            }
-            checkPermissions();
+                console.log();
+            }
+            if (next) next();
         });
     });
@@ -248,11 +301,12 @@
 
 // Display PERMISSIONS table
-function checkPermissions() {
+function checkPermissions(next) {
     console.log('\n🔐 PERMISSIONS TABLE:');
     console.log('================================================================================');
+
     tableExists('permissions', (exists) => {
         if (!exists) {
-            console.log('Table does not exist');
-            checkEmployees();
+            console.log('Table does not exist\n');
+            if (next) next();
             return;
         }
@@ -264,11 +318,11 @@
         `, [], (err, rows) => {
             if (err) {
-                console.log(`Error: ${err.message}`);
-                checkEmployees();
-                return;
-            }
-
-            if (!rows || rows.length === 0) {
-                console.log('No permissions found');
+                console.log(`Error: ${err.message}\n`);
+                if (next) next();
+                return;
+            }
+
+            if (!rows || rows.length === 0) {
+                console.log('No permissions found\n');
             } else {
                 console.log(`Total: ${rows.length} permissions\n`);
@@ -278,6 +332,7 @@
                     if (index < rows.length - 1) console.log('-'.repeat(80));
                 });
-            }
-            checkEmployees();
+                console.log();
+            }
+            if (next) next();
         });
     });
@@ -285,11 +340,12 @@
 
 // Display EMPLOYEES table
-function checkEmployees() {
+function checkEmployees(next) {
     console.log('\n👷 EMPLOYEES TABLE:');
     console.log('================================================================================');
+
     tableExists('employees', (exists) => {
         if (!exists) {
-            console.log('Table does not exist');
-            checkBoss();
+            console.log('Table does not exist\n');
+            if (next) next();
             return;
         }
@@ -301,11 +357,11 @@
         `, [], (err, rows) => {
             if (err) {
-                console.log(`Error: ${err.message}`);
-                checkBoss();
-                return;
-            }
-
-            if (!rows || rows.length === 0) {
-                console.log('No employees found');
+                console.log(`Error: ${err.message}\n`);
+                if (next) next();
+                return;
+            }
+
+            if (!rows || rows.length === 0) {
+                console.log('No employees found\n');
             } else {
                 console.log(`Total: ${rows.length} employees\n`);
@@ -315,6 +371,7 @@
                     if (index < rows.length - 1) console.log('-'.repeat(80));
                 });
-            }
-            checkBoss();
+                console.log();
+            }
+            if (next) next();
         });
     });
@@ -322,11 +379,12 @@
 
 // Display BOSS table
-function checkBoss() {
+function checkBoss(next) {
     console.log('\n👑 BOSS TABLE:');
     console.log('================================================================================');
+
     tableExists('boss', (exists) => {
         if (!exists) {
-            console.log('Table does not exist');
-            checkOrder();
+            console.log('Table does not exist\n');
+            if (next) next();
             return;
         }
@@ -338,11 +396,11 @@
         `, [], (err, rows) => {
             if (err) {
-                console.log(`Error: ${err.message}`);
-                checkOrder();
-                return;
-            }
-
-            if (!rows || rows.length === 0) {
-                console.log('No bosses found');
+                console.log(`Error: ${err.message}\n`);
+                if (next) next();
+                return;
+            }
+
+            if (!rows || rows.length === 0) {
+                console.log('No bosses found\n');
             } else {
                 console.log(`Total: ${rows.length} bosses\n`);
@@ -352,6 +410,7 @@
                     if (index < rows.length - 1) console.log('-'.repeat(80));
                 });
-            }
-            checkOrder();
+                console.log();
+            }
+            if (next) next();
         });
     });
@@ -359,11 +418,12 @@
 
 // Display ORDER table
-function checkOrder() {
+function checkOrder(next) {
     console.log('\n📦 ORDERS TABLE:');
     console.log('================================================================================');
+
     tableExists('order', (exists) => {
         if (!exists) {
-            console.log('Table does not exist');
-            checkReport();
+            console.log('Table does not exist\n');
+            if (next) next();
             return;
         }
@@ -376,11 +436,11 @@
         `, [], (err, rows) => {
             if (err) {
-                console.log(`Error: ${err.message}`);
-                checkReport();
-                return;
-            }
-
-            if (!rows || rows.length === 0) {
-                console.log('No orders found');
+                console.log(`Error: ${err.message}\n`);
+                if (next) next();
+                return;
+            }
+
+            if (!rows || rows.length === 0) {
+                console.log('No orders found\n');
             } else {
                 console.log(`Total: ${rows.length} orders\n`);
@@ -392,6 +452,7 @@
                     if (index < rows.length - 1) console.log('-'.repeat(80));
                 });
-            }
-            checkReport();
+                console.log();
+            }
+            if (next) next();
         });
     });
@@ -399,11 +460,12 @@
 
 // Display REPORT table
-function checkReport() {
+function checkReport(next) {
     console.log('\n📊 REPORTS TABLE:');
     console.log('================================================================================');
+
     tableExists('report', (exists) => {
         if (!exists) {
-            console.log('Table does not exist');
-            checkRefund();
+            console.log('Table does not exist\n');
+            if (next) next();
             return;
         }
@@ -411,11 +473,11 @@
         db.all('SELECT * FROM report', [], (err, rows) => {
             if (err) {
-                console.log(`Error: ${err.message}`);
-                checkRefund();
-                return;
-            }
-
-            if (!rows || rows.length === 0) {
-                console.log('No reports found');
+                console.log(`Error: ${err.message}\n`);
+                if (next) next();
+                return;
+            }
+
+            if (!rows || rows.length === 0) {
+                console.log('No reports found\n');
             } else {
                 console.log(`Total: ${rows.length} reports\n`);
@@ -425,6 +487,7 @@
                     if (index < rows.length - 1) console.log('-'.repeat(80));
                 });
-            }
-            checkRefund();
+                console.log();
+            }
+            if (next) next();
         });
     });
@@ -432,11 +495,12 @@
 
 // Display REFUND table
-function checkRefund() {
+function checkRefund(next) {
     console.log('\n💰 REFUND TABLE:');
     console.log('================================================================================');
+
     tableExists('refund', (exists) => {
         if (!exists) {
-            console.log('Table does not exist');
-            checkImage();
+            console.log('Table does not exist\n');
+            if (next) next();
             return;
         }
@@ -444,11 +508,11 @@
         db.all('SELECT * FROM refund', [], (err, rows) => {
             if (err) {
-                console.log(`Error: ${err.message}`);
-                checkImage();
-                return;
-            }
-
-            if (!rows || rows.length === 0) {
-                console.log('No refunds found');
+                console.log(`Error: ${err.message}\n`);
+                if (next) next();
+                return;
+            }
+
+            if (!rows || rows.length === 0) {
+                console.log('No refunds found\n');
             } else {
                 console.log(`Total: ${rows.length} refunds\n`);
@@ -459,6 +523,7 @@
                     if (index < rows.length - 1) console.log('-'.repeat(80));
                 });
-            }
-            checkImage();
+                console.log();
+            }
+            if (next) next();
         });
     });
@@ -466,11 +531,12 @@
 
 // Display IMAGE table
-function checkImage() {
+function checkImage(next) {
     console.log('\n🖼️ IMAGE TABLE:');
     console.log('================================================================================');
+
     tableExists('image', (exists) => {
         if (!exists) {
-            console.log('Table does not exist');
-            checkColor();
+            console.log('Table does not exist\n');
+            if (next) next();
             return;
         }
@@ -478,11 +544,11 @@
         db.all('SELECT * FROM image', [], (err, rows) => {
             if (err) {
-                console.log(`Error: ${err.message}`);
-                checkColor();
-                return;
-            }
-
-            if (!rows || rows.length === 0) {
-                console.log('No images found');
+                console.log(`Error: ${err.message}\n`);
+                if (next) next();
+                return;
+            }
+
+            if (!rows || rows.length === 0) {
+                console.log('No images found\n');
             } else {
                 console.log(`Total: ${rows.length} images\n`);
@@ -491,6 +557,7 @@
                     if (index < rows.length - 1) console.log('-'.repeat(80));
                 });
-            }
-            checkColor();
+                console.log();
+            }
+            if (next) next();
         });
     });
@@ -498,11 +565,12 @@
 
 // Display COLOR table
-function checkColor() {
+function checkColor(next) {
     console.log('\n🎨 COLOR TABLE:');
     console.log('================================================================================');
+
     tableExists('color', (exists) => {
         if (!exists) {
-            console.log('Table does not exist');
-            finish();
+            console.log('Table does not exist\n');
+            if (next) next();
             return;
         }
@@ -510,11 +578,11 @@
         db.all('SELECT * FROM color', [], (err, rows) => {
             if (err) {
-                console.log(`Error: ${err.message}`);
-                finish();
-                return;
-            }
-
-            if (!rows || rows.length === 0) {
-                console.log('No colors found');
+                console.log(`Error: ${err.message}\n`);
+                if (next) next();
+                return;
+            }
+
+            if (!rows || rows.length === 0) {
+                console.log('No colors found\n');
             } else {
                 console.log(`Total: ${rows.length} colors\n`);
@@ -523,23 +591,24 @@
                     if (index < rows.length - 1) console.log('-'.repeat(80));
                 });
-            }
-            finish();
-        });
-    });
-}
-
-// Start the chain of checks
-function checkNext() {
-    checkPersonal();
-}
-
+                console.log();
+            }
+            if (next) next();
+        });
+    });
+}
+
+// Finish and close database
 function finish() {
-    console.log('\n' + '='.repeat(80));
+    console.log('='.repeat(80));
     console.log('✅ Database inspection complete');
     console.log('='.repeat(80) + '\n');
 
-    db.close();
-}
-
-// Start with CLIENTS
-checkNext();
+    db.close((err) => {
+        if (err) {
+            console.error('Error closing database:', err.message);
+        }
+    });
+}
+
+// Start the execution chain
+executeChecks();
