<?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>Forem: Usman Zahid</title>
    <description>The latest articles on Forem by Usman Zahid (@usmanzahidcode).</description>
    <link>https://forem.com/usmanzahidcode</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.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1111425%2Fa9e8d504-b910-4d6c-bc73-6612287f41af.png</url>
      <title>Forem: Usman Zahid</title>
      <link>https://forem.com/usmanzahidcode</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/usmanzahidcode"/>
    <language>en</language>
    <item>
      <title>Architecting for system reliability and scalability demands clean foundational code.</title>
      <dc:creator>Usman Zahid</dc:creator>
      <pubDate>Mon, 13 Oct 2025 09:28:29 +0000</pubDate>
      <link>https://forem.com/usmanzahidcode/architecting-for-system-reliability-and-scalability-demands-clean-foundational-code-51l7</link>
      <guid>https://forem.com/usmanzahidcode/architecting-for-system-reliability-and-scalability-demands-clean-foundational-code-51l7</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Building reliable and scalable systems requires a solid foundation. This foundation is not just about choosing the right architecture patterns or cloud services. It is fundamentally about the quality of the code we write. Clean foundational code directly impacts a system's ability to remain stable under load, adapt to growth, and be maintained over its lifecycle.&lt;/p&gt;

&lt;p&gt;For developers, understanding this connection is crucial. Investing in clean code practices from the start reduces technical debt, prevents costly outages, and allows for more predictable scaling. It simplifies debugging, feature development, and overall system evolution, which are common challenges in backend development.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Core of Clean Foundational Code
&lt;/h2&gt;

&lt;p&gt;Clean foundational code is readable, maintainable, testable, and modular. When code embodies these qualities, it inherently supports reliability and scalability.&lt;/p&gt;

&lt;h3&gt;
  
  
  Defining Clean Code for Reliability and Scalability
&lt;/h3&gt;

&lt;p&gt;Clean code makes it easier to understand system behavior, which reduces the likelihood of introducing bugs during changes. For reliability, this means fewer crashes or unexpected outcomes. For scalability, it means the system can be adapted or broken down into smaller, independently deployable services more easily, without significant refactoring overhead. A well-structured codebase allows teams to work on different parts of the system concurrently with fewer conflicts.&lt;/p&gt;

&lt;h3&gt;
  
  
  Modularity and Clear Interfaces
&lt;/h3&gt;

&lt;p&gt;Breaking a system into distinct, self-contained modules with well-defined interfaces is critical. Each module should have a single responsibility. For example, in a Laravel application, this means separating business logic into dedicated services, handling data persistence through repositories, and keeping controllers lean.&lt;/p&gt;

&lt;p&gt;This separation reduces coupling between components. When one part of the system needs to scale, or an issue arises, changes can be isolated to that module. This prevents cascading failures and simplifies horizontal scaling by making components easier to distribute across different servers or containers.&lt;/p&gt;

&lt;h3&gt;
  
  
  Predictable Data Flow and State Management
&lt;/h3&gt;

&lt;p&gt;Systems become more reliable when their data flow is predictable. Avoid global mutable state where possible. Use immutable data structures when practical. Ensure clear request and response cycles.&lt;/p&gt;

&lt;p&gt;For example, when processing a user request, the data should follow a clear path through validation, business logic, and data persistence. Unintended side effects from shared state or unclear data transformations can lead to difficult-to-diagnose bugs, which impact reliability. Predictable state management also simplifies reasoning about system behavior under high concurrency, a key aspect of scalability.&lt;/p&gt;

&lt;h3&gt;
  
  
  Robust Error Handling and System Resilience
&lt;/h3&gt;

&lt;p&gt;A reliable system anticipates failures. Clean code includes structured error handling, such as using custom exceptions for different error conditions. It also involves consistent logging of critical errors, warnings, and informational messages. This ensures that when issues occur, they are caught, reported, and can be debugged efficiently.&lt;/p&gt;

&lt;p&gt;Beyond basic error handling, foundational code can incorporate resilience patterns. This includes implementing retry mechanisms with exponential backoff for external service calls or database connections, and circuit breakers to prevent system overloads when a dependency is failing. These patterns allow a system to gracefully degrade or recover, maintaining uptime and stability.&lt;/p&gt;

&lt;h3&gt;
  
  
  Performance Considerations from the Outset
&lt;/h3&gt;

&lt;p&gt;Scalability is directly tied to performance. Foundational code should be written with performance in mind. This does not mean premature optimization, but rather making sensible choices regarding algorithms, data structures, and database interactions.&lt;/p&gt;

&lt;p&gt;For instance, understanding and avoiding N+1 query problems in ORMs like Eloquent, by using eager loading, is a basic but critical optimization. Designing efficient database schemas with appropriate indexing also falls into this category. These early considerations prevent bottlenecks that would otherwise become major scaling challenges later on.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Role of Automated Testing
&lt;/h3&gt;

&lt;p&gt;Automated tests, including unit, integration, and end to end tests, are an integral part of clean foundational code. They provide a safety net, allowing developers to refactor and introduce new features with confidence, knowing that existing functionality remains intact.&lt;/p&gt;

&lt;p&gt;This confidence is vital for both reliability and scalability. For reliability, tests catch regressions before they impact production. For scalability, tests enable aggressive refactoring needed to optimize performance or re-architect components for distributed environments, without fear of breaking the system.&lt;/p&gt;

&lt;h2&gt;
  
  
  Tips and Tricks
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Prioritize Readability:&lt;/strong&gt; Code that is easy to read is easier to understand, debug, and maintain. Use clear variable names, logical structure, and avoid overly clever constructs.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Continuous Refactoring:&lt;/strong&gt; Schedule regular time to address technical debt. Small, consistent improvements prevent codebases from becoming unmanageable.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Small, Focused Functions:&lt;/strong&gt; Functions and methods should do one thing and do it well. This makes them easier to test, reason about, and reuse.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Meaningful Naming:&lt;/strong&gt; Variables, functions, and classes should accurately describe their purpose. This reduces ambiguity and the need for excessive comments.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Regular Code Reviews:&lt;/strong&gt; Peer reviews help maintain code quality standards, share knowledge, and catch potential issues early.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Don't Over Engineer:&lt;/strong&gt; Solve the current problem cleanly. Avoid building overly complex abstractions for theoretical future requirements that may never materialize.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Takeaways
&lt;/h2&gt;

&lt;p&gt;Architecting for system reliability and scalability begins with clean foundational code. This is not an optional luxury but a core technical requirement. By focusing on modularity, predictable data flow, robust error handling, performance awareness, and comprehensive automated testing, developers lay the groundwork for systems that can confidently handle growth and maintain stability. Investing in these practices early and consistently leads to more resilient, maintainable, and cost-effective solutions in the long run.&lt;/p&gt;

</description>
      <category>cleancode</category>
      <category>scalability</category>
      <category>reliability</category>
      <category>backend</category>
    </item>
    <item>
      <title>Implement effective API versioning strategies for your evolving services.</title>
      <dc:creator>Usman Zahid</dc:creator>
      <pubDate>Mon, 13 Oct 2025 09:27:55 +0000</pubDate>
      <link>https://forem.com/usmanzahidcode/implement-effective-api-versioning-strategies-for-your-evolving-services-23ge</link>
      <guid>https://forem.com/usmanzahidcode/implement-effective-api-versioning-strategies-for-your-evolving-services-23ge</guid>
      <description>&lt;p&gt;Implementing effective API versioning strategies is crucial for managing changes to your services over time. It allows you to evolve your APIs, adding new features or making necessary alterations, without immediately breaking existing client applications. This ensures stability for your consumers and reduces operational overhead for your development teams.&lt;/p&gt;

&lt;p&gt;Proper versioning is a fundamental practice in backend development, preventing unexpected outages or costly reworks for your users. It enables controlled evolution of your services, ensuring that different client versions can coexist and migrate at their own pace.&lt;/p&gt;

&lt;h2&gt;
  
  
  API Versioning Strategies
&lt;/h2&gt;

&lt;p&gt;Several common strategies exist for API versioning, each with its own advantages and considerations.&lt;/p&gt;

&lt;h3&gt;
  
  
  1. URI Path Versioning
&lt;/h3&gt;

&lt;p&gt;This strategy embeds the API version directly into the Uniform Resource Identifier, URI.&lt;br&gt;
Example: &lt;code&gt;GET /v1/products&lt;/code&gt;, &lt;code&gt;GET /v2/products&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Advantages:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Discoverability:&lt;/strong&gt; The version is immediately visible in the URL.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Caching:&lt;/strong&gt; Different versions are treated as distinct resources, simplifying caching.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Simplicity:&lt;/strong&gt; Easy to implement and understand.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Considerations:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;URI Sprawl:&lt;/strong&gt; Can lead to longer URLs and duplicated routing definitions.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Not Purely RESTful:&lt;/strong&gt; Some argue that a URI should represent a resource, not a version of that resource.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Example, Laravel Routing:&lt;/strong&gt;&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="c1"&gt;// routes/api.php&lt;/span&gt;
&lt;span class="nc"&gt;Route&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;prefix&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'v1'&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;group&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nc"&gt;Route&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'/products'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nc"&gt;App\Http\Controllers\Api\V1\ProductController&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="s1"&gt;'index'&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="nc"&gt;Route&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;prefix&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'v2'&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;group&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nc"&gt;Route&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'/products'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nc"&gt;App\Http\Controllers\Api\V2\ProductController&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="s1"&gt;'index'&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;h3&gt;
  
  
  2. Query Parameter Versioning
&lt;/h3&gt;

