# ShopDB Application - Deep Dive Technical Report

**Generated:** 2025-10-20
**Database Version:** MySQL 5.6.51
**Application:** Classic ASP (VBScript) on IIS Express
**Total Database Size:** ~3.5 MB
**Total Tables:** 29 base tables + 23 views
**Total Code Files:** 117 ASP files (~20,400 lines of code)

---

## Executive Summary

**ShopDB** is a manufacturing floor management system for GE Aviation's West Jefferson facility. It tracks 250+ CNC machines, 240+ PCs, 40 printers, network infrastructure, applications, and knowledge base articles. The system serves as a central hub for IT operations, providing real-time visibility into shopfloor equipment, warranties, network configurations, and troubleshooting documentation.

### Key Metrics
- **Machines Tracked:** 256 CNC machines across 20 different types
- **PCs Managed:** 242 active PCs (Standard, Engineer, Shopfloor)
- **Network Interfaces:** 705 monitored network interfaces
- **Knowledge Base:** 196 articles with FULLTEXT search
- **Applications:** 44 shopfloor applications with 327 installation records
- **Printers:** 40 networked printers
- **Active Notifications:** 20 system-wide notifications
- **Subnets:** 38 network segments

---

## 1. Database Architecture

### 1.1 Core Entity Tables

#### **PC Management (Main Focus)**
The PC tracking system is the heart of the application:

```
pc (242 rows)
├── pcid (PK, auto_increment)
├── hostname
├── serialnumber
├── pctypeid → pctype (Standard/Engineer/Shopfloor)
├── machinenumber (links to shopfloor machines)
├── modelnumberid → models (Dell, HP, Lenovo, etc.)
├── osid → operatingsystems (Windows 7, Windows 10, etc.)
├── pcstatusid → pcstatus (In Use, Spare, Retired, etc.)
├── warrantyenddate, warrantystatus, warrantydaysremaining
├── warrantyservicelevel, warrantylastchecked
├── loggedinuser
├── lastupdated (timestamp)
├── dateadded
├── isactive
└── requires_manual_machine_config (for multi-PC machines)
```

**Key Features:**
- Automatic warranty tracking via Dell API
- Operating system normalization (7 distinct OS versions)
- PC type classification for different use cases
- Machine number linkage for shopfloor PCs
- Multi-PC machine support (dualpath CNCs)

#### **Network Configuration Tracking**

**pc_network_interfaces (705 rows)**
```
Tracks all network adapters on each PC:
- IP addresses (corporate 10.x.x.x and machine 192.168.x.x networks)
- Subnet masks, gateways, MAC addresses
- DHCP vs Static configuration
- Machine network detection (192.168.*.*)
- Interface active status
```

**pc_comm_config (502 rows)**
```
Serial/network communication settings for machine controllers:
- Serial port configuration (COM ports, baud, parity, stop bits)
- eFocas network settings (IP, socket, etc.)
- PPDCS and Mark configurations
- Additional JSON settings storage
```

**pc_dnc_config (136 rows)**
```
GE DNC (Distributed Numerical Control) configurations:
- DNC machine numbers
- FTP host settings (primary/secondary)
- DNC service settings (uploads, scanner, dripfeed)
- DualPath detection and path names
- GE registry locations (32-bit vs 64-bit)
```

**pc_dualpath_assignments (31 rows)**
```
Maps PCs that control multiple machines simultaneously:
- primary_machine
- secondary_machine
- Used for dual-spindle CNCs
```

#### **Machine Management**

**machines (256 rows)**
```
machineid (PK)
├── machinetypeid → machinetypes (Vertical Lathe, CMM, Part Washer, etc.)
├── machinenumber (e.g., "3104", "3117")
├── alias (human-readable name)
├── printerid → printers (assigned printer)
├── businessunitid → businessunits
├── modelnumberid → models → vendors
├── ipaddress1, ipaddress2 (machine network IPs)
├── mapleft, maptop (coordinates for visual shop floor map)
├── isvnc (remote access enabled)
├── islocationonly (for mapping locations like offices)
└── machinenotes
```

**machinetypes (20 rows)**
```
- Vertical Lathe
- Horizontal Lathe
- 5-Axis Mill
- CMM (Coordinate Measuring Machine)
- Part Washer
- LocationOnly (offices, shipping, etc.)
- And 14 more types
Each has: functional account, background color, build documentation URL
```

#### **Application & Knowledge Base**

**applications (44 rows)**
```
Tracks shopfloor software applications:
- appname (FULLTEXT indexed)
- appdescription
- supportteamid → supportteams
- isinstallable (can we install it?)
- islicenced (requires license?)
- installpath, documentationpath
- ishidden (internal use only?)
- applicationnotes
```

**knowledgebase (196 rows)**
```
Troubleshooting articles and links:
- shortdescription (FULLTEXT indexed)
- keywords (FULLTEXT indexed)
- appid → applications
- linkurl (external documentation)
- clicks (popularity tracking)
- lastupdated timestamp
```

**installedapps (327 rows)**
```
Junction table: which apps are installed on which machines
- appid → applications
- machineid → machines
```

#### **Printer Management**

