<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Emilien Kopp</title>
    <description>The latest articles on DEV Community by Emilien Kopp (@emilien_kopp_88dd3031992b).</description>
    <link>https://dev.to/emilien_kopp_88dd3031992b</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1718926%2F3663a722-7a47-48b4-9c6c-183ddb013954.jpg</url>
      <title>DEV Community: Emilien Kopp</title>
      <link>https://dev.to/emilien_kopp_88dd3031992b</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/emilien_kopp_88dd3031992b"/>
    <language>en</language>
    <item>
      <title>Pain-Driven Development</title>
      <dc:creator>Emilien Kopp</dc:creator>
      <pubDate>Thu, 23 Jul 2026 11:39:49 +0000</pubDate>
      <link>https://dev.to/emilien_kopp_88dd3031992b/pain-driven-development-25l3</link>
      <guid>https://dev.to/emilien_kopp_88dd3031992b/pain-driven-development-25l3</guid>
      <description>&lt;h2&gt;
  
  
  The issue
&lt;/h2&gt;

&lt;p&gt;Today I was assigned a GitHub issue. Two Laravel event listeners, nearly identical, 130 lines each, duplicating the same orchestration logic: load an entity, manage a sync lifecycle across a few external APIs, call five &lt;code&gt;UseCase&lt;/code&gt; classes in sequence, handle errors.&lt;/p&gt;

&lt;h2&gt;
  
  
  The "okay" fix
&lt;/h2&gt;

&lt;p&gt;The fix suggested in the issue (decent, working, but probably half-AI-generated) was to extract the shared logic into a &lt;code&gt;SyncUseCase&lt;/code&gt;, and have both Listeners call that.&lt;/p&gt;

&lt;p&gt;It would have been a working fix, and I could have done it in 1 hour. AI could have done it in 10 minutes.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;But I didn't do that.&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  The itch
&lt;/h2&gt;

&lt;p&gt;I got that itch at the back of my brain. It was telling me "hey, you're gonna have use cases calling services that call use cases".&lt;br&gt;
Which would work fine in production obviously, cause code doesn't have feelings.&lt;/p&gt;

&lt;p&gt;But we would have ended up with N-level nested UseCases. With boolean flips, a bunch of match cases probably.&lt;br&gt;
And still that massive 100 line imperative code.&lt;/p&gt;

&lt;p&gt;I realized our problem wasn't the duplication of the listeners itself.&lt;br&gt;
It was naming and layering.&lt;/p&gt;

&lt;p&gt;That "God-class" UseCase would have been doing a lot of things, orchestrating other classes that were technically its "siblings" in the same layer.&lt;/p&gt;
&lt;h2&gt;
  
  
  The fix: a missing layer
&lt;/h2&gt;

&lt;p&gt;What was missing was a layer on top of that. A &lt;code&gt;Workflow&lt;/code&gt;. Some call that "Orchestrator process". Name doesn't matter as long as it's not "just another use case".&lt;/p&gt;

&lt;p&gt;To do that, I ended up creating an extra sub-layer in my application layer.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;workflowPipeline&lt;/span&gt;
    &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;send&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$payload&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;steps&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;updateRemote&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;forceSync&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
    &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;skippable&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;approve&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="n"&gt;when&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="k"&gt;fn&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt; &lt;span class="nv"&gt;$payload&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;needsAproval&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;steps&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;sincPrice&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;syncPromotion&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
    &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The Listener went from 130 lines to this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;handle&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;SomeDomainEvent&lt;/span&gt; &lt;span class="nv"&gt;$event&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;flow&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$event&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;targetId&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  The plus
&lt;/h2&gt;

&lt;p&gt;And a &lt;strong&gt;litteral bunch&lt;/strong&gt; of other Listeners, handlers, or other pieces of code will benefit from this in the future.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;I can hear people in the back, screaming "that's over-engineering! You're adding unnecessary complexity!"&lt;/em&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  If AI had done it
&lt;/h2&gt;

&lt;p&gt;If someone had thrown that GitHub issue at an AI agent, the agent would have produced something correct.&lt;br&gt;
Maybe "not overly complex" at first glance.&lt;/p&gt;