&lt;p&gt;The API version is passed as a query parameter in the request.&lt;br&gt;
Example: &lt;code&gt;GET /products?api-version=1&lt;/code&gt;, &lt;code&gt;GET /products?api-version=2&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Advantages:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Clean URIs:&lt;/strong&gt; The base URI for a resource remains consistent.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Flexibility:&lt;/strong&gt; Clients can easily switch versions by changing a parameter.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Considerations:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Less Discoverable:&lt;/strong&gt; The version is not part of the primary URI.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Caching Issues:&lt;/strong&gt; Caching can be more complex if not configured to include query parameters.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Consistency:&lt;/strong&gt; Requires careful implementation to ensure the parameter is always handled.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Example, Laravel Request Handling:&lt;/strong&gt;&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="c1"&gt;// App\Http\Controllers\Api\ProductController.php&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="kt"&gt;Request&lt;/span&gt; &lt;span class="nv"&gt;$request&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nv"&gt;$version&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$request&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;query&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'api-version'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'1'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Default to v1&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$version&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="s1"&gt;'2'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// Return V2 product data&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="c1"&gt;// Return V1 product data&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  3. Custom Header Versioning
&lt;/h3&gt;

&lt;p&gt;Clients specify the desired API version using a custom HTTP header.&lt;br&gt;
Example: &lt;code&gt;GET /products&lt;/code&gt; with &lt;code&gt;X-API-Version: 1&lt;/code&gt; or &lt;code&gt;Accept-Version: 2&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Advantages:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Clean URIs:&lt;/strong&gt; Keeps the resource URI clean and consistent.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;RESTful:&lt;/strong&gt; Aligns well with REST principles, as the header describes a characteristic of the request.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Considerations:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Less Discoverable:&lt;/strong&gt; Requires prior knowledge of the custom header.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Browser Testing:&lt;/strong&gt; Can be more cumbersome to test directly in a browser without specific tools.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Firewall/Proxy Issues:&lt;/strong&gt; Some proxies or firewalls might strip or modify custom headers.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Example, Laravel Middleware:&lt;/strong&gt;&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="c1"&gt;// App\Http\Middleware\ApiVersionCheck.php&lt;/span&gt;
&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;ApiVersionCheck&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;handle&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$request&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;Closure&lt;/span&gt; &lt;span class="nv"&gt;$next&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nv"&gt;$apiVersion&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$request&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nb"&gt;header&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'X-API-Version'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'1'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Default to v1&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$apiVersion&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="s1"&gt;'2'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="c1"&gt;// Apply logic or route to V2 controllers&lt;/span&gt;
            &lt;span class="c1"&gt;// This could involve setting a global state or rewriting the request.&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;$next&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$request&lt;/span&gt;&lt;span class="p"&gt;);&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;h3&gt;
  
  
  4. Content Negotiation Versioning (Accept Header)
&lt;/h3&gt;

&lt;p&gt;This strategy leverages the standard HTTP &lt;code&gt;Accept&lt;/code&gt; header to indicate the desired media type, including the API version.&lt;br&gt;
Example: &lt;code&gt;GET /products&lt;/code&gt; with &lt;code&gt;Accept: application/vnd.company.v1+json&lt;/code&gt;, &lt;code&gt;Accept: application/vnd.company.v2+json&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Advantages:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Most RESTful:&lt;/strong&gt; Uses a standard HTTP mechanism for content negotiation.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Clean URIs:&lt;/strong&gt; Keeps resource URIs pristine.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Flexibility:&lt;/strong&gt; Allows for different representations of the same resource.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Considerations:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Complexity:&lt;/strong&gt; The &lt;code&gt;Accept&lt;/code&gt; header format can be complex for clients.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Readability:&lt;/strong&gt; Less human-readable than URI or query parameter versions.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Browser Testing:&lt;/strong&gt; Similar to custom headers, direct browser testing is difficult.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Example, Laravel Request Handling:&lt;/strong&gt;&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="c1"&gt;// App\Http\Controllers\Api\ProductController.php&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="kt"&gt;Request&lt;/span&gt; &lt;span class="nv"&gt;$request&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$request&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;accepts&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'application/vnd.company.v2+json'&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// Return V2 product data with V2 specific content type&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;response&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;json&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="cm"&gt;/* V2 data */&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nb"&gt;header&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Content-Type'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'application/vnd.company.v2+json'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="c1"&gt;// Default to V1 product data with V1 specific content type&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;response&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;json&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="cm"&gt;/* V1 data */&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nb"&gt;header&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Content-Type'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'application/vnd.company.v1+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;h2&gt;
  
  
  When to Version Your API
&lt;/h2&gt;

&lt;p&gt;You should introduce a new API version when making a breaking change. A breaking change is any modification that could cause existing clients to fail or behave unexpectedly if they are not updated.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Examples of breaking changes:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  Removing an endpoint or a field from a response.&lt;/li&gt;
&lt;li&gt;  Changing the data type of a field, for example, from string to integer.&lt;/li&gt;
&lt;li&gt;  Altering an endpoint's path or HTTP method.&lt;/li&gt;
&lt;li&gt;  Modifying the required format of a request body.&lt;/li&gt;
&lt;li&gt;  Changing error response structures or HTTP status codes.&lt;/li&gt;
&lt;li&gt;  Introducing new mandatory request parameters.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Non-breaking changes, which typically do not require a new version:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  Adding new optional fields to a response.&lt;/li&gt;
&lt;li&gt;  Adding new endpoints.&lt;/li&gt;
&lt;li&gt;  Adding new HTTP methods to existing endpoints, provided old methods still work.&lt;/li&gt;
&lt;li&gt;  Adding new optional request parameters.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  API Lifecycle and Deprecation
&lt;/h2&gt;

&lt;p&gt;When you introduce a new API version, you will likely need to support the previous version concurrently for a period.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Support Period:&lt;/strong&gt; Define a clear policy for how long older versions will be supported.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Communication:&lt;/strong&gt; Clearly communicate new versions, changes, and deprecation timelines to your API consumers well in advance. Provide detailed migration guides.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Sunset Dates:&lt;/strong&gt; Enforce a firm sunset date for deprecated versions. This encourages migration and reduces the burden of maintaining multiple codebases indefinitely.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Monitoring:&lt;/strong&gt; Monitor the usage of older API versions. This data helps in making informed decisions about deprecation timelines.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Tips and Tricks
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Choose Early:&lt;/strong&gt; Select a versioning strategy early in your API development lifecycle to avoid rework.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Consistency is Key:&lt;/strong&gt; Apply your chosen strategy consistently across your entire API.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Default Version:&lt;/strong&gt; Always provide a default version for requests that do not explicitly specify one. This helps new clients get started without immediate versioning concerns.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Documentation:&lt;/strong&gt; Maintain comprehensive, versioned API documentation. Tools like OpenAPI/Swagger can help.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Backward Compatibility:&lt;/strong&gt; Strive for backward compatible changes whenever possible to minimize the need for new versions.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Versioning Granularity:&lt;/strong&gt; Generally, version the entire API or a major section of it, rather than individual endpoints. This simplifies client-side logic.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Graceful Deprecation:&lt;/strong&gt; Provide ample warning and a clear migration path when deprecating a version. Consider returning specific deprecation headers, like &lt;code&gt;Sunset&lt;/code&gt; or &lt;code&gt;Warning&lt;/code&gt;, from the deprecated API.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Infrastructure Support:&lt;/strong&gt; Ensure your infrastructure, including load balancers, API gateways, and CI/CD pipelines, can handle multiple API versions efficiently.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Takeaways
&lt;/h2&gt;

&lt;p&gt;API versioning is essential for building robust and evolvable services. Choose a strategy that aligns with your project's needs and your team's expertise. Prioritize clear communication with your API consumers, provide thorough documentation, and plan for the eventual deprecation of older versions. Consistent application of your chosen strategy and proactive management of API changes will ensure a stable and reliable experience for all users.&lt;/p&gt;

</description>
      <category>api</category>
      <category>backend</category>
      <category>laravel</category>
      <category>versioning</category>
    </item>
    <item>
      <title>Design your Laravel database schema for optimal query performance.</title>
      <dc:creator>Usman Zahid</dc:creator>
      <pubDate>Mon, 08 Sep 2025 19:01:36 +0000</pubDate>
      <link>https://forem.com/usmanzahidcode/design-your-laravel-database-schema-for-optimal-query-performance-23hm</link>
      <guid>https://forem.com/usmanzahidcode/design-your-laravel-database-schema-for-optimal-query-performance-23hm</guid>
      <description>&lt;p&gt;Designing an efficient database schema is fundamental for any scalable Laravel application. A well-structured schema directly translates to faster query execution, reduced server load, and a better user experience. This document outlines practical considerations for building database schemas that perform optimally under various loads.&lt;/p&gt;

&lt;p&gt;Neglecting schema design often leads to performance bottlenecks as applications grow. Understanding how your data is stored and accessed is key to preventing these issues before they impact production.&lt;/p&gt;

&lt;h4&gt;
  
  
  Normalization and Denormalization
&lt;/h4&gt;

&lt;p&gt;Database normalization aims to reduce data redundancy and improve data integrity. It organizes tables to eliminate duplicate data and ensure data dependencies make sense. While this is a good starting point, strict normalization can sometimes lead to excessive table joins, which can slow down read operations.&lt;/p&gt;

&lt;p&gt;Denormalization involves intentionally introducing redundancy to improve read performance. For example, if you frequently need a product's name and price when querying order items, you might store these details directly in the &lt;code&gt;order_items&lt;/code&gt; table instead of always joining to the &lt;code&gt;products&lt;/code&gt; table. This reduces join overhead but requires careful handling to keep redundant data consistent during updates.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Practical approach:&lt;/strong&gt; Start with a normalized design. Identify specific, read-heavy queries that perform poorly. Consider denormalization for those particular cases, weighing the read performance gain against the increased complexity of data consistency.&lt;/p&gt;

&lt;h4&gt;
  
  
  Indexing Strategies
&lt;/h4&gt;