**printers (40 rows)**
```
printerid (PK)
├── printercsfname (CSF network name)
├── printerwindowsname (Windows share name)
├── modelid → models (Xerox, Okuma, etc.)
├── serialnumber
├── ipaddress
├── fqdn (fully qualified domain name)
└── machineid → machines (assigned machine/location)
```

#### **Network Infrastructure**

**subnets (38 rows)**
```
Network segment tracking:
- ipaddress (subnet address)
- subnet (CIDR notation)
- description
- subnettypeid → subnettypes (Machine, Corporate, Management, etc.)
- vlan
- gateway
```

#### **Support Infrastructure**

**models (66 rows)** - Equipment models (Dell Optiplex 7050, HP Z4, Okuma LB3000, etc.)
**vendors (22 rows)** - Equipment manufacturers (Dell, HP, Lenovo, Okuma, Xerox, etc.)
**notifications (20 rows)** - System-wide alerts with start/end times, FULLTEXT indexed
**supportteams (9 rows)** - IT, Engineering, Facilities, etc.
**businessunits (7 rows)** - Organizational divisions

### 1.2 Advanced Features

#### **Relationship Tables**

**machine_pc_relationships (0 rows, ready for use)**
```
Explicit many-to-many relationship tracking:
- machine_id → machines
- pc_id → pc
- pc_role (control, HMI, engineering, backup, unknown)
- is_primary flag
- relationship_notes
```

**machine_overrides (0 rows, ready for use)**
```
Manual PC-to-machine assignment overrides:
- pcid → pc
- machinenumber (override value)
- Handles complex mapping scenarios
```

#### **Lookup/Reference Tables**

- **pctype (6 rows):** Standard, Engineer, Shopfloor, Server, Laptop, VM
- **pcstatus (5 rows):** In Use, Spare, Retired, Broken, Unknown
- **operatingsystems (7 rows):** Normalized OS names
- **controllertypes (2 rows):** Fanuc, Mazak
- **skilllevels (2 rows):** For training tracking
- **functionalaccounts (3 rows):** Service accounts
- **topics (27 rows):** Knowledge base categorization

### 1.3 Database Views (23 Views)

The application makes extensive use of views for complex reporting:

**Shopfloor-Specific Views:**
- `vw_shopfloor_pcs` - All shopfloor PCs with machine assignments
- `vw_shopfloor_comm_config` - Communication settings for shopfloor
- `vw_shopfloor_applications_summary` - Application installation summary
- `vw_pc_network_summary` - Network configuration overview
- `vw_pc_resolved_machines` - PC-to-machine resolution with DualPath handling
- `vw_pctype_config` - PC count by type with configuration percentages

**Machine Management Views:**
- `vw_machine_assignments` - Which PCs control which machines
- `vw_machine_type_stats` - Machine counts by type
- `vw_multi_pc_machines` - Machines controlled by multiple PCs
- `vw_unmapped_machines` - Machines missing shop floor map coordinates
- `vw_ge_machines` - GE-specific machine configurations
- `vw_dualpath_management` - DualPath CNC oversight

**PC Management Views:**
- `vw_active_pcs` - Recently updated PCs (last 30 days)
- `vw_standard_pcs` - Standard workstations
- `vw_engineer_pcs` - Engineering workstations
- `vw_pc_summary` - Overall PC inventory
- `vw_pcs_by_hardware` - Grouping by manufacturer/model
- `vw_vendor_summary` - PC counts by vendor
- `vw_recent_updates` - Recently modified records

**Warranty Views:**
- `vw_warranty_status` - Overall warranty status
- `vw_warranties_expiring` - Expiring in next 90 days

**Other:**
- `vw_dnc_config` - DNC configuration summary
- `vw_machine_assignment_status` - Assignment tracking

### 1.4 Indexing Strategy

**FULLTEXT Indexes (for search performance):**
- applications.appname
- knowledgebase.shortdescription
- knowledgebase.keywords
- notifications.notification

**Foreign Key Indexes:**
- All major FK relationships have indexes
- Examples: pc.pctypeid, pc.modelnumberid, pc.osid, machines.machinetypeid

**Performance Indexes:**
- pc.isactive, pc.lastupdated
- pc_network_interfaces.pcid, ipaddress
- warranty-related dates

### 1.5 Data Integrity

**Foreign Key Constraints:**
- `pc.pctypeid` → `pctype.pctypeid`
- `pc.modelnumberid` → `models.modelnumberid`
- `pc.osid` → `operatingsystems.osid`
- `pc_comm_config.pcid` → `pc.pcid`
- `pc_dnc_config.pcid` → `pc.pcid`
- `pc_network_interfaces.pcid` → `pc.pcid`
- `machine_pc_relationships` has CASCADE DELETE on both sides
- `machine_overrides.pcid` → `pc.pcid` with CASCADE DELETE

**Unique Constraints:**
- `machine_overrides`: unique_pc_override (pcid)
- `machine_pc_relationships`: unique_machine_pc (machine_id, pc_id)
- `pc_dnc_config`: unique_pcid (pcid)
- `pc_dualpath_assignments`: unique_pc_assignment (pcid)
- `pctype.typename`: unique
- `operatingsystems.operatingsystem`: unique

