mardev/starter-kit

Starter Kit β€” PHP MVC Boilerplate

Maintainers

Package info

github.com/rodrigomarcelo643/vanilla-php-mvc-starterkit

Type:project

pkg:composer/mardev/starter-kit

Statistics

Installs: 31

Dependents: 0

Suggesters: 0

Stars: 6

Open Issues: 0


README

Version PHP MySQL TailwindCSS Alpine.js PHPUnit Tests

πŸš€ Vanilla PHP MVC Starter Kit

A clean PHP 8+ MVC boilerplate with a structured js/ layer, split route files, super admin + admin panels, session auth with live password strength validation, role-based routing, OAuth (Google + GitHub), flash toast system, AJAX fetch helpers, Alpine.js reactive UI, Tailwind CSS, and PHPUnit β€” zero frameworks, zero fluff.

⭐ Star on GitHub Β· πŸ“– Docs Β· πŸ§ͺ Tests

πŸ“Œ About

Vanilla PHP MVC Starter Kit is a lightweight, zero-framework boilerplate for developers who want a clean starting point without the overhead of Laravel or Symfony. Built on pure PHP 8+, it ships with a hand-rolled MVC architecture, session-based authentication, role-based routing, and a full admin panel β€” all wired up and ready to go.

The frontend uses Tailwind CSS and Alpine.js via CDN, so there's no build pipeline to configure. AJAX helpers, avatar uploads, password reset flow, and a responsive multi-panel layout (super admin, admin, app, client) are included out of the box.

Backed by PHPUnit with 77 tests across unit and feature suites, GitHub Actions workflows for linting, quality checks, and deployment, and a single SQL file to get your database running in minutes.

Start building in minutes, not hours.

What's included

  • Multi-panel layout β€” Super Admin, Admin, App (authenticated users), and Client (public) views
  • Session authentication β€” Login, registration, logout, and password reset out of the box
  • OAuth login β€” Google and GitHub sign-in with auto-prefill registration for new accounts
  • Role-based routing β€” Segregated routes for super admin, admin, app, client, and AJAX calls
  • Super admin panel β€” Highest-privilege panel with admin management, full user CRUD, purple-accented UI
  • Full admin panel β€” Collapsible sidebar, topbar, user management, and data tables
  • Flash toast system β€” Session::flash() sets one-time toasts, auto-fired on next page load
  • AJAX helpers β€” Lightweight fetch wrappers for POST/GET with JSON responses
  • Avatar uploads β€” Image preview, crop, and AJAX upload built in
  • Environment config β€” .env-driven configuration, no hardcoded credentials
  • Tailwind CSS + Alpine.js β€” Modern UI via CDN, no build step required
  • Composer managed β€” PHPMailer, PHPUnit, and more via a clean composer.json
  • 77 PHPUnit tests β€” Unit and feature suites with automatic cleanup

πŸ€” Why This Over Laravel?

This starter kit is intentionally built without Laravel β€” and that's the point.

πŸŽ“ Built for Students

If you are learning PHP for the first time or studying MVC architecture, Laravel's abstractions (Eloquent, Facades, Service Containers) can hide what's actually happening under the hood. This kit exposes everything β€” the router, the auth system, the database layer β€” in plain, readable PHP so you can see exactly how it works.

Start here. Understand MVC fundamentals. Then move to Laravel with confidence.

🏒 Built for Small to Medium Projects

Not every project needs the full weight of a framework. This kit is:

  • Lightweight β€” no 30MB+ vendor folder, no service provider bootstrapping on every request
  • Shared-hosting friendly β€” runs on basic Apache/XAMPP/Laragon setups without special server config
  • Fast to deploy β€” one SQL import, one .env file, and you're live

πŸš€ A Natural Laravel On-ramp

This Kit Laravel Equivalent
Router::get() Route::get()
php kit make:controller php artisan make:controller
php kit db:seed php artisan db:seed
php kit migrate php artisan migrate
.env config .env config
Middleware classes Middleware classes
MVC structure MVC structure

The patterns here are intentionally Laravel-inspired β€” so once you understand this kit, transitioning to Laravel feels familiar, not foreign.