&lt;p&gt;Indexes are crucial for speeding up data retrieval. They allow the database to quickly locate rows without scanning the entire table.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Foreign Keys:&lt;/strong&gt; Always index foreign key columns. These are heavily used in &lt;code&gt;JOIN&lt;/code&gt; operations, and an index drastically improves join performance. Laravel's &lt;code&gt;foreignId()-&amp;gt;constrained()&lt;/code&gt; helper automatically creates an index.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;&lt;code&gt;WHERE&lt;/code&gt; clauses:&lt;/strong&gt; Index columns frequently used in &lt;code&gt;WHERE&lt;/code&gt; clauses to filter results.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;&lt;code&gt;ORDER BY&lt;/code&gt; and &lt;code&gt;GROUP BY&lt;/code&gt;:&lt;/strong&gt; Columns used for sorting or grouping data benefit from indexes.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Composite Indexes:&lt;/strong&gt; For queries that filter or sort on multiple columns, a composite index (an index on more than one column) can be more efficient than multiple single-column indexes. The order of columns in a composite index matters; place the most discriminative column first.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Caution:&lt;/strong&gt; Over-indexing can degrade write performance, as every index must be updated on data modification. Indexes also consume disk space. Regularly review your indexes based on query analysis.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example using Laravel Migrations:&lt;/strong&gt;&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="nc"&gt;Schema&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;table&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'products'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;Blueprint&lt;/span&gt; &lt;span class="nv"&gt;$table&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Automatically indexed by unique constraint&lt;/span&gt;
    &lt;span class="nv"&gt;$table&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;string&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'sku'&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;unique&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

    &lt;span class="c1"&gt;// Single column index&lt;/span&gt;
    &lt;span class="nv"&gt;$table&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;index&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'category_id'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="c1"&gt;// Composite index for efficient filtering and sorting by status and creation date&lt;/span&gt;
    &lt;span class="nv"&gt;$table&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;index&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="s1"&gt;'status'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'created_at'&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;h4&gt;
  
  
  Choosing Appropriate Data Types
&lt;/h4&gt;

&lt;p&gt;Selecting the correct data types for your columns impacts storage efficiency and query performance. Smaller, more precise types generally perform better.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Integers:&lt;/strong&gt; Use &lt;code&gt;unsignedInteger&lt;/code&gt; for IDs where negative values are not possible. For small enumerated values, consider &lt;code&gt;tinyInteger&lt;/code&gt; or &lt;code&gt;smallInteger&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Strings:&lt;/strong&gt; Use &lt;code&gt;varchar&lt;/code&gt; with an appropriate maximum length, avoiding excessively large lengths if data is typically shorter. Use &lt;code&gt;text&lt;/code&gt; only for truly long strings.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Dates:&lt;/strong&gt; Use &lt;code&gt;timestamp&lt;/code&gt; or &lt;code&gt;datetime&lt;/code&gt; for date and time values. Storing dates as strings prevents efficient date-based queries and comparisons.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Booleans:&lt;/strong&gt; Use &lt;code&gt;boolean&lt;/code&gt; or &lt;code&gt;tinyInteger(1)&lt;/code&gt; for true/false values.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;JSON:&lt;/strong&gt; The &lt;code&gt;json&lt;/code&gt; data type is useful for semi-structured data, but querying nested JSON efficiently might require specific database functions or JSON path indexes, which can be more complex than querying relational columns.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Relationships and Foreign Keys
&lt;/h4&gt;

&lt;p&gt;Defining relationships with foreign key constraints enforces referential integrity. This prevents orphaned records and helps the database optimizer understand the data model, potentially leading to better query plans. Laravel's Eloquent relationships build on these underlying database constraints.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example:&lt;/strong&gt;&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="nc"&gt;Schema&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;table&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'posts'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;Blueprint&lt;/span&gt; &lt;span class="nv"&gt;$table&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nv"&gt;$table&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;foreignId&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'user_id'&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;constrained&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="c1"&gt;// Automatically adds a foreign key constraint and an index&lt;/span&gt;
          &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;onDelete&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'cascade'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Example: delete posts if user is deleted&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Soft Deletes and Archiving
&lt;/h4&gt;

&lt;p&gt;Laravel's soft deletes, which add a &lt;code&gt;deleted_at&lt;/code&gt; timestamp column, are convenient for retaining records without physically removing them. However, every query will implicitly add &lt;code&gt;WHERE deleted_at IS NULL&lt;/code&gt;, which can impact performance on very large tables if the column is not indexed or if the ratio of deleted to active records is high.&lt;/p&gt;

&lt;p&gt;For extremely large datasets with historical data rarely accessed, consider a dedicated archiving strategy. Move old, inactive records to a separate archive table or even cold storage. This keeps your active tables smaller and faster.&lt;/p&gt;

&lt;h3&gt;
  
  
  Tips and Tricks
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Analyze Queries with &lt;code&gt;EXPLAIN&lt;/code&gt;:&lt;/strong&gt; Use &lt;code&gt;EXPLAIN&lt;/code&gt; (available in MySQL, PostgreSQL, etc.) to understand how your database executes a query. It reveals which indexes are used, table scan types, and potential bottlenecks.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Monitor Slow Query Logs:&lt;/strong&gt; Configure your database to log slow queries. Regularly review these logs to identify specific queries that need optimization.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Test with Realistic Data Volumes:&lt;/strong&gt; Before deploying to production, populate your development or staging environment with data volumes that mimic production. Performance characteristics change significantly with scale.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Prioritize Hot Spots:&lt;/strong&gt; Focus optimization efforts on tables and queries that are most frequently accessed or cause the most performance issues.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Avoid &lt;code&gt;SELECT *&lt;/code&gt;:&lt;/strong&gt; Only retrieve the columns you genuinely need. Fetching unnecessary data increases network traffic and database processing.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Understand Database-Specific Features:&lt;/strong&gt; Modern databases offer unique features. For example, PostgreSQL has specific index types like GIN or GIST for text search or JSON B-tree operations.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Takeaways
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Start Normalized, Denormalize Judiciously:&lt;/strong&gt; Begin with a clean, normalized schema and introduce denormalization only for specific, identified performance gains.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Index Strategically:&lt;/strong&gt; Index foreign keys, columns in &lt;code&gt;WHERE&lt;/code&gt;, &lt;code&gt;ORDER BY&lt;/code&gt;, and &lt;code&gt;GROUP BY&lt;/code&gt; clauses. Avoid over-indexing.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Choose Optimal Data Types:&lt;/strong&gt; Use the smallest, most appropriate data types to save space and improve query speed.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Enforce Referential Integrity:&lt;/strong&gt; Use foreign key constraints to maintain data consistency and help the query planner.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Monitor and Iterate:&lt;/strong&gt; Database schema design is not a one-time task. Continuously monitor query performance and refine your schema as your application evolves.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>laravel</category>
      <category>database</category>
      <category>performance</category>
      <category>sql</category>
    </item>
    <item>
      <title>Design your system to remain robust when external APIs evolve.</title>
      <dc:creator>Usman Zahid</dc:creator>
      <pubDate>Sun, 07 Sep 2025 19:00:38 +0000</pubDate>
      <link>https://forem.com/usmanzahidcode/design-your-system-to-remain-robust-when-external-apis-evolve-2ofm</link>
      <guid>https://forem.com/usmanzahidcode/design-your-system-to-remain-robust-when-external-apis-evolve-2ofm</guid>
      <description>&lt;p&gt;External APIs are fundamental to modern backend systems, allowing services to communicate and share data. However, these APIs are not static. They evolve, introduce new features, deprecate old ones, or change data structures. Designing your system to anticipate and handle these changes is critical for maintaining stability and reducing unplanned work for your team. A robust design ensures your application remains operational and predictable even when external dependencies shift.&lt;/p&gt;

&lt;h3&gt;
  
  
  Isolate External API Interactions
&lt;/h3&gt;

&lt;p&gt;Directly calling an external API from multiple parts of your application creates tight coupling. When the API changes, you face a complex search and replace task across your codebase.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Strategy:&lt;/strong&gt; Implement an isolation layer. Create a dedicated service or repository responsible for all communication with a specific external API. This service translates external API responses into your application's internal data models, shielding the rest of your system from external API specific details.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example (PHP/Laravel):&lt;/strong&gt;&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="c1"&gt;// app/Services/ExternalUserService.php&lt;/span&gt;
&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;ExternalUserService&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="nv"&gt;$httpClient&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;__construct&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;HttpClient&lt;/span&gt; &lt;span class="nv"&gt;$httpClient&lt;/span&gt;&lt;span class="p"&gt;)&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;httpClient&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$httpClient&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// Guzzle or similar&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;getUserData&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="nv"&gt;$userId&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;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nv"&gt;$response&lt;/span&gt; &lt;span class="o"&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;httpClient&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"/users/&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nv"&gt;$userId&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
            &lt;span class="nv"&gt;$externalData&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;json_decode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$response&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;getBody&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;getContents&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

            &lt;span class="c1"&gt;// Translate external API format to internal format&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;'id'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$externalData&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'id'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
                &lt;span class="s1"&gt;'name'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$externalData&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'displayName'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
                &lt;span class="s1"&gt;'email'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$externalData&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'contactEmail'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
                &lt;span class="c1"&gt;// Map other relevant fields&lt;/span&gt;
            &lt;span class="p"&gt;];&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Exception&lt;/span&gt; &lt;span class="nv"&gt;$e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="c1"&gt;// Handle API call errors&lt;/span&gt;
            &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;ExternalApiException&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Failed to fetch user data."&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$e&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// In your application, you interact only with ExternalUserService&lt;/span&gt;
&lt;span class="nv"&gt;$userData&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;app&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;ExternalUserService&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="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;getUserData&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'some_external_id'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the external user API changes its &lt;code&gt;displayName&lt;/code&gt; field to &lt;code&gt;fullName&lt;/code&gt;, you only update &lt;code&gt;ExternalUserService&lt;/code&gt; without touching any other part of your application that uses user data.&lt;/p&gt;

&lt;h3&gt;
  
  
  Implement Robust Error Handling and Fallbacks