**Default Values:**
- Most `isactive` fields default to `b'1'` (active)
- Timestamps use CURRENT_TIMESTAMP
- Many FKs default to ID=1 (generic/default record)

---

## 2. Application Architecture

### 2.1 Technology Stack

**Server-Side:**
- **Language:** VBScript (Classic ASP)
- **Web Server:** IIS Express (Windows 11 VM)
- **Database:** MySQL 5.6.51 (Docker container on Linux host)
- **ODBC Driver:** MySQL ODBC 8.0

**Client-Side:**
- **Framework:** Bootstrap 4
- **Icons:** Material Design Iconic Font (zmdi)
- **Charts:** Chart.js
- **Calendar:** FullCalendar
- **Tables:** DataTables (with server-side processing)
- **Utilities:** jQuery, Moment.js

**Development Environment:**
- **Code Editing:** Linux (VSCode/Claude Code)
- **File Sharing:** Samba (Linux → Windows Z: drive)
- **Testing:** Windows 11 VM via http://192.168.122.151:8080
- **Version Control:** Not currently using Git (should be added)

### 2.2 File Structure

```
shopdb/
├── *.asp (91 main application files)
│   ├── default.asp (dashboard with rotating images)
│   ├── search.asp (unified FULLTEXT search)
│   ├── calendar.asp (notification calendar)
│   ├── display*.asp (view/list pages)
│   ├── add*.asp (create forms)
│   ├── edit*.asp (update forms)
│   ├── save*.asp (backend processors)
│   ├── delete*.asp (delete handlers)
│   ├── api_*.asp (API endpoints)
│   ├── error*.asp (custom error pages)
│   └── check_*.asp (utilities/diagnostics)
│
├── includes/
│   ├── sql.asp (database connection)
│   ├── header.asp (HTML head section)
│   ├── leftsidebar.asp (navigation menu)
│   ├── topbarheader.asp (top navigation bar)
│   ├── colorswitcher.asp (theme selector)
│   ├── notificationsbar.asp (active notifications)
│   ├── error_handler.asp (centralized error handling)
│   ├── validation.asp (input validation functions)
│   ├── db_helpers.asp (database utility functions)
│   ├── data_cache.asp (query result caching)
│   ├── encoding.asp (output encoding/sanitization)
│   └── config.asp (application configuration)
│
├── assets/
│   ├── css/ (Bootstrap, custom styles)
│   ├── js/ (jQuery, charts, datatables)
│   ├── images/ (logos, icons)
│   └── plugins/ (third-party libraries)
│
├── images/
│   └── 1-9.jpg (rotating dashboard images)
│
├── sql/
│   ├── database_updates_for_production.sql
│   ├── create_printer_machines.sql
│   └── cleanup_duplicate_printer_machines.sql
│
└── docs/
    ├── ASP_DEVELOPMENT_GUIDE.md
    ├── STANDARDS.md
    ├── NESTED_ENTITY_CREATION.md
    └── DEEP_DIVE_REPORT.md (this document)
```

### 2.3 Code Patterns & Standards

#### **Include Pattern**
Every page follows this structure:
```vbscript
<!--#include file="./includes/sql.asp"-->
<!DOCTYPE html>
<html>
<head>
  <!--#include file="./includes/header.asp"-->
</head>
<%
  theme = Request.Cookies("theme")
  IF theme = "" THEN theme="bg-theme1"
%>
<body class="bg-theme <%Response.Write(theme)%>">
  <div id="wrapper">
    <!--#include file="./includes/leftsidebar.asp"-->
    <!--#include file="./includes/topbarheader.asp"-->

    <!-- Page content here -->

    <!--#include file="./includes/colorswitcher.asp"-->
  </div>

  <!-- Scripts -->
  <script src="assets/js/jquery.min.js"></script>
  <script src="assets/js/app-script.js"></script>
</body>
</html>
<%objConn.Close%>
```

#### **Database Query Pattern**
The codebase uses TWO approaches (needs standardization):

**Older pattern (direct Execute):**
```vbscript
strSQL = "SELECT * FROM machines WHERE machineid = ?"
Set rs = objConn.Execute(strSQL)
```
 **Security Issue:** Not properly parameterized!

**Modern pattern (with parameterization):**
```vbscript
<!--#include file="./includes/db_helpers.asp"-->
strSQL = "SELECT * FROM machines WHERE machineid = ?"
Set rs = ExecuteParameterizedQuery(objConn, strSQL, Array(machineId))
```

#### **Error Handling Pattern**
```vbscript
<!--#include file="./includes/error_handler.asp"-->
<%
Call InitializeErrorHandling("pagename.asp")

' Database operations
Call CheckForErrors()

' Validation errors
If invalidInput Then
    Call HandleValidationError("return.asp", "INVALID_INPUT")
End If

Call CleanupResources()
%>
```

### 2.4 Key Features Implementation

