Skip to content
livewire-principles logo

Laravel/Livewire Principles

livewire-principles

Principles for writing simple, maintainable Laravel/Livewire code. Use when writing Livewire components, tests, or Blade views. Focuses on avoiding over-engineering.

SKILL.md

Full skill instructions

Laravel/​Livewire Principles

The right mindset prevents over-engineering before it starts.

These principles guide you toward simple, maintainable code. They're not rules to follow blindly - they're questions to ask yourself as you write.


1. Trust the Framework

Laravel validation works. Livewire form binding works. Eloquent relationships work. Don't rebuild what's already there.

Ask yourself: "Does the framework already handle this?"

If Livewire tracks when a form field changes, you don't need to track it too. If Laravel validation rejects invalid input, you don't need to check it again. If an enum cast throws on invalid values, you don't need a guard clause.

// The framework handles this - you don't need to
public function save(): void
{
    $this->validate(); // Laravel validates
    $this->form->save(); // Done
}

2. Test Behavior, Not Implementation

Test what users see and what data changes. If a test would break when you refactor (without changing behavior), it's testing implementation details.

Ask yourself: "Would this test break if I refactored without changing behavior?"

Good tests survive refactoring. They verify outcomes: "A role was created in the database." They don't verify mechanics: "A modal closed and a property was reset."

// Test behavior: what changed in the world?
it('creates a new role', function () {
    Livewire::test(RolesList::class)
        ->set('roleName', 'Editor')
        ->call('saveRole');

    expect(Role::where('name', 'Editor')->exists())->toBeTrue();
});

// Not implementation: what happened inside the component?
// (Don't test that $isModalOpen became false)

3. Let Errors Surface

Don't hide problems with defensive guards and silent returns. On a trusted network with error monitoring, exceptions are helpful - they tell you something's wrong.

Ask yourself: "Am I hiding a problem or solving it?"

If invalid data reaches your code through normal use, fix the source. If it can only arrive through deliberate manipulation, let it fail loudly - that's useful information.

// Let it fail - this tells you something's wrong
public function updateLevel(int $skillId, SkillLevel $level): void
{
    $this->user->skills()->updateExistingPivot($skillId, [
        'level' => $level->value,
    ]);
}

// Don't silently swallow problems
// if (! $this->user) { return; } // Where did the user go?!

4. Simple Over Clever

The right amount of code is the minimum that works. If you're adding complexity "just in case" or "for future flexibility" - stop.

Ask yourself: "Am I adding this 'just in case'?"

Three similar lines are better than a premature abstraction. A button that's always visible is simpler than one that tracks whether it "should" be visible. Code you don't write has no bugs.

// Simple: always show the button, let validation handle invalid states
<flux:button type="submit">Save</​flux:button>

// Over-engineered: track whether the form "deserves" a save button
// @if($isFormModified && $hasRequiredFields && !$isSaving)

5. The Happy Path is Enough (Usually)

Test that things work when used correctly. Edge cases requiring malicious intent don't need testing on internal staff apps.

Ask yourself: "Who would actually do this?"

Trusted staff won't open devtools to inject invalid form values. They won't craft malicious URLs to bypass validation. Test for realistic use, not theoretical attacks.

Caveat: Student-facing features need more care. There's always one who'll try it on. For features accessible to undergraduates, add appropriate validation and authorization.

// For staff apps: test the workflow works
it('assigns a role to a user', function () { ... });

// For student-facing: also test they can't access others' data
it('prevents students accessing other students records', function () { ... });

Questions Before You Code

Pause and ask:

  1. Does the framework already handle this? If yes, don't rebuild it.

  2. Am I testing what users see, or component internals? Test outcomes, not mechanics.

  3. Would this test break if I refactored without changing behavior? If yes, it's testing implementation.

  4. Am I adding this "just in case"? If yes, probably don't.

  5. Who would actually do this? Trusted staff? Happy path is enough. Students? Be more careful.


Detailed Examples

For more thorough side-by-side comparisons, see:

  • Component Examples - Form delegation, validation, modal patterns, Blade templates
  • Test Examples - Behavior vs implementation tests, the refactoring test, staff vs student apps

What's Already Handled

Some things are already enforced or documented elsewhere:

  • Validation hooks block: DB:: queries, @php in Blade, Mockery mocks, assertDatabase, select() calls
  • CLAUDE.md documents: code style, Livewire conventions, testing practices, Eloquent patterns
  • Flux skill covers: UI component patterns, button variants, modal triggers

This skill focuses on the mindset. The details are elsewhere.


The Underlying Philosophy

"Simplicity is the ultimate sophistication."

Write code that could be read aloud to a business stakeholder. If you find yourself explaining why you needed a FormModificationTracker service, something went wrong earlier.

The goal isn't to follow rules. It's to write code so obvious that rules aren't needed.

More skills from majiayu000

xiaohongshu logo
majiayu000/claude-arsenal

xiaohongshu

xiaohongshu

286 148
View
agent-task-conductor logo
majiayu000/claude-skill-registry

agent-task-conductor

Conduct multi-agent task orchestration and workflow coordination.

663 1
View
conductor-setup logo
majiayu000/claude-skill-registry

conductor-setup

Initialize project with Conductor artifacts (product definition,

663 1
View
animation-designer logo
majiayu000/claude-skill-registry

animation-designer

Expert in web animations, transitions, and motion design using Framer Motion and CSS

663 1
View
diagramming logo
majiayu000/claude-skill-registry

diagramming

Creates Mermaid and ASCII diagrams for flowcharts, architecture, ERDs, state machines, mindmaps, and more. Use when user mentions diagram, flowchart, mermaid, ASCII diagram, text diagram, terminal diagram, visualize, C4, mindmap, architecture diagram, sequence diagram, ERD, or needs visual docume...

663 1
View
h3-pg logo
majiayu000/claude-skill-registry-data

h3-pg

PostgreSQL bindings for H3 hexagonal grid system. Use when working with H3 cells in Postgres, including spatial indexing, geometry/geography integration, and raster analysis.

23 1
View
conductor-development logo
majiayu000/claude-skill-registry

conductor-development

Context-Driven Development skill for projects using Conductor. Use this skill when you detect a `conductor/` directory in the project, when working on tasks defined in a `plan.md` file, or when the user asks about tracks, specs, or plans. Automatically applies TDD workflow, tracks task completion...

663 1
View
conductor-status logo
majiayu000/claude-skill-registry

conductor-status

Display project status, active tracks, and next actions

663 1
View
dockerization logo
majiayu000/claude-skill-registry

dockerization

Official Stakpak application containerization standard operating procedure, a step-by-step guidline to properly dockerize applications. This is a rule book curated by the Stakpak Team.

663 1
View

Popular AI tools

Kaiber logo
Video

Kaiber

Generate, edit, and beat-sync AI video with leading models in one workspace.

Paid
View
Vimcal logo
Productivity

Vimcal

The world's fastest calendar for remote work

Free
View

Transform Your Design with AI Designer by ImgCreator.ai

Freemium
View
Akool AI logo
Content & writing

Akool AI

Revolutionizing Video Production with AI-Powered Creativity

Paid
View

Extend an image past the frame and let AI fill the new aspect ratio.

Freemium
View
StarByFace logo
Security

StarByFace

Discover your celebrity doppelgänger with StarByFace!

Free
View
C

ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.

Freemium
View
Opus Clip logo
Coding & apps

Opus Clip

Opus.ai: Revolutionize Your Web Experience

Free
View