&lt;/h3&gt;

&lt;p&gt;External APIs can fail due to various reasons: network issues, rate limits, or internal server errors on their side. Your system must be prepared for these scenarios.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Strategy:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Catch specific exceptions:&lt;/strong&gt; Distinguish between network errors, client errors (4xx), and server errors (5xx).&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Retry mechanisms:&lt;/strong&gt; Implement exponential backoff for transient errors, but avoid infinite retries.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Circuit breakers:&lt;/strong&gt; Prevent your system from repeatedly calling a failing API, allowing it to recover and preventing cascading failures.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Default values or cached data:&lt;/strong&gt; If an API call is non-critical and fails, use sensible default data or a stale cached version to maintain partial functionality.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Versioning External APIs
&lt;/h3&gt;

&lt;p&gt;Many external APIs offer versioning, like &lt;code&gt;/v1/users&lt;/code&gt; or &lt;code&gt;/v2/users&lt;/code&gt;. This is the primary way API providers manage changes.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Strategy:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Explicitly specify versions:&lt;/strong&gt; Always target a specific API version in your requests. Avoid letting the API default to its latest version, which could change unexpectedly.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Plan for upgrades:&lt;/strong&gt; When a new version of an external API is released, assess the impact. If significant changes are introduced, develop a new client for that version within your isolation layer, and gradually migrate your application's usage.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Dual-client approach:&lt;/strong&gt; During migration, your isolation layer might temporarily support both old and new API versions, allowing for a phased rollout.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Monitoring and Alerting
&lt;/h3&gt;

&lt;p&gt;Detecting issues quickly is paramount for maintaining robustness.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Strategy:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Log API requests and responses:&lt;/strong&gt; Include request details, response status codes, and execution times.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Set up alerts:&lt;/strong&gt; Monitor API call success rates, latency, and specific error codes. Trigger alerts for prolonged periods of errors or performance degradation.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;External status pages:&lt;/strong&gt; Subscribe to status pages provided by your external API vendors to receive notifications about their outages or planned maintenance.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Automated Testing
&lt;/h3&gt;

&lt;p&gt;Unit and integration tests are essential for confirming your API clients work as expected.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Strategy:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Mock external API responses:&lt;/strong&gt; For unit tests, mock the external API service to ensure your internal logic processes different responses correctly.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Contract testing:&lt;/strong&gt; If feasible, use contract testing (e.g., Pact) to define and verify the expected contract between your service and the external API. This can catch breaking changes early.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Integration tests:&lt;/strong&gt; Run specific integration tests against a test or staging environment of the external API, if available. This verifies end-to-end connectivity and data mapping.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Communication and Documentation
&lt;/h3&gt;

&lt;p&gt;Stay informed about upcoming changes from your external API providers.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Strategy:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Read API documentation:&lt;/strong&gt; Regularly review the documentation for any update announcements or deprecation notices.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Subscribe to newsletters/forums:&lt;/strong&gt; Many API providers use these channels to communicate important changes.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Establish contact:&lt;/strong&gt; If you are a high-volume user, consider establishing a direct communication channel with the API provider's support or engineering team.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Tips and Tricks
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Don't over-engineer for every possible change immediately.&lt;/strong&gt; Focus on isolating the calls and handling common failure modes. Add complexity for specific known risks or after encountering issues.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Be explicit about data contracts.&lt;/strong&gt; When designing your internal data models, be clear about which fields are expected from the external API and which are optional.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Consider a dedicated API gateway for complex scenarios.&lt;/strong&gt; If you integrate with many external APIs or need to apply common policies (rate limiting, authentication, transformation), an API gateway can centralize this logic.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Avoid deep nesting in API calls.&lt;/strong&gt; Try to make your calls as flat as possible. Complex chained calls to an external API increase the surface area for failure and make error handling harder.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Use idempotent operations where possible.&lt;/strong&gt; For write operations, design your requests to be idempotent. This means making the same request multiple times has the same effect as making it once, which simplifies retry logic.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Takeaways
&lt;/h3&gt;

&lt;p&gt;Robust integration with evolving external APIs hinges on proactive design and monitoring. Isolate external interactions behind a dedicated service, implement comprehensive error handling with retries and circuit breakers, and explicitly manage API versions. Combine these technical strategies with thorough monitoring, automated testing, and active communication with API providers to ensure your system remains stable and adaptable.&lt;/p&gt;

</description>
      <category>api</category>
      <category>backend</category>
      <category>systemdesign</category>
      <category>integrations</category>
    </item>
    <item>
      <title>Manage your n8n workflows and API directly from PHP</title>
      <dc:creator>Usman Zahid</dc:creator>
      <pubDate>Sun, 07 Sep 2025 17:07:16 +0000</pubDate>
      <link>https://forem.com/usmanzahidcode/manage-your-n8n-workflows-and-api-directly-from-php-no3</link>
      <guid>https://forem.com/usmanzahidcode/manage-your-n8n-workflows-and-api-directly-from-php-no3</guid>
      <description>&lt;p&gt;Managing your n8n workflows and API directly from PHP allows developers to integrate automation into their applications more efficiently. Using a lightweight PHP SDK, you can connect to your n8n instance and start managing workflows, webhooks, variables, and more, all from PHP code. This reduces friction between your application and n8n and makes automation a first-class part of your backend.&lt;/p&gt;

&lt;h2&gt;
  
  
  Benefits
&lt;/h2&gt;

&lt;p&gt;The SDK makes it easy to manage your n8n instance from PHP. Your application can now be aware of n8n, call it programmatically, and perform many automation tasks that were previously manual or required switching contexts. It enhances n8n workflows, increases possibilities beyond just workflows, and allows your projects to leverage automation more deeply. n8n itself is already powerful, but this SDK expands what you can do with it in a PHP environment.&lt;/p&gt;

&lt;h2&gt;
  
  
  Getting Started
&lt;/h2&gt;

&lt;p&gt;Connecting to an n8n instance is straightforward:&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="kn"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;UsmanZahid\N8n\N8nClient&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nc"&gt;N8nClient&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;connect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="s1"&gt;'https://your-n8n-instance.com'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s1"&gt;'your-api-key'&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Pagination and handling large datasets are simplified and handled automatically by the SDK, so you can focus on building your automation logic without worrying about API intricacies.&lt;/p&gt;

&lt;p&gt;What It Brings to PHP Developers&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Easy connection to n8n from any PHP application&lt;/li&gt;
&lt;li&gt;Programmatic management of workflows, users, variables, and projects&lt;/li&gt;
&lt;li&gt;Expanded automation possibilities beyond what n8n provides out of the box&lt;/li&gt;
&lt;li&gt;Integration into existing backend systems, Laravel apps, or DevOps pipelines&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;With this SDK, your PHP applications can fully interact with n8n, enabling deeper automation and smarter workflows.&lt;/p&gt;

&lt;h2&gt;
  
  
  Links
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://github.com/usmanzahidcode/n8n-php" rel="noopener noreferrer"&gt;GitHub Repository&lt;/a&gt;&lt;br&gt;
&lt;a href="https://packagist.org/packages/usmanzahid/n8n-php" rel="noopener noreferrer"&gt;Packagist&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Conclusion&lt;/p&gt;

&lt;p&gt;This PHP SDK simplifies connecting to n8n, managing workflows, and extending automation possibilities directly from your PHP code. It makes n8n integration more practical and opens up new ways to enhance workflows and applications.&lt;/p&gt;

</description>
      <category>php</category>
      <category>laravel</category>
      <category>n8nbrightdatachallenge</category>
      <category>automation</category>
    </item>
    <item>
      <title>Understanding core cloud infrastructure concepts.</title>
      <dc:creator>Usman Zahid</dc:creator>
      <pubDate>Fri, 05 Sep 2025 07:25:02 +0000</pubDate>
      <link>https://forem.com/usmanzahidcode/understanding-core-cloud-infrastructure-concepts-ook</link>
      <guid>https://forem.com/usmanzahidcode/understanding-core-cloud-infrastructure-concepts-ook</guid>
      <description>&lt;p&gt;Hey there, ever felt like cloud computing is this big, mystical beast full of complex terms? You are not alone. I remember when we first started migrating some of our core Laravel applications to AWS, it felt like learning a whole new language just to get a server up and running. But trust me, once you grasp a few fundamental concepts, it clicks. It is not magic, it is just well-organized infrastructure, and understanding these basics really makes you a more capable, confident engineer. It helps you design better systems, troubleshoot faster, and even talk to your DevOps team without that blank stare.&lt;/p&gt;

&lt;p&gt;Think of it like building a house. You do not need to be an architect, but knowing what a foundation is, how walls work, and what a roof does helps you understand why your house stands up, or why it might leak. The cloud is similar, a digital house for your applications.&lt;/p&gt;

&lt;h3&gt;
  
  
  What is the Cloud, Really?
&lt;/h3&gt;

&lt;p&gt;At its heart, the cloud is just a fancy way of saying "someone else's computer" or, more accurately, "someone else's massive data center full of computers." Instead of buying and maintaining physical hardware yourself, you rent access to their resources over the internet. This rental model gives you incredible flexibility and scalability, but you still need to know how to use those rented tools effectively.&lt;/p&gt;

&lt;h3&gt;
  
  
  Your Core Cloud Building Blocks
&lt;/h3&gt;

&lt;p&gt;Let us break down the main parts you will likely encounter.&lt;/p&gt;

&lt;h4&gt;
  
  
  1. Compute Power: Your Digital Engines
&lt;/h4&gt;