⚑ When to Use This vs Laravel

Scenario Use This Kit Use Laravel
Learning MVC from scratch βœ… ❌ Too much magic
Small business site / portfolio βœ… βœ…
Shared hosting (cPanel) βœ… ⚠️ Can be tricky
Large enterprise SaaS ⚠️ βœ…
Understanding routing internals βœ… ❌ Hidden behind framework
Rapid API with auth/queues/etc ⚠️ βœ…

πŸ–ΌοΈ UI Visuals

Home Home

Sign In Sign In

Sign Up Sign Up

Forgot Password Forgot Password

Admin Dashboard Admin Dashboard

User Panel User Panel

See the full visual walkthrough in VISUALS.md

πŸ“ Project Structure

starterkit/
β”œβ”€β”€ app/
β”‚   β”œβ”€β”€ config/         # App, database, mail & OAuth config (reads from .env)
β”‚   β”œβ”€β”€ controllers/    # MVC controllers
β”‚   β”‚   β”œβ”€β”€ auth/       # AuthController, OAuthController, PasswordController, ProfileController
β”‚   β”‚   └── superadmin/ # SuperAdminDashboardController, SuperAdminAdminController
β”‚   β”œβ”€β”€ core/           # Router, Model, Auth, Session (+ flash), Database, Mailer
β”‚   β”œβ”€β”€ helpers/        # Global helper functions
β”‚   β”œβ”€β”€ models/         # Data models (User, Admin, SuperAdmin, PasswordReset)
β”‚   └── views/          # Layouts, components & pages (superadmin/admin/app/client/auth)
β”œβ”€β”€ assets/             # CSS & fonts
β”œβ”€β”€ database/
β”‚   └── starter.sql     # Database schema + seed data
β”œβ”€β”€ js/
β”‚   β”œβ”€β”€ admin/          # Admin-specific JS (admin.js, users.js)
β”‚   β”œβ”€β”€ ajax.js         # Fetch wrapper (Ajax.post / Ajax.get)
β”‚   β”œβ”€β”€ app.js          # Global utilities (toast, alert, setLoading)
β”‚   β”œβ”€β”€ auth.js         # Auth form handlers + strength meter
β”‚   β”œβ”€β”€ avatar.js       # Avatar upload with drag & drop + XHR progress
β”‚   β”œβ”€β”€ logout.js       # Logout confirmation modal
β”‚   β”œβ”€β”€ profile.js      # Profile edit + change password handlers
β”‚   β”œβ”€β”€ settings.js     # Settings page theme sync
β”‚   β”œβ”€β”€ sidebar.js      # Sidebar keyboard shortcut (Ctrl+B)
β”‚   └── theme.js        # Dark/light mode toggle
β”œβ”€β”€ routes/
β”‚   β”œβ”€β”€ web.php         # Entry point β€” loads all route files
β”‚   └── web/
β”‚       β”œβ”€β”€ superadmin/ # Super admin page + AJAX routes
β”‚       β”œβ”€β”€ admin/      # Admin page + AJAX routes
β”‚       β”œβ”€β”€ app/        # Authenticated user page + AJAX routes
β”‚       β”œβ”€β”€ auth/       # Auth page + AJAX + OAuth routes
β”‚       └── client/     # Public/client page routes
β”œβ”€β”€ storage/            # Uploads
β”œβ”€β”€ tests/              # PHPUnit unit & feature suites
β”œβ”€β”€ .agent/             # AI coding assistant context & prompt templates
β”œβ”€β”€ .claude/            # Claude/Cursor context file
β”œβ”€β”€ .github/workflows/  # CI/CD workflows
β”œβ”€β”€ .env.example        # Environment template
β”œβ”€β”€ .htaccess           # URL rewriting
β”œβ”€β”€ composer.json       # Dependencies
└── index.php           # Application entry point

βš™οΈ Installation

Requirements

  • PHP 8.0+
  • MySQL 5.7+
  • Apache with mod_rewrite enabled (XAMPP / Laragon / WAMP)
  • Composer

Steps

1. Clone the repository