&lt;p&gt;It would have extracted the shared logic into a &lt;code&gt;GigaChadSyncUseCase&lt;/code&gt;, thinned the Listeners, passed review. DRY, coherent, done.&lt;/p&gt;

&lt;p&gt;Working.&lt;/p&gt;

&lt;p&gt;It would also have been wrong. Not "logically" wrong, not "functionally" wrong.&lt;br&gt;
More like "structurally" wrong. Or "future-proofing" wrong.&lt;/p&gt;

&lt;p&gt;We'd have had just more code, more "Services" and "UseCases" calling each other in &lt;strong&gt;complete anarchy&lt;/strong&gt;.&lt;br&gt;
More code that has no real meaning. That is just a blob of instructions.&lt;br&gt;
No "big picture" thinking that &lt;strong&gt;saves time, energy, mental bandwidth, and TOKENS&lt;/strong&gt; in the long run.&lt;/p&gt;

&lt;p&gt;No one would have been able to reason about the system, because the system would have been designed to be unreasoned about.&lt;br&gt;
It would have been designed to pass unit tests, pass the AI code review, close the GitHub issue, and then &lt;strong&gt;be forgotten&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  The cost of "AI-native"
&lt;/h2&gt;

&lt;p&gt;This is what I think is the real, underappreciated cost of AI-native development done &lt;strong&gt;uncritically&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Not the code it writes today, cause honestly the code is usually good, working, and it even catches bugs humans don't.&lt;br&gt;
The cost is &lt;strong&gt;the loss of architectural insight&lt;/strong&gt;. The loss of the friction that makes us think about the system we're building, and how it should be built.&lt;/p&gt;

&lt;p&gt;When a developer has to touch six files to add one sync variant, has to trace through a 130-line Listener to find where to insert a new step, they get pissed.&lt;br&gt;
And that being pissed has value. It allows the codebase to stay more robust, in the long term.&lt;/p&gt;

&lt;p&gt;And for those who will say &lt;em&gt;"Oh but we don't need architectural insight, AI can understand the codebase and produce code regardless"&lt;/em&gt;.&lt;br&gt;
To which I will only reply with a question "&lt;strong&gt;How much are you willing to spend in tokens?&lt;/strong&gt;"&lt;/p&gt;

&lt;p&gt;I believe that kind of insight also helps future AI-agents: context is smaller, more logical, more declarative, structured.&lt;/p&gt;

&lt;p&gt;Might seem counter-intuitive, but better architectural insight turns your codebase&lt;br&gt;
into a code equivalent of "&lt;a href="https://github.com/juliusbrussee/caveman" rel="noopener noreferrer"&gt;caveman&lt;/a&gt;".&lt;/p&gt;

&lt;h2&gt;
  
  
  The difference
&lt;/h2&gt;

&lt;p&gt;So the difference is, ultimately: feelings.&lt;/p&gt;

&lt;p&gt;A developer feels the pain of the task.&lt;br&gt;
An agent just powers through. Touches the six files. Closes the ticket. No complaint, no friction, no pattern recognition firing.&lt;/p&gt;

&lt;p&gt;And you can talk about all the "memory" and "skills" you want, the agent will reset between sessions.&lt;br&gt;
It doesn't have the pain-memory-response loop that we have.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"This shouldn't be this hard."&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;That's what drives me, at least, to write better code (or to tell my agents how to do so).&lt;/p&gt;

&lt;h2&gt;
  
  
  What do we do?
&lt;/h2&gt;

&lt;p&gt;Just to be clear: my point is not "DO NOT USE AGENTS". Cause heck, I use them all the time.&lt;br&gt;
I just don't throw the work at them, wait until they spit-out something that passes tests and reviews, maybe look at the code myself a little, and move on.&lt;br&gt;
Try it yourself. Question it. Test it. Try to think whether there is something hidden behind your ticket.&lt;br&gt;
Not saying there always is. Sometimes a bugfix is a bugfix and you should have AI solve it in 60 seconds.&lt;/p&gt;

&lt;p&gt;But sometimes, you should stop and think.&lt;/p&gt;

&lt;p&gt;In the end: on a one-day scale, maybe I move a bit slower than other devs.&lt;/p&gt;

&lt;p&gt;But compounded long-term, I am pretty sure I am making the codebase easier and cheaper to maintain, &lt;strong&gt;regardless of whether the next developer is human or AI&lt;/strong&gt;.&lt;/p&gt;