&lt;p&gt;This is where your code actually runs.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Virtual Machines (VMs) or Instances&lt;/strong&gt;: Imagine a server. Now, imagine a software version of that server. That is a VM. You choose its size, operating system, and then deploy your applications onto it. For a Laravel application, this might be an EC2 instance on AWS or a Virtual Machine on Azure. You install PHP, Nginx, Composer, and your code, just like a physical server.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Containers&lt;/strong&gt;: Think of containers, like Docker, as a much lighter, self-contained package for your application and everything it needs to run. They share the operating system of the host, making them faster to start and more efficient. Services like AWS ECS or Kubernetes manage these containers at scale. When a junior developer asked me once, "Why Docker?", I simply said, "It means your app runs the same on my laptop, on the test server, and in production, no 'but it worked on my machine' excuses."&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  2. Storage: Where Your Stuff Lives
&lt;/h4&gt;

&lt;p&gt;Your application needs places to keep data.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Databases (Managed)&lt;/strong&gt;: You need a database for your Laravel app, right? Instead of setting up and maintaining MySQL or PostgreSQL yourself on a VM, cloud providers offer managed database services, like Amazon RDS or Azure SQL Database. They handle backups, scaling, and patching. This is a huge time saver. I once spent a whole weekend debugging a self-hosted database replication issue. Never again, I swore. Managed databases simplify your life.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Object Storage&lt;/strong&gt;: This is for big files, like user uploads, images, videos, or backups. Services like Amazon S3 are perfect for this. They are extremely durable, scalable, and cheap. You would not store these on your web server directly, because those servers are meant to be temporary and stateless.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  3. Networking: Connecting the Dots
&lt;/h4&gt;

&lt;p&gt;How do your different cloud components talk to each other, and how do users access your app?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Virtual Private Cloud (VPC)&lt;/strong&gt;: This is your own private, isolated network area within the cloud. You define its boundaries, IP ranges, and rules. It is like having your own dedicated office building within a huge corporate campus.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Subnets&lt;/strong&gt;: Within your VPC, you create subnets. These are smaller segments of your network, often used to separate public-facing resources (like web servers) from private resources (like databases).&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Security Groups&lt;/strong&gt;: These act as virtual firewalls for your instances. You define rules that control inbound and outbound traffic. For example, you might allow HTTP and HTTPS traffic to your web servers, but only allow your web servers to connect to your database. This is a crucial security layer, a mistake here can leave your services wide open.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  4. Identity and Access Management (IAM): Who Gets the Keys?
&lt;/h4&gt;

&lt;p&gt;This system controls who can do what within your cloud account.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Users and Roles&lt;/strong&gt;: You create users for individual people and roles for applications or services. Each user or role is granted specific permissions. For example, a developer might have permissions to deploy code but not to delete core infrastructure.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Policies&lt;/strong&gt;: These are documents that define what actions a user or role can perform on what resources. The "principle of least privilege" is key here, only give the minimum necessary permissions. I remember a time when a new intern was given admin access "just to make things easy." It was not easy when they accidentally deleted a critical S3 bucket. Lesson learned, always use least privilege.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  5. Scaling: Growing with Demand
&lt;/h4&gt;

&lt;p&gt;The cloud's superpower is its ability to grow or shrink based on demand.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Load Balancers&lt;/strong&gt;: If you have multiple web servers, a load balancer distributes incoming traffic evenly across them. If one server goes down, it stops sending traffic to it. It is like a traffic cop directing cars efficiently.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Auto-Scaling Groups&lt;/strong&gt;: These automatically add or remove compute instances based on metrics like CPU usage or network traffic. If your Laravel app suddenly gets a huge surge of users, an auto-scaling group can automatically launch more web servers to handle the load, and then shut them down when traffic drops, saving you money.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Tips and Tricks from the Trenches
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Start Small, Learn by Doing&lt;/strong&gt;: Do not try to build a massive, complex architecture on day one. Start with a single VM, deploy a simple Laravel app, and then gradually add a managed database, object storage, and basic networking.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Cost Management is Crucial&lt;/strong&gt;: Cloud costs can sneak up on you. Always keep an eye on your billing dashboard and set up cost alerts. A runaway instance can be a painful surprise at the end of the month.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Security First, Always&lt;/strong&gt;: Cloud security is a shared responsibility. While the provider secures the underlying infrastructure, &lt;em&gt;you&lt;/em&gt; are responsible for securing your applications, data, and configurations. Think carefully about those security group rules and IAM policies.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Automation is Your Best Friend&lt;/strong&gt;: Manual tasks are boring and error-prone. Learn tools like Terraform or CloudFormation to define your infrastructure as code. This makes your deployments consistent and repeatable.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Know Your Provider's Lingo&lt;/strong&gt;: Each cloud provider, AWS, Azure, GCP, has its own names for similar services. Spend some time understanding their specific terms.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Takeaways
&lt;/h3&gt;

&lt;p&gt;Understanding these core cloud concepts is not just theoretical knowledge, it is practical power. It lets you confidently design, deploy, and manage your applications in a scalable, secure, and cost-effective way. You will find yourself debugging issues faster, making better architectural decisions, and generally feeling much more in control of your digital kingdom. So, roll up your sleeves, pick a cloud provider, and start tinkering. There is no better teacher than hands-on experience, and you will be amazed at how quickly you go from confused to confident.&lt;/p&gt;

</description>
      <category>cloud</category>
      <category>aws</category>
      <category>devops</category>
      <category>laravel</category>
    </item>
    <item>
      <title>Breaking Down the Hate for PHP</title>
      <dc:creator>Usman Zahid</dc:creator>
      <pubDate>Tue, 02 Sep 2025 12:23:44 +0000</pubDate>
      <link>https://forem.com/usmanzahidcode/breaking-down-the-hate-for-php-23ek</link>
      <guid>https://forem.com/usmanzahidcode/breaking-down-the-hate-for-php-23ek</guid>
      <description>&lt;p&gt;PHP has long been a polarizing language in web development. For decades, it has faced criticism from developers for various reasons, many of which are well-documented in discussions and articles online. Some of the main points of frustration historically include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Inconsistent language design&lt;/strong&gt;: PHP evolved rapidly and organically, leading to functions with inconsistent naming conventions, parameter orders, and behavior. This made learning and maintaining code challenging.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Security concerns&lt;/strong&gt;: Older PHP codebases often suffered from vulnerabilities like SQL injection, XSS, and CSRF, largely due to improper defaults and the prevalence of copy-pasted examples online.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Legacy code and technical debt&lt;/strong&gt;: Because PHP has been around for so long, many projects are burdened by years of spaghetti code, making them difficult to refactor or modernize.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Overexposure of “bad examples”&lt;/strong&gt;: Many public tutorials and early projects promoted poor coding practices, creating a reputation that PHP is inherently messy or unsafe.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These criticisms are valid in the historical context. PHP’s early days were chaotic, and many developers were frustrated by the need to manage too much low-level boilerplate code. It often felt like developers were fighting the language as much as they were writing applications.  &lt;/p&gt;

&lt;p&gt;However, the story of PHP today is very different. Modern PHP frameworks like Laravel, Symfony, and CakePHP provide structure, enforce best practices, and reduce boilerplate, making it easier to write clean, maintainable, and secure code. Features like type declarations, namespaces, improved error handling, and Composer-based package management have brought PHP closer to modern development standards.  &lt;/p&gt;

&lt;p&gt;The persistence of PHP in powering millions of websites—including some of the world’s largest platforms—shows that despite its reputation, it remains a practical and effective tool when used with modern conventions. What used to be a chaotic ecosystem of scripts and ad-hoc coding has evolved into a robust environment with frameworks, dependency management, testing tools, and a large, supportive community.  &lt;/p&gt;

&lt;p&gt;In short, the hate for PHP is often rooted in its past, not its present. While older projects may still suffer from bad design or outdated practices, new PHP systems are increasingly structured, maintainable, and secure. Understanding this evolution helps contextualize both the criticism and the ongoing value of PHP in modern web development.&lt;/p&gt;

&lt;p&gt;Must read articles about this for further information:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://whydoesitsuck.com/why-does-php-suck/" rel="noopener noreferrer"&gt;Why does PHP suck?&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.jesuisundev.com/en/why-developers-hate-php/" rel="noopener noreferrer"&gt;Why developers hate PHP?&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;— &lt;em&gt;Usman Zahid&lt;/em&gt;&lt;/p&gt;

</description>
      <category>php</category>
      <category>laravel</category>
      <category>programming</category>
      <category>backend</category>
    </item>
    <item>
      <title>Service Responses | From Chaos to Clean APIs</title>
      <dc:creator>Usman Zahid</dc:creator>
      <pubDate>Tue, 02 Sep 2025 12:15:59 +0000</pubDate>
      <link>https://forem.com/usmanzahidcode/service-responses-from-chaos-to-clean-apis-25a6</link>
      <guid>https://forem.com/usmanzahidcode/service-responses-from-chaos-to-clean-apis-25a6</guid>
      <description>&lt;p&gt;I used to build backend services the “quick way.” Every function returned something different: sometimes arrays, sometimes strings, sometimes just a boolean. Clients never knew what to expect. Debugging? Nightmare. Error handling? Confusing.&lt;/p&gt;

&lt;p&gt;Then I realized I needed &lt;strong&gt;structure&lt;/strong&gt;. That’s when I built a &lt;strong&gt;ServiceResponse class&lt;/strong&gt;. Now, every response is predictable, consistent, and fully traceable.&lt;/p&gt;

&lt;p&gt;Here’s what it looks like:&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="cp"&gt;&amp;lt;?php&lt;/span&gt;