#### **Search System (search.asp)**
Implements unified FULLTEXT search across:
1. **Applications** - FULLTEXT + LIKE fallback for short terms
2. **Knowledge Base** - Multi-field FULLTEXT (description + keywords)
3. **Notifications** - Time-decay relevance scoring
4. **Machines** - By number, alias, type, vendor, notes
5. **Printers** - By CSF name, model, serial number

**Smart Redirects:**
- Exact printer serial → direct to printer page
- Exact printer FQDN → direct to printer page
- Exact machine number → direct to machine page

**Relevance Scoring:**
- Apps: FULLTEXT score × 10
- KB: (appname × 3) + (description × 2) + (keywords × 2.5) + (clicks × 0.1)
- Notifications: FULLTEXT score × time_factor (3.0 active, 2.0 future, 1.5 recent, 0.5 old, 0.1 very old)
- Machines/Printers: Fixed score of 15.0

#### **Calendar View (calendar.asp)**
Uses FullCalendar to display notifications:
- Color coding: Green=active, Gray=inactive/expired
- "[ONGOING]" indicator for indefinite notifications
- Click to edit notification
- Month/week/day/list views

#### **Dashboard (default.asp)**
- Rotating random image (1-9.jpg) from shop floor
- Active notifications bar
- Quick links to major sections
- Theme persistence via cookies

#### **PC Management**
- **displaypcs.asp** - DataTables with server-side filtering
- **displaypc.asp** - Detailed PC view with:
  - Hardware specs (manufacturer, model, serial)
  - Network interfaces table
  - Warranty status with color-coded alerts
  - Assigned machine (with DualPath handling)
  - Installed applications
  - Communication configuration
  - DNC settings

#### **Machine Management**
- **displaymachines.asp** - Sortable machine list
- **displaymachine.asp** - Machine details:
  - Assigned printer
  - IP addresses
  - Installed applications
  - Associated PCs (control, HMI, engineering)
  - Shop floor map coordinates

#### **Printer Management**
- **displayprinters.asp** - Printer inventory
- **displayprinter.asp** - Printer details with assigned machine/location
- **api_printers.asp** - JSON API for external systems

#### **Knowledge Base**
- **displayknowledgebase.asp** - Browsable by application
- **displayknowledgearticle.asp** - Article view with click tracking
- **addknowledgebase.asp** - Quick-add from search results

#### **Network Management**
- **displaysubnets.asp** - VLAN and subnet tracking
- Visual subnet mapping
- IP address allocation tracking

### 2.5 Caching System

The application implements a query result cache (`includes/data_cache.asp`):

```vbscript
' Check cache first
Set cachedData = GetCachedData("cache_key")
If Not IsNull(cachedData) Then
    ' Use cached data
Else
    ' Query database
    ' Store in cache with TTL
    Call CacheData("cache_key", resultSet, 300) ' 5 minutes
End If
```

**Cache Strategy:**
- Static data (vendors, models, types): 30+ minutes
- Dynamic data (PC list, machine status): 5 minutes
- Real-time data (search results): No caching
- Cache invalidation on updates

---

## 3. Data Flow & Workflows

### 3.1 PC Lifecycle

1. **Discovery** - PC inventory script runs (external PowerShell)
2. **Import** - Data uploaded via API or manual entry
3. **Classification** - Assigned pctype (Standard/Engineer/Shopfloor)
4. **Configuration** - Network, DNC, communication settings recorded
5. **Assignment** - Linked to machine number (shopfloor PCs)
6. **Monitoring** - Warranty tracking, configuration drift detection
7. **Maintenance** - Updates recorded with timestamps
8. **Retirement** - Set isactive=0, preserve historical data

### 3.2 Machine-PC Assignment Flow

**Simple Case (1 PC → 1 Machine):**
```
1. PC hostname contains machine number (e.g., "3104-HMI")
2. pc.machinenumber populated automatically
3. Views resolve PC → Machine relationship
```

**Complex Case (DualPath - 1 PC → 2 Machines):**
```
1. pc_dnc_config.dualpath_enabled = 1
2. pc_dnc_config.path1_name, path2_name populated
3. pc_dualpath_assignments created:
   - primary_machine = "3104"
   - secondary_machine = "3105"
4. pc.requires_manual_machine_config = 1
5. Views show both machines for this PC
```

**Override Case (Manual Assignment):**
```
1. Automatic detection fails or is wrong
2. Create machine_overrides record:
   - pcid = 42
   - machinenumber = "3117"
3. Override takes precedence in all views
```

### 3.3 Search Flow

```
User enters search term → search.asp
  ↓
1. Check for exact match redirects:
   - Printer serial number → displayprinter.asp?printerid=X
   - Printer FQDN → displayprinter.asp?printerid=X
   - Machine number → displaymachine.asp?machineid=X
  ↓
2. FULLTEXT Search (if term ≥ 4 characters):
   - Applications: MATCH(appname) AGAINST(term)
   - KB Articles: MATCH(description,keywords) AGAINST(term)
   - Notifications: MATCH(notification) AGAINST(term)
  ↓
3. LIKE Fallback (if FULLTEXT returns 0 or term < 4 chars):
   - Applications: LOWER(appname) LIKE '%term%'
   - Machines: machinenumber, alias, notes, type, vendor LIKE '%term%'
   - Printers: CSF name, model, serial LIKE '%term%'
  ↓
4. Combine results, sort by relevance, display unified results
```