git clone https://github.com/rodrigomarcelo643/php-vanilla-mvc-starterkit.git

Place it inside your server's web root (e.g. htdocs/ or www/).

2. Install dependencies

composer install

3. Set up the database

  • Open phpMyAdmin
  • Go to Import and select database/starter.sql
  • This creates the starter database with tables and seed data

4. Configure environment

cp .env.example .env

Edit .env with your values:

APP_NAME="Starter Kit"
BASE_URL="/your-folder-path"

DB_HOST=localhost
DB_NAME=starter
DB_USER=root
DB_PASS=

5. Visit the app

http://localhost/your-folder-path

Default Credentials

Role Email Password
Super Admin superadmin@starter.com password
Admin admin@starter.com password
User alice@example.com password

🧩 Installer Presets

When you run composer install, the setup wizard automatically launches and asks you to pick an installation mode:

====================================================
       Welcome to Vanilla PHP MVC Starter Kit
====================================================

Which preset would you like to install?
  [1] Full Stack (Alpine.js + AJAX Monolith) - Default
  [2] REST API (Full Stack with JS)
  [3] Backend Only (REST API, No UI)

Select an option [1]:

Option 1 β€” Full Stack (Alpine.js + AJAX Monolith) (default)

The classic MVC full stack mode. All views are rendered server-side. AJAX calls use the /ajax/ route prefix and return JSON. The /api/ routes are also registered and available for external consumers alongside the HTML interface.

  • βœ… All HTML views intact (client, admin, superadmin, app panels)
  • βœ… Session-based auth with login/register pages
  • βœ… AJAX endpoints under /ajax/
  • βœ… REST API endpoints under /api/ (JSON)
  • βœ… http://localhost/yourapp/ β†’ renders HTML homepage

Option 2 β€” REST API (Full Stack with JS)

Identical to Option 1 but injects the smart Controller which auto-detects /api/ prefixed requests and switches them to JSON output mode. All HTML views remain intact. The frontend JS layer drives data via /api/ fetch calls.

  • βœ… All HTML views intact
  • βœ… Smart Controller β€” /api/ routes return JSON, page routes return HTML
  • βœ… Session cookie reused for both browser and API requests
  • βœ… http://localhost/yourapp/ β†’ renders HTML homepage
  • βœ… http://localhost/yourapp/api/admin/users β†’ returns JSON user list

Option 3 β€” Backend Only (REST API, No UI)

Pure JSON API mode. All frontend assets (views, JS, CSS, client routes) are removed. Every request returns JSON. Use this when building a decoupled frontend (React, Vue, mobile app) that communicates with this backend via the /api/ endpoints.

  • βœ… All HTML views removed
  • βœ… Only routes/api.php is loaded β€” pure JSON responses
  • βœ… Smart Controller auth guard returns JSON 401/403 (no HTML redirects)
  • βœ… http://localhost/yourapp/ β†’ returns JSON welcome message
  • βœ… http://localhost/yourapp/api/admin/users β†’ returns JSON user list

Comparison

Feature Option 1 Option 2 Option 3
HTML Views βœ… βœ… ❌
Session Auth (Browser) βœ… βœ… βœ…
/ajax/ AJAX endpoints βœ… βœ… ❌
/api/ REST endpoints (JSON) βœ… βœ… βœ…
Smart JSON/HTML auto-switch ❌ βœ… βœ…
Root / returns HTML βœ… βœ… ❌
Root / returns JSON ❌ ❌ βœ…

You can re-run the installer at any time with: php kit env:setup

πŸ› οΈ Kit CLI Developer Tool

The starter kit comes with Kit (a custom PHP command-line interface helper) to streamline database setup, route inspection, scaffolding, cache management, and server management.

You can run commands using:

# On Windows/Unix
php kit [command] [arguments] [options]

# On Windows (shortcut)
kit.bat [command] [arguments] [options]

Available Commands

πŸ—„οΈ Database Management

  • php kit db:fresh β€” Drops all tables and re-imports the initial schema.
  • php kit db:seed β€” Imports the baseline schema and seed data from database/starter.sql.
  • php kit migrate β€” Runs all pending database migrations.
  • php kit migrate:rollback β€” Rolls back the last batch of migrations.