&lt;span class="kn"&gt;namespace&lt;/span&gt; &lt;span class="nn"&gt;Usmanzahid\ServiceResponse&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;ServiceResponse&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="kt"&gt;?string&lt;/span&gt; &lt;span class="nv"&gt;$message&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="kt"&gt;bool&lt;/span&gt; &lt;span class="nv"&gt;$success&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="kt"&gt;mixed&lt;/span&gt; &lt;span class="nv"&gt;$data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="kt"&gt;array&lt;/span&gt; &lt;span class="nv"&gt;$errors&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[];&lt;/span&gt;
    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="kt"&gt;?self&lt;/span&gt; &lt;span class="nv"&gt;$previous&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;null&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;withMessage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="nv"&gt;$message&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="kt"&gt;self&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;message&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$message&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="p"&gt;;&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;withSuccess&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;bool&lt;/span&gt; &lt;span class="nv"&gt;$success&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="kt"&gt;self&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;success&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$success&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="p"&gt;;&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;withError&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="nv"&gt;$key&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="nv"&gt;$message&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="kt"&gt;self&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;errors&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;$key&lt;/span&gt;&lt;span class="p"&gt;][]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$message&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="p"&gt;;&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;withErrors&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;array&lt;/span&gt; &lt;span class="nv"&gt;$errors&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="kt"&gt;self&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;foreach&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$errors&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nv"&gt;$key&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$messages&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;foreach&lt;/span&gt; &lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="k"&gt;array&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nv"&gt;$messages&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nv"&gt;$message&lt;/span&gt;&lt;span class="p"&gt;)&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="nf"&gt;withError&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$key&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$message&lt;/span&gt;&lt;span class="p"&gt;);&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="p"&gt;;&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;withData&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;mixed&lt;/span&gt; &lt;span class="nv"&gt;$data&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="kt"&gt;self&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;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$data&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="p"&gt;;&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;withPrevious&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;self&lt;/span&gt; &lt;span class="nv"&gt;$previous&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="kt"&gt;self&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;previous&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$previous&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="p"&gt;;&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;getMessage&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt; &lt;span class="kt"&gt;?string&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="n"&gt;message&lt;/span&gt;&lt;span class="p"&gt;;&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;wasSuccessful&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt; &lt;span class="kt"&gt;bool&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="n"&gt;success&lt;/span&gt;&lt;span class="o"&gt;===&lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&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;wasNotSuccessful&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt; &lt;span class="kt"&gt;bool&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="o"&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="nf"&gt;wasSuccessful&lt;/span&gt;&lt;span class="p"&gt;();&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;getErrors&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="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;errors&lt;/span&gt;&lt;span class="p"&gt;;&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;getAllErrors&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="nv"&gt;$all&lt;/span&gt; &lt;span class="o"&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;errors&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="nv"&gt;$prev&lt;/span&gt; &lt;span class="o"&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;previous&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$prev&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nv"&gt;$all&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;array_merge_recursive&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$prev&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;getErrors&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt; &lt;span class="nv"&gt;$all&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
            &lt;span class="nv"&gt;$prev&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$prev&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;previous&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;$all&lt;/span&gt;&lt;span class="p"&gt;;&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;getData&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt; &lt;span class="kt"&gt;mixed&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="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;;&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;getRootCause&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt; &lt;span class="kt"&gt;self&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nv"&gt;$origin&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$origin&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;previous&lt;/span&gt;&lt;span class="o"&gt;!==&lt;/span&gt;&lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nv"&gt;$origin&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$origin&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;previous&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;$origin&lt;/span&gt;&lt;span class="p"&gt;;&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;toArray&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;'success'&lt;/span&gt; &lt;span class="o"&gt;=&amp;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="nf"&gt;wasSuccessful&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
            &lt;span class="s1"&gt;'message'&lt;/span&gt; &lt;span class="o"&gt;=&amp;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;message&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="s1"&gt;'data'&lt;/span&gt; &lt;span class="o"&gt;=&amp;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;data&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="s1"&gt;'errors'&lt;/span&gt; &lt;span class="o"&gt;=&amp;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="nf"&gt;getAllErrors&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
        &lt;span class="p"&gt;];&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;h3&gt;
  
  
  Why It Changed Everything
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;1. Consistency&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
Every response now has the same shape: &lt;code&gt;success&lt;/code&gt;, &lt;code&gt;message&lt;/code&gt;, &lt;code&gt;data&lt;/code&gt;, &lt;code&gt;errors&lt;/code&gt;. No surprises.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Chained Methods&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
Build responses step by step with fluent syntax. For example:&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;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;ServiceResponse&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;withSuccess&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;false&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;withMessage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Something went wrong'&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;withError&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'email'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'Invalid email address'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;3. Error Aggregation&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
Multiple errors? Nested errors? Fully traceable. I finally know &lt;strong&gt;why something failed&lt;/strong&gt;, not just that it did.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Flexible Data&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
Any payload can be returned—strings, objects, arrays—while keeping the response structure intact.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5. Root Cause Tracking&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
If an error bubbles up through multiple layers, the original source is always available. Debugging becomes easier, and logs actually make sense.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Takeaway
&lt;/h3&gt;

&lt;p&gt;What started as a small class to standardize API responses turned into a tool that &lt;strong&gt;made my backend predictable, debuggable, and professional&lt;/strong&gt;. No more random return types. No more guessing. Now every request and response has &lt;strong&gt;full context&lt;/strong&gt;, and handling errors feels natural.&lt;/p&gt;

&lt;p&gt;— &lt;em&gt;Usman Zahid&lt;/em&gt;&lt;/p&gt;

</description>
      <category>api</category>
      <category>backend</category>
      <category>php</category>
      <category>codequality</category>
    </item>
    <item>
      <title>You don’t need dual boot anymore; Windows can do Linux now.</title>
      <dc:creator>Usman Zahid</dc:creator>
      <pubDate>Tue, 02 Sep 2025 12:06:05 +0000</pubDate>
      <link>https://forem.com/usmanzahidcode/you-dont-need-dual-boot-anymore-windows-can-do-linux-now-2bpk</link>
      <guid>https://forem.com/usmanzahidcode/you-dont-need-dual-boot-anymore-windows-can-do-linux-now-2bpk</guid>
      <description>&lt;p&gt;No, I’m not talking about virtual machines.  &lt;/p&gt;

&lt;p&gt;A little story: I used to keep a dual-boot setup, Windows for comfort and gaming, Linux for stability and backend development. Juggling the two was a pain: rebooting every time, managing file systems, and keeping environments in sync.  &lt;/p&gt;

&lt;p&gt;Then I discovered &lt;strong&gt;Windows Subsystem for Linux (WSL)&lt;/strong&gt;. With WSL, Windows can run a full Linux environment &lt;strong&gt;natively&lt;/strong&gt;. That means you get the stability and tooling of Linux without leaving Windows.  &lt;/p&gt;

&lt;h2&gt;
  
  
  How It Works
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Enable WSL&lt;/strong&gt;: On Windows 10 or 11, you can enable WSL from PowerShell:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="w"&gt;   &lt;/span&gt;&lt;span class="n"&gt;wsl&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;--install&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This installs the default Linux distribution (Ubuntu) automatically.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Choose Your Distribution&lt;/strong&gt;: You can pick Ubuntu, Debian, Fedora, or others from the Microsoft Store.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Run Linux Natively&lt;/strong&gt;: Open a terminal and you’re in a Linux shell. You can:

&lt;ul&gt;
&lt;li&gt;Run Bash scripts&lt;/li&gt;
&lt;li&gt;Install packages with apt or yum&lt;/li&gt;
&lt;li&gt;Start servers and backend services&lt;/li&gt;
&lt;li&gt;Access your Windows files seamlessly&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Integration&lt;/strong&gt;: Linux commands and tools can work alongside Windows apps. Use VS Code, Docker, or databases from either environment.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;h3&gt;
  
  
  Why It’s Great
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Linux stability: Manage servers, scripts, and development tools reliably.&lt;/li&gt;
&lt;li&gt;Windows familiarity: Continue using your favorite apps and workflows.&lt;/li&gt;
&lt;li&gt;No reboot needed: Switch seamlessly between environments.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For backend developers, WSL is a game-changer. You can build, test, and deploy in Linux while staying in the comfort of Windows. Dual boot is no longer necessary.&lt;/p&gt;

&lt;p&gt;— Usman Zahid&lt;/p&gt;

</description>
      <category>microsoft</category>
      <category>linux</category>
      <category>development</category>
      <category>backend</category>
    </item>
    <item>
      <title>Will your system break after 2038?</title>
      <dc:creator>Usman Zahid</dc:creator>
      <pubDate>Tue, 02 Sep 2025 11:54:35 +0000</pubDate>
      <link>https://forem.com/usmanzahidcode/will-your-system-break-after-2038-3p41</link>
      <guid>https://forem.com/usmanzahidcode/will-your-system-break-after-2038-3p41</guid>
      <description>&lt;p&gt;If your software uses timestamps, you need to know about the &lt;strong&gt;Year 2038 problem&lt;/strong&gt;.  &lt;/p&gt;

&lt;p&gt;On &lt;strong&gt;19 January 2038 at 03:14:07 UTC&lt;/strong&gt;, many systems will hit a hard limit. Why?&lt;/p&gt;

&lt;p&gt;Most Unix-like systems store time as the number of seconds since &lt;strong&gt;1 January 1970 (the Unix epoch)&lt;/strong&gt;, using a signed 32-bit integer. The maximum value that fits in that space is &lt;strong&gt;2,147,483,647&lt;/strong&gt;. One second later, it overflows into a negative number and time resets to &lt;strong&gt;13 December 1901&lt;/strong&gt;.  &lt;/p&gt;

&lt;p&gt;In short, your system may think it has traveled back in time.  &lt;/p&gt;

&lt;h2&gt;
  
  
  Where this matters:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Databases storing timestamps in 32-bit fields
&lt;/li&gt;
&lt;li&gt;Embedded systems and legacy devices
&lt;/li&gt;
&lt;li&gt;Old operating systems or runtimes that still rely on 32-bit time representations
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  How to prepare:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Use 64-bit time representations (&lt;code&gt;time_t&lt;/code&gt; on modern systems)
&lt;/li&gt;
&lt;li&gt;Update legacy databases to store timestamps in larger integer or datetime types
&lt;/li&gt;
&lt;li&gt;Audit your code and dependencies for time functions
&lt;/li&gt;
&lt;li&gt;Test your applications with future dates to see how they behave
&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  Takeaway
&lt;/h3&gt;