### 3.4 Warranty Tracking Flow

```
Nightly PowerShell Script (external)
  ↓
Calls Dell API with service tags (serial numbers)
  ↓
Updates pc table:
  - warrantyenddate
  - warrantystatus
  - warrantydaysremaining
  - warrantyservicelevel
  - warrantylastchecked = NOW()
  ↓
Views calculate warranty alerts:
  - Red: Expired
  - Yellow: Expiring in < 30 days
  - Orange: Warning (< 90 days)
  - Green: OK
  ↓
Reports generated from vw_warranties_expiring
```

---

## 4. Technical Debt & Issues

### 4.1 Security Concerns

**CRITICAL:**
1. **No Authentication System** - Application is wide open, no login required
2. **Inconsistent Parameterization** - Many queries use Execute() without proper parameterization
3. **SQL Injection Vulnerabilities** - Direct string concatenation in SQL queries
4. **No HTTPS Enforcement** - Runs on HTTP (port 8080)
5. **No CSRF Protection** - Forms lack anti-CSRF tokens
6. **No Input Validation on Some Forms** - Not all forms use validation.asp
7. **Error Messages Expose Internal Details** - Stack traces visible to users
8. **No Rate Limiting** - API endpoints unprotected
9. **Session Management Not Implemented** - No user tracking

**Recommendations:**
- Implement Active Directory authentication
- Audit all SQL queries for parameterization
- Add HTTPS certificate to IIS
- Implement CSRF tokens on all forms
- Use validation.asp consistently
- Create generic error pages
- Add API rate limiting
- Implement session-based authentication

### 4.2 Code Quality Issues

1. **Duplicate Code** - error_handler.asp and error_handler_new.asp are identical
2. **Inconsistent Naming** - Mixed camelCase and underscore_case
3. **Magic Numbers** - Hard-coded IDs (DEFAULT=1 everywhere)
4. **No Code Comments** - Minimal documentation in code
5. **Long Functions** - Some pages exceed 500 lines
6. **No Unit Tests** - Zero automated testing
7. **Mixed Patterns** - Old vs new database access patterns
8. **Global Variables** - Excessive use of session-level globals

**Recommendations:**
- Delete duplicate files (keep error_handler.asp only)
- Adopt consistent naming convention (see STANDARDS.md)
- Create constants file for common IDs
- Add inline documentation
- Refactor large pages into functions/includes
- Implement basic unit testing framework
- Standardize on ExecuteParameterizedQuery pattern
- Minimize global state

### 4.3 Database Design Issues

1. **Missing Indexes** - Some FK columns lack indexes
2. **Inconsistent Column Types** - tinytext vs varchar(255)
3. **bit(1) vs tinyint(1)** - Mixed boolean representations
4. **Nullable Foreign Keys** - Should some be NOT NULL?
5. **No Audit Logging** - No change history tracking
6. **Missing Cascades** - Some FKs should CASCADE DELETE
7. **FULLTEXT on MyISAM** - knowledgebase uses MyISAM (old)

**Recommendations:**
- Add index audit and optimization
- Standardize on VARCHAR with explicit lengths
- Migrate to tinyint(1) for booleans
- Review FK nullable constraints
- Implement audit log table
- Review CASCADE DELETE rules
- Convert knowledgebase to InnoDB

### 4.4 Performance Concerns

1. **No Query Optimization** - Some N+1 query patterns
2. **Missing Composite Indexes** - Multi-column WHERE clauses
3. **Large Views** - Some views join 6+ tables
4. **No Connection Pooling** - Each request opens new connection
5. **Synchronous Warranty Checks** - Should be async/batch
6. **No CDN** - All assets served from IIS Express
7. **No Minification** - CSS/JS served uncompressed

**Recommendations:**
- Profile slow queries with MySQL slow query log
- Add composite indexes for common filters
- Materialize complex views as cached tables
- Enable ADO connection pooling
- Move warranty checks to background job
- Consider CDN for static assets
- Implement asset minification/bundling

### 4.5 Deployment & Operations

1. **No Version Control** - Code not in Git
2. **No Deployment Pipeline** - Manual file copying
3. **No Database Migrations** - Schema changes manual
4. **No Backup Automation** - Database backups manual
5. **No Monitoring** - No uptime/error tracking
6. **No Log Aggregation** - Logs scattered across files
7. **No Documentation for Onboarding** - Until now!

**Recommendations:**
- Initialize Git repository
- Create deployment scripts
- Implement migration system (e.g., numbered SQL files)
- Automate daily database backups
- Set up Zabbix/Nagios monitoring
- Centralize logging (syslog or ELK stack)
- Maintain comprehensive documentation (this file!)

---

## 5. Strengths & Best Practices

### 5.1 What's Done Well