πŸ—οΈ Code Scaffolding

  • php kit make:controller [Name] β€” Generates a new Controller class.
    • Options: --admin (places in admin folder), --resource (adds boilerplate CRUD methods).
  • php kit make:model [Name] β€” Generates a new Model class.
    • Options: --resource (adds CRUD helper methods).
  • php kit make:view [folder/name] β€” Generates a new View template file.
    • Options: --resource (creates standard list/show/create/edit views).
  • php kit make:middleware [Name] β€” Generates a new Middleware class.
  • php kit make:migration [Name] β€” Generates a new Migration template file.
  • php kit make:auth β€” Generates full Authentication scaffolding (Controllers, Views, and Routes).

πŸ—ΊοΈ Routing

  • php kit route:list β€” Lists all registered application routes, organized by request method, URI path, and handler.
  • php kit route:test β€” Launches an interactive API endpoint tester directly in your terminal. Categorizes all registered /api/ routes by group (Auth, Admin, Superadmin, Profile, App), sends real HTTP requests via cURL (including session cookies), and displays colorized JSON responses. Press [ENTER] to return to the menu after each request. Exit with X or Ctrl+C.

πŸ’» System & Development Utilities

  • php kit serve [host?] [port?] β€” Starts the local PHP built-in development server with custom routing support.
  • php kit tinker β€” Starts an interactive PHP REPL (Read-Eval-Print Loop) session to play with your models and databases.
  • php kit key:generate β€” Generates a secure APP_KEY and updates it in your .env file.
  • php kit cache:clear β€” Clears application cache files.
  • php kit logs:clear β€” Clears application log files.
  • php kit optimize:clear β€” Clears all compiled caches and logs at once.