&lt;p&gt;The Year 2038 bug isn’t science fiction, it’s a real limitation baked into older systems.&lt;br&gt;&lt;br&gt;
If you’re still storing timestamps in 32-bit integers, the clock is ticking.  &lt;/p&gt;

&lt;p&gt;— &lt;em&gt;Usman Zahid&lt;/em&gt;&lt;/p&gt;

</description>
      <category>database</category>
      <category>epoch</category>
      <category>timestamps</category>
      <category>y2038</category>
    </item>
    <item>
      <title>Why Financial Calculations Go Wrong, and How to Get Them Right</title>
      <dc:creator>Usman Zahid</dc:creator>
      <pubDate>Tue, 06 May 2025 18:13:59 +0000</pubDate>
      <link>https://forem.com/usmanzahidcode/why-financial-calculations-go-wrong-and-how-to-get-them-right-34gm</link>
      <guid>https://forem.com/usmanzahidcode/why-financial-calculations-go-wrong-and-how-to-get-them-right-34gm</guid>
      <description>&lt;p&gt;When building systems that handle money, there’s no room for approximation. A minor rounding error or a misplaced use of floating-point arithmetic can lead to inconsistencies, broken user trust, or even financial loss. Despite the importance, many systems today still rely on flawed approaches, usually stemming from a lack of clarity around how decimal precision, rounding, and accumulation behave in real-world software environments.&lt;/p&gt;

&lt;p&gt;In this article, we’ll discuss the common problems in financial calculations, walk through best practices for dealing with them, and introduce a pragmatic solution that simplifies implementation without compromising on correctness.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Real-World Challenges of Financial Computation
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. Precision Loss Due to Floating-Point Arithmetic
&lt;/h3&gt;

&lt;p&gt;Languages like PHP provide floats and doubles for numerical operations, but these are binary representations that can’t accurately express decimal fractions like 0.1, 0.015, or 0.005. These imprecisions surface as rounding bugs, broken assertions, or mismatched totals.&lt;/p&gt;

&lt;p&gt;Example:&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="nb"&gt;var_dump&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;0.1&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mf"&gt;0.2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// float(0.30000000000000004)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This might seem harmless in isolation, but it becomes critical in systems handling totals, invoices, or taxes.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Rounding at the Wrong Place in the Pipeline
&lt;/h3&gt;

&lt;p&gt;It’s common to see developers rounding values too early, or multiple times across a transaction. Rounding during intermediate steps introduces a cumulative error that compounds as calculations grow in scale.&lt;/p&gt;

&lt;p&gt;A classic case:&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="mf"&gt;0.015&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mf"&gt;0.015&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mf"&gt;0.030&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;correct&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="nc"&gt;Rounded&lt;/span&gt; &lt;span class="n"&gt;early&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;
&lt;span class="mf"&gt;0.015&lt;/span&gt; &lt;span class="err"&gt;→&lt;/span&gt; &lt;span class="mf"&gt;0.02&lt;/span&gt;
&lt;span class="mf"&gt;0.015&lt;/span&gt; &lt;span class="err"&gt;→&lt;/span&gt; &lt;span class="mf"&gt;0.02&lt;/span&gt;
&lt;span class="mf"&gt;0.02&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mf"&gt;0.02&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mf"&gt;0.04&lt;/span&gt; &lt;span class="c1"&gt;// Incorrect sum&lt;/span&gt;

&lt;span class="nc"&gt;Rounded&lt;/span&gt; &lt;span class="n"&gt;late&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;
&lt;span class="mf"&gt;0.015&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mf"&gt;0.015&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mf"&gt;0.030&lt;/span&gt; 

&lt;span class="mf"&gt;0.015&lt;/span&gt; &lt;span class="err"&gt;→&lt;/span&gt; &lt;span class="mf"&gt;0.02&lt;/span&gt;
&lt;span class="mf"&gt;0.015&lt;/span&gt; &lt;span class="err"&gt;→&lt;/span&gt; &lt;span class="mf"&gt;0.02&lt;/span&gt;
&lt;span class="mf"&gt;0.02&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mf"&gt;0.02&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mf"&gt;0.03&lt;/span&gt; &lt;span class="c1"&gt;// Does not make sense&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To the system, the math is valid. To the user, it's a mismatch.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Accumulation of Rounding Errors Over Multiple Records
&lt;/h3&gt;

&lt;p&gt;In bulk operations, like invoice line-items, financial reports, or payouts, subtle discrepancies add up. If rounding isn't consistent and deterministic, discrepancies between the sum of parts and the total are inevitable.&lt;/p&gt;

&lt;h2&gt;
  
  
  Engineering Principles to Avoid These Issues
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Use strings, not floats.
&lt;/h3&gt;

&lt;p&gt;All monetary values should be stored and manipulated as strings. This allows for exact decimal representation and prevents hidden float errors.&lt;/p&gt;

&lt;h3&gt;
  
  
  Delay rounding until the final step.
&lt;/h3&gt;

&lt;p&gt;Never round during intermediate calculations. Perform all operations with full precision, and apply rounding only at the point of display or storage, based on system-defined rules.&lt;/p&gt;

&lt;h3&gt;
  
  
  Define precision constraints per currency.
&lt;/h3&gt;

&lt;p&gt;Hard-code expected precision per currency. For USD, enforce two decimal places. For cryptocurrencies or niche systems, precision may vary. The point is to keep it consistent and system-wide, not decided at the time of calculation.&lt;/p&gt;

&lt;h3&gt;
  
  
  Avoid implicit business logic.
&lt;/h3&gt;

&lt;p&gt;The core of your system should be predictable. If rounding behavior, tax models, or precision rules are not consistent across the board, no amount of tooling will fix the results.&lt;/p&gt;

&lt;h2&gt;
  
  
  Available Solutions
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;BCMath (Manual Control)&lt;br&gt;
Using PHP’s BCMath extension, you can write precision-safe operations. But it’s verbose and low-level, you must manually handle rounding, scaling, and precision on every step.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;usmanzahid/money-utils&lt;/code&gt; (Utility-Focused Abstraction)&lt;br&gt;
This is a minimalist utility package built on top of BCMath. It simplifies financial calculations by enforcing best practices out of the box, letting you write correct, precise, and reliable financial logic without worrying about the underlying implementation details.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Why Use &lt;code&gt;usmanzahid/money-utils&lt;/code&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Define precision once using uz_set_precision(), and the system ensures consistency across all operations.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Perform addition, subtraction, multiplication, and division with predictable, correct results.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Handle tax, discounts, and percentage operations with clean and readable function calls.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;No need to manually round, library handles rounding based on your defined precision, only when necessary.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Ensures results are correct for both calculation and display, regardless of how complex your logic becomes.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Example Usage
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="k"&gt;require&lt;/span&gt; &lt;span class="s1"&gt;'vendor/autoload.php'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="nn"&gt;Usmanzahid\MoneyUtils\&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;uz_set_precision&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nf"&gt;uz_add&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nf"&gt;uz_percent_of&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nf"&gt;uz_tax&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nf"&gt;uz_discount&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nf"&gt;uz_split&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="nf"&gt;uz_set_precision&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nf"&gt;uz_add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'10.12'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'2.34'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;                  &lt;span class="c1"&gt;// "12.46"&lt;/span&gt;
&lt;span class="nf"&gt;uz_percent_of&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'200'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'10'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;               &lt;span class="c1"&gt;// "20.00"&lt;/span&gt;

&lt;span class="nf"&gt;uz_tax&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'100.00'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'percentage'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'10%'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;    
&lt;span class="c1"&gt;// ['amount' =&amp;gt; '100.00', 'tax' =&amp;gt; '10.00', 'after_tax' =&amp;gt; '110.00']&lt;/span&gt;

&lt;span class="nf"&gt;uz_discount&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'100.00'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'fixed'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'7.00'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;   
&lt;span class="c1"&gt;// ['amount' =&amp;gt; '100.00', 'discount' =&amp;gt; '7.00', 'after_discount' =&amp;gt; '93.00']&lt;/span&gt;

&lt;span class="nf"&gt;uz_split&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'10.00'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;                     
&lt;span class="c1"&gt;// ["3.34", "3.33", "3.33"]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;All operations respect your defined precision, apply correct rounding rules, and reduce the risk of downstream discrepancies.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Instllation&lt;/strong&gt;&lt;br&gt;
Check out the package at: &lt;a href="https://packagist.org/packages/usmanzahid/money-utils" rel="noopener noreferrer"&gt;https://packagist.org/packages/usmanzahid/money-utils&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;composer require usmanzahid/money-utils
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Final Thoughts
&lt;/h2&gt;

&lt;p&gt;Money is not like other data. A mismatch of a cent or two is often enough to break user trust or raise compliance issues. Building financial software requires precision, consistency, and engineering discipline. The tools you choose must support those goals, not make them harder to reach.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;usmanzahid/money-utils&lt;/code&gt; is designed for developers who want precise and maintainable financial logic without reinventing the wheel. It simplifies implementation while enforcing correctness, and it’s suited for real-world systems that can't afford to be imprecise.&lt;/p&gt;

&lt;p&gt;For systems requiring more advanced features like multi-currency modeling or object-based monetary abstractions, the Money pattern (as described by Martin Fowler) is a common approach. Libraries like brick/money implement that pattern. However, in many practical cases, especially when working within a single currency or needing minimal configuration, such solutions may introduce unnecessary complexity.&lt;/p&gt;

&lt;p&gt;If your priority is clean, predictable, and easy-to-maintain financial logic in PHP, &lt;code&gt;money-utils&lt;/code&gt; provides a balanced and efficient path forward.&lt;/p&gt;