1. **Comprehensive Data Model** - Covers all shopfloor entities thoroughly
2. **View Layer** - Excellent use of views for complex reporting
3. **Caching System** - data_cache.asp reduces database load
4. **FULLTEXT Search** - Modern search implementation with fallbacks
5. **Responsive UI** - Bootstrap ensures mobile compatibility
6. **Theme System** - User-customizable dark/light themes
7. **Error Handling Structure** - Centralized error handler (when used)
8. **Validation Library** - validation.asp provides reusable functions
9. **Foreign Key Constraints** - Data integrity enforced at DB level
10. **Documentation Started** - STANDARDS.md and development guides exist

### 5.2 Innovative Features

1. **Unified Search** - Single search box for all entities
2. **DualPath Support** - Handles complex multi-machine PC assignments
3. **Warranty Integration** - Automated Dell API tracking
4. **Network Discovery** - Automatic network interface detection
5. **Visual Shop Floor Map** - mapleft/maptop coordinates for spatial view
6. **Click Tracking** - Knowledge base popularity metrics
7. **Notification Calendar** - FullCalendar integration with time relevance
8. **Dynamic Dashboards** - Rotating images keep UI fresh
9. **API Endpoints** - JSON APIs for external integration
10. **Smart Redirects** - Search intelligently routes to detail pages

---

## 6. Recommendations for Team

### 6.1 Immediate Priorities (Week 1)

1. **Security Audit** - Review all SQL queries for injection vulnerabilities
2. **Git Setup** - Initialize repository, commit current state
3. **Backup Automation** - Schedule daily database dumps
4. **Error Handler Cleanup** - Delete duplicate files, standardize on one
5. **Documentation Review** - All team members read STANDARDS.md

### 6.2 Short-Term Goals (Month 1)

1. **Authentication Implementation** - Add AD/LDAP login
2. **Parameterization Audit** - Convert all queries to use db_helpers.asp
3. **Input Validation** - Ensure all forms use validation.asp
4. **HTTPS Setup** - Generate certificate, configure IIS
5. **Monitoring Setup** - Install Zabbix or equivalent
6. **Code Review Process** - Establish peer review workflow

### 6.3 Medium-Term Goals (Quarter 1)

1. **Test Coverage** - Implement basic unit/integration tests
2. **CI/CD Pipeline** - Automated deployment from Git
3. **Performance Optimization** - Index tuning, query optimization
4. **API Expansion** - RESTful API for all major entities
5. **Mobile App** - Consider mobile wrapper for critical functions
6. **Database Migration System** - Versioned schema changes

### 6.4 Long-Term Vision (Year 1)

1. **Microservices** - Consider breaking into services (API, UI, Jobs)
2. **Real-Time Updates** - WebSockets for live machine status
3. **Analytics Dashboard** - Trends, predictions, KPIs
4. **Integration Hub** - Connect to ERP, CMMS, other systems
5. **Audit Logging** - Complete change history for compliance
6. **Disaster Recovery** - Automated failover, geographic redundancy

---

## 7. Team Onboarding Guide

### 7.1 For New Developers

**Day 1:**
1. Read ASP_DEVELOPMENT_GUIDE.md
2. Read STANDARDS.md
3. Read this DEEP_DIVE_REPORT.md
4. Set up development environment (Windows VM + Linux host)
5. Access test site: http://192.168.122.151:8080

**Week 1:**
1. Browse all major pages (display*, add*, edit*)
2. Run test queries in MySQL
3. Review includes/ folder files
4. Make a small bug fix or feature
5. Understand the search system (search.asp)

**Month 1:**
1. Implement a complete feature (add/edit/display)
2. Understand PC-to-machine assignment logic
3. Review all 23 database views
4. Contribute to documentation improvements
5. Pair program with experienced team member

### 7.2 For Database Administrators

**Key Tables to Understand:**
1. `pc` - Central PC inventory
2. `machines` - Shopfloor equipment
3. `pc_network_interfaces` - Network configuration
4. `pc_dnc_config` - DNC settings (critical for shopfloor)
5. `pc_dualpath_assignments` - Multi-machine assignments

**Daily Tasks:**
- Monitor database size and performance
- Check slow query log
- Review warranty data freshness
- Verify backup success
- Monitor connection pool usage

**Weekly Tasks:**
- Optimize slow queries
- Review index usage
- Check for data anomalies
- Update documentation if schema changes
- Analyze growth trends

### 7.3 For System Administrators

**Server Monitoring:**
- IIS Express uptime (should auto-start with Windows)
- MySQL container health (Docker on Linux)
- Network connectivity (192.168.122.x subnet)
- Disk space (database growth ~50MB/year)
- Log file rotation

**Backup Procedures:**
```bash
# Daily backup (automated)
docker exec dev-mysql mysqldump -u 570005354 -p570005354 shopdb \
  > /backups/shopdb-$(date +%Y%m%d).sql

# Weekly full backup (includes FULLTEXT indexes)
docker exec dev-mysql mysqldump -u 570005354 -p570005354 \
  --single-transaction --routines --triggers shopdb \
  > /backups/shopdb-full-$(date +%Y%m%d).sql
```

**Restore Procedures:**
```bash
# Restore from backup
docker exec -i dev-mysql mysql -u 570005354 -p570005354 shopdb \
  < /backups/shopdb-20251020.sql
```

### 7.4 For Business Analysts

