How mitchmac/serverlesswp works
Project Type and Purpose
• ServerlessWP is a full-stack, serverless hosting solution for WordPress. It combines a Node.js “API” layer (api/index.js + serverlesswp-node) deployed as serverless functions on Vercel, Netlify, or AWS Lambda with a PHP runtime to serve a standard WordPress core in the /wp directory.
• It supports two data-layer options:
• A managed MySQL (or MariaDB-compatible) database (e.g., TiDB)
• A SQLite file stored on demand in S3-compatible object storage
File Structure Analysis
Top-level components:
• /api – Node.js entrypoint for all HTTP requests; invokes serverlesswp-node to bootstrap PHP/WordPress
• /util – Utility scripts for directory management, installation flows, and SQLite+S3 logic
• /serverless.yml, netlify.toml, vercel.json – Deployment configurations for AWS Serverless Framework, Netlify Functions, and Vercel Functions, respectively
• package.json – Declares Node.js dependencies, including serverlesswp-node
• /wp – A full copy of the WordPress core, plus bundled plugins and themes (e.g., WP Offload Media Lite, SQLite Integration plugin)
Key README Insights
• Deploys to Vercel/Netlify/AWS using their serverless functions
• Supports environment-variable configuration for MySQL credentials or SQLite+S3 settings
• Media offload to S3 via the Amazon S3 & CloudFront plugin
• Uses serverlesswp-node to run PHP in a serverless context
Main Components
a. User & CDN Layer
• End users (browsers, mobile clients)
• CDN / edge network (Vercel Edge, Netlify Edge) serving cacheable static assets (CSS, JS, images)
b. Serverless Function / API Gateway
• Vercel/Netlify Function or AWS Lambda behind API Gateway
• Entrypoint: /api/index.js
• Middleware: serverlesswp-node (spawns PHP process, translates Node event → PHP _SERVER variables)
c. PHP / WordPress Core
• /wp directory: core PHP files + plugins + themes
• WP runs in “readonly” mode for static assets, “read/write” mode on dynamic pages or admin actions
d. Data Layer
• Primary: relational database (MySQL/TiDB)
• Optional: SQLite file streamed to/from S3 via util/sqliteS3.js (S3 bucket)
e. Object Storage for Media
• S3-compatible bucket hosting uploads, served via CDN or delivery provider (CloudFront, Cloudflare, KeyCDN, etc.)
• WP Offload Media Lite plugin handles uploads → S3
f. External Services & CI
• GitHub Actions for tests (.github/workflows/*.yml)
• Serverless Framework (serverless.yml) for AWS
• Third-party services: TiDB Cloud, AWS S3, CDN providers
Interactions & Data Flow
1. Browser requests a URL → hits CDN edge
2. If static, CDN returns asset; if dynamic → routes to serverless function
3. Node function (api/index.js)
• Parses event, sets up PHP environment, calls serverlesswp-node
4. PHP process loads wp/index.php, runs WordPress bootstrap
5. WordPress queries either the MySQL database (via wp-config.php ENV variables) or reads/writes database.sqlite on S3 through util/sqliteS3
6. For media uploads, WP plugin intercepts and writes files to S3 bucket; returns S3 URLs
7. Response flows back through Node function → CDN → client
Architectural Patterns & Design Principles
• Microservices / serverless functions for isolation and scaling
• Plugin architecture in WordPress for extensibility (media offload, SQLite integration)
• Environment-driven configuration (ENV variables choose MySQL vs SQLite+S3)
• Immutable deployment: WordPress core & plugins are part of Git repository
• Edge caching: static assets served directly from CDN
Essential Elements
• CDN / edge network
• Serverless function boundary
• Node.js ↔ PHP bridge (serverlesswp-node)
• WordPress core directory
• Plugin/utility modules (S3 offload, SQLite integration)
• Data planes: MySQL vs SQLite+S3
• Media storage in S3