<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Shakil Ahmmed on Medium]]></title>
        <description><![CDATA[Stories by Shakil Ahmmed on Medium]]></description>
        <link>https://medium.com/@shakilfci461?source=rss-b12da4e0614f------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*5xpNUQd4m52O2DciH4cMmQ.jpeg</url>
            <title>Stories by Shakil Ahmmed on Medium</title>
            <link>https://medium.com/@shakilfci461?source=rss-b12da4e0614f------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 17:57:02 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@shakilfci461/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Architectural Pattern -Day 2]]></title>
            <link>https://shakilfci461.medium.com/architectural-pattern-day-2-a105ae7bee0e?source=rss-b12da4e0614f------2</link>
            <guid isPermaLink="false">https://medium.com/p/a105ae7bee0e</guid>
            <category><![CDATA[software-architecture]]></category>
            <category><![CDATA[software-engineering]]></category>
            <dc:creator><![CDATA[Shakil Ahmmed]]></dc:creator>
            <pubDate>Thu, 24 Sep 2026 08:37:57 GMT</pubDate>
            <atom:updated>2026-09-24T10:01:36.003Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YQXjZdM2B0Rn-dLun70s8A.png" /></figure><p>Recap from Day 1:</p><p>We split the system into layers so each part can change without touching everything else. Controller here, business rules there, repositories at the bottom. Clean.</p><p>But here’s a question I couldn’t stop thinking about after Day 1… <strong>where does logging go?</strong></p><p>Presentation layer? Business layer? Infrastructure? The honest answer is: <strong>everywhere </strong>😩. And that’s exactly the problem this post is about.</p><blockquote>Dijkstra called the idea behind all of this “the separation of concerns”. His point was simple: study one aspect of a problem in isolation, knowing you’re only looking at one aspect. Correctness one day, efficiency another day. Mixing them all at once gains you nothing.</blockquote><p>Layers separate some concerns. Today we look at the ones that refuse to stay in one layer.</p><p>Module Patterns</p><p>Last time it was the Layered pattern. Today’s module pattern deals with the concerns that cut across all the modules.</p><blockquote>Aspect-Oriented Pattern</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Z2TS_ayvR59dMAhwZn5cjQ.png" /></figure><p>Context</p><p>So why would you need this? Because… your system already has nice modules, but some behaviour is needed by almost all of them:</p><ol><li><em>Logging and tracing</em></li><li><em>Access control</em></li><li>And in AI systems: a cost check before every model call, retries, tenant checks…</li></ol><p>None of these is the “real” job of the module. An <em>AnswerService</em> exists to answer questions, not to count tokens.</p><p>Problem</p><p>These are called cross-cutting concerns. If you modularize them the normal way, you get two diseases:</p><ol><li><em>Scattering</em>: the implementation of one concern is dispersed all over the place</li><li><em>Tangling</em>: the implementation of one concern is intertwined with the implementation of others</li></ol><blockquote>There’s a classic illustration from the early AspectJ work that shows this really nicely, using Apache Tomcat. XML parsing lived in one class 👍. URL handling lived in two related classes 👍. Logging? A little bit in almost every class 👎. Not separated from anything.</blockquote><p>Imagine an LLM-powered feature with no aspects:</p><pre>&lt;?php<br><br>final class AnswerService<br>{<br>    public function __construct(<br>        private LlmClient $llm,<br>        private LoggerInterface $logger,<br>        private Budget $budget,<br>    ) {}<br><br>    public function answer(Prompt $prompt): string<br>    {<br>        $this-&gt;logger-&gt;info(&#39;answer() called&#39;, [&#39;tenant&#39; =&gt; $prompt-&gt;tenantId]); // logging<br><br>        if (!$this-&gt;budget-&gt;canSpend($prompt-&gt;tenantId, $prompt-&gt;estimatedCost())) { // cost guard<br>            throw new BudgetExceeded($prompt-&gt;tenantId);<br>        }<br><br>        $start = hrtime(true);<br>        $completion = $this-&gt;llm-&gt;complete($prompt);  // &lt;- the ONLY line that is the actual job<br><br>        $this-&gt;logger-&gt;info(&#39;llm.complete&#39;, [                                     // logging again<br>            &#39;ms&#39; =&gt; (hrtime(true) - $start) / 1e6,<br>        ]);<br><br>        return $completion-&gt;text;<br>    }<br>}</pre><p>One line of real business logic. Everything else is “concerns”. Now copy this into <em>SummaryService</em>, <em>TaggingService</em>, <em>TranslationService</em>…</p><p>Sooooo……. one day you change how the budget works, and you have to touch every single service. Some of them you forget. That’s scattering. And reading <em>answer</em>() is painful because the actual job is hidden between logging lines. That’s tangling.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HOE6thUp3u18jRJEiJhFRw.png" /></figure><p>Solution</p><p>Take the cross-cutting concern out and put it in its own module, called an aspect. An aspect consists of:</p><ol><li>Advice [<em>what to do</em>]: the code of the cross-cutting concern itself</li><li>Pointcut expression [<em>where to do it</em>]: selects the join points in the base program where the aspect should be composed</li><li>Join points [<em>the possible “where”s</em>]: depend on the AOP language, e.g., method invocation, method execution, instance creation, error throwing…</li></ol><p>Let’s go back to the kitchen from <a href="https://medium.com/@shakilfci461/architectural-pattern-day-1-fce13b652bb9">Day 1</a>. Gordon has three stations: grill, salad, dessert. Every plate needs a hygiene check before it leaves the kitchen. You could teach every chef to do their own checks, in their own slightly different way. Or you hire one inspector who steps in before every plate is served.</p><ol><li>The inspection itself = advice</li><li>“Before every plate is served” = pointcut</li><li>Every single moment a plate is about to leave = a join point</li><li>The chefs just cook. They don’t even know the inspector exists.</li></ol><p><em>The pattern also defines:</em></p><ol><li><em>Relation</em>: crosscuts, from an aspect to the module it affects</li><li><em>Constraints</em>: an aspect can crosscut normal modules and other aspects. But be careful: an aspect that crosscuts itself can end in infinite recursion (imagine a logging aspect that logs its own logging calls…)</li></ol><p>But how does the aspect actually get “inside” the code? 🤔…</p><p>That’s called weaving:</p><ul><li><em>AspectJ</em> weaves aspect bytecode into the base bytecode at compile-time or load-time. Very powerful, less popular these days.</li><li><em>Spring AOP</em> uses auto-generated proxies. More limited (only before/after/around advice on method execution), but still widely used in Spring applications.</li><li><em>Scala</em> can do something similar with stackable traits. It’s a built-in language feature, but you lose the “quantification”: you can’t say “every method matching X”, you compose it explicitly per type.</li></ul><p>One fun thing: aspects are not only for cross-cutting behaviour. You can also write an enforcement aspect that checks, at compile time, whether code violates design rules. For example, “controllers must never call the DB directly” from <a href="https://medium.com/@shakilfci461/architectural-pattern-day-1-fce13b652bb9">Day 1</a>. The aspect becomes your architecture police 👮.</p><p><strong>Strengths</strong>:</p><ul><li>Modularizes cross-cutting concerns.</li><li>Supports comprehension and modifiability: the business code reads like business code again.</li></ul><p><strong>Weaknesses:</strong></p><ul><li>Little language support (PHP has none natively, for example).</li><li>Fragility: pointcuts and advice make many implicit assumptions about the modules they cut into. Rename a method, and your pointcut silently stops matching. Nobody tells you.</li></ul><p>Example</p><p>PHP has no native AOP, so let’s do what Spring AOP does under the hood: <em>proxies</em>. Technically this is the <em>Decorator/Proxy</em> pattern giving us AOP-like behaviour, but the idea is exactly the same. Every aspect wraps the real client and implements the same interface.</p><pre><br>&lt;?php<br><br>interface LlmClient<br>{<br>    public function complete(Prompt $prompt): Completion;<br>}<br><br>// The base module: only knows how to call the model<br>final class BedrockLlmClient implements LlmClient<br>{<br>    public function __construct(private BedrockRuntimeClient $bedrock) {}<br><br>    public function complete(Prompt $prompt): Completion<br>    {<br>        // call the model, map the response<br>    }<br>}</pre><pre>&lt;?php<br><br>// &quot;before&quot; advice: cost guard<br>final class CostGuardAspect implements LlmClient<br>{<br>    public function __construct(private LlmClient $inner, private Budget $budget) {}<br><br>    public function complete(Prompt $prompt): Completion<br>    {<br>        if (!$this-&gt;budget-&gt;canSpend($prompt-&gt;tenantId, $prompt-&gt;estimatedCost())) {<br>            throw new BudgetExceeded($prompt-&gt;tenantId);<br>        }<br><br>        return $this-&gt;inner-&gt;complete($prompt);<br>    }<br>}<br><br>// &quot;around&quot; advice: tracing<br>final class TracingAspect implements LlmClient<br>{<br>    public function __construct(private LlmClient $inner, private LoggerInterface $logger) {}<br><br>    public function complete(Prompt $prompt): Completion<br>    {<br>        $start = hrtime(true);<br><br>        try {<br>            return $this-&gt;inner-&gt;complete($prompt);<br>        } finally {<br>            $this-&gt;logger-&gt;info(&#39;llm.complete&#39;, [<br>                &#39;tenant&#39; =&gt; $prompt-&gt;tenantId,<br>                &#39;ms&#39;     =&gt; (hrtime(true) - $start) / 1e6,<br>            ]);<br>        }<br>    }<br>}</pre><p>And now the business code is just… business code:</p><pre>&lt;?php<br><br>final class AnswerService<br>{<br>    public function __construct(private LlmClient $llm) {}<br><br>    public function answer(Prompt $prompt): string<br>    {<br>        return $this-&gt;llm-&gt;complete($prompt)-&gt;text;<br>    }<br>}</pre><p>The weaving happens in the composition root (same idea as <a href="https://medium.com/@shakilfci461/architectural-pattern-day-1-fce13b652bb9">Day 1</a>):</p><pre>&lt;?php<br><br>$llm = new TracingAspect(<br>    new CostGuardAspect(<br>        new BedrockLlmClient($bedrock),<br>        $budget,<br>    ),<br>    $logger,<br>);<br><br>$answerService = new AnswerService($llm);</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ChUyk8sXRJ8OeUEAHp_Vbw.png" /></figure><p>One thing I like to point out here:</p><ol><li><em>The order matters</em>. Tracing is outside the cost guard, so even rejected calls (budget exceeded) get traced. Swap them, and those rejections disappear from your traces.</li></ol><p>But what about Laravel?</p><p>If you use Laravel, you already have two places where you can weave aspects in, without any AOP library.</p><p><em>Middleware</em>: aspects on HTTP requests</p><p>Middleware works a lot like AOP, where the join points are HTTP requests. Let’s say every AI endpoint must check the tenant’s quota before doing anything expensive:</p><pre>&lt;?php<br><br>namespace App\Http\Middleware;<br><br>use Closure;<br>use Illuminate\Http\Request;<br>use Symfony\Component\HttpFoundation\Response;<br><br>final class EnsureAiQuota<br>{<br>    public function __construct(private Budget $budget) {}<br><br>    public function handle(Request $request, Closure $next): Response<br>    {<br>        $tenantId = $request-&gt;user()-&gt;tenant_id;<br><br>        // &quot;before&quot; advice<br>        if (!$this-&gt;budget-&gt;hasQuota($tenantId)) {<br>            return response()-&gt;json([&#39;message&#39; =&gt; &#39;AI quota exceeded&#39;], 429);<br>        }<br><br>        $response = $next($request); // proceed to the actual controller<br><br>        // &quot;after&quot; advice<br>        $response-&gt;headers-&gt;set(&#39;X-AI-Quota-Remaining&#39;, (string) $this-&gt;budget-&gt;remaining($tenantId));<br><br>        return $response;<br>    }<br>}<br><br><br>// routes/api.php<br><br>Route::middleware([&#39;auth:sanctum&#39;, EnsureAiQuota::class])-&gt;prefix(&#39;ai&#39;)-&gt;group(function () {<br>    Route::post(&#39;/answer&#39;, [AnswerController::class, &#39;store&#39;]);<br>    Route::post(&#39;/summarize&#39;, [SummaryController::class, &#39;store&#39;]);<br>});</pre><p>Mapping it back to the pattern:</p><ul><li><em>handle()</em> = the advice</li><li><em>$next($request)</em> = “now run the original code”, what AspectJ calls proceed</li><li><em>The route group with EnsureAiQuota</em> = the pointcut [<em>which requests get the aspect</em>]</li><li>Every incoming request to /ai/* = a join point</li><li>The controllers have no idea the quota check exists, exactly like Gordon’s chefs.</li></ul><p>But… middleware only lives at the HTTP boundary. What if a queue job calls the LLM? No request, no middleware. The cost check is simply skipped.</p><p><em>Service container</em>: aspects on the LLM client itself</p><p>So the second place is closer to the real thing, the model call. Laravel’s container has extend(), which lets you wrap a binding every time it’s resolved. That’s weaving, Laravel style.</p><p>We reuse the exact same CostGuardAspect and TracingAspect from above. Only the weaving moves, from a hand-written composition root into a service provider:</p><pre>&lt;?php<br><br>namespace App\Providers;<br><br>use Illuminate\Support\ServiceProvider;<br>use Psr\Log\LoggerInterface;<br><br>final class AiServiceProvider extends ServiceProvider<br>{<br>    public function register(): void<br>    {<br>        // the base module: only knows how to call the model<br>        $this-&gt;app-&gt;singleton(LlmClient::class, BedrockLlmClient::class);<br><br>        // each extend() wraps the previous one<br>        $this-&gt;app-&gt;extend(LlmClient::class, fn (LlmClient $client, $app) =&gt;<br>            new CostGuardAspect($client, $app-&gt;make(Budget::class))<br>        );<br><br>        $this-&gt;app-&gt;extend(LlmClient::class, fn (LlmClient $client, $app) =&gt;<br>            new TracingAspect($client, $app-&gt;make(LoggerInterface::class))<br>        );<br>    }<br>}</pre><p>And now look at the business code. A controller and a queue job, both just asking for LlmClient:</p><pre>&lt;?php<br><br>final class AnswerController<br>{<br>    public function store(AnswerRequest $request, LlmClient $llm): JsonResponse<br>    {<br>        return response()-&gt;json([<br>            &#39;answer&#39; =&gt; $llm-&gt;complete($request-&gt;toPrompt())-&gt;text,<br>        ]);<br>    }<br>}<br><br>final class SummarizeDocument implements ShouldQueue<br>{<br>    public function __construct(private Document $document) {}<br><br>    public function handle(LlmClient $llm): void<br>    {<br>        $this-&gt;document-&gt;update([<br>            &#39;summary&#39; =&gt; $llm-&gt;complete($this-&gt;document-&gt;toSummaryPrompt())-&gt;text,<br>        ]);<br>    }<br>}</pre><p>Neither of them knows about budgets or tracing. But both get them, because the container hands out the wrapped client, no matter who asks. The queue job, which middleware could never reach, is now covered too.</p><blockquote>Layers split the system by responsibility, but some concerns refuse to live in one layer. Aspects give them a home of their own. When the same code shows up in every module, stop copy-pasting it, and give it one place to live. Next up, Day 3: the Shared-Data pattern, and why your vector database is one 😉.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a105ae7bee0e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Architectural Pattern — Day 1]]></title>
            <link>https://shakilfci461.medium.com/architectural-pattern-day-1-fce13b652bb9?source=rss-b12da4e0614f------2</link>
            <guid isPermaLink="false">https://medium.com/p/fce13b652bb9</guid>
            <dc:creator><![CDATA[Shakil Ahmmed]]></dc:creator>
            <pubDate>Wed, 21 Jan 2026 11:27:25 GMT</pubDate>
            <atom:updated>2026-09-24T07:07:02.167Z</atom:updated>
            <content:encoded><![CDATA[<h3>Architectural Pattern -Day 1</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/712/0*wdYI_RbvMYiEyXrU.png" /></figure><p><em>What is an architectural pattern?</em></p><blockquote>When people say “architecture pattern”, they don’t mean a random diagram. An architectural pattern actually connects three things:</blockquote><ul><li><strong><em>A context:</em></strong><br>- A recurring real-world situation that gives rise to a problem. For example, your app is growing, and more developers join, and features keep changing.</li><li><strong><em>A problem:</em></strong><br>- The problem, <em>appropriately generalized</em>, that arises in the given context. In other words, suppose I told you to change one place that breaks many other things, or the code becomes hard to test.</li><li><strong><em>A solution: <br></em></strong>A successful architectural resolution to the problem, <em>appropriately abstracted</em>. The solution for a pattern is determined and described by<br> 1. A set of element types [<em>what building blocks exist] </em>( Data Repositories, processes, and objects)<br> 2. A set of interaction mechanisms or connectors <em>[how they talk to each other]</em> ( Method calls, events, or message bus)<br> 3. A topological layout of the components <em>[what the structure looks like]</em><br> 4. A set of semantic constraints covering topology, element behavior, and interaction mechanisms <em>[who is allowed to call whom]</em></li></ul><p><strong>Module Patterns</strong></p><blockquote><strong>Layered Pattern</strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OiaVNhnhL-7_Y9lo2N0UlA.png" /></figure><p><strong><em>Context:</em></strong><br>So why do you actually need the layered pattern? Maybe… You are building a system and</p><ol><li>Your app has API endpoints, business rules, a database, external services, background jobs, etc.</li><li>Multiple developers are working at the same time.</li><li>Requirements keep changing. and…..</li><li>You want to add features without breaking existing ones.</li></ol><blockquote>So the big need is: Let me change one part of the system without touching everything else, means you want to develop and change parts independently.</blockquote><p><strong><em>Problem:<br></em></strong>The software needs to be segmented in such a way that the modules can be developed and evolved separately, with minimal… minimal… interaction among the parts.</p><p>Why “minimal interaction” matters?</p><ol><li>hard to change code (a small change forces many changes)</li><li>hard to reuse code (a module is too tied to others)</li><li>hard to move the code to another platform (portability is low)</li><li>hard to maintain (modifiability is low)</li></ol><p>Imagine you have a small feature: “Place an order,” and your controller directly talks to the DB ( the president), and also contains business rules, then:</p><ul><li>Changing the database table will break controller logic</li><li>Changing business rules will require DB code changes</li><li>Testing becomes painful because everything is mixed together</li></ul><p>Sooooo……. the application needs to be segmented so each part can evolve without constant coordination</p><p><strong><em>Solution:</em></strong><br>To achieve this separation of concerns, the layered pattern divides the software into units, known as layers. Each layer is a grouping of modules that offers a cohesive set of services. The usage (e.g., import type, invoke method) must be <strong><em>unidirectional</em></strong>. Layers completely partition a set of software, and each partition is exposed through a public interface.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MrMsGFrnV8mZrHpl2gufDA.png" /></figure><p>The layered pattern defines layers (groupings of modules that offer a cohesive set of services) and a unidirectional [allowed-to-use] relationship among the layers. So it’s not just “folders”. It’s the actual architectural rules. A layer description should define what modules it contains, for example:</p><ul><li>Presentation layer contains controllers, request DTOs, and response formatting</li><li>The infrastructure layer contains DB repositories and external API clients</li></ul><p>The design should define what the layer usage rules are and any<br>allowable exceptions, for example:</p><ul><li>Controllers can call Repositories.</li><li>Controllers should not call the DB directly.</li></ul><p>and impose Constraints</p><ul><li>Every piece of software is allocated to exactly one layer. (ex, SQL queries must be in the repository/data layer, not in controllers)</li><li>Layer n provides services to Layer <em>n+1</em> and uses the services of Layer <em>n-1</em>. Think like a chain: the DB layer provides data access services to the repository layer, and the repository layer provides business operations to the controller layer.</li><li>“Layer bridging” (meaning “skipping” a layer) is sometimes allowed downwards, but should be avoided. (e,x: Controller directly calls DB (skips Repository layer)</li><li>Stable interface between adjacent layers, meaning the interface can stay stable, but the implementation can change inside the layer ( switching to ClickHouse from MySQL for OLAP implementation inside the repository implementation)</li></ul><p>Ahhh….ha</p><p><strong>Strengths:</strong></p><ol><li>Promotes modifiability, reuse, and portability.</li><li>Achieves separation of concerns.</li><li>Manages complexity and facilitates communication of code structure to developers.</li></ol><p><strong>Weaknesses:</strong></p><ol><li>The addition of layers adds up-front cost and complexity to a system.</li><li>Layers contribute a performance penalty.</li></ol><p>Example code :</p><pre>&lt;?php<br><br>// Presentation layer (Controller)<br>final class OrderController {<br>    public function __construct(private OrderService $service) {}<br><br>    public function create(int $userId, float $total): int <br>    {<br>        return $this-&gt;service-&gt;createOrder($userId, $total);<br>    }<br>}<br><br>// Application layer (Service / Use-case)<br>final class OrderService {<br>    public function __construct(private OrderRepository $repo) {}<br><br>    public function createOrder(int $userId, float $total): int <br>    {<br>        if ($total &lt;= 0) throw new InvalidArgumentException(&quot;Total must be &gt; 0&quot;);<br>        return $this-&gt;repo-&gt;save($userId, $total);<br>    }<br>}<br><br>// Infrastructure layer (Repository)<br>final class OrderRepository {<br>    public function __construct(private PDO $pdo) {}<br><br>    public function save(int $userId, float $total): int <br>    {<br>        $stmt = $this-&gt;pdo-&gt;prepare(&quot;INSERT INTO orders(user_id,total) VALUES(?,?)&quot;);<br>        $stmt-&gt;execute([$userId, $total]);<br>        return (int)$this-&gt;pdo-&gt;lastInsertId();<br>    }<br>}<br><br>// Wiring (composition root)<br>$pdo = new PDO(&quot;mysql:host=localhost;dbname=test&quot;, &quot;root&quot;, &quot;&quot;);<br>$controller = new OrderController(new OrderService(new OrderRepository($pdo)));<br><br>echo $controller-&gt;create(10, 99.5);</pre><p>Dependency Inversion: from Layer to Onion</p><p>So what is the problem in “normal layered” design?</p><p>In a typical layered app, dependencies often look like this:</p><p>Controller → Repositories/Services → DB</p><p>So the business code (high-level) ends up depending on the low-level</p><p>But why is that bad?… Because low-level things change a lot:</p><ol><li>You want to change OLAP integration to ClickHouse</li><li>You changed a library implementation</li><li>You changed the external API integration</li></ol><p>So your business layer directly depends on those details, and then this forces you to change the business logic itself.</p><p>So what does Dependency Inversion do?</p><blockquote>Flips the dependency direction. High-level layer declares interface<br>implemented by low-level layer.</blockquote><ol><li>Coupling direction is inwards: from outer low-level layer (e.g., for persistence) to inner high-level layer (e.g., for business logic).</li><li>Outer layers depend on inner layers, as they implement the interfaces declared there.</li><li>Changes to outer layers do not affect inner layers; the inner layers do not know about the outer layers</li><li>Inner layers can be compiled, run, and tested separately from the infrastructure layers (e.g., swap an outer layer for a mock<br>when testing an inner layer)</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/778/1*Pgf4g4VhPVWVDDXTU2G6Fg.png" /></figure><p><strong>Example code:</strong></p><ol><li><em>Example folder layout</em></li></ol><pre>src/<br>  Domain/<br>    Cook.php<br>    Egg.php<br>    EggStyle.php<br>    FryingPan.php<br>    Repositories.php<br>  Api/<br>    FoodPrepApi.php<br>  Infrastructure/<br>    InMemoryCookRepository.php<br>    InMemoryEggRepository.php<br>public/<br>  index.php   (composition root / wiring)</pre><p>So this separated the code into rings:</p><ul><li>Domain in the center (pure business rules)</li><li>API uses the domain to serve the requests/use- cases</li><li>Infrastructure contains technical details (DB, memory storage)</li></ul><p>Here, the core (domain) should stay stable, and the outer things (DB, HTTP) can change often, and changing the outer layer should not force changes inside the domain.</p><p><em>2. Domain ring</em></p><blockquote>The Domain block defines the core business ideas like EggStyle, RawEgg, CookedEgg, and FryingPan states. It focuses only on “what the business is” and “what rules apply” (for example, how an egg becomes cooked over time). It does not contain database code, HTTP code, or any framework-specific code. It also defines interfaces like CookRepository and EggRepository to describe what data the domain needs, without saying how it will be stored. This keeps the domain stable and easy to understand. The goal is that the domain can be tested and changed without touching infrastructure details.</blockquote><pre>&lt;?php<br>// src/Domain/EggStyle.php<br>enum EggStyle: int {<br>    case Scrambled  = 180; // seconds<br>    case SunnySideUp= 180;<br>    case OverEasy   = 240;<br>    case OverMedium = 300;<br>    case OverHard   = 360;<br>    case SoftBoiled = 180;<br>    case HardBoiled = 360;<br>    case Poached    = 300;<br><br>    public function cookTimeSeconds(): int <br>    { <br>        return $this-&gt;value; <br>    }<br>}<br></pre><pre>&lt;?php<br>// src/Domain/Egg.php<br><br>interface Egg {}<br><br>interface CookedEgg extends Egg <br>{<br>    public function style(): EggStyle;<br>}<br><br>final class RawEgg implements Egg <br>{<br>    public function startCooking(EggStyle $style): PartiallyCookedEgg<br>    {<br>        return new PartiallyCookedEgg($style, time());<br>    }<br>}<br><br>final class PartiallyCookedEgg implements CookedEgg<br>{<br>    public function __construct(<br>        private EggStyle $style,<br>        private int $startTime<br>    ) {}<br><br>    public function style(): EggStyle <br>    { <br>        return $this-&gt;style;<br>    }<br><br>    public function isDone(): bool <br>    {<br>        return (time() - $this-&gt;startTime) &gt;= $this-&gt;style-&gt;cookTimeSeconds();<br>    }<br><br>    /** If done =&gt; FullyCookedEgg, else keep the same partially cooked egg */<br>    public function finishCooking(): CookedEgg<br>   {<br>        return $this-&gt;isDone() ? new FullyCookedEgg($this-&gt;style) : $this;<br>    }<br>}<br><br>final class FullyCookedEgg implements CookedEgg <br>{<br>    public function __construct(private EggStyle $style) {}<br><br>    public function style(): EggStyle<br>    { <br>      return $this-&gt;style;<br>    }<br>}</pre><pre>&lt;?php<br>// src/Domain/FryingPan.php<br><br>interface FryingPan {}<br><br>final class EmptyFryingPan implements FryingPan <br>{<br>    public function add(RawEgg $egg, EggStyle $style): FullFryingPan <br>    {<br>        return new FullFryingPan($egg-&gt;startCooking($style));<br>    }<br>}<br><br>final class FullFryingPan implements FryingPan <br>{<br>    public function __construct(private PartiallyCookedEgg $egg) {}<br><br>    public function checkDoneness(): bool<br>    {<br>        return $this-&gt;egg-&gt;isDone();<br>    }<br><br>    /** Returns: [new pan state, cooked egg state] */<br>    public function remove(): array <br>    {<br>        return [new EmptyFryingPan(), $this-&gt;egg-&gt;finishCooking()];<br>    }<br>}</pre><pre>&lt;?php<br>// src/Domain/Repositories.php<br><br>use React\Promise\PromiseInterface;<br><br>final class Cook <br>{<br>    public function __construct(public string $name) {}<br>}<br><br>interface CookRepository <br>{<br>    /** @return PromiseInterface&lt;Cook&gt; */<br>    public function findOne(): PromiseInterface;<br>}<br><br>interface EggRepository <br>{<br>    /** Might run out of eggs =&gt; null */<br>    /** @return PromiseInterface&lt;?RawEgg&gt; */<br>    public function findAndRemove(): PromiseInterface;<br><br>    /** @return PromiseInterface&lt;void&gt; */<br>    public function add(RawEgg $egg): PromiseInterface;<br>}</pre><p><em>3. Infrastructure ring</em></p><blockquote>The Infrastructure block contains the technical implementations of the domain interfaces. For example, InMemoryCookRepository and InMemoryEggRepository store data in memory, but you could later replace them with a PDO/MySQL or Redis implementation. This block depends on the Domain block because it must implement the interfaces declared there. The domain does not depend on infrastructure, so infrastructure changes do not force domain changes. Infrastructure is considered “replaceable details” in Onion Architecture. This separation makes it easy to swap technologies without rewriting business logic.</blockquote><pre>&lt;?php<br>// src/Infrastructure/InMemoryCookRepository.php<br><br>use React\Promise\PromiseInterface;<br>use function React\Promise\resolve;<br><br>final class InMemoryCookRepository implements CookRepository <br>{<br>    public function findOne(): PromiseInterface <br>    {<br>        return resolve(new Cook(&quot;Gordon&quot;));<br>    }<br>}</pre><pre>&lt;?php<br>// src/Infrastructure/InMemoryEggRepository.php<br><br>use React\Promise\PromiseInterface;<br>use function React\Promise\resolve;<br><br>final class InMemoryEggRepository implements EggRepository<br> {<br>    /** @var RawEgg[] */<br>    private array $eggs;<br><br>    public function __construct(int $initialCount = 3) <br>    {<br>        $this-&gt;eggs = array_fill(0, $initialCount, new RawEgg());<br>    }<br><br>    public function findAndRemove(): PromiseInterface <br>    {<br>        $egg = array_pop($this-&gt;eggs);     // null if empty<br>        return resolve($egg);<br>    }<br><br>    public function add(RawEgg $egg): PromiseInterface<br>    {<br>        $this-&gt;eggs[] = $egg;<br>        return resolve(null);<br>    }<br>}</pre><p><em>4. API ring</em></p><blockquote>The API block is the use-case/workflow layer that coordinates the steps of a feature. In this example, FoodPrepApi does not cook eggs by itself; it calls the domain objects and repository interfaces in the correct order. It does things like: get a cook, get an egg, start cooking, and return the final result. It depends on domain interfaces, not on concrete database classes, so it stays clean and testable. This block is where you put application flow, not low-level technical code. It keeps the domain focused on rules and the API focused on orchestration.</blockquote><pre>&lt;?php<br>// src/Api/FoodPrepApi.php<br><br>use React\Promise\PromiseInterface;<br>use function React\Promise\reject;<br><br>final class FoodPrepApi <br>{<br>    public function __construct(<br>        private CookRepository $cookRepo,<br>        private EggRepository $eggRepo<br>    ) {}<br><br>    /** @return PromiseInterface&lt;CookedEgg&gt; */<br>    public function prepareEgg(EggStyle $style): PromiseInterface<br>   {<br>        // 1) find cook (async)<br>        return $this-&gt;cookRepo-&gt;findOne()<br>            // 2) then find egg (async)<br>            -&gt;then(function (Cook $cook) use ($style) {<br>                return $this-&gt;eggRepo-&gt;findAndRemove()<br>                    -&gt;then(function (?RawEgg $egg) use ($cook, $style) {<br>                        if ($egg === null) {<br>                            return reject(new RuntimeException(&quot;No eggs left&quot;));<br>                        }<br><br>                        // domain logic (pure)<br>                        $pan = new EmptyFryingPan();<br>                        $fullPan = $pan-&gt;add($egg, $style);<br><br>                        // in real life you’d wait asynchronously; here we just remove<br>                        [$newPan, $cookedEgg] = $fullPan-&gt;remove();<br><br>                        return $cookedEgg; // promise resolves to CookedEgg<br>                    });<br>            });<br>    }<br>}</pre><blockquote>This block represents the idea that repository calls can be asynchronous. Instead of blocking while waiting for a database or network response, the code returns a Promise and continues when the result is ready. Promise chaining (then) keeps the workflow readable and helps avoid deeply nested callbacks (callback hell). It also matches the Onion idea because async is part of how the outer world works, while domain rules remain the same. In real apps, async improves throughput because threads are not wasted waiting. Even if you run sync today, the design stays ready for async tomorrow.</blockquote><p><em>5. Composition root</em></p><pre>&lt;?php<br>// public/index.php<br><br>require __DIR__ . &#39;/../vendor/autoload.php&#39;;<br><br>$cookRepo = new InMemoryCookRepository();<br>$eggRepo  = new InMemoryEggRepository(initialCount: 2);<br><br>$api = new FoodPrepApi($cookRepo, $eggRepo);<br><br>$api-&gt;prepareEgg(EggStyle::OverEasy)-&gt;then(<br>    fn(CookedEgg $egg) =&gt; print(&quot;Egg style: &quot; . $egg-&gt;style()-&gt;name . PHP_EOL),<br>    fn(Throwable $e)   =&gt; print(&quot;Error: &quot; . $e-&gt;getMessage() . PHP_EOL),<br>);</pre><blockquote>The wiring block is where you construct and connect everything together. It creates the infrastructure objects (like repositories) and injects them into the API layer (FoodPrepApi). This keeps “new PDO()” or “choose repository implementation” decisions out of the domain and API logic. It is the only place that knows the full configuration of the application. Because wiring is isolated, switching from in-memory storage to a real database is a small change here only. This makes the architecture easier to maintain and safer to evolve.</blockquote><p>Patterns don’t magically “make code better,” rather, they reduce the cost of change. Layering gives structure, and Onion/DIP protects your core logic from infrastructure churn. My takeaway: design for change first, performance tweaks can come after.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fce13b652bb9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Design Pattern’s with Bro — Part 1 (The Untold Story)]]></title>
            <link>https://shakilfci461.medium.com/design-patterns-with-bro-part-1-the-untold-story-493f4abd65dd?source=rss-b12da4e0614f------2</link>
            <guid isPermaLink="false">https://medium.com/p/493f4abd65dd</guid>
            <category><![CDATA[object-oriented-concepts]]></category>
            <category><![CDATA[object-oriented-design]]></category>
            <category><![CDATA[object-oriented]]></category>
            <category><![CDATA[design-patterns]]></category>
            <dc:creator><![CDATA[Shakil Ahmmed]]></dc:creator>
            <pubDate>Tue, 07 Jan 2025 22:50:50 GMT</pubDate>
            <atom:updated>2025-01-07T23:49:52.846Z</atom:updated>
            <content:encoded><![CDATA[<h3>Design Pattern’s with Bro — Part 1 (The Untold Story)</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/250/1*RqvSEGHlCTllFeAW442gAg.jpeg" /></figure><p>Cool Bro: Hey, Niko, What’s Up?</p><p>Niko: “The sky! But if you’re asking about my life, it’s more like a rainy day”.</p><p>Cool Bro: Little, Niko, You’re saying things that make you feel good 😝😝.</p><p>Niko: Bro, Let’s do some chaos 😆</p><p>Cool Bro: I know, Little Niko, what’s behind these words 😫.</p><p>Niko: Bro, Why does Everyone talk about something Pattern’s in Coding ,,,,,,,🤔🤔🤔 “Design Pattern’s”, What is it?</p><p>Cool Bro: Little, Niko, You can write code in the Object Oriented Programming Paradigm, Right?</p><p>Niko: 😎😎😎. Yes, Bro, I create classes, do Inheritance, sometimes I do the magic with Polymorphism 😎, and again I do Encapsulation for keeping an Object’s attributes (data) and behavior (methods) confined to the object itself, ensuring that it is not directly accessible or modifiable by external entities.</p><p>Cool Bro: You rock harder than a hurricane 🌪🌪🌪!</p><p>Niko: Bro, Little Niko is not Little anymore 😎😎😎. But Bro, What Is Design Patterns?</p><p>Cool Bro: Litte Niko ,,,, “Don’t count your chickens before they hatch” 😎😎😎</p><p>Niko: 🤔🤔🤔</p><p>Cool Bro: Listen, Suppose a few engineers are working together. Now they are discussing how a code or code pattern can avoid some design flaws in code (Rotting Design).</p><p>Niko: Bro, What are these?</p><p>Cool Bro:</p><blockquote><strong>Rigidity:</strong> This is a situation in the code that is difficult to change, even if there is an easy way. In other words, suppose I told you to change one place, but in the subsequence of that change, you have to change several other places.</blockquote><blockquote><strong>Fragility: </strong>This situation in the code is very similar to <strong>Rigidity. </strong>Suppose I told you to change one part of the code and this changes broke everything else, dependent or independent code.</blockquote><blockquote><strong>Immobility: </strong>We often have situations where we want to use a portion of one project or module in another project or module, but that is not possible due this situation that you have coded in a way that cannot be reused in any way, whether in the same project or in another project.</blockquote><blockquote><strong>Viscosity: </strong>This is a situation in your code where a problem is difficult to solve in a simple way but easy in a hacky way.In simpler terms, the code was written in such a way or the design choices of the code were such that it was easy to do wrong things but hard to do right things.</blockquote><p>Niko: 😣😣😣. But where are the Design Patterns?</p><p>Cool Bro: Litte Niko ,,,, Again “Don’t count your chickens before they hatch” 😎😎😎</p><p>Niko: 🤫🤫🤫</p><p>Cool Bro: Hmmmm…..Design Patterns! 😌😌 … As I said earlier, a few engineers are working together, and made some design choices to avoid all these (Rotting Design) problems, How each class will behave and what kind of relationship each will have with each other, and they implemented this. But if they want to use the same code design for the similar kind problem in future, how will they address this code design?</p><p>Niko: 😱😱😱…… Bro…….I understand, Bro, I understand. Then they will name the design to make it easier for each other to understand which code structure to follow.</p><p>Cool Bro: Exactly, Litte Niko…. 😌😌. But I’ll tell you one thing, so you don’t get upset 🫣🫣.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9WrPFNDZPs6AxPYhWHiPmw.jpeg" /></figure><p>Niko: 🤧🤧🤧,,,,,,, Bro….</p><p>Cool Bro: Everyone talks about Design Patterns, but all Design Patterns depend on some <strong><em>Object-oriented Design Principles</em></strong>.</p><p>Niko: Bro…… What is this <strong><em>Design Principles</em></strong> again? I was fine with the magic of inheritance and polymorphism. 🥴🥴🥴</p><p>Cool Bro: 🥱🥱</p><p>Niko: Bro….</p><p>Cool Bro: Do some chaos another day…. 🥱🥱</p><p>Niko: Bro……..</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=493f4abd65dd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Bro এর সাথে Database Scaling]]></title>
            <link>https://shakilfci461.medium.com/bro-%E0%A6%8F%E0%A6%B0-%E0%A6%B8%E0%A6%BE%E0%A6%A5%E0%A7%87-database-scaling-9e38a8093d78?source=rss-b12da4e0614f------2</link>
            <guid isPermaLink="false">https://medium.com/p/9e38a8093d78</guid>
            <category><![CDATA[database]]></category>
            <category><![CDATA[database-scaling]]></category>
            <category><![CDATA[database-scalability]]></category>
            <dc:creator><![CDATA[Shakil Ahmmed]]></dc:creator>
            <pubDate>Fri, 03 Jan 2025 05:32:11 GMT</pubDate>
            <atom:updated>2025-01-03T19:36:51.407Z</atom:updated>
            <content:encoded><![CDATA[<p>Cool Bro : কিরে ছোট্ট Niko কি অবস্থা, খোমার (চেহারার) এই অবস্থা কেন ? প্রেমিকা কষ্ট দিতেসে নাকি 😆</p><p>Niko: না ভাই , কষ্ট তো অন্য কিছু দিতেসে 🥹, উদ্ধার করবেন কিনা সেটা কন (বলেন)</p><p>Cool Bro: কি এমন তোরে কষ্ট দিতেসে , ওষুধ তো দিমু(দিবো) পরে আগে সমস্যা ক(বল) 😎</p><p>Niko: ভাই Database 😩</p><p>Cool Bro: কি Database Slow, Indexing করস তাও সমাধান হচ্ছে না, বেশি Connection এ কথা বলে না😆 😆?</p><p>Niko: হ ভাই 😩.</p><p>Cool Bro: 😆 😆 বুঝসি বুঝসি, এই জীবনে কষ্ট দেয়ার তো এই একটা জিনিষ.</p><p>Niko: আপনার কষ্ট পরে ভাই আগে আমারে ওষুধ দেন.</p><p>Cool Bro: ধর্য্য ধর , ধর্য্য ধর 😎</p><p>Cool Bro: আগে বল Application Scaling এর জন্য কেমনে কি করা যায়?</p><p>Niko: এত কিছু বুঝি না ভাই , মানুষ জন কি-জানি কি বলে Load Balancer কিন্তু সেটা তো Application এর জন্য .</p><p>Cool Bro: ধর্য্য ধর , ধর্য্য ধর, আগে বল এই Load Balancer কোন কোন লেয়ার এ কাজ করে.</p><p>Niko: ধুর ভাই , বিপদে ফালাইলেন না.</p><p>Cool Bro: ধর্য্য ধর , ধর্য্য ধর 😎, এই LoadBalancer Configure করা যায় ২ টা লেয়ার এ, OSI এর ৭ টা লেয়ার এর মধ্যে Transport (L4) এবং Application(L7) এ.</p><p>Niko: ভাই, Transport Layer(L4) এবং Application Layer(L7) এ পার্থক্য কোথায়?</p><p>Cool Bro: ভালো কথা , এই Transport (L4) লেয়ারে যে LoadBalancer Configure থাকে এর কাজ শুধু Packet Forward করা ,এই TCP আর UDP Packet , আর Application(L7) লেয়ারে তোর Packet Inspect করতে পারে যেমন HTTP Headers,URL.</p><p>Niko: ভাই বুঝতে পারলাম, সেই ভাই সেই ,তাহলে ভাই আমি ওই কি Database Replication না কি আছে Master-follower করে, ৩/৪ টা Follower বানাই নি যেখান থেকে ডাটা রিড হবে আর Master এ ডাটা রাইট হবে , যেহেতু Application থেকে Database এর Communication TCP তাইলে আমি কয়েকটা L4 LoadBalancer Configure করে দি Follower এর সামনে, সমস্যা সমাধান 🤩.</p><p>Cool Bro: ছোট্ট Niko……. সমস্যা তো অন্য জায়গায় 😎</p><p>Niko: ভাই,…………..?</p><p>Cool Bro: ধর্য্য ধর , ধর্য্য ধর 😎 , কিন্তু আগে বল SQL commands গুলো কি কি?</p><p>Niko: ভাই এইটা তো সহজ 😎 , DDL,DQL,DML….(etc)</p><p>Cool Bro: ধর তুই Load Balancer Configure করলি Nginx দিয়ে, কিন্তু Nginx কেমনে বুঝবে কোন Request Master এ যাবে কোন Request Follower এ.</p><p>Niko: এ……., কথা তো সত্য ভাই, Nginx তো আর SQL commands Inspect করতে পারে না 😑</p><p>Cool Bro: কি বুঝলি ছোট্ট Niko…. 😆</p><p>Niko: তার মানে ভাই আমার এমন কিছু লাগবে যেটা বুঝতে পারবে কোন Request Master এ যাবে কোন Request Follower এ, আরো সহজ করে বললে Application থেকে আসা কোনগুলো DDL, DML আর কোনগুলো DQL.</p><p>Cool Bro: ছোট্ট Niko…. জায়গামত ধরলি</p><p>Niko: জী ভাই, Application থেকে আসা DQL গুলো যাবে Follower এ আর DDL, DML গুলো যাবে Master এ, Master থেকে Follower গুলো Synchronous বা Asynchronous way তে Master এর State ট্রান্সফার করে নিবে.</p><p>Cool Bro: তুই আর ছোট্ট নাইরে……..</p><p>Niko: কিন্তু ভাই এই DDL,DML,DQL বুঝবে এমন জিনিষ কি পাই 😫</p><p>Cool Bro: ধর্য্য ধর , ধর্য্য ধর 😎, <a href="https://proxysql.com/">ProxySQL</a> নাম এ একটা জিনিষ আছে</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*14Kp1bOMi-dRpg6s.png" /></figure><p>Niko: 😱 সেই ভাই সেই ,……… ভাই…… কিন্তু Configure কেমনে করে এই জিনিষ.</p><p>Cool Bro: এইটা তোরে আরেকদিন শুনাই 🥱🥱🥱</p><p>Niko: ভাই রাতে তো ঘুম হবে না, 😫😫😫😫</p><p>Cool Bro: ঘুম না হইলে <a href="https://decentralizedthoughts.github.io/2020-12-22-what-is-a-merkle-tree/">Merkel Tree</a> কি এইটা পড় , ভাল ঘুম হবে 🥱🥱🥱</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9e38a8093d78" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Master-Slave Replication Using Docker]]></title>
            <link>https://shakilfci461.medium.com/master-slave-replication-using-docker-7d33aeb0c04b?source=rss-b12da4e0614f------2</link>
            <guid isPermaLink="false">https://medium.com/p/7d33aeb0c04b</guid>
            <dc:creator><![CDATA[Shakil Ahmmed]]></dc:creator>
            <pubDate>Thu, 22 Sep 2022 16:45:28 GMT</pubDate>
            <atom:updated>2022-09-22T16:45:28.479Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/720/0*yvL_o0oDUnGwcSzs.jpg" /></figure><p><strong>What Is Replication?</strong></p><pre>Replication enables data from one MySQL database server (known as a source) to be copied to one or more MySQL database servers (known as replicas). Replication is asynchronous by default; replicas do not need to be connected permanently to receive updates from a source.</pre><h3>Create docker compose file</h3><pre>version: &quot;3.7&quot;<br>services:<br>  master_database:<br>    image: mysql:5.7<br>    container_name: replica-master-database<br>    restart: unless-stopped<br>    volumes:<br>      -  ./master/conf/mysql.conf.cnf:/etc/mysql/conf.d/mysql.conf.cnf<br>      - ./master/data:/var/lib/mysql<br>    environment:<br>      MYSQL_DATABASE: master_database<br>      MYSQL_ROOT_PASSWORD: &quot;@@@2083@@@&quot;<br>      MYSQL_PASSWORD: &quot;@@@2083@@@&quot;<br>      MYSQL_USER: &quot;root&quot;<br>      SERVICE_TAGS: dev<br>      SERVICE_NAME: mysql<br>    networks:<br>      - replica-network<br>  master_phpmyadmin:<br>    image: phpmyadmin<br>    container_name: replica-master-phpmyadmin<br>    restart: always<br>    tty: true<br>    depends_on:<br>      - master_database<br>    ports:<br>      - &quot;7001:80&quot;<br>    environment:<br>      PMA_HOST: master_database<br>      PMA_PORT: 3306<br>      PMA_USER: &quot;root&quot;<br>      PMA_PASSWORD: &quot;@@@2083@@@&quot;<br>      MYSQL_ROOT_PASSWORD: &quot;@@@2083@@@&quot;<br>      UPLOAD_LIMIT: 2048M<br>    networks:<br>      - replica-network<br><br>  slave_database:<br>    image: mysql:5.7<br>    container_name: replica-slave-database<br>    restart: unless-stopped<br>    depends_on:<br>      - master_database<br>    volumes:<br>      - ./slave/conf/mysql.conf.cnf:/etc/mysql/conf.d/mysql.conf.cnf<br>      - ./slave/data:/var/lib/mysql<br>    environment:<br>      MYSQL_DATABASE: master_database<br>      MYSQL_ROOT_PASSWORD: &quot;@@@2083@@@&quot;<br>      MYSQL_PASSWORD: &quot;@@@2083@@@&quot;<br>      MYSQL_USER: &quot;root&quot;<br>      SERVICE_TAGS: dev<br>      SERVICE_NAME: mysql<br>    networks:<br>      - replica-network<br><br><br>  slave_phpmyadmin:<br>    image: phpmyadmin<br>    container_name: replica-slave-phpmyadmin<br>    restart: always<br>    tty: true<br>    depends_on:<br>      - slave_database<br>    ports:<br>      - &quot;7002:80&quot;<br>    environment:<br>      PMA_HOST: slave_database<br>      PMA_PORT: 3306<br>      PMA_USER: &quot;root&quot;<br>      PMA_PASSWORD: &quot;@@@2083@@@&quot;<br>      MYSQL_ROOT_PASSWORD: &quot;@@@2083@@@&quot;<br>      UPLOAD_LIMIT: 2048M<br>    networks:<br>      - replica-network<br><br>networks:<br>  replica-network:<br>    driver: bridge</pre><p><strong>Folder Structure:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/464/1*M5u8ZQ4K20hMv3gWV4oDJQ.png" /></figure><p><strong>Master Conf [Inside master/conf/mysql.conf.cnf] :</strong></p><pre>[mysqld]<br><br>skip-name-resolve<br>default_authentication_plugin = mysql_native_password<br><br>server-id = 1<br>log_bin = 1 [ N.B 1 means enable]<br>binlog_format = ROW <br>[N.B Possible values are ROW (replica replay only actual changes on the row), STATEMENT (replica replay all the queries that changes the data), MIXED (statement-based replication is used unless server decides only row-based replication can give proper result, like replicating result of GUUID() ) ]</pre><p><strong>Slave Conf [Inside slave/conf/mysql.conf.cnf] :</strong></p><pre>[mysqld]<br><br>skip-name-resolve<br>default_authentication_plugin = mysql_native_password<br><br>server-id = 2<br>log_bin = 1</pre><p><strong>Run Docker Containers:</strong></p><pre>sudo docker-compose up -d </pre><p><strong>Goto master container using</strong></p><pre>sudo docker exec -it replica-master-database bash</pre><p><strong>Run Mysql :</strong></p><pre>mysql -u root -p</pre><pre>mysql &gt; CREATE USER &#39;replication&#39;@&#39;%&#39; IDENTIFIED WITH mysql_native_password BY &#39;@@@2083@@@&#39;;<br>mysql &gt; GRANT REPLICATION SLAVE ON *.* TO &#39;replication&#39;@&#39;%&#39;;</pre><pre>mysql &gt; show grants for replication@&#39;%&#39;;</pre><pre>mysql &gt; SHOW MASTER STATUS\G;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/676/1*SIK_M7Hje52OrblJg5K3jA.png" /></figure><p><strong>[N.B : Copy File and Position]</strong></p><p><strong>Goto Slave Container Using:</strong></p><pre>sudo docker exec -it replica-slave-database bash</pre><p>Run Mysql:</p><pre>mysql -u root -p</pre><pre>mysql &gt; CHANGE MASTER TO<br>     -&gt; MASTER_HOST=&#39;master_database&#39;,<br>     -&gt; MASTER_USER=&#39;mydb_slave_user&#39;,<br>     -&gt; MASTER_PASSWORD=&#39;@@@2083@@@&#39;,<br>     -&gt; MASTER_LOG_FILE=&#39;1.000004&#39;, [ FROM Master File Name which we copied]<br>     -&gt; MASTER_LOG_POS=1224; [ FROM Master Position which we copied]</pre><pre>mysql &gt; START SLAVE; [ start the slave on mysql ]</pre><pre>mysql &gt; SHOW SLAVE STATUS\G;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/790/1*DHoa-C_C-mGZhzkJHkUavg.png" /></figure><p><strong>MySQL master slave replication on the docker machine is now successfully set.</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7d33aeb0c04b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[লারাভেল মিডলওয়্যার]]></title>
            <link>https://shakilfci461.medium.com/%E0%A6%B2%E0%A6%BE%E0%A6%B0%E0%A6%BE%E0%A6%AD%E0%A7%87%E0%A6%B2-%E0%A6%AE%E0%A6%BF%E0%A6%A1%E0%A6%B2%E0%A6%93%E0%A6%AF%E0%A6%BC%E0%A7%8D%E0%A6%AF%E0%A6%BE%E0%A6%B0-f7dedc21c340?source=rss-b12da4e0614f------2</link>
            <guid isPermaLink="false">https://medium.com/p/f7dedc21c340</guid>
            <category><![CDATA[middlware]]></category>
            <category><![CDATA[php]]></category>
            <category><![CDATA[laravel]]></category>
            <dc:creator><![CDATA[Shakil Ahmmed]]></dc:creator>
            <pubDate>Wed, 12 Aug 2020 13:20:51 GMT</pubDate>
            <atom:updated>2020-08-12T13:20:51.602Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*OBUcbqID3HF98hWi.png" /></figure><p><strong>মিডলওয়্যার কি ? </strong><br>মিডলওয়্যার হচ্চে লেয়ার , যান লেয়ার না বুজলে মনে করেন সিকিউরিটি গার্ড (👨‍✈️), যে কিনা আপনার এপ্লিকেশন এ আসা প্রত্যেক টি HTTP রিকোয়েস্ট কে ফিল্টার করবে , আহা ধরে নেন কিছু একটা চেক করবে। 😁</p><p>মনে করেন বাংলাদেশ আর ইন্ডিয়ার মধ্যে জমজমাট খেলা হচ্ছে এখন আপনি খেলা দেখতে যাবেন , আপনার কাছে টিকেট আছে , এখন টিকেট দিয়ে এতো আপনাকে খেলা দেখতে দিবে , নাইলে কি দিবে ? 😋 ওই যে সিকিউরিটি গার্ড (👨‍✈️) যে আপনার টিকেট চেক করবে , উনি হচ্চে মিডলওয়্যার.</p><p>তো আসেন লারাভেল এর মিডলওয়্যার কোথায় থাকে ? 🙄</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/455/1*Kh0xRXoufvLgA5qzUZUAXA.png" /><figcaption>এইগুলা হচ্চে মিডলওয়্যার (<strong>app/Http/Middleware</strong>)</figcaption></figure><p><strong>লারাভেল এ আমরা নিজেরা কিভাবে মিডলওয়্যার</strong> <strong>বানাবো ?</strong></p><p>টার্নিমাল এ গিয়ে কমান্ড টা দিয়ে দেন 💻</p><blockquote>php artisan make:middleware Test</blockquote><p><strong>app/Http/Middleware </strong>এই খানে দেখতে পারবেন নতুন একটি ফাইল</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/666/1*Wq_WczT61mqZH4zq408o4g.png" /><figcaption>ওনার চেহারা এমন 😜</figcaption></figure><p>এই মিডলওয়্যার টি আপনার এপ্লিকেশন এ ব্যবহার করতে চাইলে (app/Http/kernel.php) এই ফাইল এ রেজিস্টার করে দিতে হবে .</p><p>যদি আপনার এমন প্রয়োজন হয় যে , প্রত্যেকটা রিকোয়েস্ট এ আপনার মিডলওয়্যার টি রান করবে তাহলে :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*J9udmcO3HniC6sFwJ4eHPA.png" /></figure><p>এইখানে লিখে দিতে হবে , অর্থাৎ গ্লোবাল মিডলওয়্যার গুলা এই array তে রেজিস্টার করতে দিতে হবে.</p><p>যদি Route এ Assign করতে চান তাহলে এইখানে রেজিস্টার করে দিতে হবে :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/857/1*TxvBQPFzlmrnFJ4QczRz9Q.png" /></figure><p>যদি একাধিক মিডলওয়্যার থাকে এবং ঐগুলা আপনি একসাথে কল করতে চান তাহলে এইখানে গ্রূপ করে নিতে পারেন :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/736/1*aoUaG-mzRZUfPngFPtiy2A.png" /></figure><p><strong>তো মিডলওয়্যার কিভাবে কল করবেন রেজিস্টার করা তো শেষ </strong>🤔 <strong>:</strong></p><pre>Route::get(&quot;/hello&quot;,<em>function </em>(){<br>    <em>return </em>&quot;Hello&quot;;<br>})-&gt;middleware(&quot;test&quot;);</pre><p><strong>যদি একাধিক মিডলওয়্যার কল করতে হয় </strong>🤔<strong>?</strong></p><pre>Route::get(&quot;/hello&quot;,<em>function </em>(){<br>    <em>return </em>&quot;Hello&quot;;<br>})-&gt;middleware(&quot;test&quot;,&quot;test_second&quot;);</pre><p><strong>অর্ডার অনুযায়ী কল হবে</strong></p><p><strong>একাধিক Route এ একই মিডলওয়্যার কল করবো কিভাবে </strong>🤔<strong>:</strong></p><pre>Route::group([&#39;middleware&#39;=&gt;&#39;test&#39;],<em>function </em>(){<br>    Route::get(&quot;/hello&quot;,<em>function </em>(){<br>        <em>return </em>&quot;Hello&quot;;<br>    });<br>    Route::get(&quot;/about&quot;,<em>function </em>(){<br>        <em>return </em>&quot;about&quot;;<br>    });<br>    Route::get(&quot;/blog&quot;,<em>function </em>(){<br>        <em>return </em>&quot;blog&quot;;<br>    });<br>});</pre><p><strong>যদি কোনো Route থেকে মিডলওয়্যার বাদ দিতে হয় </strong>🤔<strong>:</strong></p><pre>Route::group([&#39;middleware&#39;=&gt;&#39;test&#39;],<em>function </em>(){<br>    Route::get(&quot;/hello&quot;,<em>function </em>(){<br>        <em>return </em>&quot;Hello&quot;;<br>    });<br>    Route::get(&quot;/about&quot;,<em>function </em>(){<br>        <em>return </em>&quot;about&quot;;<br>    });<br>    Route::get(&quot;/blog&quot;,<em>function </em>(){<br>        <em>return </em>&quot;blog&quot;;<br>    })-&gt;withoutMiddleware(&quot;test&quot;);<br>});</pre><blockquote>এইটা শুধুমাত্র $routeMiddleware এ রেজিস্টার করা মিডলওয়্যার এর উপর কাজ করবে , গ্লোবাল মিডলওয়্যার এ কাজ করবে না.</blockquote><p><strong>যদি একই সাথে একাদিক মিডলওয়্যার গ্রূপ বা মিডলওয়্যার কে কল করতে </strong>🤔<strong>:</strong></p><pre>Route::group([&#39;middleware&#39;=&gt;[&#39;test&#39;,&#39;test_second&#39;]],<em>function </em>(){<br>    Route::get(&quot;/hello&quot;,<em>function </em>(){<br>        <em>return </em>&quot;Hello&quot;;<br>    });<br>    Route::get(&quot;/about&quot;,<em>function </em>(){<br>        <em>return </em>&quot;about&quot;;<br>    });<br>    Route::get(&quot;/blog&quot;,<em>function </em>(){<br>        <em>return </em>&quot;blog&quot;;<br>    })-&gt;withoutMiddleware(&quot;test&quot;);<br>});</pre><blockquote>লারাভেল বাই ডিফল্ট (web.php) তে লিখা প্রত্যেকটি Route এ “web”(<strong>গ্রূপ মিডলওয়্যার</strong>) টি কল করে এবং (api.php) তে লিখা প্রত্যেকটি Route এ “api” (<strong>গ্রূপ মিডলওয়্যার</strong>) টি কল করে</blockquote><p>ধন্যবাদ 🥳</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f7dedc21c340" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>