**Key Reports Available:**
1. PC Inventory by Type (vw_pctype_config)
2. Warranty Expiration (vw_warranties_expiring)
3. Machine Utilization (installedapps counts)
4. Network Configuration (vw_pc_network_summary)
5. Shopfloor Coverage (vw_shopfloor_pcs)
6. Knowledge Base Popularity (knowledgebase.clicks)
7. Vendor Distribution (vw_vendor_summary)

**Data Export:**
- Most display*.asp pages have DataTables export (CSV/Excel)
- Direct SQL access for custom reports
- API endpoints for programmatic access

---

## 8. Glossary

**CNC** - Computer Numerical Control (machine tool)
**DNC** - Distributed Numerical Control (file transfer system for CNCs)
**DualPath** - CNC feature allowing one PC to control two spindles/machines
**eFocas** - Fanuc protocol for CNC communication
**FQDN** - Fully Qualified Domain Name
**HMI** - Human-Machine Interface
**PPDCS** - Part Program Distribution and Control System
**Shopfloor** - Manufacturing floor with CNC machines
**Zabbix** - Open-source monitoring software

**GE-Specific Terms:**
- **Machine Number** - Unique identifier for each CNC (e.g., "3104")
- **CSF** - Computer Services Factory (legacy term for IT department)
- **Build Doc** - Standard configuration document for PC/machine setup
- **Functional Account** - Service account for automated processes

---

## 9. Architecture Diagram

```
┌─────────────────────────────────────────────────────────────────┐
│                      SHOPDB APPLICATION                          │
├─────────────────────────────────────────────────────────────────┤
│                                                                  │
│  ┌──────────────┐      ┌──────────────┐      ┌──────────────┐ │
│  │  Users       │      │  External    │      │  Automated   │ │
│  │  (Browser)   │      │  Systems     │      │  Scripts     │ │
│  └──────┬───────┘      └──────┬───────┘      └──────┬───────┘ │
│         │                     │                     │          │
│         │ HTTP :8080          │ API Calls           │ API      │
│         ↓                     ↓                     ↓          │
│  ┌──────────────────────────────────────────────────────────┐ │
│  │              IIS EXPRESS (Windows 11 VM)                  │ │
│  │                                                            │ │
│  │  ┌─────────────────────────────────────────────────────┐ │ │
│  │  │          Classic ASP Application (VBScript)          │ │ │
│  │  │                                                       │ │ │
│  │  │  ┌─────────┐  ┌─────────┐  ┌─────────┐  ┌────────┐ │ │ │
│  │  │  │ Pages   │  │Includes │  │ Views   │  │ APIs   │ │ │ │
│  │  │  │ (*.asp) │  │(helpers)│  │(display)│  │(JSON)  │ │ │ │
│  │  │  └─────────┘  └─────────┘  └─────────┘  └────────┘ │ │ │
│  │  │       ↓             ↓            ↓           ↓       │ │ │
│  │  │  ┌──────────────────────────────────────────────┐  │ │ │
│  │  │  │        MySQL ODBC 8.0 Driver                  │  │ │ │
│  │  │  └──────────────────┬───────────────────────────┘  │ │ │
│  │  └────────────────────│──────────────────────────────┘ │ │
│  └───────────────────────│────────────────────────────────┘ │
│                          │ MySQL Protocol (TCP 3306)        │
│                          │ to 192.168.122.1                 │
│                          │                                  │
│  ┌───────────────────────▼────────────────────────────────┐ │
│  │           MySQL 5.6.51 (Docker Container)               │ │
│  │                                                          │ │
│  │  ┌─────────────┐  ┌──────────────┐  ┌───────────────┐ │ │
│  │  │ Base Tables │  │    Views     │  │    Indexes    │ │ │
│  │  │  (29)       │  │    (23)      │  │  (FULLTEXT)   │ │ │
│  │  └─────────────┘  └──────────────┘  └───────────────┘ │ │
│  │                                                          │ │
│  │  shopdb Database (3.5 MB)                               │ │
│  └──────────────────────────────────────────────────────────┘ │
│                                                                │
│  ┌──────────────────────────────────────────────────────────┐ │
│  │              File System (Samba Share)                    │ │
│  │  Linux: ~/projects/windows/shopdb                        │ │
│  │  Windows: Z:\shopdb                                       │ │
│  └──────────────────────────────────────────────────────────┘ │
│                                                                │
└────────────────────────────────────────────────────────────────┘

External Data Sources:
┌─────────────────┐
│  Dell API       │ ──► Warranty Data
└─────────────────┘

┌─────────────────┐
│ PowerShell      │ ──► PC Inventory Scripts
│ Inventory       │
└─────────────────┘

┌─────────────────┐
│ Network Scans   │ ──► IP/MAC Discovery
└─────────────────┘
```

---

## 10. Database Schema Diagram

