Scaffold Overview

Grafite Scaffold provides an elegant solution for starting an application by having the most basic views, controllers, models, migrations, packages and other features built in advance. It is a fine tuned boilerplate for any client application you may need to develop. Below we'll cover all the basic additions that are not part of a fresh Laravel 13 application.

PHP Code

Dependencies

Please consult documentation related to these packages if you wish to work with their functionality. The first-party Grafite packages define most of the app's conventions, so when their behaviour isn't obvious from usage, read their source in vendor/grafite/*.

Grafite

grafite/auth
grafite/blacksmith
grafite/charts
grafite/database
grafite/forms
grafite/html
grafite/maintenance
grafite/mission-control-laravel
grafite/support

Laravel

laravel/ai
laravel/cashier
laravel/helpers
laravel/mcp
laravel/passport
laravel/sanctum
laravel/socialite
livewire/livewire

Other

aws/aws-sdk-php
bacon/bacon-qr-code
bepsvpt/secure-headers
dedoc/scramble
erag/laravel-disposable-email
hisorange/browser-detect
intervention/image
laravel-notification-channels/webpush
pragmarx/google2fa-laravel
pragmarx/recovery
pusher/pusher-php-server
shiftonelabs/laravel-sqs-fifo-queue
silviolleite/laravelpwa
spatie/laravel-honeypot
tightenco/ziggy
yorcreative/laravel-scrubber


Application Bootstrap

Scaffold uses the Laravel 13 application skeleton. There is no HTTP or Console Kernel, no exception Handler, and no Route, Auth or Event service provider.

bootstrap/app.php

Holds the routing, global middleware, group additions, middleware aliases (admin, roles, permissions, two-factor, activity), CSRF exceptions and exception rendering. public_facing.php and web.php share the web group, while scripts.php loads with no middleware so the service worker never receives a session cookie. Errors on api/* and ajax/* always render as JSON. The health check lives at /up.

routes/console.php

The schedule lives here: Mission Control reports and stats, plus the monthly maintenance commands for log purging and outdated PHP/JS dependency reports.

AppServiceProvider

Defines the application's gates in defineGates(), the @permission Blade condition, a placeholder @nonce directive, and the Scramble API docs routes. Listeners in app/Listeners are auto-discovered, so they don't need to be registered by hand.

Controller Middleware

The base Controller is an empty abstract class. Controllers that need their own middleware implement HasMiddleware with a static middleware() method rather than calling $this->middleware() in the constructor.

public static function middleware(): array
{
    return [
        new Middleware('guest', except: ['logout']),
    ];
}

Actions

One-off pieces of business logic that don't warrant a full service live in app/Actions.

AppStats

Collects basic app counts, such as the number of users.

Exa

Queries the Exa search API. It backs the SearchWeb chat tool.

ProcessUserTwoFactorSettings

Handles a user changing their two factor platform, resetting codes and starting the authenticator setup when needed.

UpdateUserAvatar

Processes and stores a user's uploaded avatar.


AI

The AI chat is built on laravel/ai. See the AI Chat docs for the full picture.

Agents

Assistant runs the conversation, ThreadRelevance decides if a message belongs in the current thread, and ThreadSummarizer writes thread summaries. Concerns/UsesConversationProviders handles provider failover.

Tools

AppTool is the base class for tools that act on the app. Scaffold ships RecallThreads, SearchWeb, Users/GetMyProfile and Users/UpdateMyProfile.


Charts

Charts are declarative classes that extend the shared CanChart base and produce grafite/charts config. Blade-facing wrappers live in app/View/Components/Charts/. New ones can be generated with php artisan make:chart.

ActivityThirtyDays

Shows the count of all user activity over the course of 30 days. The chart is visible in the Admin Dashboard.

RegistrationThirtyDays

Shows the count of all user registrations over the course of 30 days. The chart is visible in the Admin Dashboard.

GlobalChart, UsChart, WordyChart

Example charts showing other chart types.


Events

GeneralPusherEvent

A broadcast event sent to every user, triggered by pusher_notify_general().

UserPusherEvent

A broadcast event sent on a single user's private channel, triggered by pusher_notify_user().


Helpers

Helpers are global functions loaded through Composer's autoload.files, so they're available everywhere without a use statement.

ActivityHelper

The activity() helper is in place to call anywhere in your application that you want to log a user activity.

BuildVersionHelper

build_version(), build_assets() and pwa_warm_assets() give the service worker a cache-busting version and the list of files to precache. See PWA.

NotificationHelper

app_notify(), email_notify(), pusher_notify_general() and pusher_notify_user() avoid writing multiple lines of code for every notification. See Notifications.


Controllers

Controllers are kept thin. Each injects a single App\Services\*Service and delegates its create/update/destroy logic to it, wraps service calls in try/catch, and uses abort_unless or Gate::allows for authorization. We section the app with API and Ajax controller directories. The API uses Sanctum tokens and is intended to be external. The Ajax controllers use the standard session auth for calls from inside the app.

DashboardController

After login this is the general home page for the application.

PagesController

For general public pages: home, support, terms of service and privacy policy.

ResendInviteController / RevokeInviteController

Single action controllers to resend or revoke an invite. Sending invites is performed by the InviteService.

TeamsController

Handles Team CRUD for teams a user owns, delegating to the TeamService.

TeamMembersController

Handles viewing a team, leaving it, and inviting, editing and removing members.

ThreadsController

The AI chat pages: list threads, show a thread and delete a thread.


Admin

All Admin routes require the admin role and a recently confirmed password (password.confirm).

AnnouncementController

Sends an important in-app notification to every user.

DashboardController

Loads the charts mentioned above for a basic overview of the app user state.

QueueController

A simple queue manager: view queued and failed jobs, retry failed jobs, and delete jobs individually or all at once.

RoleController

A CRUD controller for the application roles. Permissions are defined in the permissions config file, but roles are dynamic.

UserController

A CRUD controller for app Users. Admins can search users, invite users, see their activity records, and switch to (log in as) a user for testing, then switch back.


Ajax

CookiePolicyController

Handles the acceptance of the cookie policy for a user.

FileUploadController

Handles file and image uploads from form fields such as Dropzone. Uploads go to the default disk.

NotificationCountController

Returns the count of a user's unread notifications.


API

ApiController

A base controller for the API with a user() method that returns the Sanctum-authenticated user.

ApiDeviceLoginController

Exchanges an email, password and device name for a Sanctum token.

ChatController

Lists a user's chat threads and sends a chat message.

UsersController

Gets a user's info, updates it, and deletes the user.


Auth

The auth routes come from grafite/auth. The controllers in app/Http/Controllers/Auth are where you customise them.

LoginController

Logs a login activity and records the user's device after authentication.

RegisterController

Sets the newly created user's role, blocks disposable email addresses, and handles registration via invites.

Concerns/RegisterViaInvites

Handles the landing page provided by the invitation link as well as its validation method.

TwoFactorController / RecoveryController

Verify a two factor code at login, and reset two factor with a recovery code.

SocialiteController

The callback for Socialite logins. It is a starting point and needs to be completed for your provider.

ConfirmPasswordController, ForgotPasswordController, ResetPasswordController, VerificationController

The standard auth flows.


User

ApiTokenController

Lists, creates and deletes a user's Sanctum API tokens.

BillingController

The billing page, the Stripe Checkout subscribe action, and the success and cancel landing routes.

DestroyController

A dedicated delete controller for the user.

InvitesController

Lists a user's invites and handles accepting and rejecting them.

LogoutSessionsController

Logs the user out of all their other devices.

NotificationsController

Lists in-app notifications, and marks them read, deletes them, or clears them all.

PushSubscriptionController

Stores and removes a browser's web push subscription, and sends a test push.

SecurityController

Handles the password updating for a given user.

SettingsController

For updating user settings and removing an avatar.

TwoFactorSettingsController

Sets up and confirms email or authenticator app two factor authentication.


Forms

Scaffold uses Grafite Forms so you can manage app forms via PHP Form Classes. Forms live in app/View/Forms, extend ModelForm or WizardForm, and define their fields in a fields() method. A model opts into a form by setting public $form = SomeForm::class; and using HasForm. Don't hand-roll a <form> in Blade for model CRUD.

AdminUserForm - The form for when admins manage users.
AnnouncementForm - The admin announcement form.
CartForm - An example form used by the Cart Livewire component.
ConfirmTwoFactorForm - Confirms a two factor code.
ImageUploadForm - An image upload form.
InviteUserForm - The base form for inviting users.
LoginForm - The login form.
LogoutForm - The logout form.
RegistrationForm - The registration form.
RoleForm - The role CRUD form.
TeamForm - The team CRUD form.
TeamInviteForm - The base form for inviting people to teams.
TeamMemberForm - The team member CRUD form.
TokenForm - Creates an API token.
UserForm - The user settings form.
UserPasswordForm - The user password update form.
UserTwoFactorForm - Chooses the two factor platform.
UserWizardForm - An example wizard form.

Fields

AddressField

A custom field example. New fields can be generated with php artisan make:field.


View Components

Layout

AppNavbar, AppNavbarFluid, AppNavbarStatic, AppSidebar, AppSubnav, AppSubnavContents and GuestNavbar.

Forms

Blade-facing wrappers for forms: ImageUpload, Role, TeamInvite, TeamMember, User, UserDeleteAccount, UserPassword and UserWizard.

Global

Components available on every page: ConfirmationModal, ContentModal, CopyButton, LivewireConfirmationModal, Notifications, Offcanvas and PendingOverlay. New ones can be generated with php artisan make:global-component.


Livewire

Scaffold uses Livewire 4 sparingly. Most interactivity goes through Grafite view components. Livewire assets are included manually (@livewireScripts in layouts/main.blade.php) and served from a hashed /livewire-{hash}/ prefix, which the service worker's cache rule expects.

Cart - An example component with a form.
NotificationBadge - The unread notification count in the navigation.
ThreadChat - The AI chat window.
UserSettings - Live user settings.


Jobs and Listeners

SummarizeThread

Refreshes a chat thread's summary in the background.

RemovePushSubscriptionOnLogout

Removes the browser's push subscription when a user logs out.


MCP

app/Mcp/Servers/UsersServer and its tools in app/Mcp/Tools/Users let MCP clients such as Claude work with user accounts. See the MCP docs.


Middleware

There are a few custom middleware classes added, and most revolve around roles and permissions.

Activity

Logs a request as an activity for a user. Apply it with the activity alias where you want it.

Admin

Checks if the user has the admin role.

hCaptcha

Verifies an h-captcha-response with hCaptcha when a request includes one.

Permissions

Requires a permission key, and then checks if the user accessing the route has the permission based on their roles.

Roles

Checks for any of the listed roles and confirms or rejects the request.

Subscription

Confirms that the user passes the subscribed gate before proceeding.

TwoFactor

Sends users who haven't confirmed their two factor code to the verification page.


Requests

Request validation lives in app/Http/Requests. Authorization is handled in the controllers.

AdminUserUpdateRequest - Rules for admins updating users.
ApiChatRequest - A chat message, with an optional thread_id and new flag.
ApiUserUpdateRequest - Rules for updating a user through the API.
PushSubscriptionRequest - A browser push subscription.
RoleCreateRequest - Rules for creating roles.
TeamCreateRequest / TeamUpdateRequest - Rules relevant to teams.
UserPasswordUpdateRequest - Confirms matching passwords.
UserUpdateRequest - Rules for email, name and avatar.


Resources

UserResource

Sets the visible attributes of a user for the API and MCP tools.

ThreadResource / ThreadMessageResource

The API output for chat threads and their messages.


Models

Activity, DatabaseNotification, FailedJob, Invite, Job, Role, Team, Thread, ThreadMessage and User. User is the composition root: it pulls in most of the concerns below plus the Grafite, Cashier and Sanctum traits, so look there first to see what a user "has".


Concerns

Capability is added through single-purpose traits rather than inheritance.

DatabaseSearchable

Provides a simple search method that looks at every column of the model for the keyword. This is a simple use case tool, which when scale calls for it we recommend replacing with laravel/scout.

HasActivity

Contains the activities relationship.

HasAvatar

Provides the avatar URL, falling back to generated initials.

HasCachedValues

Helpers for caching values per model and clearing them.

HasDevices

Records the devices a user logs in from and lets them log out of the others.

HasPermissions

Collects the permissions that apply to the user from their roles.

HasRoles

Contains the relationships of roles to the model.

HasSubscribedUser / HasSubscription

Extra methods for active vs cancelled subscriptions, the current plan, and the subscription cache.

HasTeams

Contains the teams relationship (teams the user owns) and team memberships (teams the user is a member of).

HasThreads

Contains the chat threads relationship and the user's active thread.

HasTwoFactor

Two factor codes, recovery codes, and confirmation state.

Invitable

Contains the invites relationship and the invite creation method itself.


Notifications

InAppNotification

Creates a notification in the database that the user can mark as read or delete. It is also sent as a web push when the user allows it.

StandardEmail

A basic email with a subject, greeting, message and a login button.

UserInviteEmail

Includes a token for account activation and a message for the user's invite.

ResetPassword, TwoFactorNotification, TwoFactorRecoveryNotification

The password reset email, the emailed two factor code, and the recovery codes email.


Services

ActivityService

Extracts the key data points from the request in order to log them into the activities table.

ConversationService

Files chat messages into threads and records the Assistant's replies. Conversation/ThreadResolver decides which thread a message belongs to.

InviteService

Handles the creation of invites and the validation of invites.

TeamService

Handles the basic CRUD actions of a team as well as leaving, adding and removing members, including sending notifications.

UserService

User logic shared by the REST API, the MCP tools and the chat tools.


Code Generators

Beyond the stock Laravel generators, Scaffold ships extra make:* commands (mostly from grafite/blacksmith and grafite/support) that produce stubs matching the project's conventions. Run php artisan list or php artisan help make:X before writing a Form, Chart, Field or global component by hand.

php artisan make:model-form
php artisan make:wizard-form
php artisan make:modal-form
php artisan make:base-form
php artisan make:field
php artisan make:chart
php artisan make:livewire-form
php artisan make:global-component
php artisan make:regex-class
php artisan make:mcp-tool

Config

The config/ directory has one file per package or feature (billing.php, conversation.php, google2fa.php, honeypot.php, laravelpwa.php, mcp.php, mission-control.php, permissions.php, scramble.php, secure-headers.php, webpush.php, ...). config/general.php is the catch-all for app-specific settings. When looking for where a package is tuned, check config/<package>.php before searching .env.


Observability

grafite/mission-control-laravel (config: mission-control.php) logs errors, slow queries and pages, and queue activity to an external Mission Control instance.


JavaScript Code


Dependencies

Assets are built with Vite. npm run build also runs PurgeCSS and gzip/brotli compression.

@grafite/bootstrap-magic-extras
@grafite/helpers
axios
bootstrap
clipboard
collect.js
laravel-echo
pulltorefreshjs
pusher-js
vue


Script Components

Plain JavaScript modules in resources/js/script-components.

ajax-forms - Handles window.ajax form submissions.
app-events - A place to listen for app events, such as a form's success.
clipboard - window.copyToClipboard().
core - The shared event system (window.app.$events) to fire and listen to events anywhere.
echo-events - Listens for the Pusher events sent by the notification helpers.
livewire-events - Re-initialises form fields, tooltips and popovers after Livewire updates.
mobile - Special handling for mobile devices, such as iOS.
online - Optional notices when the network connection is lost or restored.
push - Web push subscriptions for the browser.
sidebar - Hides and reveals the sidebar.
theme-switcher - Optional support for following the OS dark/light mode.
tooltips - Bootstrap tooltips and popovers.
utilities - Small shared helpers such as window.app.debounce.
warm-cache - Asks the service worker to fetch heavier form field files while the browser is idle.

Vue Components

CopyButton

A copy button that accepts the value to copy when clicked. Most UI is now handled by Blade, Grafite view components and Livewire rather than Vue.