php-vs-nextjs/SKILL.md
Decision framework for choosing PHP vs Next.js/Node.js for web projects. Covers when to use each, migration strategies, and the hybrid approach. Use when starting a new project, evaluating technology stack, or deciding whether to extend PHP...
npx skillsauth add peterbamuhigire/skills-web-dev php-vs-nextjsInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
php-vs-nextjs or would be better handled by a more specific companion skill.SKILL.md first, then load only the referenced deep-dive files that are necessary for the task.PHP and Next.js are not competing for the same jobs. PHP excels at server-rendered backends, multi-tenant SaaS, and CMS. Next.js excels at React-based full-stack apps, dynamic UIs, and real-time features.
Default rule: Start with PHP if the team knows PHP and the use case is a traditional multi-tenant SaaS. Start with Next.js if the frontend needs to be a rich interactive application.
| Factor | Choose PHP | Choose Next.js | |---|---|---| | Team expertise | PHP team in place | JavaScript/TypeScript team | | Frontend complexity | Simple server-rendered pages, minimal JS | Rich SPA, dashboards, real-time UI | | Backend logic | Complex DB operations, multi-tenant SaaS | Thin backend, mostly API calls to services | | Real-time features | Not needed | WebSockets, live updates, streaming | | Rendering strategy | Server-rendered HTML (traditional) | SSR + SSG + ISR + CSR mix | | CMS / WordPress | WordPress plugin, WooCommerce | Headless CMS with Next.js frontend | | Existing codebase | PHP codebase already exists | Greenfield project | | Mobile API | Laravel/Slim REST API for mobile | Next.js Route Handlers as API | | File uploads / processing | PHP handles well natively | Route Handlers + storage service | | SEO | PHP renders HTML naturally | Next.js SSR/SSG equally good | | Deployment infrastructure | LAMP/WAMP, shared hosting | Vercel, Railway, Docker | | Database | MySQL via PDO/Eloquent | PostgreSQL/MySQL via Prisma | | Auth complexity | Full auth + RBAC + sessions | NextAuth or Clerk | | Email / queues | Laravel Queues, Swift Mailer | BullMQ, Resend, Sendgrid | | Multi-tenant SaaS | Strong — DB isolation per tenant easy | Possible but more setup | | Time to first page | Very fast on VPS | Fast with Vercel Edge | | Type safety | PHP 8 + PHPStan/Psalm | TypeScript end-to-end |
franchise_id is PHP's sweet spot.// PHP strength: multi-tenant query isolation — every query is tenant-scoped
$stmt = $db->prepare('SELECT * FROM invoices WHERE tenant_id = ? AND id = ?');
$stmt->execute([$user['tenant_id'], $id]); // tenant can NEVER see other tenants' data
// Next.js strength: full-stack TypeScript, types shared between frontend and backend
type Invoice = { id: string; amount: number; tenantId: string }; // shared type
// Server component fetches directly from DB — no extra API round trip
export default async function InvoicePage({ params }: { params: { id: string } }) {
const invoice = await db.invoice.findFirst({ where: { id: params.id, tenantId: getSession().tenantId } });
return <InvoiceView invoice={invoice} />;
}
Many production systems use both:
┌─────────────────────────────────────────────────────────┐
│ User's Browser │
└──────────────────────┬──────────────────────────────────┘
│
┌──────────────┴──────────────┐
▼ ▼
┌───────────────┐ ┌────────────────┐
│ Next.js App │ │ PHP Backend │
│ (Frontend UI) │◄──────────►│ (Business API) │
│ React + TS │ REST API │ Laravel/Slim │
└───────────────┘ └────────────────┘
│
┌───────▼───────┐
│ MySQL / Redis │
└───────────────┘
Pattern: PHP handles business logic, multi-tenant data, auth tokens. Next.js handles the rich UI, SSR/ISR for SEO, and calls PHP API.
// Next.js fetches from PHP backend
export default async function DashboardPage() {
const data = await fetch(`${process.env.PHP_API_URL}/api/v1/dashboard`, {
headers: { Authorization: `Bearer ${await getToken()}` },
next: { revalidate: 30 }, // ISR — refresh every 30s
}).then(r => r.json());
return <Dashboard data={data} />;
}
Never rewrite everything at once — migrate incrementally.
Phase 1: New pages in Next.js, PHP handles existing routes
/new-feature → Next.js
/old-feature → PHP (unchanged)
Phase 2: Migrate high-value pages one at a time
/dashboard → Next.js (better UX)
/settings → Next.js
/legacy → PHP (still running)
Phase 3: PHP becomes pure API backend
All UI → Next.js
All data → PHP REST API
| Priority | Reason | |---|---| | Marketing pages | Quick wins: ISR for SEO, fast deploy | | Dashboard / analytics | Rich React components, real-time | | User-facing UI | End-user experience improvement | | Admin panels | TypeScript safety reduces bugs | | Auth flow | NextAuth handles social providers |
| Component | Reason | |---|---| | Business logic / calculations | Complex, tested, working | | Multi-tenant data layer | Proven isolation patterns | | Payment processing | Risk too high to rewrite | | Background jobs | Laravel Queues mature | | File storage / image processing | PHP handles well | | Email system | Existing templates, tested |
| Situation | Consider | |---|---| | Pure mobile backend | Laravel API (PHP) or Hono (Node.js) | | Real-time chat / gaming | Go, Elixir, or Node.js + Socket.io | | Data-heavy analytics | Python FastAPI | | Microservices | Each service picks its own language | | WordPress site | Stay WordPress, use ACF + REST API |
Is the frontend a rich React SPA? YES → Next.js
Does the team know PHP? YES → PHP (unless above)
Is there an existing PHP codebase? YES → Extend PHP
Do you need real-time features? YES → Next.js
Is this a multi-tenant SaaS backend? YES → PHP
Is this AI-powered (LLMs, streaming)? YES → Next.js
Are you on shared/LAMP hosting? YES → PHP
Do you want TypeScript end-to-end? YES → Next.js
data-ai
Use when adding AI-powered analytics to a SaaS platform — semantic search over business data, natural language queries, trend detection, anomaly alerts, and AI-generated insights for dashboards. Covers embeddings, NL2SQL, and per-tenant analytics...
data-ai
Design AI-powered analytics dashboards — what metrics to show, how to display AI predictions and confidence, drill-down patterns, KPI cards, trend visualisation, AI Insights panels, export design, and role-based dashboard variants. Invoke when...
development
Use when designing, building, reviewing, or upgrading production software systems that must be secure, performant, maintainable, scalable, and user-centered. Apply before writing specs, code, architecture, APIs, databases, mobile apps, SaaS platforms, or ERP systems.
development
Professional web app UI using commercial templates (Tabler/Bootstrap 5) with strong frontend design direction when needed. Use for CRUD interfaces, dashboards, admin panels with SweetAlert2, DataTables, Flatpickr. Clone seeder-page.php, use...