βš™οΈ Environment & Routing Intelligence

  • Environment-Aware Server Router (server.php): Dynamically parses the BASE_URL from .env to strip any path prefix when serving requests using PHP's built-in development server (php kit serve).
  • Dynamic URI Parsing (app/core/Router.php): Fully decoupled from hardcoded subdirectory dependencies, allowing routing to work seamlessly whether served from an Apache alias (e.g., http://localhost/starterkit) or the built-in server (e.g., http://localhost:8000).

πŸ—ΊοΈ Routes Overview

File Prefix Description
client/pages.php / Public pages (home, about, blog…)
superadmin/pages.php superadmin/ Super admin dashboard, admins, users
superadmin/ajax.php ajax/admins/ Admin CRUD AJAX endpoints
admin/pages.php admin/ Admin dashboard, users, settings
app/pages.php app/ Authenticated user pages
auth/ajax.php ajax/ Login, register + AJAX endpoints
auth/oauth.php oauth/ Google + GitHub OAuth redirect/callback
routes/api.php api/ Unified REST API β€” JSON-only endpoints for all roles

REST API Endpoints (routes/api.php)

All /api/ routes return JSON only, regardless of installation mode.

Method Endpoint Description
GET /api/ping Health check
GET /api API info + endpoint list
POST /api/auth/login Login
POST /api/auth/register Register
POST /api/auth/logout Logout
POST /api/auth/forgot-password Request password reset
POST /api/auth/reset-password Complete password reset
GET /api/admin/users Get all users (admin)
POST /api/admin/users Create user (admin)
POST /api/admin/users/update Update user (admin)
POST /api/admin/users/delete Delete user (admin)
GET /api/admin/dashboard Admin dashboard stats
GET /api/superadmin/admins Get all admins (superadmin)
POST /api/superadmin/admins Create admin (superadmin)
POST /api/superadmin/admins/update Update admin (superadmin)
POST /api/superadmin/admins/delete Delete admin (superadmin)
GET /api/superadmin/users Get all users (superadmin)
GET /api/superadmin/dashboard Superadmin dashboard stats
GET /api/profile Get current user profile
POST /api/profile/avatar Upload avatar
POST /api/profile/update Update profile
POST /api/profile/change-password Change password
GET /api/app/home Authenticated user home data

πŸ‘‘ Super Admin Panel

The super admin is the highest-privilege role in the system. It has its own dedicated panel at /superadmin/dashboard with a purple-accented UI to distinguish it from the regular admin panel.

What super admin can do

  • Dashboard β€” Overview stats: total users, active/inactive users, total admins, new this month
  • Manage Admins β€” Full CRUD: create, edit, delete admin accounts (super_admins table)
  • Manage Users β€” Full CRUD on all user accounts (same as admin panel)
  • Profile β€” Update name, email, avatar, and password
  • Settings β€” Appearance and notification preferences

Database table

Super admins are stored in a dedicated super_admins table, separate from both users and admins.

CREATE TABLE `super_admins` (
    `id`         INT UNSIGNED NOT NULL AUTO_INCREMENT,
    `name`       VARCHAR(100) NOT NULL,
    `email`      VARCHAR(150) NOT NULL,
    `password`   VARCHAR(255) NOT NULL,
    `avatar`     VARCHAR(255) DEFAULT NULL,
    `status`     ENUM('active','inactive') NOT NULL DEFAULT 'active',
    `created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
    `updated_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    PRIMARY KEY (`id`),
    UNIQUE KEY `uq_super_admins_email` (`email`)
);

New files added

app/models/SuperAdmin.php
app/controllers/superadmin/SuperAdminDashboardController.php
app/controllers/superadmin/SuperAdminAdminController.php
app/views/layouts/superadmin/header.php
app/views/layouts/superadmin/footer.php
app/views/components/superadmin/sidebar.php
app/views/components/superadmin/topbar.php
app/views/superadmin/dashboard.php
app/views/superadmin/admins.php
app/views/superadmin/users.php
app/views/superadmin/profile.php
app/views/superadmin/settings.php
routes/web/superadmin/pages.php
routes/web/superadmin/ajax.php

Modified files

File Change
app/core/Controller.php Added superadmin() layout method
app/core/Router.php Added app/controllers/superadmin/ to auto-discovery
app/models/Admin.php Added update(), delete(), adminCreate() methods
app/controllers/auth/AuthController.php Login checks super_admins table, redirects to /superadmin/dashboard
app/controllers/auth/ProfileController.php Avatar upload, profile update, and password change support superadmin role
app/controllers/admin/UserController.php Guard allows both admin and superadmin roles
routes/web.php Loads super admin page + AJAX route files
database/starter.sql Added super_admins table + seed account

πŸ” OAuth Login

Google and GitHub OAuth are wired up and ready β€” just add credentials to .env to activate.

Flow

  1. User clicks Google or GitHub on login or register page
  2. Redirected to provider β†’ user authenticates
  3. Existing email β†’ logged in directly, flash toast shown, redirect to dashboard
  4. New email β†’ redirected to /register with name + email auto-filled and locked, user only sets a password
  5. On register submit β†’ OAuth prefill cleared from session

Setup

Add to .env:

# Google: https://console.cloud.google.com/ β†’ APIs & Services β†’ Credentials β†’ OAuth 2.0 Client ID
# Redirect URI: BASE_URL/oauth/google/callback
GOOGLE_CLIENT_ID=your-client-id
GOOGLE_CLIENT_SECRET=your-client-secret

# GitHub: https://github.com/settings/developers β†’ OAuth Apps β†’ New OAuth App
# Callback URL: BASE_URL/oauth/github/callback
GITHUB_CLIENT_ID=your-client-id
GITHUB_CLIENT_SECRET=your-client-secret

New files added

app/config/oauth.php
app/controllers/auth/OAuthController.php
routes/web/auth/oauth.php

πŸ”” Flash Toast System

Session::flash() stores a one-time message that fires as a toast on the next page load. All layout footers (auth, app, admin, superadmin) read and display it automatically.

// Set in any controller before redirecting
Session::flash('toast', ['message' => 'Saved successfully!', 'type' => 'success']);
// types: success | error | info
Router::redirect('dashboard');

The toast renders bottom-right with a gradient background, progress bar, and auto-dismisses after 4 seconds.

The project uses PHPUnit 11 with 77 tests and 98 assertions across two suites.

tests/
β”œβ”€β”€ bootstrap.php               β€” loads .env, constants, and core classes for CLI
β”œβ”€β”€ unit/
β”‚   β”œβ”€β”€ RouterTest.php          β€” URI parsing, query strings, trailing slashes, isAjax, route registration
β”‚   β”œβ”€β”€ AuthSessionTest.php     β€” Auth::check, Session set/get/destroy, edge payloads
β”‚   └── HelperTest.php          β€” dd() output wrapping, types, nested arrays
└── feature/
    β”œβ”€β”€ UserModelTest.php       β€” create, findByEmail, findById, emailExists, count, getAll, default role/status
    β”œβ”€β”€ AdminModelTest.php      β€” findByEmail, role normalization, password verify, getAll
    └── AuthValidationTest.php  β€” login/register validation, bcrypt, role redirects, inactive status
Suite Tests Needs DB
Unit 32 No
Feature 45 Yes
Total 77 β€”

Running tests

# All tests
php vendor/phpunit/phpunit/phpunit

# Unit only (no database required)
php vendor/phpunit/phpunit/phpunit --testsuite Unit

# Feature only (requires MySQL running with .env credentials)
php vendor/phpunit/phpunit/phpunit --testsuite Feature

Or via Composer:

composer test           # all
composer test:unit      # unit only
composer test:feature   # feature only

Feature tests hit the real database. Make sure your .env credentials are correct and database/starter.sql has been imported before running the feature suite. Test data is created and cleaned up automatically β€” no permanent records are left behind.

βš™οΈ GitHub Workflows

All workflows live in .github/workflows/ and are inactive by default β€” they only run when manually triggered via Actions β†’ Run workflow. Uncomment the push/pull_request triggers inside each file to activate them.

File Purpose Activate on
php-lint.yml Syntax-checks every .php file with php -l push / PR
php-quality.yml PHPMD mess detection + PHPCS PSR-12 style check on app/ push / PR
secret-scan.yml Gitleaks scan for hardcoded credentials and API keys push / PR
sql-validate.yml Imports database/starter.sql into MySQL and verifies all tables SQL file changes
deploy.yml rsync deploy to remote server over SSH push to main

Enabling a workflow

  1. Open the workflow file in .github/workflows/
  2. Uncomment the push / pull_request block under on:
  3. Commit and push β€” GitHub Actions picks it up automatically

Deploy secrets

Before enabling deploy.yml, add these in Settings β†’ Secrets β†’ Actions:

Secret Value
SSH_HOST Server IP or hostname
SSH_USER SSH username
SSH_PRIVATE_KEY Contents of your id_rsa private key
DEPLOY_PATH Absolute path on server e.g. /var/www/html/project

πŸ€– Agent Context (AI Coding Assistant)

This project ships with ready-made context files for AI coding assistants so they understand the architecture, conventions, and patterns without you having to explain them every time.

.claude/
└── CLAUDE.md             # Context file for Claude (Cursor, Claude.ai)

.agent/
β”œβ”€β”€ context/
β”‚   └── project.md        # Universal project map β€” stack, patterns, DB, env vars
└── prompts/
    β”œβ”€β”€ scaffold-feature.md   # Prompt template: new controller + view + route
    β”œβ”€β”€ scaffold-model.md     # Prompt template: new model with CRUD methods
    β”œβ”€β”€ scaffold-ajax.md      # Prompt template: new AJAX POST endpoint
    └── debug-review.md       # Prompt templates: debug routes, views, controllers
  • Claude / Cursor β€” paste or reference .claude/CLAUDE.md at the start of a session
  • Any agent β€” point it to .agent/context/project.md for the full project map
  • Prompt templates β€” copy a template from .agent/prompts/, fill in the placeholders, and send it to your agent

πŸ“ˆ Star History

Star History Chart

πŸ“„ License

This project is open-source software licensed under the MIT License. Created and maintained by Marcelo Rodrigo (MarDev) - Software Developer.

You are free to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the software, subject to the conditions outlined in the LICENSE file.

Developed by MarDev β€” Software Developer