</description>
      <category>php</category>
      <category>laravel</category>
      <category>money</category>
      <category>calculation</category>
    </item>
    <item>
      <title>Creating Custom Classes in Laravel Without Custom Commands</title>
      <dc:creator>Usman Zahid</dc:creator>
      <pubDate>Sun, 27 Apr 2025 13:15:46 +0000</pubDate>
      <link>https://forem.com/usmanzahidcode/creating-custom-classes-in-laravel-without-custom-commands-2i8j</link>
      <guid>https://forem.com/usmanzahidcode/creating-custom-classes-in-laravel-without-custom-commands-2i8j</guid>
      <description>&lt;p&gt;As a Laravel developer, I often encounter repetitive tasks that slow down development and add unnecessary complexity. One such challenge is creating custom class types, such as Services, Repositories, or Data Transfer Objects (DTOs). &lt;/p&gt;

&lt;p&gt;While Laravel’s Artisan commands are excellent for generating standard components like models or controllers, they don’t natively support custom class types. This leads to a common problem: manually creating Artisan commands for each class type, which is time, consuming and difficult to maintain. &lt;/p&gt;

&lt;p&gt;In this post, I’ll share my experience with this issue and introduce a practical solution, the &lt;code&gt;usmanzahid/laravel-custom-make&lt;/code&gt; package, that streamlines the process with minimal configuration.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Challenge: Managing Custom Artisan Commands
&lt;/h3&gt;

&lt;p&gt;In many Laravel projects, I need to create custom classes to keep my code organized and maintainable. For example, I might use a Service class for business logic, a Repository for data access, or a DTO for structured data transfer. Without built-in Artisan commands for these, I initially resorted to creating custom commands, such as &lt;code&gt;make:service&lt;/code&gt; or &lt;code&gt;make:repository&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;While this approach worked, it was far from ideal. Each command required its own class and a stub file for the template. For a single class type, this might take an hour to set up. &lt;/p&gt;

&lt;p&gt;As the project grew, I found myself maintaining multiple commands, each with its own logic and stub files. Updating a stub meant editing the corresponding command’s code, and debugging issues across several commands became a hassle. &lt;/p&gt;

&lt;p&gt;This repetitive boilerplate felt inefficient and distracted me from focusing on the actual application logic.&lt;/p&gt;

&lt;p&gt;I needed a solution that would allow me to define custom class types quickly, without the overhead of creating and managing individual Artisan commands. That’s when I created the &lt;code&gt;usmanzahid/laravel-custom-make&lt;/code&gt; package, which elegantly solves this problem.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;laravel-custom-make&lt;/code&gt; package provides a lightweight and efficient way to generate custom class types in Laravel. Instead of writing a new Artisan command for each class type, you can define your custom types in a single configuration file, specify their output paths and stub templates, and let the package handle the rest. With just two lines of configuration per class type, you can create a new generator, making it a seamless addition to Laravel’s ecosystem.&lt;/p&gt;

&lt;p&gt;This package is particularly valuable because it eliminates the need for repetitive command creation while maintaining flexibility. It’s compatible with Laravel 10, 11, or 12 and requires PHP 8.0 or higher, ensuring broad applicability.&lt;/p&gt;

&lt;p&gt;Usage Guide: Setting Up &lt;code&gt;laravel-custom-make&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Below, I’ll walk through the steps to install and configure the package, demonstrating how to create custom class types efficiently.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 1: Install the Package
&lt;/h3&gt;

&lt;p&gt;Begin by installing the package via Composer:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;composer require usmanzahid/laravel-custom-make
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command adds the package to your Laravel project, along with its dependencies.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 2: Publish Configuration and Stubs
&lt;/h3&gt;

&lt;p&gt;Next, publish the package’s configuration file and stub templates:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;php artisan vendor:publish &lt;span class="nt"&gt;--provider&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"Usmanzahid&lt;/span&gt;&lt;span class="se"&gt;\L&lt;/span&gt;&lt;span class="s2"&gt;aravelCustomMake&lt;/span&gt;&lt;span class="se"&gt;\L&lt;/span&gt;&lt;span class="s2"&gt;aravelCustomMakeProvider"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;OR&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;php artisan vendor:publish &lt;span class="nt"&gt;--tag&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;config
php artisan vendor:publish &lt;span class="nt"&gt;--tag&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;stubs
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This creates a &lt;code&gt;config/laravel_custom_maker.php&lt;/code&gt; file and a &lt;code&gt;stubs/&lt;/code&gt; directory in your project’s root. The configuration file defines your custom class types, while the stubs directory contains the templates for generated classes.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 3: Configure Custom Class Types
&lt;/h3&gt;

&lt;p&gt;Open the &lt;code&gt;config/laravel_custom_maker.php&lt;/code&gt; file. Here, you’ll define each custom class type by specifying its output path and stub file. For example, to configure Service and DTO class types:&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;return&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="s1"&gt;'service'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
        &lt;span class="s1"&gt;'path'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;app_path&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Services'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
        &lt;span class="s1"&gt;'stub'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;base_path&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'stubs/service.stub'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="p"&gt;],&lt;/span&gt;
    &lt;span class="s1"&gt;'dto'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
        &lt;span class="s1"&gt;'path'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;app_path&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'DTOs'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
        &lt;span class="s1"&gt;'stub'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;base_path&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'stubs/dto.stub'&lt;/span&gt;&lt;span class="p"&gt;),&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;Each class type requires only two settings: path (where the generated file will be saved) and stub (the template file to use). This simplicity makes it easy to add new class types as needed.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 4: Create Stub Templates
&lt;/h3&gt;

&lt;p&gt;Navigate to the &lt;code&gt;stubs/&lt;/code&gt; directory, where you can create or modify stub files. For a Service class, create a service.stub:&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="cp"&gt;&amp;lt;?php&lt;/span&gt;

&lt;span class="kn"&gt;namespace&lt;/span&gt; &lt;span class="nn"&gt;App\Services&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="n"&gt;class&lt;/span&gt; &lt;span class="p"&gt;{{&lt;/span&gt; &lt;span class="n"&gt;class&lt;/span&gt; &lt;span class="p"&gt;}}&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;__construct&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// Initialize service&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="c1"&gt;// Define service methods&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For a DTO class, create a &lt;code&gt;dto.stub&lt;/code&gt;:&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="cp"&gt;&amp;lt;?php&lt;/span&gt;

&lt;span class="kn"&gt;namespace&lt;/span&gt; &lt;span class="nn"&gt;App\DTOs&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="n"&gt;class&lt;/span&gt; &lt;span class="p"&gt;{{&lt;/span&gt; &lt;span class="n"&gt;class&lt;/span&gt; &lt;span class="p"&gt;}}&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Define DTO properties&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;{{ class }}&lt;/code&gt; placeholder is automatically replaced with the class name provided during generation. Additional placeholders, such as &lt;code&gt;{{ namespace }}&lt;/code&gt;, can be used for more complex templates.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 5: Generate Custom Classes
&lt;/h3&gt;

&lt;p&gt;With the configuration and stubs in place, you can generate classes using the &lt;code&gt;make:custom&lt;/code&gt; Artisan command. For example, to create an AuthService class:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;php artisan make:custom service AuthService
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This generates &lt;code&gt;app/Services/AuthService.php&lt;/code&gt; based on the &lt;code&gt;service.stub&lt;/code&gt;:&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="cp"&gt;&amp;lt;?php&lt;/span&gt;

&lt;span class="kn"&gt;namespace&lt;/span&gt; &lt;span class="nn"&gt;App\Services&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;AuthService&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;__construct&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// Initialize service&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="c1"&gt;// Define service methods&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Similarly, to create a &lt;code&gt;UserDTO&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;php artisan make:custom dto UserDTO
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This produces &lt;code&gt;app/DTOs/UserDTO.php&lt;/code&gt;:&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="cp"&gt;&amp;lt;?php&lt;/span&gt;

&lt;span class="kn"&gt;namespace&lt;/span&gt; &lt;span class="nn"&gt;App\DTOs&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;UserDTO&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Define DTO properties&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The process is straightforward and eliminates the need for custom command classes.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 6: Extend and Customize
&lt;/h3&gt;

&lt;p&gt;To add a new class type, such as a Repository, update the configuration:&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="s1"&gt;'repository'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="s1"&gt;'path'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;app_path&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Repositories'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="s1"&gt;'stub'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;base_path&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'stubs/repository.stub'&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;Create a &lt;code&gt;repository.stub&lt;/code&gt;, and you can generate Repository classes using the same &lt;code&gt;make:custom&lt;/code&gt; command. The package supports unlimited class types, and stubs can be customized with additional placeholders or logic as needed.&lt;/p&gt;

&lt;h3&gt;
  
  
  Benefits of laravel-custom-make
&lt;/h3&gt;

&lt;p&gt;The laravel-custom-make package addresses the pain points of custom class generation by offering:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Efficiency: Define new class types with minimal configuration, avoiding the need for custom Artisan commands.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Flexibility: Customize stub templates to match your project’s conventions.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Maintainability: Centralize class type definitions in a single configuration file, simplifying updates.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Seamless Integration: Works naturally within Laravel’s Artisan ecosystem.
&lt;/h3&gt;

&lt;p&gt;This package has significantly reduced the time I spend on boilerplate code, allowing me to focus on developing core application features.&lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;For Laravel developers seeking a streamlined approach to generating custom class types, the usmanzahid/laravel-custom-make package is an invaluable tool. By replacing repetitive command creation with a simple configuration-based system, it saves time and reduces maintenance overhead. I encourage you to explore the package, experiment with custom stubs, and integrate it into your workflow.&lt;/p&gt;

&lt;p&gt;You can find more details and contribute to the package on GitHub or install it via Packagist. If you have questions or insights about custom class generation in Laravel, feel free to share them in the comments—I’d love to hear your thoughts.&lt;/p&gt;

&lt;p&gt;Thank you for reading, and happy coding!&lt;/p&gt;

</description>
      <category>laravel</category>
      <category>php</category>
      <category>webdev</category>
      <category>packagist</category>
    </item>
  </channel>
</rss>
