Skip to content

An open-source PHP documentation & data exploration platform by Mark Hazleton (WebSpark suite) showcasing hybrid server-side + modern asset pipeline techniques.

License

Notifications You must be signed in to change notification settings

markhazleton/PHPDocSpark

Repository files navigation

πŸš€ PHPDocSpark by Mark Hazleton

Live Demo Canonical PHP Node.js Vite Bootstrap

An open-source PHP documentation & data exploration platform by Mark Hazleton (WebSpark suite) showcasing hybrid server-side + modern asset pipeline techniques.

Educational Focus: This project serves as a comprehensive reference implementation for building modern PHP applications with contemporary tooling, showcasing patterns for documentation management, data visualization, API integration, and responsive UI development.


πŸ“‹ Table of Contents


🎯 Project Overview

PHPDocSpark demonstrates modern PHP web development practices by building a comprehensive documentation and portfolio platform. It integrates traditional server-side PHP with a contemporary client-side build toolchain, creating a hybrid architecture that leverages the best of both worlds.

Learning Objectives

  • Modern PHP Development: PHP 8.2+ features, clean architecture patterns
  • Hybrid Build System: Vite-powered asset pipeline with PHP backend
  • Content Management: Markdown-based documentation with full-text search
  • Data Visualization: Interactive charts and data analysis tools
  • API Integration: GitHub API, external services, caching strategies
  • Responsive Design: Bootstrap 5, mobile-first approach
  • DevOps: Azure Pipelines, automated deployment workflows
  • Brand Integration: Part of the WebSpark suite (https://webspark.markhazleton.com)

Target Audience

  • PHP developers exploring modern development workflows
  • Full-stack developers interested in hybrid architectures
  • Technical writers and documentation maintainers
  • Students learning web development best practices
  • Teams seeking reference implementations for internal tools

✨ Key Features

🎨 Frontend Excellence

  • Modern Build System: Vite 7.1+ with hot module replacement
  • Responsive Design: Bootstrap 5.3 with custom SCSS compilation
  • Interactive Components: DataTables, Chart.js integration
  • Asset Optimization: Automated minification, compression, source maps

πŸ“š Content Management

  • Markdown Documentation: Recursive directory scanning with Parsedown
  • Full-Text Search: File content indexing with relevance scoring
  • Dynamic Navigation: Auto-generated menus from file structure
  • Content Caching: Performance-optimized file serving

πŸ“Š Data Analysis Tools

  • CSV Analysis: Automatic field statistics and data profiling
  • Interactive Tables: Sortable, filterable data grids
  • Chart Generation: Dynamic visualization with Chart.js
  • Export Capabilities: Multiple format support (CSV, Excel, PDF ready)

πŸ”— API Integration

  • GitHub Integration: Repository stats, commit history, contributor data
  • External APIs: JokeAPI demo with error handling
  • Caching Layer: JSON-based response caching with TTL
  • Rate Limiting: Built-in API call optimization

πŸ’Ύ Database Features

  • SQLite Integration: Zero-configuration database setup
  • CRUD Operations: Complete contact management system
  • Data Seeding: Sample data population for testing
  • Duplicate Prevention: Smart data validation logic

πŸ—οΈ Architecture

Hybrid Architecture Pattern

graph TB
    A[Client Browser] --> B[PHP Front Controller]
    B --> C[Page Router]
    C --> D[Feature Pages]
    D --> E[Layout System]
    E --> F[Built Assets]
    
    G[Vite Build System] --> F
    H[SCSS/JS Sources] --> G
    
    D --> I[SQLite Database]
    D --> J[File System]
    D --> K[External APIs]
    
    L[Azure Pipeline] --> M[Azure Web App]
    B --> M
Loading

Request Flow

  1. Routing: Clean URL handling via index.php front controller
  2. Page Logic: Feature-specific PHP scripts with embedded HTML
  3. Layout Composition: Output buffering for template inheritance
  4. Asset Delivery: Optimized CSS/JS via Vite build pipeline
  5. Data Sources: SQLite, Markdown files, JSON, external APIs

πŸ”§ Technology Stack

Backend Stack

Component Technology Version Purpose
Runtime PHP 8.2+ Server-side logic, templating
Database SQLite 3.x Embedded database, zero config
Parser Parsedown Latest Markdown to HTML conversion
Server PHP Built-in 8.2+ Development server

Frontend Stack

Component Technology Version Purpose
Build Tool Vite 7.1+ Asset bundling, HMR
CSS Framework Bootstrap 5.3.7 Responsive design system
Icons Bootstrap Icons 1.13+ Scalable icon library
JavaScript jQuery 3.7+ DOM manipulation, AJAX
Data Tables DataTables 2.3+ Interactive table enhancement
Charts Chart.js Latest Data visualization

Build & DevOps

Component Technology Version Purpose
CSS Preprocessing Sass 1.90+ Advanced CSS features
Linting ESLint 9.15+ JavaScript code quality
Formatting Prettier 3.3+ Code formatting
CI/CD Azure Pipelines Latest Automated deployment
Hosting Azure Web Apps Linux Production hosting

πŸš€ Quick Start

Prerequisites

  • PHP 8.2+ with SQLite extension
  • Node.js 18+ and npm 8+
  • Git for version control

1. Clone & Setup

git clone https://github.com/markhazleton/PHPDocSpark.git
cd documents

# Install dependencies
composer install  # PHP dependencies
npm install       # Node.js dependencies

2. Build Assets

# Development build with watching
npm run dev

# Or full development server (recommended)
npm run dev:serve  # Builds assets + starts PHP server

3. Access Application

Open http://localhost:8001 in your browser.

Alternative: Manual Setup

# Build assets once
npm run build

# Start PHP server
cd website
php -S localhost:8001

πŸ“ Project Structure

documents/
β”œβ”€β”€ πŸ“‚ src/                          # Frontend source files
β”‚   β”œβ”€β”€ main.js                      # Vite entry point
β”‚   β”œβ”€β”€ πŸ“‚ css/                      # SCSS stylesheets
β”‚   β”‚   β”œβ”€β”€ site.scss               # Main stylesheet
β”‚   β”‚   β”œβ”€β”€ custom.scss             # Custom components
β”‚   β”‚   └── vendor.scss             # Third-party styles
β”‚   └── πŸ“‚ js/                      # JavaScript modules
β”‚       β”œβ”€β”€ custom.js               # Custom functionality
β”‚       └── vendor.js               # Third-party libraries
β”‚
β”œβ”€β”€ πŸ“‚ website/                      # PHP application root
β”‚   β”œβ”€β”€ index.php                   # Front controller & router
β”‚   β”œβ”€β”€ layout.php                  # Main template layout
β”‚   β”œβ”€β”€ πŸ“‚ pages/                   # Feature implementations
β”‚   β”‚   β”œβ”€β”€ document_view.php       # Markdown viewer
β”‚   β”‚   β”œβ”€β”€ data-analysis.php       # CSV analysis
β”‚   β”‚   β”œβ”€β”€ database.php            # CRUD operations
β”‚   β”‚   β”œβ”€β”€ project_list.php        # Portfolio showcase
β”‚   β”‚   β”œβ”€β”€ github.php              # GitHub integration
β”‚   β”‚   β”œβ”€β”€ search.php              # Full-text search
β”‚   β”‚   └── joke.php                # API demo
β”‚   β”œβ”€β”€ πŸ“‚ assets/                  # Built assets (generated)
β”‚   β”‚   β”œβ”€β”€ css/site.css            # Compiled stylesheets
β”‚   β”‚   β”œβ”€β”€ js/site.js              # Bundled JavaScript
β”‚   β”‚   β”œβ”€β”€ fonts/                  # Font files
β”‚   β”‚   β”œβ”€β”€ images/                 # Optimized images
β”‚   β”‚   └── πŸ“‚ markdown/            # Documentation content
β”‚   β”‚       β”œβ”€β”€ πŸ“‚ PHP/             # PHP documentation
β”‚   β”‚       β”œβ”€β”€ πŸ“‚ Git/             # Git guides
β”‚   β”‚       β”œβ”€β”€ πŸ“‚ ChatGPT/         # AI assistance docs
β”‚   β”‚       └── πŸ“‚ Build/           # Build system docs
β”‚   └── πŸ“‚ data/                    # Application data
β”‚       β”œβ”€β”€ database.db             # SQLite database
β”‚       β”œβ”€β”€ projects.json           # Portfolio data
β”‚       β”œβ”€β”€ commits_cache.json      # GitHub API cache
β”‚       └── *.csv                   # Sample datasets
β”‚
β”œβ”€β”€ πŸ“‚ scripts/                     # Build automation
β”‚   └── build.js                    # Custom build script
β”œβ”€β”€ πŸ“‚ .github/                     # GitHub configuration
β”‚   └── copilot-instructions.md     # AI assistant config
β”œβ”€β”€ azure-pipelines.yml             # CI/CD pipeline
β”œβ”€β”€ vite.config.js                  # Vite configuration
β”œβ”€β”€ package.json                    # Node.js dependencies
β”œβ”€β”€ composer.json                   # PHP dependencies
└── README.md                       # This file

πŸ› οΈ Development

Available Commands

Development

npm run dev           # Build assets with file watching
npm run dev:serve     # Build + serve (recommended for development)
npm run serve         # Start PHP development server only

Production Build

npm run build         # Production build with optimizations
npm run build:prod    # Production build with NODE_ENV set
npm run start         # Clean + build + serve pipeline

Code Quality

npm run lint:js       # Lint JavaScript with ESLint
npm run lint:css      # Lint SCSS with Stylelint
npm run format        # Format code with Prettier

Maintenance

npm run clean         # Remove built assets
composer install      # Update PHP dependencies

Development Workflow

  1. Start Development Server:

    npm run dev:serve
  2. Make Changes: Edit files in src/ (assets) or website/ (PHP)

  3. Asset Changes: Automatically rebuilt and browser-refreshed

  4. PHP Changes: Refresh browser manually

  5. Before Committing:

    npm run format      # Format code
    npm run build       # Test production build

πŸ“ˆ Build System

Modern Asset Pipeline

The project uses Vite as its build system, providing:

  • ⚑ Lightning Fast: Sub-second rebuilds with HMR
  • 🎯 Optimized Output: Minification, tree-shaking, code splitting
  • πŸ”§ SCSS Processing: Advanced CSS features with Bootstrap integration
  • πŸ“¦ Smart Bundling: Vendor chunks, asset optimization
  • πŸ—ΊοΈ Source Maps: Development debugging support

Build Configuration Highlights

// vite.config.js - Key features:
{
  build: {
    rollupOptions: {
      output: {
        entryFileNames: 'js/site.js',      // Consistent naming
        assetFileNames: 'css/site.css',    // Organized output
      }
    },
    minify: 'terser',                      // Advanced minification
    sourcemap: isDev,                      // Conditional source maps
  },
  css: {
    preprocessorOptions: {
      scss: {
        includePaths: ['node_modules'],    // Library imports
        silenceDeprecations: ['legacy-js-api']
      }
    }
  }
}

Performance Metrics

  • Build Time: ~3.8 seconds (production)
  • CSS Output: 320.77 kB β†’ 47.28 kB (gzipped, 85% reduction)
  • JS Output: 273.21 kB β†’ 87.87 kB (gzipped, 68% reduction)
  • Total Assets: ~1.2 MB β†’ ~200 kB (transferred)

πŸ§ͺ Features Showcase

πŸ“– Documentation Viewer (/)

  • Markdown Rendering: Parsedown integration with syntax highlighting
  • Dynamic Navigation: Auto-generated from folder structure
  • File Organization: Hierarchical content with optgroups
  • Performance: Cached file scanning with lazy loading

πŸ” Search Engine (/?page=search)

  • Full-Text Search: Content indexing across all markdown files
  • Relevance Scoring: Frequency-based result ranking
  • Context Highlighting: Search term emphasis with surrounding context
  • Performance: File modification tracking for cache invalidation

πŸ“Š Data Analysis (/?page=data-analysis)

  • CSV Processing: Automatic field detection and statistics
  • Data Profiling: Min/max/average calculations, frequency analysis
  • Interactive Tables: Sortable, filterable with DataTables
  • Export Ready: Infrastructure for multiple format downloads

πŸ’Ύ Database CRUD (/?page=database)

  • SQLite Integration: Auto-creation with migration logic
  • Contact Management: Full CRUD with duplicate prevention
  • Data Seeding: Star Trek character sample data
  • UI Components: Modal editing, inline forms, confirmation dialogs

🎨 Project Portfolio (/?page=project_list)

  • JSON-Driven: Configurable project cards with metadata
  • Filtering: Live search and category filters
  • Responsive Layout: Bootstrap grid with mobile optimization
  • Image Optimization: Lazy loading and responsive images

πŸ”— GitHub Integration (/?page=github)

  • Repository Stats: Commits, contributors, file counts
  • Commit History: Recent commits with file change deltas
  • API Caching: 1-hour TTL with timestamp display
  • Error Handling: Graceful fallbacks for API failures

πŸ˜„ API Demo (/?page=joke)

  • External Integration: JokeAPI with cURL implementation
  • AJAX Interface: Dynamic content updates with fade transitions
  • Session Tracking: Joke counter with statistics
  • Error Recovery: Network failure handling with user feedback

πŸš€ Deployment

Azure Pipeline Configuration

The project includes a complete CI/CD pipeline via azure-pipelines.yml:

# Production deployment workflow:
trigger: [main]

stages:
  - stage: Build
    - PHP 8.1 setup
    - Composer install
    - Asset compilation
    - Archive website/ folder
    
  - stage: Deploy
    - Azure Web App deployment
    - Zero-downtime deployment
    - Health checks

Deployment Targets

Manual Deployment

# 1. Build production assets
npm run build

# 2. Archive website folder
zip -r site.zip website/

# 3. Deploy via Azure CLI (if configured)
az webapp deployment source config-zip \
  --resource-group controlorigins \
  --name controlorigins-docs \
  --src site.zip

πŸ“– Documentation

Project Documentation

External Resources


🀝 Contributing

We welcome contributions! This project serves as an educational resource, so improvements that enhance learning value are especially appreciated.

Development Setup

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/amazing-feature
  3. Make changes following existing patterns
  4. Test across different PHP versions
  5. Format code: npm run format
  6. Submit a pull request

Contribution Guidelines

  • Code Style: Follow existing PHP and JavaScript patterns
  • Documentation: Update README and inline docs for new features
  • Testing: Manually test all affected functionality
  • Compatibility: Ensure PHP 8.0+ and modern browser support
  • Performance: Consider impact on build times and runtime

Priority Areas

  • Unit test coverage (PHPUnit integration)
  • Accessibility improvements (ARIA labels, keyboard nav)
  • Performance optimizations (caching, lazy loading)
  • Security enhancements (input validation, CSRF protection)
  • Mobile experience improvements

πŸ“Š Performance

Metrics & Optimization

  • Time to First Byte: < 200ms (average)
  • First Contentful Paint: < 1.2s
  • Largest Contentful Paint: < 2.5s
  • Cumulative Layout Shift: < 0.1

Optimization Techniques

  • Asset Bundling: Vite-optimized CSS/JS delivery
  • Image Optimization: WebP format support ready
  • Caching Strategy: File-based caching for API responses
  • Database: SQLite for zero-config performance
  • CDN Ready: Asset structure prepared for CDN deployment

πŸ”’ Security

Current Safeguards

  • Input Validation: Allow-list routing prevents arbitrary file inclusion
  • SQL Injection Prevention: PDO prepared statements throughout
  • XSS Protection: HTML escaping with htmlspecialchars()
  • Dependency Security: Regular updates via npm audit

Recommended Enhancements

  • CSRF Protection: Add token validation for forms
  • Content Security Policy: Implement CSP headers
  • Rate Limiting: Add API call throttling
  • Environment Variables: Move secrets out of code
  • HTTPS Enforcement: SSL-only in production

πŸ“ License

Released under the MIT License β€” see LICENSE for full text.

Copyright (c) Mark Hazleton.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


🌟 Acknowledgments

  • PHP Community: For excellent documentation and best practices
  • Vite Team: For revolutionary build tooling
  • Bootstrap Team: For consistent, beautiful UI components
  • Azure Team: For reliable cloud hosting and DevOps tools
  • Open Source Community: For the amazing ecosystem we build upon

About

An open-source PHP documentation & data exploration platform by Mark Hazleton (WebSpark suite) showcasing hybrid server-side + modern asset pipeline techniques.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published