</description>
      <category>architecture</category>
      <category>ai</category>
      <category>agents</category>
      <category>vibecoding</category>
    </item>
    <item>
      <title>Inertia and API responses living together in harmony</title>
      <dc:creator>Emilien Kopp</dc:creator>
      <pubDate>Thu, 23 Jul 2026 03:40:11 +0000</pubDate>
      <link>https://dev.to/emilien_kopp_88dd3031992b/inertia-and-api-responses-living-together-in-harmony-3mdl</link>
      <guid>https://dev.to/emilien_kopp_88dd3031992b/inertia-and-api-responses-living-together-in-harmony-3mdl</guid>
      <description>&lt;h2&gt;
  
  
  I love InertiaJS to the point where it's becoming a personality trait
&lt;/h2&gt;

&lt;p&gt;I tend to want to use it for everything, but adding Inertia to an existing Laravel API gets awkward fast. Same thing happens in the other direction: you start with a full Inertia frontend and then realize you want to expose some of that data as a public API too.&lt;/p&gt;

&lt;p&gt;The naive solutions are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Sprinkle &lt;code&gt;if ($request-&amp;gt;wantsJson())&lt;/code&gt; into your controllers&lt;/li&gt;
&lt;li&gt;Maintain two separate routes that return the exact same data&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Neither feels right. So I made &lt;strong&gt;&lt;a href="https://github.com/EmilienKopp/inertia-split" rel="noopener noreferrer"&gt;inertia-split&lt;/a&gt;&lt;/strong&gt; &lt;/p&gt;

&lt;h2&gt;
  
  
  Starting fresh with Inertia: serve both from the same controller
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;ProjectController&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;Controller&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;HasHybridResponses&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;index&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;respond&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;component&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Projects/Index'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
            &lt;span class="s1"&gt;'projects'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nc"&gt;Project&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;all&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
        &lt;span class="p"&gt;]);&lt;/span&gt; &lt;span class="c1"&gt;// Inertia request → renders the Svelte/Vue/React component&lt;/span&gt;
          &lt;span class="c1"&gt;// API request     → returns JSON&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The controller doesn't check anything. Inertia requests get an Inertia response, API clients get JSON.&lt;/p&gt;

&lt;h2&gt;
  
  
  Existing API? Don't touch it
&lt;/h2&gt;

&lt;p&gt;If you just want to make an existing API method Inertia-aware, one annotation is enough:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="na"&gt;#[InertiaComponent('Users/Show')]&lt;/span&gt;
&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;show&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;User&lt;/span&gt; &lt;span class="nv"&gt;$user&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="kt"&gt;array&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'user'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$user&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The method body stays exactly as it was.&lt;/p&gt;

&lt;p&gt;Inertia requests get the component rendered with your data as props.&lt;/p&gt;

&lt;p&gt;Everything else gets the same JSON as before.&lt;br&gt;
Methods without the annotation are completely unaffected.&lt;/p&gt;
&lt;h3&gt;
  
  
  Wait, how does this even work?
&lt;/h3&gt;

&lt;p&gt;The package can out Inertia's ResponseFactory for its own in the service provider (opt-in):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;singleton&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;ResponseFactory&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;class&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;HybridResponseFactory&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;class&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;// checks if it's an Inertia request and returns appropriate response&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Good old OOP. Thank you polymorphism.&lt;/p&gt;

&lt;h2&gt;
  
  
  Wrap-up
&lt;/h2&gt;

&lt;p&gt;Whatever the direction of your problem, making Inertia and API endpoints use the same controller is a big win.&lt;br&gt;
You're still responsible for writing routes and wiring middlewares, but this should save a lot of time and effort.&lt;/p&gt;




&lt;p&gt;Still in beta, use accordingly!&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;GitHub:&lt;/strong&gt; &lt;a href="https://github.com/EmilienKopp/inertia-split" rel="noopener noreferrer"&gt;https://github.com/EmilienKopp/inertia-split&lt;/a&gt;&lt;/p&gt;

</description>
      <category>api</category>
      <category>laravel</category>
      <category>php</category>
      <category>softwaredevelopment</category>
    </item>
  </channel>
</rss>