```
┌──────────────┐
│  vendors     │
│  (22 rows)   │
└──────┬───────┘
       │
       │ 1:N
       ↓
┌──────────────┐
│   models     │
│  (66 rows)   │
└──────┬───────┘
       │
       │ 1:N
       ├────────────────────────┐
       ↓                        ↓
┌──────────────┐        ┌─────────────┐
│   machines   │        │     pc      │
│  (256 rows)  │        │  (242 rows) │
│              │        │             │
│ machinenumber│        │  machinenumber ← Links here
│ alias        │        │  hostname   │
│ ipaddress1/2 │        │  serialnumber│
│ mapleft/top  │        └──────┬──────┘
└──────┬───────┘               │
       │                       │ 1:N
       │ 1:N                   ├─────────────────────┐
       ↓                       ↓                     ↓
┌──────────────┐        ┌────────────────┐   ┌──────────────────┐
│installedapps│        │pc_network_     │   │ pc_comm_config   │
│  (327 rows) │        │  interfaces    │   │   (502 rows)     │
│             │        │   (705 rows)   │   │                  │
│ appid ──────┼───┐    │                │   │ Serial settings  │
│ machineid   │   │    │ ipaddress      │   │ eFocas settings  │
└─────────────┘   │    │ subnetmask     │   └──────────────────┘
                  │    │ isdhcp         │
                  │    └────────────────┘
                  │
                  │            1:N
                  │    ┌──────────────────┐
                  └────►  applications    │
                       │   (44 rows)      │
                       │                  │
                       │  appname ◄─FULLTEXT
                       │  isinstallable   │
                       │  islicenced      │
                       └────────┬─────────┘
                                │
                                │ 1:N
                                ↓
                       ┌──────────────────┐
                       │ knowledgebase    │
                       │   (196 rows)     │
                       │                  │
                       │  shortdescription ◄─FULLTEXT
                       │  keywords ◄─FULLTEXT
                       │  linkurl         │
                       │  clicks          │
                       └──────────────────┘

┌──────────────┐        ┌──────────────────┐
│  subnets     │        │  notifications   │
│  (38 rows)   │        │   (20 rows)      │
│              │        │                  │
│ ipaddress    │        │  notification ◄─FULLTEXT
│ subnet       │        │  starttime       │
│ vlan         │        │  endtime         │
│ subnettypeid │        │  isactive        │
└──────────────┘        └──────────────────┘

┌──────────────┐        ┌──────────────────────┐
│  printers    │        │ pc_dnc_config        │
│  (40 rows)   │        │   (136 rows)         │
│              │        │                      │
│ printercsfname│       │ dualpath_enabled     │
│ serialnumber │        │ path1_name/path2_name│
│ ipaddress    │        │ ftphostprimary       │
│ fqdn         │        │ site, cnc, ncif      │
│ machineid ───┼────────►                      │
└──────────────┘        └──────────────────────┘

Lookup Tables:
┌──────────────┐  ┌──────────────┐  ┌──────────────┐
│   pctype     │  │  pcstatus    │  │ operatingsys │
│   (6 rows)   │  │  (5 rows)    │  │  (7 rows)    │
│              │  │              │  │              │
│ Standard     │  │ In Use       │  │ Windows 10   │
│ Engineer     │  │ Spare        │  │ Windows 7    │
│ Shopfloor    │  │ Retired      │  │ etc.         │
└──────────────┘  └──────────────┘  └──────────────┘

┌──────────────┐  ┌──────────────┐  ┌──────────────┐
│ machinetypes │  │ supportteams │  │ businessunits│
│  (20 rows)   │  │  (9 rows)    │  │  (7 rows)    │
└──────────────┘  └──────────────┘  └──────────────┘

Advanced Relationship Tables:
┌──────────────────────────┐
│ machine_pc_relationships │ (Many-to-Many)
│                          │
│ machine_id ──┐           │
│ pc_id ────────┼───────────┤
│ pc_role       │           │
│ is_primary    │           │
└───────────────┘

┌──────────────────────────┐
│ pc_dualpath_assignments  │
│                          │
│ pcid ──────────┐         │
│ primary_machine │         │
│ secondary_machine        │
└──────────────────────────┘

┌──────────────────────────┐
│  machine_overrides       │
│                          │
│ pcid ──────────┐         │
│ machinenumber (override) │
└──────────────────────────┘
```

---

## 11. Conclusion

ShopDB is a mature, feature-rich manufacturing floor management system with a comprehensive data model and modern search capabilities. The application successfully tracks hundreds of PCs, machines, and printers with complex relationships and automated data collection.

**Strengths:**
- Comprehensive entity coverage
- Modern FULLTEXT search implementation
- Well-structured database with views
- Responsive UI with theming
- Caching and performance considerations

**Areas for Improvement:**
- Security (authentication, parameterization, HTTPS)
- Code standardization and quality
- Version control and deployment automation
- Testing and monitoring
- Documentation (now addressed!)

**Next Steps for Team:**
1. Review this document thoroughly
2. Implement security fixes (highest priority)
3. Establish Git workflow
4. Begin code standardization
5. Set up monitoring and backups

This application is the central nervous system for shopfloor IT operations at West Jefferson. Understanding its architecture, data flows, and patterns is essential for maintaining and extending it effectively.

---

**Document Maintained By:** Development Team
**Last Major Update:** 2025-10-20
**Review Cycle:** Quarterly or after major changes
**Questions/Feedback:** See team lead or update this document directly
