<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>José Postiga</title><description>Most teams can get an AI prototype working in a week. Making it reliable enough to run a business on is the hard part.</description><link>https://josepostiga.com/</link><language>en</language><item><title>Customer relationship 101: keep your customers informed about their processes</title><link>https://josepostiga.com/writing/customer-relationship-101-keep-your-customers-informed-about-their-processes/</link><guid isPermaLink="true">https://josepostiga.com/writing/customer-relationship-101-keep-your-customers-informed-about-their-processes/</guid><description>I’m currently waiting on car parts to arrive with zero visibility on the timeline. Six days ago, I sent a quick email to the official body shop asking for a simple status update. The response? None……</description><pubDate>Tue, 11 Aug 2026 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;I’m currently waiting on car parts to arrive with zero visibility on the timeline. Six days ago, I sent a quick email to the official body shop asking for a simple status update. The response? None…&lt;/p&gt;
&lt;p&gt;It was a sharp reminder that customer satisfaction is rarely just about getting the lowest price. It’s about receiving great service. And “service” goes far beyond the core product or deliverable. It’s how you guide someone through the sale; It’s the post-sale support when things are moving slowly; It’s the proactive updates that prevent a customer from feeling left in a vacuum.&lt;/p&gt;
&lt;p&gt;You don’t always need to have the final solution immediately. Sometimes a simple, “We’re still working on this, here is where things stand,” is all it takes to preserve trust. Proactive communication costs almost nothing, but radio silence will eventually cost you the customer.&lt;/p&gt;
&lt;p&gt;And you can replace customer with any other stakeholder, and do the same in any other context. This is not about car pieces, it’s about basic communication skills and project management. Basic!&lt;/p&gt;
&lt;p&gt;Apply this now: if you have some pending tasks involving other people, open your email client and write a one paragraph with a quick status update on their process. Do this on a weekly basis. Hell, use AI to do half the work and generate a draft. Review and send! Watch the reactions…&lt;/p&gt;
</content:encoded><category>Journal</category><category>Career</category></item><item><title>What AI Agents Teach Us About Human Potential</title><link>https://josepostiga.com/writing/what-ai-agents-teach-us-about-human-potential/</link><guid isPermaLink="true">https://josepostiga.com/writing/what-ai-agents-teach-us-about-human-potential/</guid><description>An AI agent’s true power doesn’t just come from the model itself. It comes from the harness and the context it operates within. You can take a smaller, modestly parametered model, give it a brilliant…</description><pubDate>Mon, 10 Aug 2026 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;An AI agent’s true power doesn’t just come from the model itself. It comes from the harness and the context it operates within. You can take a smaller, modestly parametered model, give it a brilliant harness (great context retrieval, well-structured tools, clear constraints, and strong feedback loops) and it will consistently outperform a massive, cutting-edge model trapped in a poor framework.&lt;/p&gt;
&lt;p&gt;Humans work the exact same way. Your output and growth aren’t defined solely by raw talent or potential. They depend heavily on the environment you’re in, the team around you, the inputs you receive, and the culture you absorb, what anchors you: your purpose, core values, faith, habits, and self-discipline.&lt;/p&gt;
&lt;p&gt;Put a high-performing person in a chaotic, toxic context with zero guidance or grounding, and their output will degrade. Put someone in a supportive, high-signal context anchored by strong values, and they can achieve excellence far beyond what they thought possible.&lt;/p&gt;
&lt;p&gt;The take-away: If you ever feel like you aren’t “good enough” or aren’t being valued for what you bring to the table, check your framework before you question your worth. Don’t just try to rewrite who you are. Change your context, and refine the harness you rely on.&lt;/p&gt;
</content:encoded><category>Journal</category><category>Career</category></item><item><title>Human In The Driver Seat</title><link>https://josepostiga.com/writing/human-in-the-driver-seat/</link><guid isPermaLink="true">https://josepostiga.com/writing/human-in-the-driver-seat/</guid><description>It’s extremely tempting to prompt an LLM to write an RFC, an ADR, or similar technical docs. In seconds, you get a clean, polished, multi-page document that seems to overflow knowledge and…</description><pubDate>Mon, 03 Aug 2026 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;It’s extremely tempting to prompt an LLM to write an RFC, an ADR, or similar technical docs. In seconds, you get a clean, polished, multi-page document that seems to overflow knowledge and professionalism. While AI is brilliant at identifying edge cases, reviewing existing drafts, or suggesting missing considerations, it should never take the driver’s seat when writing core technical docs.&lt;/p&gt;
&lt;p&gt;Drafting an RFC or ADR isn’t just transcription; it forces you to confront trade-offs, weigh organizational constraints, and internalize the consequences. Offloading the writing means offloading the actual reasoning. An AI doesn’t know your team’s historical tech debt, your org’s risk tolerance, or the subtle political trade-offs between two conflicting engineering teams.&lt;/p&gt;
&lt;p&gt;AI-generated docs sound authoritative even when the underlying architecture is flawed. A poorly formatted human doc with deep insight beats a beautifully structured AI doc with shallow assumptions every single time. Use AI as an interactive reviewer, a devil’s advocate, or a proofreader. But never as the author.&lt;/p&gt;
&lt;p&gt;Let AI find the holes in your logic, but keep human engineers firmly behind the wheel.&lt;/p&gt;
</content:encoded><category>Journal</category><category>AI</category><category>architecture</category><category>Career</category><category>software</category></item><item><title>Best High Impact/Low Effort First AI Initiative</title><link>https://josepostiga.com/writing/best-high-impact-low-effort-first-ai-initiative/</link><guid isPermaLink="true">https://josepostiga.com/writing/best-high-impact-low-effort-first-ai-initiative/</guid><description>If you’re driving AI adoption in your company, here is the single best low-effort / high-impact win to start with: Build a contextualized knowledge agent for your internal teams. Connect standard…</description><pubDate>Sat, 01 Aug 2026 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;If you’re driving AI adoption in your company, here is the single best low-effort / high-impact win to start with: Build a contextualized knowledge agent for your internal teams. Connect standard product, sales, and support documentation into a single conversational agent, and place it directly where your teams (Product, Sales, Support) already work.&lt;/p&gt;
&lt;p&gt;The immediate impact will be massive! It cuts down hours spent digging through documentation tools such as Confluence, Notion, or Slack, to find basic answers. It handles internal queries first, giving you a safe playground to test accuracy before going customer-facing.&lt;/p&gt;
&lt;p&gt;Start small. Focus on internal enablement. Add a simple feedback loop (thumbs up/down + comments) on every response so you can observe what needs to be improved. Iterate publicly.&lt;/p&gt;
</content:encoded><category>Journal</category><category>AI</category><category>Career</category><category>software</category></item><item><title>Hiring Should Be Easy</title><link>https://josepostiga.com/writing/hiring-should-be-easy/</link><guid isPermaLink="true">https://josepostiga.com/writing/hiring-should-be-easy/</guid><description>Almost 20 years in the tech industry, and I’m still amazed on how flawed the interview process is. Why are we hammering candidates with leet code questions, or some other bullshit process that tries…</description><pubDate>Fri, 31 Jul 2026 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;Almost 20 years in the tech industry, and I’m still amazed on how flawed the interview process is. Why are we hammering candidates with leet code questions, or some other bullshit process that tries to classify the person in a very sintethic way?&lt;/p&gt;
&lt;p&gt;In my humble experience both as an interviewee and an interviewer the best to scout for the very best is by doing a very simple question: “Out of all the work you’ve done so far, what is the single project you’re most proud of, and why?”&lt;/p&gt;
&lt;p&gt;It sounds almost too simple, but it opens the door to everything you actually need to know:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Execution &amp;amp; Logic: How do they structure a problem, navigate obstacles, and bring an idea to life?&lt;/li&gt;
&lt;li&gt;Collaboration: Do they say “I” or “We”? How do they navigate team dynamics when things get tough?&lt;/li&gt;
&lt;li&gt;Definition of Success: Do they measure success by business impact, personal growth, or vanity metrics?&lt;/li&gt;
&lt;li&gt;Self-Awareness: Can they talk openly about what went wrong, what they learned, and what they’d do differently today?&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;By anchoring the conversation on their absolute best work, you get to see them at their highest energy and deepest level of detail. The best interviews rarely feel like interrogations. They feel like a great coffee chat: two people digging into a subject they’re passionate about.&lt;/p&gt;
</content:encoded><category>Journal</category><category>Career</category></item><item><title>Get Promoted By Walking The Walk</title><link>https://josepostiga.com/writing/get-promoted-by-walking-the-walk/</link><guid isPermaLink="true">https://josepostiga.com/writing/get-promoted-by-walking-the-walk/</guid><description>One thing people need to start understanding is how promotions work. Waiting for a title before stepping up is like waiting for a campfire to give you heat before you put in the wood. If you want to…</description><pubDate>Mon, 27 Jul 2026 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;One thing people need to start understanding is how promotions work. Waiting for a title before stepping up is like waiting for a campfire to give you heat before you put in the wood.&lt;/p&gt;
&lt;p&gt;If you want to achieve that promotion, you gotta grow into the position while still executing your current level and with your current pay. When you start consistently demonstrating the skills, strategic thinking, and leadership required for the next role, you make it almost impossible for management to say no.&lt;/p&gt;
&lt;p&gt;If you’re ready to bridge the gap between where you are and where you want to be, try this framework:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Align with Your Leader Early.: don’t wait for your annual review. Tell your manager: “I’m aiming for [Target Role]. What are 2 or 3 responsibilities from that level I can start taking off your plate this quarter?” This shows initiative and gives them permission to delegate strategic tasks to you.&lt;/li&gt;
&lt;li&gt;Solve Problems Outside Your Scope: look for friction points in your team’s workflow or cross-departmental communication. Taking initiative to fix a broken process is classic next-level behavior.&lt;/li&gt;
&lt;li&gt;Build Organizational Context: start paying attention to company-wide goals, financial metrics, and industry trends. The higher up you go, the less your job is about execution and the more it is about context and strategy.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Shift your focus from “What do I get?” to “How am I already operating?” and the titles (and money) will follow.&lt;/p&gt;
</content:encoded><category>Journal</category><category>Career</category></item><item><title>Customers don’t care about your dependency tree</title><link>https://josepostiga.com/writing/customers-dont-care-about-your-dependency-tree/</link><guid isPermaLink="true">https://josepostiga.com/writing/customers-dont-care-about-your-dependency-tree/</guid><description>There is a hard truth in SaaS: You can outsource your infrastructure, your payments, and your CRM, but you cannot outsource your responsibility. Nothing is more frustrating for an engineering team…</description><pubDate>Wed, 14 Jan 2026 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;There is a hard truth in SaaS: You can outsource your infrastructure, your payments, and your CRM, but you cannot outsource your responsibility.&lt;/p&gt;
&lt;p&gt;Nothing is more frustrating for an engineering team than dropping everything to patch a bug caused by an upstream vendor. It feels like cleaning up a mess you didn’t make.&lt;/p&gt;
&lt;p&gt;It’s even worse when shared customers are affected. It is incredibly tempting to say, “It’s not us, it’s [Vendor Name].”&lt;/p&gt;
&lt;p&gt;But to the customer? That sounds like an excuse.&lt;/p&gt;
&lt;p&gt;If they pay us, the “whole product” experience is on us. If a vendor breaks, it means our resilience strategy failed, or our vendor selection process needs review.&lt;/p&gt;
&lt;p&gt;The perception of fault is a reality of ownership. We take the heat so the customer doesn’t have to navigate the complexity of the supply chain.&lt;/p&gt;
</content:encoded><category>Journal</category><category>Engineering</category><category>Product Management</category><category>SaaS</category></item><item><title>The Paradox of AI: How It’s Starving the Hand That Feeds It</title><link>https://josepostiga.com/writing/the-paradox-of-ai-how-its-starving-the-hand-that-feeds-it/</link><guid isPermaLink="true">https://josepostiga.com/writing/the-paradox-of-ai-how-its-starving-the-hand-that-feeds-it/</guid><description>The Internet used to be a place where we easily had access to “free” knowledge. It was an open digital world. As we scrolled and ingested such content, there was opportunity to learn about the…</description><pubDate>Tue, 13 Jan 2026 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;The Internet used to be a place where we easily had access to “free” knowledge. It was an open digital world. As we scrolled and ingested such content, there was opportunity to learn about the authors and distributors of such knowledge, which also added a possibility for them to upsell or direct our attention to other things.&lt;/p&gt;
&lt;p&gt;Now, in the age of AI, it’s no more “X person has this awesome article about the problem and how to solve them” and more “X model can fix or teach about that”. No author, no references, nothing… It’s brutal! This will cause, and has caused already, businesses to lose revenue. Worst, or equally worst, is that open core businesses (to speak in a topic closer to my heart as an engineer) that depend on such revenue to fund constant work on their open source projects that everybody else can freely use, will stop maintaining it because it’s no longer viable.&lt;/p&gt;
&lt;p&gt;I’m very concerned that this can push such businesses or individual maintainers to close access to, for example, documentation (at least anything beyond the basics of what it is and how to install it) in favor of taking back control and to have new ways to publicize other work and direct attention. At the very least, to be known…&lt;/p&gt;
&lt;p&gt;This will throw us back 30+ years, when if we wanted knowledge we would have to buy books. And this would starve the models of training data, eventually, which would also make them less interesting. So it’s extremely evident to me that AI models, and their owners, need to at least make ways for authors to have a little more control or take crediting way more seriously!&lt;/p&gt;
</content:encoded><category>Journal</category><category>AI</category></item><item><title>The Decomposition Pattern Podcast</title><link>https://josepostiga.com/writing/the-decomposition-pattern-podcast/</link><guid isPermaLink="true">https://josepostiga.com/writing/the-decomposition-pattern-podcast/</guid><description>“The Decomposition Pattern” is a podcast where we break down the hottest takes in tech and programming into their fundamental components. We separate signal from noise, tackle complex topics with…</description><pubDate>Sun, 12 Jan 2025 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;“The Decomposition Pattern” is a podcast where we break down the hottest takes in tech and programming into their fundamental components. We separate signal from noise, tackle complex topics with clarity, and rebuild our understanding from the ground up.&lt;/p&gt;
&lt;div class=&quot;video&quot;&gt;&lt;iframe src=&quot;https://www.youtube-nocookie.com/embed/diSikVxbSLw&quot; title=&quot;YouTube video player&quot; loading=&quot;lazy&quot; allow=&quot;accelerometer; encrypted-media; gyroscope; picture-in-picture&quot; allowfullscreen&gt;&lt;/iframe&gt;&lt;/div&gt;
&lt;p&gt;Useful Links:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;YouTube: &lt;a href=&quot;https://www.youtube.com/playlist?list=PLSkYRPXyFmgcBg7ljH-U4GIlSPTMKymXp&quot;&gt;https://www.youtube.com/playlist?list=PLSkYRPXyFmgcBg7ljH-U4GIlSPTMKymXp&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Discord: &lt;a href=&quot;https://discord.gg/xFhADmfEyZ&quot;&gt;https://discord.gg/xFhADmfEyZ&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
</content:encoded><category>Videos</category><category>architecture</category><category>Podcast</category><category>software</category></item><item><title>Inheritance only with abstract classes</title><link>https://josepostiga.com/writing/inheritance-only-with-abstract-classes/</link><guid isPermaLink="true">https://josepostiga.com/writing/inheritance-only-with-abstract-classes/</guid><description>Here’s a Sunday thought: inheritance should only be done for abstract classes. Anything else you think you need from inheritance should probably be done with composition. Take the canonical human…</description><pubDate>Sun, 10 Dec 2023 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;Here’s a Sunday thought: inheritance should only be done for abstract classes. Anything else you think you need from inheritance should probably be done with composition.&lt;/p&gt;
&lt;p&gt;Take the canonical human example. We’re not only humans, right? We’re actually a specific type of human: male, female (or any other gender, irrelevant for the example). We have common behaviour but then specific features based on the base gender.&lt;/p&gt;
&lt;p&gt;Being a human is an abstract concept. More specific than a mammal, but more abstract than any of its subtypes.&lt;/p&gt;
&lt;p&gt;Have a nice weekend! 👋&lt;/p&gt;
</content:encoded><category>Journal</category><category>architecture</category><category>inheritance</category><category>software</category></item><item><title>Automatically preventing access to ill services using Circuit Breakers</title><link>https://josepostiga.com/writing/automatically-preventing-access-to-ill-services-using-circuit-breakers/</link><guid isPermaLink="true">https://josepostiga.com/writing/automatically-preventing-access-to-ill-services-using-circuit-breakers/</guid><description>In software architecture, there’s a fascinating pattern called Circuit Breaker. As the electrical counterpart, the goal of this pattern is to completely prevent requests from hitting an ill service,…</description><pubDate>Tue, 08 Aug 2023 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;In software architecture, there’s a fascinating pattern called Circuit Breaker. As the electrical counterpart, the goal of this pattern is to completely prevent requests from hitting an ill service, lowering possible frustrations from clients submitting data that would, then, possibly be lost due to errors in the application. Normally, a Circuit Breaker is automatically activated, and orchestrated, when the error rate of such service hits a predetermined threshold.&lt;/p&gt;
&lt;p&gt;With the possibility of losing information or, worst yet, having data being mishandled or corrupted, it’s best to have a part of the application virtually amputated than to deal with possible very bad aftermath. This gives developers a certain level of calm, although still being a critical event that needs fixing. But, at least, the “bleeding” is stopped.&lt;/p&gt;
&lt;p&gt;Once things get fixed, the circuit breaker is turned off and requests can flow, once again, to the recovered service.&lt;/p&gt;
&lt;p&gt;This pattern matches pretty well with another concept in the realm of continuous deployment: feature flags. If we use FF to roll out access to a service, we can make the circuit breaker turn off that FF, signalling that that service isn’t to be used at this time.&lt;/p&gt;
</content:encoded><category>Journal</category><category>architecture</category><category>circuitbreakers</category><category>featureflags</category><category>software</category></item><item><title>We all want to catch Pokémon</title><link>https://josepostiga.com/writing/we-all-want-to-catch-pokemon/</link><guid isPermaLink="true">https://josepostiga.com/writing/we-all-want-to-catch-pokemon/</guid><description>“No one wants to use software. They just want to catch Pokémon”. Such a powerful and eye-opener quote from the book I read, “The Staff Engineer’s Path”. It means that no one cares about which…</description><pubDate>Mon, 31 Jul 2023 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;“No one wants to use software. They just want to catch Pokémon”.&lt;/p&gt;
&lt;p&gt;Such a powerful and eye-opener quote from the book I read, “The Staff Engineer’s Path”. It means that no one cares about which technologies are deployed in a given project, as long as they can use it for its purpose.&lt;/p&gt;
&lt;p&gt;I see a lot of – imo useless – discussions and comparisons around frameworks, programming languages and scaling that leads me to believe we forgot the most important thing about software: creating solutions to users problems.&lt;/p&gt;
&lt;p&gt;Steve Jobs once said – and I’m paraphrasing here – “We have to work on the user experience and work backwards to the technology”. And that’s something we need to keep on top of our minds. Ultimately it doesn’t matter if we use PHP, Go, Rust, Typescript, OCAML, C, or bloody Pascal. What matters is is we’re creating solutions that make people’s life better!&lt;/p&gt;
</content:encoded><category>Journal</category><category>software</category></item><item><title>Encapsulate behaviour with anonymous classes</title><link>https://josepostiga.com/writing/encapsulate-behaviour-with-anonymous-classes/</link><guid isPermaLink="true">https://josepostiga.com/writing/encapsulate-behaviour-with-anonymous-classes/</guid><description>Today, a colleague – Joel Piccoli da Rosa – sent a link to a blog post by a fellow developer, Sebastian De Deyne, where Sebastian describes something he wished PHP had native support: nested…</description><pubDate>Mon, 10 Jul 2023 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;Today, a colleague – &lt;a href=&quot;https://www.linkedin.com/in/ACoAAArgQ3wB2cEU3WtKqUtti-FlUuebuqsTBpM&quot;&gt;Joel Piccoli da Rosa&lt;/a&gt; – sent a link to a blog post by a fellow developer, Sebastian De Deyne, where Sebastian describes something he wished PHP had native support: nested properties. Something like the pseudo-code the following image shows:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://josepostiga.com/images/posts/encapsulate-behaviour-with-anonymous-classes/image.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;I found the &lt;a href=&quot;https://sebastiandedeyne.com/php-wishlist-nested-properties/&quot;&gt;article&lt;/a&gt; very interesting and I understand why Sebastian would like something like what exists in Typescript. It’s a very brief and concise syntax. He also says that not having this leads devs to either, and I’m quoting, &lt;em&gt;“[…] use less types (by using an associative array) or worse: create the wrong abstraction (abstract class Endpoints is not a good use of inheritance).”&lt;/em&gt;. +1 for not recommending inheritance!&lt;/p&gt;
&lt;p&gt;The gist of the problem, as I understood, was how to encapsulate the “endpoints” information without using associative arrays or external classes (abstract or not) that would only be used within the context of “ContactResource” without losing type inference, autocompletion, and all those goodies. This got me thinking… And I reached this solution:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://josepostiga.com/images/posts/encapsulate-behaviour-with-anonymous-classes/image-1.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;Is it as elegant as Sebastian’s proposed syntax? Nope. But I don’t think it’s ugly or unmanageable, either. I find it quite elegant: we have encapsulation, we don’t use associative arrays, and we don’t point to external classes that will only be used in this context.&lt;/p&gt;
</content:encoded><category>Journal</category><category>architecture</category><category>software</category></item><item><title>Set your ego aside</title><link>https://josepostiga.com/writing/set-your-ego-aside/</link><guid isPermaLink="true">https://josepostiga.com/writing/set-your-ego-aside/</guid><description>If I had to point out something that has taken away opportunities to learn and grow, from me, I would say: ego. The arrogance of quickly dismissing other points of view, and approaches to problems,…</description><pubDate>Fri, 30 Jun 2023 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;If I had to point out something that has taken away opportunities to learn and grow, from me, I would say: ego. The arrogance of quickly dismissing other points of view, and approaches to problems, due to the assumption that I knew better or simply because of ignorance, prevented me from exploring other paths and experiencing things outside my comfort zone.&lt;/p&gt;
&lt;p&gt;I now know better. As a leader, I question more than I answer, I don’t share opinions just because, and I don’t talk about what I don’t truly know and understand. When it comes to making decisions, I try my hardest to give everyone the space to share their thoughts and make sure no idea gets dismissed without being properly analyzed. This I believe is very important, especially when we’re in a position of leadership.&lt;/p&gt;
&lt;p&gt;I developed a simple framework to prevent my ego from messing things up: whenever I’m getting together with my teams to decide on something, I continuously ask these simple questions:&lt;/p&gt;
&lt;p&gt;1. What’s the problem we’re trying to solve;&lt;/p&gt;
&lt;p&gt;2. What the team thinks could be possible solutions and possible impacts of each presented solution (positive and less positive);&lt;/p&gt;
&lt;p&gt;3. What solution the team believes should be pursued and implemented.&lt;/p&gt;
&lt;p&gt;Note that none of those questions is to be answered by me but by the team. I only guide and steer how the analyses are made, making questions and ensuring every angle is looked upon with the same measure. That’s influence: ultimately, the team might get to the solution I probably knew would be best.&lt;/p&gt;
&lt;p&gt;Sometimes, new and unexpected solutions arise, and we all grow!&lt;/p&gt;
</content:encoded><category>Journal</category><category>growth</category><category>influence</category><category>leadership</category></item><item><title>An Important Decision</title><link>https://josepostiga.com/writing/an-important-decision/</link><guid isPermaLink="true">https://josepostiga.com/writing/an-important-decision/</guid><description>Here’s another unsolicited career advice: at some point, every senior software engineer will have to make a decision on which track to focus. Up until that point, I believe the main objective should…</description><pubDate>Wed, 28 Jun 2023 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;Here’s another unsolicited career advice: at some point, every senior software engineer will have to make a decision on which track to focus. Up until that point, I believe the main objective should be to gain experience and try things: be exposed to many different technical challenges, languages, and engineering cultures as possible.&lt;/p&gt;
&lt;p&gt;This is to get a better feeling of what clicks with us and understand what we don’t see ourselves doing in the future, building up to the point where we need to decide what to specialize on: technical leadership, management, or even individual contributor. Each of those paths has its own challenges, expectations, and prerequisites. It can even vary from company to company.&lt;/p&gt;
&lt;p&gt;It’s not to say that once we decide on a path, we can’t change it afterwards. It’s just to avoid frustrations. And that’s what the “exposed to many things” objective gives us: perspective.&lt;/p&gt;
&lt;p&gt;So don’t worry about building a career early on. Experiment, try, fail (as fast as possible), and get busy. And don’t forget to live, too.&lt;/p&gt;
</content:encoded><category>Journal</category><category>Career</category><category>future</category><category>software</category></item><item><title>Easing database decomposition</title><link>https://josepostiga.com/writing/easing-database-decomposition/</link><guid isPermaLink="true">https://josepostiga.com/writing/easing-database-decomposition/</guid><description>When talking about monolith decomposition into microservices, it’s not unusual to assume that data should also be decomposed and moved within the infrastructure boundaries of the new services that…</description><pubDate>Mon, 26 Jun 2023 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;When talking about monolith decomposition into microservices, it’s not unusual to assume that data should also be decomposed and moved within the infrastructure boundaries of the new services that arise. It must – no discussion there – but it doesn’t necessarily mean immediately.&lt;/p&gt;
&lt;p&gt;There’s a lot to think about when decomposing a monolithic database. In a relational database, for example, we might have foreign keys checks to disable, pivot tables connecting tables that now will be separated. It might sound minor but it adds up to the code decomposition and all the work around getting the new service up and running. It can be overwhelming.&lt;/p&gt;
&lt;p&gt;An option to ease the transition of the data to the service boundaries, without having to completely move data to another datastore instance, is to do what’s called a logical decomposition. It actually means using new schemas or collections (depending on the database type).&lt;/p&gt;
&lt;p&gt;Yes, it still makes the current, monolithic, database a single point of failure for two services (the monolith and the new service) but serves as an intermediate step: the new service will still handle this as if it was a different DB, but it allows for the gradual decomposition of the database.&lt;/p&gt;
&lt;p&gt;When that logical decomposition is done, we can safely move all data and schemas/collections to a new, dedicated, instance within the owning service boundaries. Until then, we’re free to gradually re-architect all the data logic and structure as necessary until we reach a state we’re satisfied with.&lt;/p&gt;
</content:encoded><category>Journal</category><category>architecutre</category><category>database</category><category>decomposition</category><category>migration</category><category>monolith</category><category>soa</category></item><item><title>Please be my Proxy</title><link>https://josepostiga.com/writing/please-be-my-proxy/</link><guid isPermaLink="true">https://josepostiga.com/writing/please-be-my-proxy/</guid><description>The Proxy design pattern is handy when we want to defer the instantiation of an object only when it’s absolutely necessary. To do such a thing, it must comply with the same interface of the object it…</description><pubDate>Thu, 22 Jun 2023 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;The Proxy design pattern is handy when we want to defer the instantiation of an object only when it’s absolutely necessary. To do such a thing, it must comply with the same interface of the object it proxies to so that it can be used anywhere that object is used and not break any expectations.&lt;/p&gt;
&lt;p&gt;Another usefulness of the design pattern is to allow calculating access to the underlying object. If a caller should have specific access conditions validated, the Proxy can do it seamlessly.&lt;/p&gt;
&lt;p&gt;It’s a beast of a design pattern, in my opinion. I approve of it! 😂&lt;/p&gt;
</content:encoded><category>Journal</category><category>architecture</category><category>design</category><category>software</category></item><item><title>For a better career management!</title><link>https://josepostiga.com/writing/for-a-better-career-management/</link><guid isPermaLink="true">https://josepostiga.com/writing/for-a-better-career-management/</guid><description>Here’s a piece of unsolicited career advice: have recurrent 1:1s with your direct manager, set objectives and clear expectations, discuss the major struggles you have with them, and define action…</description><pubDate>Wed, 21 Jun 2023 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;Here’s a piece of unsolicited career advice: have recurrent 1:1s with your direct manager, set objectives and clear expectations, discuss the major struggles you have with them, and define action points to resolve them. Do this throughout the year. Take notes.&lt;/p&gt;
&lt;p&gt;Then, every 12 months, do a quick reflection on all notes taken and do a self-review with expectations for the career review, and send it to your manager. This will greatly help them clearly understand if a career progression should happen.&lt;/p&gt;
&lt;p&gt;The idea is to have a continuous alignment between both parties and for the career review to not be a complete surprise. The big mistake is to wait until the last minute to do all this and get surprised or, worst, not understand why it didn’t align with our expectations.&lt;/p&gt;
</content:encoded><category>Journal</category><category>Career</category><category>Documentation</category><category>Review</category></item><item><title>Branching the monolith</title><link>https://josepostiga.com/writing/branching-the-monolith/</link><guid isPermaLink="true">https://josepostiga.com/writing/branching-the-monolith/</guid><description>Last Friday, I discussed one of my favourite service migration patterns: The Decorating collaborator. Today, I want to discuss another cool pattern: Branch by Abstraction. This one has fewer…</description><pubDate>Mon, 19 Jun 2023 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;Last Friday, I discussed one of my favourite service migration patterns: The Decorating collaborator. Today, I want to discuss another cool pattern: Branch by Abstraction.&lt;/p&gt;
&lt;p&gt;This one has fewer infrastructure requirements and allows for migrating subsystems of the application by switching concrete implementations that, instead of calling more subsystems of the monolith will call a dedicated service, instead. Obviously, this is dependent on the use of abstractions (e.g. interfaces) – thus the name.&lt;/p&gt;
&lt;p&gt;The power of enabling this composition of applications doesn’t come without two big trade-offs: 1) it requires access to the source code of the application to migrate; and 2) it creates a dependency on the new service to execute, correctly, the part of the feature it’s responsible for when called upon doing it, requiring the new service to be healthy 100% of the time.&lt;/p&gt;
&lt;p&gt;That dependency on the health and correctness of the service at the time of the execution (synchronous flow) can be removed and better handled, in my opinion, with an event-driven architecture (asynchronous).&lt;/p&gt;
</content:encoded><category>Journal</category><category>architecture</category><category>monolith</category><category>soa</category><category>software</category></item><item><title>Decorate your monolith away!</title><link>https://josepostiga.com/writing/decorate-your-monolith-away/</link><guid isPermaLink="true">https://josepostiga.com/writing/decorate-your-monolith-away/</guid><description>A few months back, in March, I was invited to talk at PHP Portugal #[Lisbon] v7 meetup. My talk was titled “Three strategies to split your monolith into services” where I briefly introduced The…</description><pubDate>Sat, 17 Jun 2023 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;A few months back, in March, I was invited to talk at PHP Portugal #[Lisbon] v7 meetup. My talk was titled “Three strategies to split your monolith into services” where I briefly introduced The Strangler Fig, Branch by Abstraction, and The Decorating Collaborator patterns.&lt;/p&gt;
&lt;p&gt;Of those three, my favourite is the last one, The Decorating Collaborator, because is the one that allows programmers to stop developing in the monolith immediately and focus on developing new functionality in a new service. To do so, it requires a proxy application that will be responsible for decorating – thus the name – new behaviour into the old monolith’s, making it look like we’re still calling the monolith when, in fact, we might be interacting with the new service.&lt;/p&gt;
&lt;p&gt;Another trade-off to consider is that the more information is required for interacting with the new service, the more complex and tangled the proxy application implementation becomes.&lt;/p&gt;
&lt;p&gt;This pattern is best used to compose responses and side effects from the inbound request and/or the response from the monolith but we can’t, or won’t, change the monolith itself. It can stay feature freeze, or even outside of our control, but it still can be evolved.&lt;/p&gt;
&lt;p&gt;Maybe, gradually, replace features completely until the monolith ceases to exist.&lt;/p&gt;
</content:encoded><category>Journal</category><category>architecture</category><category>services</category><category>soa</category><category>software</category></item><item><title>SOLID principles are just that: principles!</title><link>https://josepostiga.com/writing/solid-principles-are-just-that-principles/</link><guid isPermaLink="true">https://josepostiga.com/writing/solid-principles-are-just-that-principles/</guid><description>I love the SOLID design principles. It’s a pity that there is a lot of “hate” towards them, and I think it’s mostly because they are pushed as a dogmatic way of developing software, as a set of…</description><pubDate>Fri, 16 Jun 2023 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;I love the SOLID design principles. It’s a pity that there is a lot of “hate” towards them, and I think it’s mostly because they are pushed as a dogmatic way of developing software, as a set of inflexible rules that need to be respected at all costs.&lt;/p&gt;
&lt;p&gt;That pushes people away from seeing and understanding how useful these principles are. And that’s exactly what they are: a set of principles. It’s literally in the name. But I’m not here to regurgitate, yet again, what SOLID means or represents. I think that every programmer, eventually, will learn exactly that. But take that knowledge for what they are: principles!&lt;/p&gt;
&lt;p&gt;My love for is exactly in that nuance. They help me guide my applications’ architecture, but I don’t feel bad if a function or class has more than one responsibility, or if I decide to modify them instead of extending their functionality, or if I’m not adhering completely to every other principle. But I know and respect that those principles exist for valid reasons: to develop manageable and extensible software.&lt;/p&gt;
&lt;p&gt;But I’m also not naive to the point of not understanding that there are many possible contexts, be it architecturally or because of team dynamics, in which one might consciously need to decide that it can’t or shouldn’t be done now.&lt;/p&gt;
&lt;p&gt;And that is totally fine. Perfection is a lie.&lt;/p&gt;
</content:encoded><category>Journal</category><category>architecture</category><category>software</category><category>solid</category></item><item><title>Don’t be afraid of huge load spikes!</title><link>https://josepostiga.com/writing/dont-be-afraid-of-huge-load-spikes/</link><guid isPermaLink="true">https://josepostiga.com/writing/dont-be-afraid-of-huge-load-spikes/</guid><description>Huge traffic spikes hitting our applications can be very problematic and scary, especially if we’re not prepared for such situations. The common solution I see being applied is to have some type of…</description><pubDate>Thu, 15 Jun 2023 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;Huge traffic spikes hitting our applications can be very problematic and scary, especially if we’re not prepared for such situations.&lt;/p&gt;
&lt;p&gt;The common solution I see being applied is to have some type of auto-scaling strategy. It’s a good and simple enough solution: launch more instances to deal with more traffic and reduce them when the spike is over. But this automation might take some time to kick in, so the thresholds need to account for that as we don’t want to react too late and too close to the hardware limits or risk losing instances in the process and, consequently, data.&lt;/p&gt;
&lt;p&gt;Another solution, although it’s not for every type of request, is to have what’s called a Firehose event stream. This means that instead of having variadic loads of requests hitting your application, directly, they are first put in an event stream before being consumed by the application. We basically create a virtual dam, and we can control the flow of incoming work.&lt;/p&gt;
&lt;p&gt;Now, I want to be clear: this dam needs to be robust. And it fundamentally changes the underlying problem from the application to the workers that compose this dam. But since those workers have a simpler workflow – take the request and store it in the event stream – they probably can handle more requests per second than the application. So it can probably do more with less.&lt;/p&gt;
&lt;p&gt;With this approach, the application won’t hit resource exhaustion because the load of the work is under our control. It won’t need to scale until it can’t keep up with the lag of events to consume or any other SLA or SLO we have to guarantee.&lt;/p&gt;
&lt;p&gt;But, as said before, this is not for every type of request. If you need to deliver a response immediately, it’s an incompatible solution. And that, alongside the additional infrastructure requirements of adding an event or message broker and the actual workers, are pretty much the trade-offs implied.&lt;/p&gt;
</content:encoded><category>Journal</category><category>architecture</category><category>event-streaming</category><category>software</category></item><item><title>Monoliths are Majestic</title><link>https://josepostiga.com/writing/monoliths-are-majestic/</link><guid isPermaLink="true">https://josepostiga.com/writing/monoliths-are-majestic/</guid><description>I love a good monolith. It’s easy to develop and maintain, deploy and scale. It’s a real beauty. But, as with everything, developing in a monolith has its trade-offs and requires some effort to keep…</description><pubDate>Wed, 14 Jun 2023 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;I love a good monolith. It’s easy to develop and maintain, deploy and scale. It’s a real beauty. But, as with everything, developing in a monolith has its trade-offs and requires some effort to keep it from being a huge bottleneck to our companies and teams.&lt;/p&gt;
&lt;p&gt;If there’s no care about keeping a separation by business domains (yep, DDD) it ends up creating a lot of attrition, coupling, and conflicts between the teams. With well-defined domains, changes in a domain have a very low possibility of impacting other domains.&lt;/p&gt;
&lt;p&gt;The ease of deployment carries a huge responsibility. Since the monolith is deployed as a whole, there’s little to no way to really only do it when all teams have finished their work completely. Unfinished features must be protected from executing or we risk having errors thrown at the user and the application terminating unexpectedly. Feature flags allow the continuous deployment of the monolith, deferring access to unfinished features for a posterior occasion.&lt;/p&gt;
&lt;p&gt;The development itself gets limited to one or two programming languages. In the context of web applications, for example, this can mean having a backend and a frontend language (in the case of a full-stack app). This can impact how recruitment is done in the company and the talent pool available.&lt;/p&gt;
</content:encoded><category>Journal</category><category>DDD</category><category>monoliths</category><category>software</category></item><item><title>Short-lived database transactions</title><link>https://josepostiga.com/writing/short-lived-database-transactions/</link><guid isPermaLink="true">https://josepostiga.com/writing/short-lived-database-transactions/</guid><description>We all know that database transactions ensure that data is only persisted if all write queries are successfully executed. Otherwise, the entire operation is automatically rolled back. This is super…</description><pubDate>Tue, 13 Jun 2023 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;We all know that database transactions ensure that data is only persisted if all write queries are successfully executed. Otherwise, the entire operation is automatically rolled back. This is super helpful, and I believe we all rely or relied on this feature forever!&lt;/p&gt;
&lt;p&gt;But transactions have trade-offs. The engine will lock either entire tables, or rows, depending on the operations being made. And depending on the type of locks, even read queries will wait for the transaction to be completed to gain access to the data. This can accumulate, in a busy enough service or domain, and can become a performance bottleneck.&lt;/p&gt;
&lt;p&gt;So be very careful about operations that could make those transactions opened for an extended period of time. As a rule of thumb, we should open transactions as close as possible of the write operations and close them as soon as the work is done. This is to lower the possibilities of extending those locks for too long.&lt;/p&gt;
</content:encoded><category>Journal</category><category>database</category><category>software</category><category>transactions</category></item><item><title>Don’t be afraid of using caching strategies in your applications</title><link>https://josepostiga.com/writing/dont-be-afraid-of-using-caching-strategies-in-your-applications/</link><guid isPermaLink="true">https://josepostiga.com/writing/dont-be-afraid-of-using-caching-strategies-in-your-applications/</guid><description>This is something I see not being much discussed within development teams. It’s almost as if there’s some kind of fear of serving stale content, or an internal assumption that information should be…</description><pubDate>Mon, 12 Jun 2023 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;This is something I see not being much discussed within development teams. It’s almost as if there’s some kind of fear of serving stale content, or an internal assumption that information should be always fetched and guaranteed to be fresh by the second.&lt;/p&gt;
&lt;p&gt;Here’s another (kind of) hot take for this calm Monday morning: there’s a very finite number of reasons to not use a caching strategy. In fact, I believe it should be something we default to using unless proven otherwise.&lt;/p&gt;
&lt;p&gt;Here’s a basic strategy to cache and refresh data: many of the data I usually see applications manage are mostly updated through specific side effects or endpoints. This is a perfect use case for caching on updates: refresh the cache whenever the data is explicitly updated and always try to serve from the cache whenever that data is being retrieved.&lt;/p&gt;
&lt;p&gt;Even in more complex workflows, where parts of the data must be fetched or go through some type of real-time calculation/transformation/etc., when the request comes in, we can always:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Fetch the cached base data from the cache.&lt;/li&gt;
&lt;li&gt;Fetch or calculate only the needed “real-time” data from the appropriate data sources.&lt;/li&gt;
&lt;li&gt;Compose and serve the entire information.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Caching data also creates a temporary redundancy in our systems. As long as the TTL (Time To Live) of the data hasn’t expired, the underlying data source can be offline because we’re still going to serve the cached data. The response times will go down, too.&lt;/p&gt;
&lt;p&gt;I’m generalising, of course, but it should give a push into, at least, initiating a discussion on your particular cases if caching could bring benefits.&lt;/p&gt;
&lt;p&gt;It’s better to discuss and conclude that it’s not something you want to add, rather than not discussing and continuing to invest computational power and service communication to always fetch fresh data without needing it.&lt;/p&gt;
</content:encoded><category>Journal</category><category>architecture</category><category>cache</category></item><item><title>Avoid hidden control flows</title><link>https://josepostiga.com/writing/avoid-hidden-control-flows/</link><guid isPermaLink="true">https://josepostiga.com/writing/avoid-hidden-control-flows/</guid><description>Here’s an hot take (I think) to end this beautiful Sunday: avoid using hidden control flows in your applications. I’m referring to throwing exceptions, specifically, here. When we throw an exception,…</description><pubDate>Sun, 11 Jun 2023 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;Here’s an hot take (I think) to end this beautiful Sunday: avoid using hidden control flows in your applications. I’m referring to throwing exceptions, specifically, here. When we throw an exception, we lose control on the application flow.&lt;/p&gt;
&lt;p&gt;It’s also something that can’t really be ignored. The caller needs to wrap interactions to methods and functions that throws exceptions if they don’t really need to do anything with the exception. Without that their own flow would be impacted and interrupted unnecessarily.&lt;/p&gt;
&lt;p&gt;A more sensible solution is to do something like Go and Rust does: return the error. Let the caller decide what to do with the returned values instead of being forced to handle everything with awful try/catch blocks.&lt;/p&gt;
&lt;p&gt;Maybe this could be a nice topic to blog about or submit to a meetup/conference?… 🤷‍♂️&lt;/p&gt;
</content:encoded><category>Journal</category><category>controlflows</category><category>software</category></item><item><title>Event-driven architectures creates resilient and fail-tolerant software</title><link>https://josepostiga.com/writing/event-driven-architectures-creates-resilient-and-fail-tolerant-software/</link><guid isPermaLink="true">https://josepostiga.com/writing/event-driven-architectures-creates-resilient-and-fail-tolerant-software/</guid><description>I do find event-driven architectures to be the pinnacle of resilience and fail-tolerance in software. In fact, that’s pretty much how the real world works: for every action, there’s a reaction. In…</description><pubDate>Sun, 11 Jun 2023 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;I do find event-driven architectures to be the pinnacle of resilience and fail-tolerance in software. In fact, that’s pretty much how the real world works: for every action, there’s a reaction.&lt;/p&gt;
&lt;p&gt;In synchronous communication, we have an orchestration of interactions between services. The orchestrator needs to know every single service and the order it should be called. High coupling: consumers and producers of information need to constantly know each other. Adding or removing services, or upgrade their interfaces are hard so the owning teams need constantly syncs with each other to know what breaking changes need to be prepared for. It guarantees data is updated after the action is executed.&lt;/p&gt;
&lt;p&gt;In asynchronous communication, we have a choreography of services reacting to each other’s events. There’s no orchestrator, no single point of failure (theoretically; realistically there’s the event broker). Adding or removing services can be done at any time, without disrupting other services. Data will eventually be consistent, but there’s no guarantee when exactly that’ll be.&lt;/p&gt;
&lt;p&gt;And here’s the kicker: complex systems will most probably use a mix of both. And it’s very healthy that that happens. We have processes that can be eventually consistent, and asynchronous, but there are other systems that need to do things now and need to do it well, or everything must fail. And even in success there needs to be idempotency guarantees.&lt;/p&gt;
</content:encoded><category>Journal</category><category>architecture</category><category>eda</category></item><item><title>Layering decoupled and cohesive applications</title><link>https://josepostiga.com/writing/layering-decoupled-and-cohesive-applications/</link><guid isPermaLink="true">https://josepostiga.com/writing/layering-decoupled-and-cohesive-applications/</guid><description>Something I wish I had known earlier in my career is that all applications consist of four layers with specific responsibilities: Presentation layer: UI (views). Application layer: orchestration…</description><pubDate>Sun, 11 Jun 2023 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;Something I wish I had known earlier in my career is that all applications consist of four layers with specific responsibilities:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Presentation layer: UI (views).&lt;/li&gt;
&lt;li&gt;Application layer: orchestration (routers, controllers, input validation).&lt;/li&gt;
&lt;li&gt;Domain layer: business logic and invariants.&lt;/li&gt;
&lt;li&gt;Infrastructure layer: persistence, data transfer, low-level operations.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;And there’s an implicit order of dependencies: higher layers should depend on classes/functions from lower layers. If a lower layer needs to communicate with a higher layer, it should do so through events.&lt;/p&gt;
&lt;p&gt;This has greatly helped me understand and design highly decoupled, cohesive, applications.&lt;/p&gt;
</content:encoded><category>Journal</category><category>layered architecture</category><category>software</category></item><item><title>Don’t Let Your Queues Crash Your Applications</title><link>https://josepostiga.com/writing/dont-let-your-queues-crash-your-applications/</link><guid isPermaLink="true">https://josepostiga.com/writing/dont-let-your-queues-crash-your-applications/</guid><description>When implementing a queueing system, it’s easy to forget that the async benefits only apply after the jobs are dispatched to the queues. The dispatching, itself, is almost always a sync process. If…</description><pubDate>Mon, 29 May 2023 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;When implementing a queueing system, it’s easy to forget that the async benefits only apply after the jobs are dispatched to the queues. The dispatching, itself, is almost always a sync process. If that fails, our systems might return errors to the users. And there are other ways of producing errors besides bugs in the code.&lt;/p&gt;
&lt;p&gt;This was a lesson recently learned the hard way. When everything’s working well, we tend to almost forget we have this additional infrastructure that supports some workloads that we don’t want to – and probably don’t need to – make our users wait to be fully executed. When we implement a queueing system we subconsciously assume that the two planes of operation (sync and async; the request and the processing of that request, respectively) are fully independent and that exceptions and problems in one don’t affect the other.&lt;/p&gt;
&lt;p&gt;And, to some extent, we’re right!&lt;/p&gt;
&lt;h2 id=&quot;a-basic-queue-system-design&quot;&gt;A basic queue system design&lt;/h2&gt;
&lt;p&gt;If we research how to implement a queue system, we’ll get to an architecture something like the following:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://josepostiga.com/images/posts/dont-let-your-queues-crash-your-applications/basic_queue_example.png&quot; alt=&quot;A basic queue system design&quot;&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Fig1. A basic queueing system architecture diagram&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Don’t delve too much into its simplicity as it was on purpose. But it does capture what we might describe as a valid queueing system: we have our Web Application producing (or queueing) jobs in our Queue Cluster, and then Queue Workers (long-lived processes) will continuously pool for new jobs, reserve and process them.&lt;/p&gt;
&lt;p&gt;Nothing exotic; nothing magically complex. So what’s this blog post about?&lt;/p&gt;
&lt;h2 id=&quot;how-a-queue-system-quickly-becomes-a-single-point-of-failure&quot;&gt;How a queue system quickly becomes a single point of failure&lt;/h2&gt;
&lt;p&gt;We can’t blindly consider a queueing system as something secondary, unimportant, and not critical to our system’s architecture. Here’s what I mean: if we look at Fig. 1, above, we can say that everything north of the Queue Cluster is a synchronous flow and everything south of it is asynchronous. We tend to instinctively assume a queueing system is totally asynchronous and fail-tolerant but that will lead to possible headaches and unavailability of part of our system.&lt;/p&gt;
&lt;p&gt;You see, the synchronous part can still fail for any number of reasons, and when that happens we’ll probably lose the job that should have been dispatched to the queue unless we take proactive actions.&lt;/p&gt;
&lt;p&gt;If we look closely at the aforementioned architecture, we can note a few problems:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;The dispatching of the jobs relies on the operation being 100% correct all the time and no problem occurs between services’ communication (between the Web Application and the Queue Cluster).&lt;/li&gt;
&lt;li&gt;Relying on a single cluster to persist data from (possibly) multiple application domains/services.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;If any of those problems happen, we’ll probably lose any reference to the jobs that aren’t dispatched to the queue, and we won’t have a way to retry that operation.&lt;/p&gt;
&lt;h2 id=&quot;how-to-improve-resilience-and-have-a-fail-tolerant-dispatching-logic&quot;&gt;How to improve resilience and have a fail-tolerant dispatching logic&lt;/h2&gt;
&lt;p&gt;So, what to do to prevent the first issue, above, and handle failures gracefully with the option to eventually retry them when the error is fixed? Well, here’s a possible solution to guarantee that:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://josepostiga.com/images/posts/dont-let-your-queues-crash-your-applications/better_queue_example.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Fig. 2 – Adding an log for dispatching jobs&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;We can introduce a transactional outbox pattern. What this means, putting it simply is that a copy of the job is saved in a log before the dispatch itself.&lt;/p&gt;
&lt;p&gt;This, in fact, will allow us to re-dispatch jobs for whatever reason. If retrying failed dispatching jobs is all we need, we can remove this record after the dispatch is successfully done or simply only write to this log on dispatch failures. The Queue Cluster can be unavailable for whatever time necessary, and once it comes back online, all jobs’ dispatching can be retried.&lt;/p&gt;
&lt;p&gt;Now, to the next problem.&lt;/p&gt;
&lt;h2 id=&quot;minimise-a-domains-cluster-specific-problems-impact-on-other-domains&quot;&gt;Minimise a domain’s cluster-specific problems’ impact on other domains&lt;/h2&gt;
&lt;p&gt;With the dispatching failures being gracefully handled, we can turn to the problem of depending on a single Cluster. If it goes down – for maintenance or because it’s filled up, to name a few possibilities- it’ll take the entire async part of our architecture down, impacting all the consumers of that Cluster.&lt;/p&gt;
&lt;p&gt;A possible solution for guaranteeing that the blast radius of the unavailability of a Cluster doesn’t propagate to all domains/services is as follows:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://josepostiga.com/images/posts/dont-let-your-queues-crash-your-applications/better_queue_example_2.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Fig. 3 – Multiple Queue Clusters per domain/service&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Introducing a Queue Cluster per domain/service, each one independent from the others can limit the impact on the owning domain/service. So if one Cluster is down for any reason, the others will continue to operate normally.&lt;/p&gt;
&lt;p&gt;This brings, of course, other consequences: increased infrastructure to manage and increased costs. As with everything in life, use this wisely and in the correct measure to the criticality of your architecture.&lt;/p&gt;
&lt;h2 id=&quot;in-conclusion&quot;&gt;In conclusion&lt;/h2&gt;
&lt;p&gt;This is a cautionary tale. I was recently reminded the hard way that having a queueing system doesn’t magically detach itself from the application it belongs to and can, actually, bring it to its knees. Addin redundancy and some fallback strategies to prevent it from losing data when things aren’t working as expected.&lt;/p&gt;
&lt;p&gt;At least, now, we learned a few to make queues more resilient, robust, and trustworthy.&lt;/p&gt;
</content:encoded><category>Articles</category><category>architecture</category><category>queues</category></item><item><title>Avoiding Instantiating Invalid Entity Classes</title><link>https://josepostiga.com/writing/avoiding-instantiating-invalid-entity-classes/</link><guid isPermaLink="true">https://josepostiga.com/writing/avoiding-instantiating-invalid-entity-classes/</guid><description>At Infraspeak, the entire engineering team gets a couple of days, every month, to fully dedicate to pet projects. As me and my friend Nelson were working on our automations Bot, we were introducing…</description><pubDate>Fri, 26 Aug 2022 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;At &lt;a href=&quot;https://infraspeak.com&quot;&gt;Infraspeak&lt;/a&gt;, the entire engineering team gets a couple of days, every month, to fully dedicate to pet projects. As me and my friend Nelson were working on our automations Bot, we were introducing the first Entities to our domains without noticing, at first, that we were creating invalid instances. This article shows why those instances were broken from the start, and how to ensure we always work with valid instances even before persisting them in a data store.&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;Entities are defined by a thread of continuity and identity. This means that due to having a unique ID, whenever their properties’ values change, it’ll still be the same Entity and we’ll always be able to reference to it (that’s the continuity part).&lt;/p&gt;
&lt;p&gt;When developing software, it’s broadly accepted that we should strive for immutable objects. If we want to change something inside immutable objects, we make new instances with the updated values. This prevents that during execution of the application logic, an object gets unintentionally mutated, probably putting it in an invalid state. I won’t delve to much into this pattern (rain check for another post), but the point is that when working with immutable objects, they should be in a valid and usable state. Anywhere that accepts that object doesn’t need to worry about constantly check for its validity.&lt;/p&gt;
&lt;p&gt;So, if having an identity, via a unique ID, completely defines an Entity, and it should be considered immediately valid upon instantiation, then using sequentially-generated number from a data store as the source of the Entity identity is a problem. And here’s why: we can’t safely predict what the next number is, and it’s not even the Entity responsibility to do so, leaving us in a dilemma: we need to instantiate an Entity to persist it, and get that ID, but we can’t because to instantiate it we need to have an ID. So, what to do?&lt;/p&gt;
&lt;p&gt;A naive, instinctive, workaround would be to accept two types for the ID property: an &lt;code&gt;integer&lt;/code&gt; or a &lt;code&gt;null&lt;/code&gt;. This does fix the problem of instantiating the object but doesn’t make it valid, and we implicitly created a dependency on the data store, now, because we need to persist the entity first, and create a new instance with the actual ID, before we can use it further in the application.&lt;/p&gt;
&lt;p&gt;The thing is, although clearly broken, this is the most common implementation that I’ve seen when working with Entities. I, too, have done it this way, but I’ve recently found another way of working with totally valid Entities without requiring them to be persisted to the data store before being used in the application.&lt;/p&gt;
&lt;p&gt;The trick is to drop the use of internally-generated sequential IDs that come from the data store, at application level, and replace them with randomly, uniquely-identifiable IDs, like UUIDs. By using UUIDS, we can both generate unique IDs and have fully valid Entity instances to work with immediately, and remove a hard dependency on the data store for that purpose.&lt;/p&gt;
&lt;p&gt;We can even save on object instantiation times, since we no longer need to re-create an Entity class upon persistence because there’s probably no new properties to fetch, where before we would need to do it to have the ID populated from the data store. Persistence of the Entity becomes an implementation detail.&lt;/p&gt;
</content:encoded><category>Articles</category><category>DDD</category></item><item><title>Using The Singleton Pattern For Service Classes</title><link>https://josepostiga.com/writing/using-the-singleton-pattern-for-service-classes/</link><guid isPermaLink="true">https://josepostiga.com/writing/using-the-singleton-pattern-for-service-classes/</guid><description>A few weeks ago, during a mentoring session that I hosted with a few colleagues from work, we ended up talking about good examples of using the Singleton Pattern in software development. As we…</description><pubDate>Sun, 21 Aug 2022 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;A few weeks ago, during a mentoring session that I hosted with a few colleagues from work, we ended up talking about good examples of using the Singleton Pattern in software development. As we discussed, it appeared that this pattern was in the “no-no” box, for some reason, and labeled as an anti-pattern. I think, however, that there are very good use cases for using it. This article shows how to leverage the Singleton pattern to optimize resources and prevent our applications from holding unnecessary class instances in memory.&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;The Singleton pattern is a creational design pattern with the purpose of enforcing the use of the same instance of a class in the application. It means that the investment of creating an instance of a class with this pattern is only paid once, making subsequent calls to methods of the same class faster. However, this means that that instance also shares any and all state, which makes it tricky to use in cases where the different calls to the class needs to have independent state management. That’s why, generally speaking, that using this design pattern is not taken into much consideration. Which is a shame, because I think it’s perfect to create and manage instances of service classes.&lt;/p&gt;
&lt;p&gt;Service classes, also known as Managers or Handlers, are a set of classes that host behaviour methods. This definition is a little vague, on purpose, since the actual type of behaviour they’ll contain depends on which software layer it’s on (application, domain, infrastructure). Nevertheless, the key point is that they should be stateless, so instantiating several instances of the same service class is unnecessary and redundant. But that’s what I generally see happening when using Dependency Injection of service classes.&lt;/p&gt;
&lt;p&gt;Creating instances of objects takes computational resources (mainly, memory), and they’ll live in-memory for as long as a request is being handled, before being garbage-collected or explicitly removed. If we have many uses of the same service class, instantiating it several times is a waste of resources and makes the process take more time to be handled than necessary, which is not very performant either.&lt;/p&gt;
&lt;p&gt;That’s when I find that using the Singleton pattern shines, because after the first instantiation of the service class, the same instance will be used, instead of continuously creating new instances.&lt;/p&gt;
</content:encoded><category>Articles</category><category>Design Patterns</category></item><item><title>Programming Tip #5 – Design Patterns</title><link>https://josepostiga.com/writing/programming-tip-5-design-patterns/</link><guid isPermaLink="true">https://josepostiga.com/writing/programming-tip-5-design-patterns/</guid><description>Every week I join Daniel Maciel to share tips and suggestions for developers. In this episode, we talk about Design Patterns as generalist solutions to solve recurring problems in software…</description><pubDate>Sun, 04 Jul 2021 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;Every week I join Daniel Maciel to share tips and suggestions for developers.&lt;/p&gt;
&lt;p&gt;In this episode, we talk about Design Patterns as generalist solutions to solve recurring problems in software development. It is important that programmers know and learn about these patterns and knows how to research and analyze the need for their implementation in a project.&lt;/p&gt;
&lt;p&gt;(Content in Portuguese)&lt;/p&gt;
&lt;div class=&quot;video&quot;&gt;&lt;iframe src=&quot;https://www.youtube-nocookie.com/embed/5cOs5gS2Fjc&quot; title=&quot;YouTube video player&quot; loading=&quot;lazy&quot; allow=&quot;accelerometer; encrypted-media; gyroscope; picture-in-picture&quot; allowfullscreen&gt;&lt;/iframe&gt;&lt;/div&gt;
</content:encoded><category>Videos</category><category>Career</category><category>CI/CD</category><category>Documentation</category><category>Open-Source</category><category>Podcast</category><category>Review</category><category>TDD</category></item><item><title>Programming Tip #4 – Code Review</title><link>https://josepostiga.com/writing/programming-tip-4-code-review/</link><guid isPermaLink="true">https://josepostiga.com/writing/programming-tip-4-code-review/</guid><description>Every week I join Daniel Maciel to share tips and suggestions for developers. In this episode we talk about the activity of reviewing code to ensure its quality, also known as: “Code Review”. When…</description><pubDate>Fri, 04 Jun 2021 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;Every week I join Daniel Maciel to share tips and suggestions for developers.&lt;/p&gt;
&lt;p&gt;In this episode we talk about the activity of reviewing code to ensure its quality, also known as: “Code Review”. When should we do it? What are the main concerns and how should we start?&lt;/p&gt;
&lt;p&gt;(Content in Portuguese)&lt;/p&gt;
&lt;div class=&quot;video&quot;&gt;&lt;iframe src=&quot;https://www.youtube-nocookie.com/embed/icQ0aWxf_mY&quot; title=&quot;YouTube video player&quot; loading=&quot;lazy&quot; allow=&quot;accelerometer; encrypted-media; gyroscope; picture-in-picture&quot; allowfullscreen&gt;&lt;/iframe&gt;&lt;/div&gt;
</content:encoded><category>Videos</category><category>Career</category><category>CI/CD</category><category>Documentation</category><category>Open-Source</category><category>Podcast</category><category>Review</category><category>TDD</category></item><item><title>Practical Docker for Developers</title><link>https://josepostiga.com/writing/practical-docker-for-developers/</link><guid isPermaLink="true">https://josepostiga.com/writing/practical-docker-for-developers/</guid><description>Last May 29th, 2021, my very first talk was played live, via YouTube, as part of the Speaking About Web &amp; Mobile Development conference, the biggest event related to software development in Beira…</description><pubDate>Mon, 31 May 2021 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;Last May 29th, 2021, my very first talk was played live, via YouTube, as part of the Speaking About Web &amp;amp; Mobile Development conference, the biggest event related to software development in Beira Baixa, bringing together communities of meet-ups and events, speakers, companies and sponsors in one place, promoting the national ecosystem.&lt;/p&gt;
&lt;p&gt;It’s a very special occasion for me, because it’s my very first participation as a speaker in a conference! In this talk I shared a lot of actionable advice on how to configure a local Docker setup that enables developers to work on as many projects as they need in a simple and practical way.&lt;/p&gt;
&lt;p&gt;(Content in Portuguese)&lt;/p&gt;
&lt;div class=&quot;video&quot;&gt;&lt;iframe src=&quot;https://www.youtube-nocookie.com/embed/e1yhN5ogKMM&quot; title=&quot;YouTube video player&quot; loading=&quot;lazy&quot; allow=&quot;accelerometer; encrypted-media; gyroscope; picture-in-picture&quot; allowfullscreen&gt;&lt;/iframe&gt;&lt;/div&gt;
</content:encoded><category>Videos</category><category>Docker</category><category>Keynote</category></item><item><title>Programming Tip #3 – Tests</title><link>https://josepostiga.com/writing/programming-tip-3-tests/</link><guid isPermaLink="true">https://josepostiga.com/writing/programming-tip-3-tests/</guid><description>Every week I join Daniel Maciel to share tips and suggestions for developers. In this episode we talk about the development of TESTS. When should we do it? What are the main concerns and how should…</description><pubDate>Thu, 20 May 2021 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;Every week I join Daniel Maciel to share tips and suggestions for developers.&lt;/p&gt;
&lt;p&gt;In this episode we talk about the development of TESTS. When should we do it? What are the main concerns and how should we start?&lt;/p&gt;
&lt;p&gt;(Content in Portuguese)&lt;/p&gt;
&lt;div class=&quot;video&quot;&gt;&lt;iframe src=&quot;https://www.youtube-nocookie.com/embed/icQ0aWxf_mY&quot; title=&quot;YouTube video player&quot; loading=&quot;lazy&quot; allow=&quot;accelerometer; encrypted-media; gyroscope; picture-in-picture&quot; allowfullscreen&gt;&lt;/iframe&gt;&lt;/div&gt;
</content:encoded><category>Videos</category><category>Career</category><category>CI/CD</category><category>Documentation</category><category>Open-Source</category><category>Podcast</category><category>Review</category><category>TDD</category></item><item><title>Programming Tip #2 – Refactor</title><link>https://josepostiga.com/writing/programming-tip-2-refactor/</link><guid isPermaLink="true">https://josepostiga.com/writing/programming-tip-2-refactor/</guid><description>Every week I join Daniel Maciel to share tips and suggestions for developers. In this episode we talk about refactor. When should we refactoring the code and what can we do to minimize problems in…</description><pubDate>Wed, 05 May 2021 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;Every week I join Daniel Maciel to share tips and suggestions for developers.&lt;/p&gt;
&lt;p&gt;In this episode we talk about refactor. When should we refactoring the code and what can we do to minimize problems in this process? These are some of the issues that are addressed.&lt;/p&gt;
&lt;p&gt;(Content in Portuguese)&lt;/p&gt;
&lt;div class=&quot;video&quot;&gt;&lt;iframe src=&quot;https://www.youtube-nocookie.com/embed/icQ0aWxf_mY&quot; title=&quot;YouTube video player&quot; loading=&quot;lazy&quot; allow=&quot;accelerometer; encrypted-media; gyroscope; picture-in-picture&quot; allowfullscreen&gt;&lt;/iframe&gt;&lt;/div&gt;
</content:encoded><category>Videos</category><category>Career</category><category>CI/CD</category><category>Documentation</category><category>Open-Source</category><category>Podcast</category><category>Review</category><category>TDD</category></item><item><title>Programming Tip #1 – Documentation</title><link>https://josepostiga.com/writing/programming-tip-1-documentation/</link><guid isPermaLink="true">https://josepostiga.com/writing/programming-tip-1-documentation/</guid><description>Every week I join Daniel Maciel to share tips and suggestions for developers. In this episode we talk about the importance of documentation associated with development. Is it really important to…</description><pubDate>Thu, 22 Apr 2021 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;Every week I join Daniel Maciel to share tips and suggestions for developers.&lt;/p&gt;
&lt;p&gt;In this episode we talk about the importance of documentation associated with development. Is it really important to document a project? It is the question that we will answer.&lt;/p&gt;
&lt;p&gt;(Content in Portuguese)&lt;/p&gt;
&lt;div class=&quot;video&quot;&gt;&lt;iframe src=&quot;https://www.youtube-nocookie.com/embed/9s03_7D0xw0&quot; title=&quot;YouTube video player&quot; loading=&quot;lazy&quot; allow=&quot;accelerometer; encrypted-media; gyroscope; picture-in-picture&quot; allowfullscreen&gt;&lt;/iframe&gt;&lt;/div&gt;
</content:encoded><category>Videos</category><category>Career</category><category>CI/CD</category><category>Documentation</category><category>Open-Source</category><category>Podcast</category><category>Review</category><category>TDD</category></item><item><title>Talking about Laravel Octane</title><link>https://josepostiga.com/writing/talking-about-laravel-octane/</link><guid isPermaLink="true">https://josepostiga.com/writing/talking-about-laravel-octane/</guid><description>Talking about the recently announced Laravel Octane. What is it, and what impact it brings to the Laravel ecosystem.</description><pubDate>Fri, 26 Mar 2021 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;A week ago Taylor Otwell, the creator of the Laravel framework, announced a new project: Laravel Octane. On the next day, Daniel Maciel and I recorded a video talking about the first impressions and how this project has a huge impact in the current Laravel ecosystem. (Content is in portuguese.)&lt;/p&gt;
&lt;div class=&quot;video&quot;&gt;&lt;iframe src=&quot;https://www.youtube-nocookie.com/embed/2pA_zOTazMc&quot; title=&quot;YouTube video player&quot; loading=&quot;lazy&quot; allow=&quot;accelerometer; encrypted-media; gyroscope; picture-in-picture&quot; allowfullscreen&gt;&lt;/iframe&gt;&lt;/div&gt;
</content:encoded><category>Videos</category><category>Laravel</category><category>Podcast</category></item><item><title>Talking About the Laravel-Portugal Community and Web Development</title><link>https://josepostiga.com/writing/talking-about-the-laravel-portugal-community-and-web-development/</link><guid isPermaLink="true">https://josepostiga.com/writing/talking-about-the-laravel-portugal-community-and-web-development/</guid><description>Last week I had the pleasure to talk with my friend Daniel Maciel, for his YouTube channel, about the state of the Portuguese Laravel Community, Laravel-Portugal. We talked about how PHP has matured…</description><pubDate>Sat, 27 Feb 2021 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;Last week I had the pleasure to talk with my friend Daniel Maciel, for &lt;a href=&quot;https://www.youtube.com/channel/UC4YJiWr3V4SAIO0ctRNFxrw&quot;&gt;his YouTube channel&lt;/a&gt;, about the state of the Portuguese Laravel Community, &lt;a href=&quot;https://laravel.pt/&quot;&gt;Laravel-Portugal&lt;/a&gt;. &lt;/p&gt;
&lt;p&gt;We talked about how PHP has matured over the years, how the Laravel framework became a big influence in current web-development ecosystem, the differences between a junior and senior developer, and a whole lot more interesting topics!&lt;/p&gt;
&lt;p&gt;I won’t spoil the video much further. (Content is in portuguese.)&lt;/p&gt;
&lt;div class=&quot;video&quot;&gt;&lt;iframe src=&quot;https://www.youtube-nocookie.com/embed/2z0PczykKdc&quot; title=&quot;YouTube video player&quot; loading=&quot;lazy&quot; allow=&quot;accelerometer; encrypted-media; gyroscope; picture-in-picture&quot; allowfullscreen&gt;&lt;/iframe&gt;&lt;/div&gt;
</content:encoded><category>Videos</category><category>Laravel</category><category>Podcast</category></item><item><title>#3 Meetup 2021 Laravel.Portugal</title><link>https://josepostiga.com/writing/3-meetup-2021-laravel-portugal/</link><guid isPermaLink="true">https://josepostiga.com/writing/3-meetup-2021-laravel-portugal/</guid><description>The third edition of Laravel-Portugal official online meetup. Talking about entrepreneurial programmer and a tell-tale about TDD.</description><pubDate>Thu, 25 Feb 2021 00:00:00 GMT</pubDate><content:encoded>&lt;h3 id=&quot;schedule&quot;&gt;Schedule&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;6:30 pm – 6:40 pm: &lt;strong&gt;Welcome&lt;/strong&gt; 😁&lt;/li&gt;
&lt;li&gt;6:40 pm – 7:10 pm: &lt;strong&gt;Entrepreneurial Programmer: What kind is this? –&lt;/strong&gt; Daniel Maciel, Software Engineer &amp;amp; Co-Founder @ Surge&lt;/li&gt;
&lt;li&gt;7:10 pm – 7:40 pm: &lt;strong&gt;How TDD has increased my confidence as a developer&lt;/strong&gt; – Felipe Goulart, Backend Developer @ Infraspeak&lt;/li&gt;
&lt;li&gt;7:40 pm – 8:00 pm: &lt;strong&gt;Q&amp;amp;A and Networking&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&quot;video&quot;&gt;&lt;iframe src=&quot;https://www.youtube-nocookie.com/embed/Xad8SoWk0eo&quot; title=&quot;YouTube video player&quot; loading=&quot;lazy&quot; allow=&quot;accelerometer; encrypted-media; gyroscope; picture-in-picture&quot; allowfullscreen&gt;&lt;/iframe&gt;&lt;/div&gt;
</content:encoded><category>Videos</category><category>Laravel</category><category>Meetup</category><category>Open-Source</category></item><item><title>Laravel-Portugal Podcast S02E12</title><link>https://josepostiga.com/writing/laravel-portugal-podcast-s02e12/</link><guid isPermaLink="true">https://josepostiga.com/writing/laravel-portugal-podcast-s02e12/</guid><description>In this special episode, we gathered the people from the first episode of Laravel Live Portugal and we will remember the best moments. It will be epic! And this time we are going to have Medlar “Bolo…</description><pubDate>Thu, 03 Dec 2020 00:00:00 GMT</pubDate><content:encoded>&lt;h3 id=&quot;participants&quot;&gt;Participants&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://twitter.com/caneco&quot;&gt;Caneco&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://twitter.com/josepostiga&quot;&gt;José Postiga&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://twitter.com/enunomaduro&quot;&gt;Nuno Maduro&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://twitter.com/ijpatricio&quot;&gt;João Patrício&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://twitter.com/JoseLABorges&quot;&gt;José Borges&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://twitter.com/QuetzyG&quot;&gt;Quetzycóatl Garcia&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&quot;video&quot;&gt;&lt;iframe src=&quot;https://www.youtube-nocookie.com/embed/l_3I478kzjo&quot; title=&quot;YouTube video player&quot; loading=&quot;lazy&quot; allow=&quot;accelerometer; encrypted-media; gyroscope; picture-in-picture&quot; allowfullscreen&gt;&lt;/iframe&gt;&lt;/div&gt;
</content:encoded><category>Videos</category><category>Laravel</category><category>Meetup</category></item><item><title>Laravel-Portugal Podcast S02E11</title><link>https://josepostiga.com/writing/laravel-portugal-podcast-s02e11/</link><guid isPermaLink="true">https://josepostiga.com/writing/laravel-portugal-podcast-s02e11/</guid><description>In this episode, the coffee conversation was about “Product launch” – the difficulties; challenges; achievements. And as is already a habit, we move on to the traditional “Nêspera”; ending with a…</description><pubDate>Thu, 05 Nov 2020 00:00:00 GMT</pubDate><content:encoded>&lt;h3 id=&quot;participants&quot;&gt;Participants&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://twitter.com/caneco&quot;&gt;Caneco&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://twitter.com/josepostiga&quot;&gt;José Postiga&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://twitter.com/brunocfalcao&quot;&gt;Bruno Falcão&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://twitter.com/SoniaTelesF&quot;&gt;Sónia Fernandes&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&quot;video&quot;&gt;&lt;iframe src=&quot;https://www.youtube-nocookie.com/embed/4HUtQNdCjgA&quot; title=&quot;YouTube video player&quot; loading=&quot;lazy&quot; allow=&quot;accelerometer; encrypted-media; gyroscope; picture-in-picture&quot; allowfullscreen&gt;&lt;/iframe&gt;&lt;/div&gt;
</content:encoded><category>Videos</category><category>Laravel</category><category>Meetup</category></item><item><title>Laravel-Portugal Podcast S02E10</title><link>https://josepostiga.com/writing/laravel-portugal-podcast-s02e10/</link><guid isPermaLink="true">https://josepostiga.com/writing/laravel-portugal-podcast-s02e10/</guid><description>In this episode the coffee conversation we will see how the #Hacktoberfest 2020 is going, and discuss the current status of the Portuguese Laravel community. This is followed by the traditional…</description><pubDate>Thu, 22 Oct 2020 00:00:00 GMT</pubDate><content:encoded>&lt;h3 id=&quot;participants&quot;&gt;Participants&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://twitter.com/caneco&quot;&gt;Caneco&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://twitter.com/josepostiga&quot;&gt;José Postiga&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://twitter.com/tiagoff&quot;&gt;Tiago Fernandes&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://twitter.com/ijpatricio&quot;&gt;João Patrício&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&quot;video&quot;&gt;&lt;iframe src=&quot;https://www.youtube-nocookie.com/embed/zzv59LHrDBw&quot; title=&quot;YouTube video player&quot; loading=&quot;lazy&quot; allow=&quot;accelerometer; encrypted-media; gyroscope; picture-in-picture&quot; allowfullscreen&gt;&lt;/iframe&gt;&lt;/div&gt;
</content:encoded><category>Videos</category><category>Laravel</category><category>Meetup</category></item><item><title>Laravel-Portugal Podcast S02E09</title><link>https://josepostiga.com/writing/laravel-portugal-podcast-s02e09/</link><guid isPermaLink="true">https://josepostiga.com/writing/laravel-portugal-podcast-s02e09/</guid><description>In this episode the coffee talk we talked about many of the paradigms in recruiting a job offer, followed by the traditional “Nêspera”, and to finish, a round of Quickies.</description><pubDate>Thu, 01 Oct 2020 00:00:00 GMT</pubDate><content:encoded>&lt;h3 id=&quot;participants&quot;&gt;Participants&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://twitter.com/caneco&quot;&gt;Caneco&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://twitter.com/josepostiga&quot;&gt;José Postiga&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://josepostiga.com/laravel-portugal-podcast-s02e09/twitter.com/rosabrancaa&quot;&gt;Rita Mendes&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://josepostiga.com/laravel-portugal-podcast-s02e09/twitter.com/miguelmartins77&quot;&gt;Carlos Martins&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&quot;video&quot;&gt;&lt;iframe src=&quot;https://www.youtube-nocookie.com/embed/gGUOUld7tGs&quot; title=&quot;YouTube video player&quot; loading=&quot;lazy&quot; allow=&quot;accelerometer; encrypted-media; gyroscope; picture-in-picture&quot; allowfullscreen&gt;&lt;/iframe&gt;&lt;/div&gt;
</content:encoded><category>Videos</category><category>Laravel</category><category>Meetup</category></item><item><title>Laravel-Portugal Podcast S02E08</title><link>https://josepostiga.com/writing/laravel-portugal-podcast-s02e08/</link><guid isPermaLink="true">https://josepostiga.com/writing/laravel-portugal-podcast-s02e08/</guid><description>In this episode the coffee conversation will be about On-call – stories and methodologies, followed by the traditional “Nêspera”, and, to finish, a round of Quickies.</description><pubDate>Thu, 17 Sep 2020 00:00:00 GMT</pubDate><content:encoded>&lt;h3 id=&quot;participants&quot;&gt;Participants&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://twitter.com/caneco&quot;&gt;Caneco&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://twitter.com/josepostiga&quot;&gt;José Postiga&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://twitter.com/_pedro_torres&quot;&gt;Pedro Torres&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://twitter.com/jorgercosta&quot;&gt;Jorge Costa&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&quot;video&quot;&gt;&lt;iframe src=&quot;https://www.youtube-nocookie.com/embed/oZI_MDnorHY&quot; title=&quot;YouTube video player&quot; loading=&quot;lazy&quot; allow=&quot;accelerometer; encrypted-media; gyroscope; picture-in-picture&quot; allowfullscreen&gt;&lt;/iframe&gt;&lt;/div&gt;
</content:encoded><category>Videos</category><category>Laravel</category><category>Meetup</category></item><item><title>Laravel-Portugal Podcast S02E07</title><link>https://josepostiga.com/writing/laravel-portugal-podcast-s02e07/</link><guid isPermaLink="true">https://josepostiga.com/writing/laravel-portugal-podcast-s02e07/</guid><description>In this episode the coffee talk will be about the aftermath of the past Laracon Summer Edition 2020, followed by the traditional “Nêspera”, and, to finish, a round of Quickies.</description><pubDate>Thu, 03 Sep 2020 00:00:00 GMT</pubDate><content:encoded>&lt;h3 id=&quot;participants&quot;&gt;Participants&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://twitter.com/caneco&quot;&gt;Caneco&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://twitter.com/josepostiga&quot;&gt;José Postiga&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://twitter.com/_ana_lisboa_&quot;&gt;Ana Lisboa&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://twitter.com/Ghunti&quot;&gt;Gonçalo Queirós&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&quot;video&quot;&gt;&lt;iframe src=&quot;https://www.youtube-nocookie.com/embed/xvaXDLjO1Rs&quot; title=&quot;YouTube video player&quot; loading=&quot;lazy&quot; allow=&quot;accelerometer; encrypted-media; gyroscope; picture-in-picture&quot; allowfullscreen&gt;&lt;/iframe&gt;&lt;/div&gt;
</content:encoded><category>Videos</category><category>Laravel</category><category>Meetup</category></item><item><title>Laravel-Portugal Podcast S02E06</title><link>https://josepostiga.com/writing/laravel-portugal-podcast-s02e06/</link><guid isPermaLink="true">https://josepostiga.com/writing/laravel-portugal-podcast-s02e06/</guid><description>In this episode our conversation will be about: “Fogos e Laravel”, followed by the traditional “Nêspera no Teclado”, and we ended with a round of Quickies.</description><pubDate>Thu, 20 Aug 2020 00:00:00 GMT</pubDate><content:encoded>&lt;h3 id=&quot;participants&quot;&gt;Participants&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://twitter.com/caneco&quot;&gt;Caneco&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://twitter.com/josepostiga&quot;&gt;José Postiga&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://twitter.com/tomahock&quot;&gt;João Pina&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://twitter.com/pvasconcelos&quot;&gt;Pedro Vasconcelos&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&quot;video&quot;&gt;&lt;iframe src=&quot;https://www.youtube-nocookie.com/embed/x0S-yLm8jKQ&quot; title=&quot;YouTube video player&quot; loading=&quot;lazy&quot; allow=&quot;accelerometer; encrypted-media; gyroscope; picture-in-picture&quot; allowfullscreen&gt;&lt;/iframe&gt;&lt;/div&gt;
</content:encoded><category>Videos</category><category>Laravel</category><category>Meetup</category></item><item><title>How to quickly upgrade PostgreSQL version using Docker</title><link>https://josepostiga.com/writing/how-to-quickly-upgrade-postgresql-version-using-docker/</link><guid isPermaLink="true">https://josepostiga.com/writing/how-to-quickly-upgrade-postgresql-version-using-docker/</guid><description>Learn how to quickly upgrade your PostgreSQL version and migrate your data using Docker.</description><pubDate>Sat, 15 Aug 2020 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;Recently I had to upgrade my local PostgreSQL version from 10.10 to 11.8, to mirror the same version that exists in the production environment. I originally thought the upgrade would be simple: turn off the container, update the docker-compose service to reference the new version, and then spin the container.&lt;/p&gt;
&lt;p&gt;However, as soon as the container went up, an error started showing up in the logs:‌&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://josepostiga.com/images/posts/how-to-quickly-upgrade-postgresql-version-using-docker/117796674_394423708204417_8532468209818894714_n-1.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;The error is very explicit: my data, because it was created by an earlier version, was incompatible with the new version. When I searched for possible solutions to this problem, all I could read was related to MacOS, and relied on using Brew to execute some shell commands that would take care of upgrading the data and making it compatible with the new version.&lt;/p&gt;
&lt;p&gt;The problem is that I use Docker for this (well, for everything web-related, really), and since I use Linux Ubuntu, I can’t use Brew (it’s only for MacOS). So I needed a solution that was quick, reliable, and that leveraged Docker (preferably) so that I don’t need to install things on my local machine.&lt;/p&gt;
&lt;p&gt;After a lot of searching, and some discovery of my own, I came to the following, simple, three-step based solution.&lt;/p&gt;
&lt;h3 id=&quot;step-1-make-a-backup-of-your-current-data&quot;&gt;Step 1: Make a backup of your current data&lt;/h3&gt;
&lt;p&gt;With the old PostgreSQL service still running, we’ll execute the following command on the directory where the docker-compose file is located:&lt;/p&gt;
&lt;pre class=&quot;astro-code synthwave-84&quot; style=&quot;background-color:#262335;color:#bbbbbb; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;bash&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FE4450&quot;&gt;docker-compose&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; exec&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; {service_name}&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; pg_dumpall&lt;/span&gt;&lt;span style=&quot;color:#F97E72&quot;&gt; -U&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; {postgres_user}&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt; &amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; dump.sql&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This command makes a SQL file which will contain all our current data, from every database, roles, etc. We’ll use this later on when we import it to the new PostgreSQL version.&lt;/p&gt;
&lt;p&gt;If you want to do it without relying on a docker-compose file configuration, you can spin up a container dedicated to this process with the following command:&lt;/p&gt;
&lt;pre class=&quot;astro-code synthwave-84&quot; style=&quot;background-color:#262335;color:#bbbbbb; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;bash&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FE4450&quot;&gt;docker&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; run&lt;/span&gt;&lt;span style=&quot;color:#F97E72&quot;&gt; --rm&lt;/span&gt;&lt;span style=&quot;color:#F97E72&quot;&gt; -v&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; ${&lt;/span&gt;&lt;span style=&quot;color:#FF7EDB&quot;&gt;pwd&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;}&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;:/tmp&lt;/span&gt;&lt;span style=&quot;color:#F97E72&quot;&gt; -v&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; {local_postgres_data_folder}:/var/lib/postgresql/data&lt;/span&gt;&lt;span style=&quot;color:#F97E72&quot;&gt; -w&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; /tmp&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; {postgres_image}:{current_version_tag}&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; pg_dumpall&lt;/span&gt;&lt;span style=&quot;color:#F97E72&quot;&gt; -U&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; {postgres_user}&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt; &amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; dump.sql&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;step-2-delete-your-current-service-mapped-volume&quot;&gt;Step 2: Delete your current service mapped volume &lt;/h3&gt;
&lt;p&gt;We can’t use the old data structure because it’ll be incompatible with the new version’s. There’s no other option, here, but to remove the volume our old PostgreSQL service uses so that we can update the version tag, later, and let the service create the base folders/files as if it was a first clean run. &lt;/p&gt;
&lt;p&gt;Let’s find where the volume is mapped to, open a terminal, go to that location, and run the command to delete it completely:&lt;/p&gt;
&lt;pre class=&quot;astro-code synthwave-84&quot; style=&quot;background-color:#262335;color:#bbbbbb; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;bash&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FE4450&quot;&gt;sudo&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; rm&lt;/span&gt;&lt;span style=&quot;color:#F97E72&quot;&gt; -rf&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; {postgres_volume_directory}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;step-3-update-the-postgresql-version&quot;&gt;Step 3: Update the PostgreSQL version&lt;/h3&gt;
&lt;p&gt;With a backup of our current data, we can now shutdown the old PostgreSQL service container, update the docker-compose configuration to reference the newer version tag, and spin that service back up.&lt;/p&gt;
&lt;p&gt;After the service is done starting, it should be referencing a new volume with fresh-created files that are supported by the new version. We only need to kick-off the import process so that our backup can also be used by this new version. We can do it by using the internal bash terminal, with the following command:&lt;/p&gt;
&lt;pre class=&quot;astro-code synthwave-84&quot; style=&quot;background-color:#262335;color:#bbbbbb; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;bash&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#848BBD;font-style:italic&quot;&gt;# Connect to the container&apos;s bash terminal&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FE4450&quot;&gt;docker-compose&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; exec&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; {service_name}&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; bash&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#848BBD;font-style:italic&quot;&gt;# Now we run the import command&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FE4450&quot;&gt;psql&lt;/span&gt;&lt;span style=&quot;color:#F97E72&quot;&gt; -U&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; {postgres_user}&lt;/span&gt;&lt;span style=&quot;color:#F97E72&quot;&gt; -d&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; {default_postgres_database}&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt; &amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; {mapped_volume_folder_path}/dump.sql&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;em&gt;&lt;strong&gt;Note:&lt;/strong&gt; this command only works if you have a volume mapped inside the container, on your docker-compose file.&lt;/em&gt; &lt;/p&gt;
&lt;p&gt;If you prefer a one-off command to run this import, you can use the following command:&lt;/p&gt;
&lt;pre class=&quot;astro-code synthwave-84&quot; style=&quot;background-color:#262335;color:#bbbbbb; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;bash&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FE4450&quot;&gt;docker&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; run&lt;/span&gt;&lt;span style=&quot;color:#F97E72&quot;&gt; --rm&lt;/span&gt;&lt;span style=&quot;color:#F97E72&quot;&gt; -v&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; ${&lt;/span&gt;&lt;span style=&quot;color:#FF7EDB&quot;&gt;pwd&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;}&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;:/tmp&lt;/span&gt;&lt;span style=&quot;color:#F97E72&quot;&gt; -v&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; {local_postgres_data_folder}:/var/lib/postgresql/data&lt;/span&gt;&lt;span style=&quot;color:#F97E72&quot;&gt; -w&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; /tmp&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; {postgres_image}:{new_version_tag}&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; psql&lt;/span&gt;&lt;span style=&quot;color:#F97E72&quot;&gt; -U&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; {postgres_user}&lt;/span&gt;&lt;span style=&quot;color:#F97E72&quot;&gt; -d&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; {default_postgres_database}&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;  &amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; dump.sql&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And that’s it! We now have a new version of PostgreSQL running and we kept all our data compatible with that version.&lt;/p&gt;
</content:encoded><category>Articles</category><category>Docker</category><category>Infrastructure</category></item><item><title>Laravel-Portugal Podcast S02E05</title><link>https://josepostiga.com/writing/laravel-portugal-podcast-s02e05/</link><guid isPermaLink="true">https://josepostiga.com/writing/laravel-portugal-podcast-s02e05/</guid><description>In this episode our conversation will be about Indie Games (both sides), followed by our traditional “Nêspera” (with a small twist), and ending with a round of Quickies</description><pubDate>Fri, 07 Aug 2020 00:00:00 GMT</pubDate><content:encoded>&lt;h3 id=&quot;participants&quot;&gt;Participants&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://twitter.com/caneco&quot;&gt;Caneco&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://twitter.com/josepostiga&quot;&gt;José Postiga&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://twitter.com/dj_link&quot;&gt;David Amador&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://twitter.com/hydrarevenge&quot;&gt;Ricardo Gomes&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&quot;video&quot;&gt;&lt;iframe src=&quot;https://www.youtube-nocookie.com/embed/Al9iO8ei8No&quot; title=&quot;YouTube video player&quot; loading=&quot;lazy&quot; allow=&quot;accelerometer; encrypted-media; gyroscope; picture-in-picture&quot; allowfullscreen&gt;&lt;/iframe&gt;&lt;/div&gt;
</content:encoded><category>Videos</category><category>Laravel</category><category>Meetup</category></item><item><title>#2 Meetup 2020 Laravel.Portugal</title><link>https://josepostiga.com/writing/2-meetup-2020-laravel-portugal/</link><guid isPermaLink="true">https://josepostiga.com/writing/2-meetup-2020-laravel-portugal/</guid><description>The second edition of Laravel-Portugal official online meetup. Talking about scoped slots (VueJS) and using abstract resources with Laravel Nova.</description><pubDate>Wed, 29 Jul 2020 00:00:00 GMT</pubDate><content:encoded>&lt;h3 id=&quot;schedule&quot;&gt;Schedule&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;18h30 – 18h40: &lt;strong&gt;Welcome introduction&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;18h40 – 19h10: &lt;strong&gt;Slot machines. No, this is not gambling. It’s leveraging&lt;/strong&gt; – João Patrício, Sotware Engineer @ Grupo Valco&lt;/li&gt;
&lt;li&gt;19h10 – 19h40: &lt;strong&gt;Using abstract resources in Laravel Nova&lt;/strong&gt; – Bruno Falcão, Program Manager @ Roche&lt;/li&gt;
&lt;li&gt;19h40 – 20h00: &lt;strong&gt;Q&amp;amp;A and Networking&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&quot;video&quot;&gt;&lt;iframe src=&quot;https://www.youtube-nocookie.com/embed/pw5yd8ba_OQ&quot; title=&quot;YouTube video player&quot; loading=&quot;lazy&quot; allow=&quot;accelerometer; encrypted-media; gyroscope; picture-in-picture&quot; allowfullscreen&gt;&lt;/iframe&gt;&lt;/div&gt;
</content:encoded><category>Videos</category><category>Laravel</category><category>Meetup</category><category>Open-Source</category></item><item><title>Laravel-Portugal Podcast S02E04</title><link>https://josepostiga.com/writing/laravel-portugal-podcast-s02e04/</link><guid isPermaLink="true">https://josepostiga.com/writing/laravel-portugal-podcast-s02e04/</guid><description>In this episode the conversation will really be coffee – full of news. And to finish one more “Nêspera no Teclado”, and the beautiful round of Quickies.</description><pubDate>Fri, 24 Jul 2020 00:00:00 GMT</pubDate><content:encoded>&lt;h3 id=&quot;participants&quot;&gt;Participants&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://twitter.com/caneco&quot;&gt;Caneco&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://josepostiga.com/laravel-portugal-podcast-s02e04/twitter.com/ijpatricio&quot;&gt;João Patrício&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://josepostiga.com/laravel-portugal-podcast-s02e04/twitter.com/enunomaduro&quot;&gt;Nuno Maduro&lt;/a&gt; (Laravel)&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://josepostiga.com/laravel-portugal-podcast-s02e04/twitter.com/vitorspencer&quot;&gt;Vitor Spencer&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&quot;video&quot;&gt;&lt;iframe src=&quot;https://www.youtube-nocookie.com/embed/DYWSUc6RJDQ&quot; title=&quot;YouTube video player&quot; loading=&quot;lazy&quot; allow=&quot;accelerometer; encrypted-media; gyroscope; picture-in-picture&quot; allowfullscreen&gt;&lt;/iframe&gt;&lt;/div&gt;
</content:encoded><category>Videos</category><category>Laravel</category><category>Meetup</category></item><item><title>Laravel-Portugal Podcast S02E03</title><link>https://josepostiga.com/writing/laravel-portugal-podcast-s02e03/</link><guid isPermaLink="true">https://josepostiga.com/writing/laravel-portugal-podcast-s02e03/</guid><description>In this episode, the coffee talk will be about the Project Management status during this COVID – 19 in job offers, followed by the new “Nêspera no Teclado”, and we ended with a round of Quickies.</description><pubDate>Fri, 10 Jul 2020 00:00:00 GMT</pubDate><content:encoded>&lt;h3 id=&quot;participants&quot;&gt;Participants&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://twitter.com/caneco&quot;&gt;Caneco&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://twitter.com/josepostiga&quot;&gt;José Postiga&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://twitter.com/brunocfalcao&quot;&gt;Bruno Falcão&lt;/a&gt; (Roche)&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://twitter.com/JoseLABorges&quot;&gt;José Borges&lt;/a&gt; (Algardata)&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&quot;video&quot;&gt;&lt;iframe src=&quot;https://www.youtube-nocookie.com/embed/Zz5Lj3w5K4w&quot; title=&quot;YouTube video player&quot; loading=&quot;lazy&quot; allow=&quot;accelerometer; encrypted-media; gyroscope; picture-in-picture&quot; allowfullscreen&gt;&lt;/iframe&gt;&lt;/div&gt;
</content:encoded><category>Videos</category><category>Laravel</category><category>Meetup</category></item><item><title>Add control to JSON Web Tokens generation on Laravel Passport</title><link>https://josepostiga.com/writing/add-control-to-json-web-tokens-generation-on-laravel-passport/</link><guid isPermaLink="true">https://josepostiga.com/writing/add-control-to-json-web-tokens-generation-on-laravel-passport/</guid><description>How to quickly extend the default JWT generation behavior to add personalized claims and make it hold more relevant information.</description><pubDate>Fri, 26 Jun 2020 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;Recently I needed to tap on Laravel’s Passport programming to control how the JSON Web Tokens (JWT) were being issued. Specifically, I needed to add more claims to it (to hold more user information) and to control how the scopes were being generated. The idea was to add information like the authenticated user’s email, VAT number, account type, and, also, to forcibly add the scopes that were associated with the user’s role.&lt;/p&gt;
&lt;p&gt;However, changing Laravel Passport’s behavior to make it happen isn’t quite obvious, and in a world were service-oriented architectures are becoming ever more common, JWT being the &lt;em&gt;de facto&lt;/em&gt; way of carrying user’s information through multiple services, and since I couldn’t find quite a good resource to understand how to do it, I thought I could share with you how I approached and solved my own problem.&lt;/p&gt;
&lt;h3 id=&quot;the-need-for-control&quot;&gt;The need for control&lt;/h3&gt;
&lt;p&gt;I’m developing &lt;a href=&quot;https://github.com/itsoup&quot;&gt;ITsoup&lt;/a&gt;, an IT support/helpdesk software system, designed to simplify and streamline all its related processes, based in a service-oriented architecture. This means that I’ll have many services that handle specific domains of work. In order to authenticate the requests, properly, I needed some way of holding users’ information in a way that could be passed around from service to service. The &lt;em&gt;de facto&lt;/em&gt; way of doing this is with JWTs, so I started investigating how I could make those changes to the JWT generation logic.&lt;/p&gt;
&lt;p&gt;The problem with current Laravel Passport implementation is that it only includes one identification claim for the user: it’s internal ID. That’s not of much use for me on this project. Using only the ID would require any other services to request any additional user information to the &lt;a href=&quot;https://github.com/itsoup/organization&quot;&gt;Organization Domain&lt;/a&gt; service’s API if they need, for example, the e-mail. &lt;/p&gt;
&lt;p&gt;Doing that way would create an unwanted, unnecessary, dependency between this service and all others that work with the user’s data and would increase the load on this Organization Domain service as new services and/or traffic increased.&lt;/p&gt;
&lt;h3 id=&quot;understanding-laravel-passports-service-provider&quot;&gt;Understanding Laravel Passport’s Service Provider&lt;/h3&gt;
&lt;p&gt;Before anything, I like to always understand what’s going on under the hood. By getting a broader context of the system I need to change, I can make informed decisions on how to approach a solution.&lt;/p&gt;
&lt;p&gt;As far as I understood, it all goes down on &lt;code&gt;Laravel\Passport\PassportServiceProvider&lt;/code&gt;. Here we can find the &lt;code&gt;registerAuthorizationServer()&lt;/code&gt; method, which is responsible for defining how Laravel instantiates the &lt;code&gt;AuthorizationServer&lt;/code&gt; class and registers the supported oAuth2 authorization grants. But before that happens, there’s a call to a &lt;code&gt;makeAuthorizationServer()&lt;/code&gt; method. This method is the one that’s responsible to define how the &lt;code&gt;AuthorizationServer&lt;/code&gt; gets instantiated, and injects the proper dependencies from the Laravel’s Container! &lt;/p&gt;
&lt;p&gt;The key class to this whole thing is the &lt;code&gt;Bridge\AccessTokenRepository&lt;/code&gt;, which is one of the dependencies injected. Since it’s being injected via the Container, we can take advantage of it and inject our own instance of that class, instead. This class has a very special method, &lt;code&gt;getNewToken()&lt;/code&gt;, which is called when an enabled authorization grant needs to generate a new token. &lt;/p&gt;
&lt;p&gt;Hooking to the logic flow, here, and direct it through our own implementation of the &lt;code&gt;AccessTokenRepository&lt;/code&gt; class enables us to control how the JWT is created, the information it holds, and many other aspects of it.&lt;/p&gt;
&lt;h3 id=&quot;building-bridges&quot;&gt;Building bridges&lt;/h3&gt;
&lt;p&gt;So, now that I’ve pinpointed exactly the class that I need to override, I defined that a call to the &lt;code&gt;Bridge\AccessTokenRepository&lt;/code&gt; class, within Laravel’s Container, would return an instance of my own &lt;code&gt;AccessTokenRepository&lt;/code&gt; class, which would extend the previous one but with the single detail of overriding the &lt;code&gt;getNewToken()&lt;/code&gt; method. As of this moment, I successfully routed the logic to my own class.&lt;/p&gt;
&lt;p&gt;Now, this method needs to return an implementation of the &lt;code&gt;AccessTokenEntityInterface&lt;/code&gt;. This interface defines how to compute an access token (a JWT, for example). Laravel’s Passport implementation is exactly the one that The PHP League’s implements. In fact, not wanting to override that default behavior is one of the &lt;a href=&quot;https://github.com/laravel/passport/issues/94#issuecomment-438240951&quot;&gt;main reasons&lt;/a&gt; that Passport doesn’t supply any simple solution around this problem. In order for being able to add more claims, and control how JWT is generated – and even the scopes associated – we need to override this exact implementation.&lt;/p&gt;
&lt;p&gt;At this point, I just needed to return an implementation of the &lt;code&gt;AccessTokenEntityInterface&lt;/code&gt; that suited my needs. There’re two methods, specifically, that I needed to override: &lt;code&gt;convertToJWT()&lt;/code&gt; and &lt;code&gt;getScopes()&lt;/code&gt;. The first is the one that actually generates the JWT, and the second one is the one that compiles the scopes to associate with that JWT. &lt;/p&gt;
&lt;p&gt;So, basically, my extended &lt;code&gt;convertToJWT()&lt;/code&gt; method looked like this:&lt;/p&gt;
&lt;pre class=&quot;astro-code synthwave-84&quot; style=&quot;background-color:#262335;color:#bbbbbb; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;php&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;private&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt; function&lt;/span&gt;&lt;span style=&quot;color:#36F9F6&quot;&gt; convertToJWT&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#FE4450&quot;&gt;CryptKey&lt;/span&gt;&lt;span style=&quot;color:#FF7EDB&quot;&gt; $privateKey&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#FE4450&quot;&gt; Token&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;    return&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;new&lt;/span&gt;&lt;span style=&quot;color:#FE4450&quot;&gt; Builder&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;())&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;        -&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#36F9F6&quot;&gt;permittedFor&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#FE4450;font-weight:bold&quot;&gt;$this&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#36F9F6&quot;&gt;getClient&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;()&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#36F9F6&quot;&gt;getIdentifier&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;())&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;        -&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#36F9F6&quot;&gt;identifiedBy&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#FE4450;font-weight:bold&quot;&gt;$this&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#36F9F6&quot;&gt;getIdentifier&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;())&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;        -&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#36F9F6&quot;&gt;issuedAt&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#FE4450&quot;&gt;\&lt;/span&gt;&lt;span style=&quot;color:#36F9F6&quot;&gt;time&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;())&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;        -&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#36F9F6&quot;&gt;canOnlyBeUsedAfter&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#FE4450&quot;&gt;\&lt;/span&gt;&lt;span style=&quot;color:#36F9F6&quot;&gt;time&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;())&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;        -&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#36F9F6&quot;&gt;expiresAt&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#FE4450;font-weight:bold&quot;&gt;$this&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#36F9F6&quot;&gt;getExpiryDateTime&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;()&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#36F9F6&quot;&gt;getTimestamp&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;())&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;        -&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#36F9F6&quot;&gt;relatedTo&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;((&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#FE4450;font-weight:bold&quot;&gt;$this&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#36F9F6&quot;&gt;getUserIdentifier&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;())&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;        -&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#36F9F6&quot;&gt;withClaim&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#FF8B39&quot;&gt;&apos;scopes&apos;&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#FE4450;font-weight:bold&quot;&gt;$this&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#36F9F6&quot;&gt;getScopes&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;())&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;        -&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#36F9F6&quot;&gt;withClaim&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#FF8B39&quot;&gt;&apos;customer_id&apos;&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#FE4450;font-weight:bold&quot;&gt;$this&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#FF7EDB&quot;&gt;user&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#FF7EDB&quot;&gt;customer_id&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;        -&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#36F9F6&quot;&gt;withClaim&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#FF8B39&quot;&gt;&apos;vat_number&apos;&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#FE4450;font-weight:bold&quot;&gt;$this&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#FF7EDB&quot;&gt;user&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#FF7EDB&quot;&gt;vat_number&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;        -&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#36F9F6&quot;&gt;withClaim&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#FF8B39&quot;&gt;&apos;name&apos;&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#FE4450;font-weight:bold&quot;&gt;$this&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#FF7EDB&quot;&gt;user&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#FF7EDB&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;        -&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#36F9F6&quot;&gt;withClaim&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#FF8B39&quot;&gt;&apos;email&apos;&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#FE4450;font-weight:bold&quot;&gt;$this&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#FF7EDB&quot;&gt;user&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#FF7EDB&quot;&gt;email&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;        -&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#36F9F6&quot;&gt;withClaim&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#FF8B39&quot;&gt;&apos;account_type&apos;&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#FE4450;font-weight:bold&quot;&gt;$this&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#FF7EDB&quot;&gt;user&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#FF7EDB&quot;&gt;account_type&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;        -&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#36F9F6&quot;&gt;getToken&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;new&lt;/span&gt;&lt;span style=&quot;color:#FE4450&quot;&gt; Sha256&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;(), &lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;new&lt;/span&gt;&lt;span style=&quot;color:#FE4450&quot;&gt; Key&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#FF7EDB&quot;&gt;$privateKey&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#36F9F6&quot;&gt;getKeyPath&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;(), &lt;/span&gt;&lt;span style=&quot;color:#FF7EDB&quot;&gt;$privateKey&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#36F9F6&quot;&gt;getPassPhrase&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;()));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And my &lt;code&gt;getScopes()&lt;/code&gt; method looked like this:&lt;/p&gt;
&lt;pre class=&quot;astro-code synthwave-84&quot; style=&quot;background-color:#262335;color:#bbbbbb; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;php&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;public&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt; function&lt;/span&gt;&lt;span style=&quot;color:#36F9F6&quot;&gt; getScopes&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;()&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt; array&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;    return&lt;/span&gt;&lt;span style=&quot;color:#FE4450;font-weight:bold&quot;&gt; $this&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#FF7EDB&quot;&gt;user&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;        -&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#36F9F6&quot;&gt;roles&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;        -&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#36F9F6&quot;&gt;pluck&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#FF8B39&quot;&gt;&apos;scopes&apos;&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;        -&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#36F9F6&quot;&gt;flatten&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;        -&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#36F9F6&quot;&gt;unique&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;        -&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#36F9F6&quot;&gt;map&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;static&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt; function&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#FF7EDB&quot;&gt;$scope&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;            return&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt; new&lt;/span&gt;&lt;span style=&quot;color:#FE4450&quot;&gt; Scope&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#FF7EDB&quot;&gt;$scope&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;        })&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;        -&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#36F9F6&quot;&gt;toArray&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now, the JWT is generated with what I defined to be the relevant user information, and can be passed around and, hopefully, reduce the need to query the Organization Domain service if the JWT itself already holds the data needed.&lt;/p&gt;
</content:encoded><category>Articles</category><category>Laravel</category></item><item><title>Laravel-Portugal Podcast S02E02</title><link>https://josepostiga.com/writing/laravel-portugal-podcast-s02e02/</link><guid isPermaLink="true">https://josepostiga.com/writing/laravel-portugal-podcast-s02e02/</guid><description>In this episode the coffee talk will be about the current status of PHP and Laravel in job offers; followed by the new “Nêspera no Teclado”; and we ended with a round of Quickies.</description><pubDate>Fri, 26 Jun 2020 00:00:00 GMT</pubDate><content:encoded>&lt;h3 id=&quot;participants&quot;&gt;Participants&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://twitter.com/caneco&quot;&gt;Caneco&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://twitter.com/pcbo&quot;&gt;Pedro Oliveira&lt;/a&gt; (Landing.jobs)&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://twitter.com/josepostiga&quot;&gt;José Postiga&lt;/a&gt; (Infraspeak)&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&quot;video&quot;&gt;&lt;iframe src=&quot;https://www.youtube-nocookie.com/embed/RvJnRP2HXdw&quot; title=&quot;YouTube video player&quot; loading=&quot;lazy&quot; allow=&quot;accelerometer; encrypted-media; gyroscope; picture-in-picture&quot; allowfullscreen&gt;&lt;/iframe&gt;&lt;/div&gt;
</content:encoded><category>Videos</category><category>Laravel</category><category>Podcast</category></item><item><title>Integrating Infraspeak’s API authentication on first-party clients</title><link>https://josepostiga.com/writing/integrating-infraspeaks-api-authentication-on-first-party-clients/</link><guid isPermaLink="true">https://josepostiga.com/writing/integrating-infraspeaks-api-authentication-on-first-party-clients/</guid><description>How we leveraged Laravel’s custom Guards and Providers on Place Checkup to authenticate users against our existent API service.</description><pubDate>Fri, 19 Jun 2020 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;We’ve recently launched &lt;a href=&quot;https://placecheckup.com/&quot;&gt;Place Checkup&lt;/a&gt;, a web application that allows users to check if a given place follows the WHO recommended safety and prevention measures against COVID-19. Business owners, which are not yet &lt;a href=&quot;https://infraspeak.com/&quot;&gt;Infraspeak&lt;/a&gt;‘s customers, can register through this website, claim their places and register how and what measures they’re actually following. In the end, they get an A, B, or C badge qualifying their places.&lt;/p&gt;
&lt;p&gt;Since Infraspeak’s core software business is directly related to infrastructure maintenance management, and since we develop with an API-first approach, we already had the core functionalities available to easily use on Place Checkup. Besides that, and to avoid having multiple accounts spread over different projects, we defined that we’d leverage our existent API authentication, and centralize all the accounts there.&lt;/p&gt;
&lt;p&gt;Our API uses Passport, an oAuth2 server implementation for Laravel projects, so by sending a user’s credentials to the API service, if they are valid, it returns an encoded JWT with the user information we’d need. To keep things simple, and to avoid having to implement a Machine-to-Machine authentication, we wanted to simply store the generated JWT in session, on Place Checkup, for further usage on subsequent calls to the API.&lt;/p&gt;
&lt;p&gt;Laravel has a very good, and extendable, authentication system, referenced throughout the documentation as Guards. Their job is to know how an authentication request gets processed and how to communicate with a Provider, whose responsibility is to know how to get the requested data from whatever persistent layer it handles. &lt;/p&gt;
&lt;p&gt;If correctly implemented, a custom Guard would allow us to tap into middlewares, facades, and helper methods commonly used within Laravel to handle authentication, like the &lt;code&gt;Auth&lt;/code&gt; facade, or getting the currently authenticated user via &lt;code&gt;$request-&amp;gt;user()&lt;/code&gt;, or even use the &lt;code&gt;auth&lt;/code&gt; middleware to secure access to private routes. That looked exactly what we needed for this project!&lt;/p&gt;
&lt;p&gt;But adding a custom Guard and Provider proved to be a little more difficult than what the documentation shows to be. Reading through the sections that describe how Guards and Providers work, I could only see how to register the custom classes to the Container, which interfaces to implement, and which type of classes it needs to return. I couldn’t quite get a clear picture of how the flow was, so I realized I’d need to dive deep into the authentication system and try to map it from within.&lt;/p&gt;
&lt;h3 id=&quot;understanding-guards&quot;&gt;Understanding Guards&lt;/h3&gt;
&lt;p&gt;Laravel’s documentation describes Guards as the following:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Guards define how users are authenticated for each request.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;But, what does that really mean? That was the question I had on my head while deep on the &lt;code&gt;SessionGuard&lt;/code&gt; class – a preexistent Guard shipped by default with the framework – trying to understand what’s going on under the hood. I figured that a Guard has the sole responsibility of receiving requests to authenticate a user and to call the configured Provider to fetch that user on the persistent layer.&lt;/p&gt;
&lt;p&gt;This means that, for example, when we call &lt;code&gt;Auth::attempt()&lt;/code&gt; to attempt a login action, Laravel will defer that call to the same method on the configured Guard. This Guard will, in turn, prepare all it needs to send that request through the related Provider, which may (or may not) return an instance of the &lt;code&gt;Authenticatable&lt;/code&gt; interface, the object that represents the authenticated user.&lt;/p&gt;
&lt;p&gt;I’ve also found that we actually have two interfaces for Guards:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The &lt;code&gt;Guard&lt;/code&gt; interface, referenced in the docs, aimed to a stateless authentication, like APIs;&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;StatefulGuard&lt;/code&gt; interface, that extends the previous &lt;code&gt;Guard&lt;/code&gt; interface but also defines how to persist the authentication information in the configured session storage.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The fundamental difference between them: state management. The knowledge of the existence of this &lt;code&gt;StatefulGuard&lt;/code&gt;interface pointed me to a good direction of how I could develop a Guard that would persist the JWT in the session that integrates perfectly with the expectations of Laravel itself. I was finally in a good place on understanding the key concepts of the whole authentication system.&lt;/p&gt;
&lt;h3 id=&quot;understanding-providers&quot;&gt;Understanding Providers&lt;/h3&gt;
&lt;p&gt;Laravel’s documentation describes Providers as the following:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Providers define how users are retrieved from your persistent storage.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Looking at the two default providers that Laravel supports, &lt;code&gt;EloquentUserProvider&lt;/code&gt; and &lt;code&gt;DatabaseUserProvider&lt;/code&gt;, I noticed that first returns an instance of &lt;code&gt;Model&lt;/code&gt; (an Eloquent model class) and the other handles direct calls to a database table and returns an instance of &lt;code&gt;GenericUser&lt;/code&gt; (a slight variation of a Value Object). Both follow the same &lt;code&gt;UserProvider&lt;/code&gt;interface.&lt;/p&gt;
&lt;p&gt;I concluded that Providers are an implementation of the Repository pattern, and exist only to abstract away how you validate the user’s credentials and fetch their data on whatever persistent layer it’s stored in. &lt;/p&gt;
&lt;p&gt;Actually, that’s probably why the user’s credentials are passed on inside an array structure: because Laravel doesn’t want to be opinionated towards how you authenticate your users. You can use a combination of e-mail and password, or a one-time hash (like magic links sent to an e-mail), or whatever you want to use. It’s pretty clever, actually!&lt;/p&gt;
&lt;p&gt;But it’s basically this… It’s inside a Provider that you actually define what data you need to authenticate a user (the credentials) and how you communicate with the persistent layer to get the relevant data. No matter how that’s done, a Provider must return an object that implements the &lt;code&gt;Authenticatable&lt;/code&gt; interface. This is to ensure that Laravel uses the correct methods when working with that object, directly, like when calling &lt;code&gt;Auth::id()&lt;/code&gt;.&lt;/p&gt;
&lt;h3 id=&quot;making-all-parts-work-together-nicely&quot;&gt;Making all parts work together nicely&lt;/h3&gt;
&lt;p&gt;I’m pretty sure that at this point you already have a clearer understanding of the role Guards and Providers take within the Laravel’s authentication workflow: Guards receive the request to authenticate a user and pass the credentials to the defined Provider. The Provider, in turn, queries the underlying persistent storage about the relevant user data associated with those credentials and returns it all the way back to the Guard, which makes that information available for usage.&lt;/p&gt;
&lt;p&gt;But even if you create all the required classes, you still need to register them within Laravel’s Container, so that it knows how to call those classes:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;To register the Provider, we use the &lt;code&gt;Auth::provider()&lt;/code&gt; method and define how the framework should instantiate the custom provider class;&lt;/li&gt;
&lt;li&gt;To register the Guard, we use the &lt;code&gt;Auth::extend()&lt;/code&gt; method and define how the framework should instantiate the custom Guard.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Let me show you exactly what we’ve done to register the custom Guard and Provider used on the Place Checkup project:&lt;/p&gt;
&lt;pre class=&quot;astro-code synthwave-84&quot; style=&quot;background-color:#262335;color:#bbbbbb; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;php&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;public&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt; function&lt;/span&gt;&lt;span style=&quot;color:#36F9F6&quot;&gt; boot&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;()&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt; void&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FE4450&quot;&gt;    Auth&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color:#36F9F6&quot;&gt;provider&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#FF8B39&quot;&gt;&apos;infraspeak-users&apos;&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;static&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt; function&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#FE4450&quot;&gt;Application&lt;/span&gt;&lt;span style=&quot;color:#FF7EDB&quot;&gt; $app&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;array&lt;/span&gt;&lt;span style=&quot;color:#FF7EDB&quot;&gt; $config&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;        return&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt; new&lt;/span&gt;&lt;span style=&quot;color:#FE4450&quot;&gt; InfraspeakUserProvider&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#FF7EDB&quot;&gt;$app&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#36F9F6&quot;&gt;make&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#FE4450&quot;&gt;InfraspeakApiService&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;::class&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;), &lt;/span&gt;&lt;span style=&quot;color:#FF7EDB&quot;&gt;$config&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;    });&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FE4450&quot;&gt;    Auth&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color:#36F9F6&quot;&gt;extend&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#FF8B39&quot;&gt;&apos;infraspeak-jwt&apos;&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;static&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt; function&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#FE4450&quot;&gt;Application&lt;/span&gt;&lt;span style=&quot;color:#FF7EDB&quot;&gt; $app&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#FF7EDB&quot;&gt;$name&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;array&lt;/span&gt;&lt;span style=&quot;color:#FF7EDB&quot;&gt; $config&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;        return&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt; new&lt;/span&gt;&lt;span style=&quot;color:#FE4450&quot;&gt; JwtSessionGuard&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FE4450&quot;&gt;            Auth&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color:#36F9F6&quot;&gt;createUserProvider&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#FF7EDB&quot;&gt;$config&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color:#FF8B39&quot;&gt;&apos;provider&apos;&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;]),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FF7EDB&quot;&gt;            $app&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#36F9F6&quot;&gt;make&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#FF8B39&quot;&gt;&apos;session.store&apos;&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;        );&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;    });&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The &lt;code&gt;InfraspeakUserProvider&lt;/code&gt; class has all the code to communicate with our API service and validate a user’s credentials and returns an instance of the &lt;code&gt;Authenticatable&lt;/code&gt; interface. The &lt;code&gt;JwtSessionGuard&lt;/code&gt; class has the code that takes that object, from the Provider, and persists it to the session, avoiding new calls being dispatched to the API service while that session is active and valid, protecting our API service from being flooded with authentication requests every time a protected endpoint is being processed.&lt;/p&gt;
&lt;p&gt;The very final step in all this work was to update the &lt;code&gt;config/auth.php&lt;/code&gt;, and switch the default Guard and Provider used for the web routes:&lt;/p&gt;
&lt;pre class=&quot;astro-code synthwave-84&quot; style=&quot;background-color:#262335;color:#bbbbbb; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;php&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FF8B39&quot;&gt;&apos;guards&apos;&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; [&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FF8B39&quot;&gt;    &apos;web&apos;&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; [&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FF8B39&quot;&gt;        &apos;driver&apos;&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#FF8B39&quot;&gt; &apos;infraspeak-jwt&apos;&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FF8B39&quot;&gt;        &apos;provider&apos;&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#FF8B39&quot;&gt; &apos;infraspeak-users&apos;&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;    ],&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;],&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now we could use Laravel’s native classes to authenticate a user and use our API service to serve as the data repository to get that information.&lt;/p&gt;
</content:encoded><category>Articles</category><category>Laravel</category></item><item><title>#1 Meetup 2020 Laravel.Portugal</title><link>https://josepostiga.com/writing/1-meetup-2020-laravel-portugal/</link><guid isPermaLink="true">https://josepostiga.com/writing/1-meetup-2020-laravel-portugal/</guid><description>The very first Laravel-Portugal official online meetup. Talking about testing and integration with Telegram and WhatsApp services</description><pubDate>Wed, 27 May 2020 00:00:00 GMT</pubDate><content:encoded>&lt;h3 id=&quot;schedule&quot;&gt;Schedule&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;18h30 – 18h40: &lt;strong&gt;Welcome introduction&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;18h40 – 19h10: &lt;strong&gt;Testing back and testing forward&lt;/strong&gt; – António Fernandes, Senior Backend Developer @ Infraspeak&lt;/li&gt;
&lt;li&gt;19h10 – 19h40: &lt;strong&gt;Integrating Laravel 7 with Telegram and WhatsApp&lt;/strong&gt; – Vinícius Melo, Backend Developer @ VC Cloud&lt;/li&gt;
&lt;li&gt;19h40 – 20h00: &lt;strong&gt;Q&amp;amp;A and Networking&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&quot;video&quot;&gt;&lt;iframe src=&quot;https://www.youtube-nocookie.com/embed/IvR1BZrIlBg&quot; title=&quot;YouTube video player&quot; loading=&quot;lazy&quot; allow=&quot;accelerometer; encrypted-media; gyroscope; picture-in-picture&quot; allowfullscreen&gt;&lt;/iframe&gt;&lt;/div&gt;
</content:encoded><category>Videos</category><category>Laravel</category><category>Meetup</category><category>Open-Source</category></item><item><title>My 2019 In Review</title><link>https://josepostiga.com/writing/my-2019-in-review/</link><guid isPermaLink="true">https://josepostiga.com/writing/my-2019-in-review/</guid><description>Wow! That’s the perfect word to describe my 2019. So far, my best year ever! At Work My 2019 started with me leaving TBFiles and joining Infraspeak. The change came as a surprise, even to me. I was…</description><pubDate>Sat, 04 Jan 2020 00:00:00 GMT</pubDate><content:encoded>&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Wow! That’s the perfect word to describe my 2019. So far, my best year ever!&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 id=&quot;at-work&quot;&gt;&lt;strong&gt;At Work&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;My 2019 started with me leaving TBFiles and joining Infraspeak. The change came as a surprise, even to me. I was not looking for a job change, but a casual visit to the Infraspeak’s HQ, to discuss the development of a Laravel related event, which led me to meet a lot of my (soon-to-be) colleagues and the company’s vision, goals, and culture, impressed me so much that I got stuck with the feeling that I belonged there.&lt;/p&gt;
&lt;p&gt;My work, at Infraspeak, ranged from developing new, and exciting, features, to help to improve the overall code quality, improving the development workflow and stack used and implementing a Continuous Integration pipeline. I’ve been learning and growing so much! &lt;a href=&quot;https://app.escapethecity.org/organisation/1549883291653x608145287664047200&quot;&gt;It’s definitely the best place to work&lt;/a&gt;, right now. &lt;a href=&quot;https://app.escapethecity.org/organisation/1549883291653x608145287664047200&quot;&gt;Consider applying to one of our job openings&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;There’s a lot more I plan to do here, in 2020, which I’ll blog about on Infraspeak’s Tech Blog.&lt;/p&gt;
&lt;h2 id=&quot;open-source&quot;&gt;&lt;strong&gt;Open Source&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;I did less open-source work than what I intended. In fact, I didn’t even complete 2019’s Hacktoberfest, with only two PRs made…&lt;/p&gt;
&lt;p&gt;However, I contributed to the &lt;a href=&quot;https://github.com/akaunting/akaunting&quot;&gt;akaunting/akaunting&lt;/a&gt; and &lt;a href=&quot;https://github.com/spatie/laravel-permission&quot;&gt;spatie/laravel-permission&lt;/a&gt; projects, created a side project that I’m still actively developing (&lt;a href=&quot;https://github.com/speakhub&quot;&gt;SpeakHub&lt;/a&gt;) and I’ve joined the &lt;a href=&quot;https://info.vost.pt/&quot;&gt;VOST Portugal&lt;/a&gt; organization, where I’ve been helping in the API layer development and maintenance.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;For 2020&lt;/strong&gt;, I’ll be releasing a beta version of my side project and dedicate more time to Open Source contributions. I’ll definitely not miss this year’s Hacktoberfest challenge!&lt;/p&gt;
&lt;h2 id=&quot;community-events&quot;&gt;&lt;strong&gt;Community Events&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;I tried something new in this area: &lt;a href=&quot;https://medium.com/infraspeak/laravel-portugal-meetup-1st-edition-will-happen-in-porto-4c44661efdc0&quot;&gt;I organized a Meetup around the Portuguese Laravel community&lt;/a&gt;. I tried to organize another one, but several things happened that made it impossible to create a second event. In 2020, however, there will be a new edition of this event.&lt;/p&gt;
&lt;p&gt;I’ve also attended some events, too. I was present in the first Laracon Madrid, representing the Infraspeak Engineering Team. I met a lot of new people there, got to personally thank some of my favorite creators, like &lt;a href=&quot;https://twitter.com/christophrumpel&quot;&gt;Christoph Rumpel&lt;/a&gt;, &lt;a href=&quot;https://twitter.com/freekmurze&quot;&gt;Freek Van der Herten&lt;/a&gt; and &lt;a href=&quot;https://twitter.com/adamwathan&quot;&gt;Adam Wathan&lt;/a&gt;. I got to be with other Laravel Portugal members and even fellow podcasters &lt;a href=&quot;https://twitter.com/enunomaduro&quot;&gt;Nuno Maduro&lt;/a&gt;, &lt;a href=&quot;https://twitter.com/Caneco&quot;&gt;Caneco&lt;/a&gt; and &lt;a href=&quot;https://twitter.com/brunocfalcao&quot;&gt;Bruno Falcão&lt;/a&gt;. I’ve also attended &lt;a href=&quot;https://techinporto.com/archive/2019/&quot;&gt;TechInPorto&lt;/a&gt;, a tech-related event in the beautiful Porto city.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;For 2020&lt;/strong&gt;, I’ll aim to speak on one conference, I’ll try to attend not only TechInPorto 2020 but also Laracon Madrid 2020 and I’ll definitely organise the second edition of &lt;a href=&quot;https://josepostiga.com/journal/2020-01-04-my-2019-in-review/https/www.laravel.pt&quot;&gt;Laravel Portugal&lt;/a&gt; meetup.&lt;/p&gt;
&lt;h2 id=&quot;publications-and-podcasts&quot;&gt;&lt;strong&gt;Publications and Podcasts&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;I’ve published &lt;a href=&quot;https://josepostiga.com/articles&quot;&gt;three articles&lt;/a&gt; and &lt;a href=&quot;https://josepostiga.com/journal&quot;&gt;twenty-one journal entries&lt;/a&gt;. It was amazing getting to write and share this much information with the developers’ community.&lt;/p&gt;
&lt;p&gt;I’ve also been invited to participate in the amazing &lt;a href=&quot;https://podcastubuntuportugal.org/ep-56-laravel-dingo/&quot;&gt;Ubuntu Portugal Podcast&lt;/a&gt;, where I discussed my transition from the Apple ecosystem to Ubuntu. I had a very good and friendly talk with the hosts Diogo Constantino e David Negreira.&lt;/p&gt;
&lt;p&gt;Unfortunately, the &lt;a href=&quot;https://www.youtube.com/channel/UCIbMW1h5VReAQAwJGi_zT3w/videos&quot;&gt;Laravel Portugal Podcast&lt;/a&gt; only had one episode recorded in the whole year. It’s so sad that we (me and the other hosts) didn’t get enough time to do it more often. I always believed that a Portuguese podcast about the Laravel ecosystem makes sense to exist.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;For 2020&lt;/strong&gt;, I’ll definitely try to resurrect the Laravel Portugal Podcast, making it a once or twice per month event. Also, I’ll also make a weekly journal entry to round-up about work done and other relevant events. Maybe I’ll make a 2-in-1 and we might have a weekly Portuguese podcast about that. Who knows…&lt;/p&gt;
&lt;h2 id=&quot;final-words&quot;&gt;&lt;strong&gt;Final Words&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;This last year was a year full of experiments and trials and errors. As I close 2019 as the best year ever, so far, I look for 2020 with a lot of expectations to surpass the previous one. I’ll definitely begin to see the results of my work in Infraspeak, and will channel all my experience gathered until now towards open source and community development.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Wishing you all the best for this new year!&lt;/strong&gt;&lt;/p&gt;
</content:encoded><category>Journal</category><category>Career</category><category>Review</category></item><item><title>I had my first PR rejection</title><link>https://josepostiga.com/writing/i-had-my-first-pr-rejection/</link><guid isPermaLink="true">https://josepostiga.com/writing/i-had-my-first-pr-rejection/</guid><description>Yeah, it sucks. Last week I tried to contribute to Mohammed Said’s Wink Laravel package ( https://github.com/writingink/wink ) in order to make it use the Laravel’s default auth system, since Wik…</description><pubDate>Thu, 14 Nov 2019 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;Yeah, it sucks.&lt;/p&gt;
&lt;p&gt;Last week I tried to contribute to Mohammed Said’s Wink Laravel package (&lt;a href=&quot;https://github.com/writingink/wink&quot;&gt;https://github.com/writingink/wink&lt;/a&gt;) in order to make it use the Laravel’s default auth system, since Wik uses its own guards, register and login workflow.&lt;/p&gt;
&lt;p&gt;After a couple days of work, and a nice discussion on the PR, Mohammed though that it was best not to merge the PR because he wanted it to be a more flexible solution as my PR would force Wink to use Laravel’s default database connection and would update the users table with Wink specific columns.&lt;/p&gt;
&lt;p&gt;Although the feeling of rejection sucks, I thank Mohammed, and others that commented on my PR, as they allowed me to grow and learn that contributing with open source is not all about quantity of PRs merged, but the quality of the products afterwards.&lt;/p&gt;
&lt;p&gt;But this isn’t over, yet. We’re still discussing a better approach to this situation. If you’re interesting what we’re planning, check the issue on GitHub: &lt;a href=&quot;https://github.com/writingink/wink/issues/13&quot;&gt;https://github.com/writingink/wink/issues/13&lt;/a&gt;.&lt;/p&gt;
</content:encoded><category>Journal</category><category>Open-Source</category></item><item><title>Stop Messing With The Hosts File</title><link>https://josepostiga.com/writing/stop-messing-with-the-hosts-file/</link><guid isPermaLink="true">https://josepostiga.com/writing/stop-messing-with-the-hosts-file/</guid><description>How to leverage Dnsmasq to route all local development traffic to localhost.</description><pubDate>Mon, 09 Sep 2019 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;&lt;em&gt;This article was originally submitted on the&lt;/em&gt; &lt;a href=&quot;https://medium.com/infraspeak/stop-messing-with-the-hosts-file-a760aa660c20&quot;&gt;&lt;em&gt;Infraspeak tech blog&lt;/em&gt;&lt;/a&gt;&lt;em&gt;.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;The hosts file is used by the system’s DNS resolver to map a fully qualified domain name (FQDN) to its related IP, without the need to query any of the Internet’s DNS servers. However, since updating this file, manually, by the common computer user would be impractical, its common use is to map the local IP 127.0.0.1 to localhost domain so that it resolves to the host machine.&lt;/p&gt;
&lt;p&gt;So, since this file overrides the default behavior of querying the Internet’s DNS servers, and directly maps any string of characters to an IP, it’s frequently used by programmers to associate a development domain with the localhost IP address. This enables the use of a non-existent domain like, for example, &lt;code&gt;my-secret-project.test&lt;/code&gt; as an FQDN on a browser, as you’d normally access a registered &lt;code&gt;.com&lt;/code&gt; (or any other TLD) domain.&lt;/p&gt;
&lt;p&gt;At Infraspeak, we have several projects that use personalized domain names in our development environment. This requires that each of those domain names have to be mapped in the hosts file of every developer’s computer. Every time we use a new, or change an existent, project domain name, we have to warn everybody about it, and each developer has to update the hosts file.&lt;/p&gt;
&lt;p&gt;Since we’re investing a lot in hiring, it got me thinking about the tedious work of every new colleague editing the same file and paste the same mappings over and over again, and I decided to investigate a way of automating the process. I’ve come across several infrastructure-related projects, in my past, that does this. Valet, for example, which is a Laravel development environment, does this exact thing: it routes all requests for domains that use the &lt;code&gt;.test&lt;/code&gt; TLD to a preconfigured folder with the same name of the domain requested. So, a request to &lt;code&gt;my-secret-project.test&lt;/code&gt; would route to a project inside a my-secret-project folder.&lt;/p&gt;
&lt;p&gt;I knew that Valet leveraged Dnsmasq to do that, so I went to read more about how that software works and how could I add it to my stack and route the development domains, without editing the hosts file. While following the documentation to install it in my machine, I got an error related to port 53 being already in use. While trying to find which service was using that port, I found that a package named &lt;code&gt;dnsmasq-base&lt;/code&gt; was already installed on my Ubuntu machine.&lt;/p&gt;
&lt;p&gt;I don’t really know what Ubuntu is using that package for, or if it was really used at all, but I guess that it could be that the NetworkManager was leveraging the capabilities of DNS caching that Dnsmasq has. Anyway, the fact that it was already installed saved me some steps on configuring the environment. Now, I just needed to find a way to configure the Ubuntu NetworkManager to use Dnsmasq instead of system-resolve.&lt;/p&gt;
&lt;p&gt;A little more time investigating showed me that NetworkManager already supports Dnsmasq out-of-the-box and that to enable its use all that’s required is a single key in the &lt;code&gt;[main]&lt;/code&gt; section of its configuration file. That’s simple enough, but I’ve been working with Linux for a lot of time now, to know that almost every system’s service has a &lt;code&gt;conf.d&lt;/code&gt; folder that’s used to override the default configuration with the use of partial overriding of variables. Without any surprise, I found that the NetworkManager was no exception to this.&lt;/p&gt;
&lt;p&gt;That meant I simply needed to add a file to the &lt;code&gt;conf.d&lt;/code&gt; folder with only the configuration needed to activate the Dnsmasq support. I called the file &lt;code&gt;dnsmasq.conf&lt;/code&gt; and put it inside the folder &lt;code&gt;/etc/NetworkManager/conf.d&lt;/code&gt;, with the following content:&lt;/p&gt;
&lt;pre class=&quot;astro-code synthwave-84&quot; style=&quot;background-color:#262335;color:#bbbbbb; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;plaintext&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;[main]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;dns=dnsmasq&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;It was that simple! Now, the NetworkManager service was being instructed to use Dnsmasq to resolve all domains, instead of the native system-resolve service. However, this configuration alone was insufficient to route all local development domains to the localhost IP address. I still needed to add a specific Dnsmasq configuration file, to instruct it to not query the Internet’s DNS servers for requests of specific TLDs (our development TLDs).&lt;/p&gt;
&lt;p&gt;The file that was missing needed to be inside the &lt;code&gt;dnsmasq.d&lt;/code&gt; folder, which is very close to the previous folder: &lt;code&gt;/etc/NetworkManager/dnsmasq.d&lt;/code&gt;. Creating a file there, with the name &lt;code&gt;development-tld.conf&lt;/code&gt;, and adding a single line with &lt;code&gt;address=/development/127.0.0.1&lt;/code&gt; is all that was missing. Now, Dnsmasq won’t query the Internet’s DNS servers to know what’s the IP for every domain that uses &lt;code&gt;.development&lt;/code&gt; TLD.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;We use &lt;code&gt;.development&lt;/code&gt; as a local development TLD, but we could use the exact same steps to use any other TLD, like &lt;code&gt;.test&lt;/code&gt; Just take note that whatever you use, won’t reach the Internet. So, if you use &lt;code&gt;.com&lt;/code&gt;, for example, all requests for domains with that TLD will try to be resolved to your machine. Stick with a TLD that you know it’s not a “valid” one on the Internet, to avoid such problems.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Finally, I had everything properly configured. I only needed to disable the system-resolve service, permanently, and restart the NetworkManager service. The commands to do so were the following:&lt;/p&gt;
&lt;pre class=&quot;astro-code synthwave-84&quot; style=&quot;background-color:#262335;color:#bbbbbb; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;bash&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FE4450&quot;&gt;sudo&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; systemctl&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; disable&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; systemd-resolved.service&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FE4450&quot;&gt;sudo&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; systemctl&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; stop&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; systemd-resolved.service&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FE4450&quot;&gt;sudo&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; rm&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; /etc/resolv.conf&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FE4450&quot;&gt;sudo&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; systemctl&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; restart&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; network-manager.service&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The line &lt;code&gt;sudo rm /etc/resolv.conf&lt;/code&gt; forces the O.S. to regenerate the file with the new, updated, configuration, and the last line forces NetworkManager to load the all-new configuration.&lt;/p&gt;
&lt;p&gt;Now I had all my development domains auto-resolving to the localhost machine, even with domains that I never configured in the hosts file. Here’s an excerpt of what happens when pinging any domain with the configured &lt;code&gt;.development&lt;/code&gt; TLD:&lt;/p&gt;
&lt;pre class=&quot;astro-code synthwave-84&quot; style=&quot;background-color:#262335;color:#bbbbbb; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;bash&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FE4450&quot;&gt;▶&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; ping&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; infraspeak.development&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FE4450&quot;&gt;PING&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; infraspeak.development&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; (127.0.0.1) 56(&lt;/span&gt;&lt;span style=&quot;color:#FE4450&quot;&gt;84&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;) bytes of data.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FE4450&quot;&gt;64&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; bytes&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; from&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; localhost&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; (127.0.0.1): &lt;/span&gt;&lt;span style=&quot;color:#FF7EDB&quot;&gt;icmp_seq&lt;/span&gt;&lt;span style=&quot;color:#FFFFFFEE&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#FF7EDB&quot;&gt; ttl&lt;/span&gt;&lt;span style=&quot;color:#FFFFFFEE&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;64&lt;/span&gt;&lt;span style=&quot;color:#FF7EDB&quot;&gt; time&lt;/span&gt;&lt;span style=&quot;color:#FFFFFFEE&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;0.025&lt;/span&gt;&lt;span style=&quot;color:#FE4450&quot;&gt; ms&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FE4450&quot;&gt;64&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; bytes&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; from&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; localhost&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; (127.0.0.1): &lt;/span&gt;&lt;span style=&quot;color:#FF7EDB&quot;&gt;icmp_seq&lt;/span&gt;&lt;span style=&quot;color:#FFFFFFEE&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color:#FF7EDB&quot;&gt; ttl&lt;/span&gt;&lt;span style=&quot;color:#FFFFFFEE&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;64&lt;/span&gt;&lt;span style=&quot;color:#FF7EDB&quot;&gt; time&lt;/span&gt;&lt;span style=&quot;color:#FFFFFFEE&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;0.038&lt;/span&gt;&lt;span style=&quot;color:#FE4450&quot;&gt; ms&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FE4450&quot;&gt;---&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; infraspeak.development&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; ping&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; statistics&lt;/span&gt;&lt;span style=&quot;color:#F97E72&quot;&gt; ---&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FE4450&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; packets&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; transmitted,&lt;/span&gt;&lt;span style=&quot;color:#F97E72&quot;&gt; 2&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; received,&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; 0%&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; packet&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; loss,&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; time&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; 32ms&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FE4450&quot;&gt;rtt&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; min/avg/max/mdev&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; 0.025/0.031/0.038/0.008&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; ms&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FE4450&quot;&gt;▶&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; ping&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; non-existing-subdomain.infraspeak.development&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FE4450&quot;&gt;PING&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; non-existing-subdomain.infraspeak.development&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; (127.0.0.1) 56(&lt;/span&gt;&lt;span style=&quot;color:#FE4450&quot;&gt;84&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;) bytes of data.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FE4450&quot;&gt;64&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; bytes&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; from&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; localhost&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; (127.0.0.1): &lt;/span&gt;&lt;span style=&quot;color:#FF7EDB&quot;&gt;icmp_seq&lt;/span&gt;&lt;span style=&quot;color:#FFFFFFEE&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#FF7EDB&quot;&gt; ttl&lt;/span&gt;&lt;span style=&quot;color:#FFFFFFEE&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;64&lt;/span&gt;&lt;span style=&quot;color:#FF7EDB&quot;&gt; time&lt;/span&gt;&lt;span style=&quot;color:#FFFFFFEE&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;0.027&lt;/span&gt;&lt;span style=&quot;color:#FE4450&quot;&gt; ms&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FE4450&quot;&gt;64&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; bytes&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; from&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; localhost&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; (127.0.0.1): &lt;/span&gt;&lt;span style=&quot;color:#FF7EDB&quot;&gt;icmp_seq&lt;/span&gt;&lt;span style=&quot;color:#FFFFFFEE&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color:#FF7EDB&quot;&gt; ttl&lt;/span&gt;&lt;span style=&quot;color:#FFFFFFEE&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;64&lt;/span&gt;&lt;span style=&quot;color:#FF7EDB&quot;&gt; time&lt;/span&gt;&lt;span style=&quot;color:#FFFFFFEE&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;0.041&lt;/span&gt;&lt;span style=&quot;color:#FE4450&quot;&gt; ms&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FE4450&quot;&gt;---&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; non-existing-subdomain.infraspeak.development&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; ping&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; statistics&lt;/span&gt;&lt;span style=&quot;color:#F97E72&quot;&gt; ---&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FE4450&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; packets&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; transmitted,&lt;/span&gt;&lt;span style=&quot;color:#F97E72&quot;&gt; 2&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; received,&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; 0%&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; packet&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; loss,&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; time&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; 20ms&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FE4450&quot;&gt;rtt&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; min/avg/max/mdev&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; 0.027/0.034/0.041/0.007&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; ms&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FE4450&quot;&gt;▶&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; ping&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; customer-x.infraspeak.development&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;            &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FE4450&quot;&gt;PING&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; customer-x.infraspeak.development&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; (127.0.0.1) 56(&lt;/span&gt;&lt;span style=&quot;color:#FE4450&quot;&gt;84&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;) bytes of data.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FE4450&quot;&gt;64&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; bytes&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; from&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; localhost&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; (127.0.0.1): &lt;/span&gt;&lt;span style=&quot;color:#FF7EDB&quot;&gt;icmp_seq&lt;/span&gt;&lt;span style=&quot;color:#FFFFFFEE&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#FF7EDB&quot;&gt; ttl&lt;/span&gt;&lt;span style=&quot;color:#FFFFFFEE&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;64&lt;/span&gt;&lt;span style=&quot;color:#FF7EDB&quot;&gt; time&lt;/span&gt;&lt;span style=&quot;color:#FFFFFFEE&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;0.025&lt;/span&gt;&lt;span style=&quot;color:#FE4450&quot;&gt; ms&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FE4450&quot;&gt;64&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; bytes&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; from&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; localhost&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; (127.0.0.1): &lt;/span&gt;&lt;span style=&quot;color:#FF7EDB&quot;&gt;icmp_seq&lt;/span&gt;&lt;span style=&quot;color:#FFFFFFEE&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color:#FF7EDB&quot;&gt; ttl&lt;/span&gt;&lt;span style=&quot;color:#FFFFFFEE&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;64&lt;/span&gt;&lt;span style=&quot;color:#FF7EDB&quot;&gt; time&lt;/span&gt;&lt;span style=&quot;color:#FFFFFFEE&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;0.045&lt;/span&gt;&lt;span style=&quot;color:#FE4450&quot;&gt; ms&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FE4450&quot;&gt;---&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; customer-x.infraspeak.development&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; ping&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; statistics&lt;/span&gt;&lt;span style=&quot;color:#F97E72&quot;&gt; ---&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FE4450&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; packets&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; transmitted,&lt;/span&gt;&lt;span style=&quot;color:#F97E72&quot;&gt; 2&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; received,&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; 0%&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; packet&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; loss,&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; time&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; 23ms&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FE4450&quot;&gt;rtt&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; min/avg/max/mdev&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; 0.025/0.035/0.045/0.010&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; ms&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Pretty sweet, right? No more messing around the hosts file!&lt;/p&gt;
</content:encoded><category>Articles</category><category>Infrastructure</category></item><item><title>Continuous Integration with Bitbucket Pipelines</title><link>https://josepostiga.com/writing/continuous-integration-with-bitbucket-pipelines/</link><guid isPermaLink="true">https://josepostiga.com/writing/continuous-integration-with-bitbucket-pipelines/</guid><description>How we automated integration testing in a simple and effective way at Infraspeak.</description><pubDate>Sun, 21 Jul 2019 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;&lt;em&gt;This article was originally submitted on the&lt;/em&gt; &lt;a href=&quot;https://medium.com/infraspeak/continuous-integration-with-bitbucket-pipelines-96d1a55a28d1&quot;&gt;&lt;em&gt;Infraspeak tech blog&lt;/em&gt;&lt;/a&gt;&lt;em&gt;.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Infraspeak is a startup founded in 2015, focused on developing the best maintenance management software in the market. Built around simplicity and a user-friendly UI/UX, we have more than 25000 buildings being managed every day, with the help of our product.&lt;/p&gt;
&lt;p&gt;You might think that due to this number, there’s a big team of software engineers developing and maintaining the software. You’d be wrong. The Product Team is composed of 12 people, distributed between Backend, Frontend, Mobile, AI, and Integrations, and I’m also counting with the CTO.&lt;/p&gt;
&lt;p&gt;Although we’re actively recruiting new developers to the team, we’re perfectly comfortable in maintaining such a user base and still making sure we keep improving the codebase with optimizations, as well as deploying new features because we automate as much as possible. One automation we have in place is the Continuous Integration pipeline.&lt;/p&gt;
&lt;p&gt;The need for a Continuous Integration pipeline came from the fact that we were quickly becoming a critical dependency for our customers daily operations and, because of that, we needed to focus on constant quality assurance of our work. We needed a way of automating the integration testing of the work that was merged to the master branch (which is then deployed to production) with as minimal human interference as possible.&lt;/p&gt;
&lt;p&gt;When searching for options for a pipeline system, we were looking for something simple and quick to implement, but also easy to maintain. We had three ways of doing this:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Invest in preparing and actively maintaining a dedicated infrastructure for a self-hosted system, like Jenkins or Drone CI.&lt;/li&gt;
&lt;li&gt;Pay a lot of money, recurrently, to use another external tool, like Travis CI or Circle CI.&lt;/li&gt;
&lt;li&gt;Use Bitbucket Pipelines, which is natively integrated with their software repository, which we were already using.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Since we have a relatively small team, allocating resources to configure a dedicated CI infrastructure, and actively support it, was very hard to reason about, so this option was quickly disregarded. We looked at Travis CI and Circle CI with good eyes, because we didn’t have to handle the maintenance ourselves, but even being a well-funded company, their pricing plans were very expensive for our first attempt at using a pipeline system. We needed to gather more information, and experience, before requesting more resources to be invested in this.&lt;/p&gt;
&lt;p&gt;In the end, we went with Bitbucket Pipelines. Since we were already a paid customer, we had access to a 500 minutes pipeline execution plan without any additional costs. For what we wanted to do at the moment, it was good enough.&lt;/p&gt;
&lt;p&gt;Activating Bitbucket Pipelines was as simple as clicking on the dedicated “Enable Pipelines” button, available in the repository settings page. The interesting and a little bit more complicated part was creating the configuration YAML file according to the project specification so that Bitbucket knew when to run and how to instantiate and automatically configure the pipeline’s infrastructure. The main goal was to activate the pipeline in specific points on our branching strategy.&lt;/p&gt;
&lt;p&gt;We have a pretty standard branching strategy: we have a master branch, always in sync with production, we have a development branch and we have n working branches corresponding to an active task. As soon as developers are finished with their task, they send a PR targeting the development branch, which then is peer-reviewed and, finally, merged. At the end of the sprint cycle, the development branch gets merged to master and deployed to production.&lt;/p&gt;
&lt;p&gt;To be confident about the changes we continuously made to the project, and to minimize the need for manual testing between merges to the development and the master branch, without sacrificing speed and agility of development, we needed the pipeline to run on key events of our workflow:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;When a PR is opened targeting the master or the development branch.&lt;/li&gt;
&lt;li&gt;When a push is done directly to the development or the master branch.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Because we had a limited execution time, we couldn’t include every push to the working branches but assumed that each developer would run the full test suite locally and only push the changes when they had them all passing. The pipeline would only continuously check the integration of all developers code into the development and the master branch, as we knew that those were the points in time where bugs, conflicts, and other problems could happen.&lt;/p&gt;
&lt;p&gt;We decided that the first project which we were to have the pipeline configured to test was our main API layer. It’s where we have the main business logic and data, making it one of the main critical points of failure to our business. If it failed, then all other tools we provide were going to fail too. Having this in mind, we started to map all the steps required to automatically instantiate the project and run the full test suite (unit and feature tests):&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Checkout the project from the repository.&lt;/li&gt;
&lt;li&gt;Install all the dependencies and instantiate a PostgreSQL database.&lt;/li&gt;
&lt;li&gt;Run the full test suite.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Digging through the Bitbucket Pipelines documentation, we learned that it’s all run inside a dockerized environment and that the main base image they recommend using would check out the correct branch and make the code available to all other steps of the pipeline. That was exactly what we needed to handle the first step.&lt;/p&gt;
&lt;p&gt;For step two, we needed to have a way to run Composer, to install the dependencies, and run PHP for the test suite. The Bitbucket Pipelines documentation states that each pipeline step can have a dedicated docker image running. That would support our initial idea for running Composer and the PHPUnit test suite in two different steps.&lt;/p&gt;
&lt;p&gt;The documentation also refers to the fact that we can have shared containers (they call it services) running and accessible from all steps throughout the whole pipeline execution. Since we rely on PostgreSQL as our persistent layer, and we had a lot of feature tests that would use that layer, it was a very much appreciated functionality that we would definitely need.&lt;/p&gt;
&lt;p&gt;After having the first draft of the pipeline configuration file, we created a test branch, pushed the file to the repository and watched the pipeline come to life. It started to run and we were watching happily, for about a minute, then it failed hard. The logs stated that the vendor folder, which is where Composer downloads and installs the dependencies, was nowhere to be found. It seemed that it was being removed at the end of the step (at the teardown phase).&lt;/p&gt;
&lt;p&gt;We got to scratch our heads, a lot, about this. We were installing the dependencies in the previous step and we were declaring the composer cache strategy, which is natively supported by Bitbucket and is specifically built for keeping Composer dependencies for the next step. After a little investigation, and reading a lot of documentation, we found out that this was happening because the artifacts configuration key was missing. This configuration maps the Composer vendor folder, and all files it contains, to transition to the next step.&lt;/p&gt;
&lt;p&gt;After updating the configuration file, we got it running successfully. The vendor folder was transitioning correctly to the next step and the test suite was passing. Everything was green and we had our first successful pipeline execution!&lt;/p&gt;
&lt;p&gt;Since it was running, it was time to optimize it. The first optimization was around the Composer dependencies install. It was slow, taking around three minutes to install all the dependencies. Was there something we could do to improve this? After a little more digging, we found out that we should use a caching strategy. Composer, when running locally in your machine, saves a reference to the remote dependencies repositories, allowing it to skip several steps when fetching those dependencies.&lt;/p&gt;
&lt;p&gt;Since the Composer binary, on our pipeline, was running in a docker container, the references cache were compiled but they would never persist. Docker containers don’t persist data after being destroyed, unless you add volumes to them. And that’s what we needed to add: a cache volume to persist those references.&lt;/p&gt;
&lt;p&gt;Doing that was not an easy task. The Bitbucket Pipelines documentation states that it has a predefined caching strategy for Composer, which is awesome and would save a lot of time by not requiring us to configure a personalized one, but it forgot to mention that if you use the default Composer docker image you need to also declare the /tmp folder as the one that needs to be cached.&lt;/p&gt;
&lt;p&gt;But after we finished updating the configuration file, the time it took to install the dependencies went down to around fifteen seconds. That’s fast! Considering that this was intended to run several times, per developer, in a normal workday, it would stretch out our available execution time cap.&lt;/p&gt;
&lt;p&gt;And it was pretty much it. We only needed to make it run on the predefined events (pull requests and pushes to master or development branch) and we had our pipeline fully working so we made the PR to the development branch. Our final configuration file was similar to the following:&lt;/p&gt;
&lt;pre class=&quot;astro-code synthwave-84&quot; style=&quot;background-color:#262335;color:#bbbbbb; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;yaml&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#72F1B8&quot;&gt;image&lt;/span&gt;&lt;span style=&quot;color:#B6B1B1&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; atlassian/default-image:latest&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#72F1B8&quot;&gt;pipelines&lt;/span&gt;&lt;span style=&quot;color:#B6B1B1&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#72F1B8&quot;&gt;  pull-requests&lt;/span&gt;&lt;span style=&quot;color:#B6B1B1&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FF8B39&quot;&gt;    &apos;**&apos;&lt;/span&gt;&lt;span style=&quot;color:#B6B1B1&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;      - &lt;/span&gt;&lt;span style=&quot;color:#72F1B8&quot;&gt;step&lt;/span&gt;&lt;span style=&quot;color:#B6B1B1&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#72F1B8&quot;&gt;          name&lt;/span&gt;&lt;span style=&quot;color:#B6B1B1&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; Install dependencies&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#72F1B8&quot;&gt;          image&lt;/span&gt;&lt;span style=&quot;color:#B6B1B1&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; composer&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#72F1B8&quot;&gt;          caches&lt;/span&gt;&lt;span style=&quot;color:#B6B1B1&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;            - &lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;composer&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#72F1B8&quot;&gt;          artifacts&lt;/span&gt;&lt;span style=&quot;color:#B6B1B1&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;            - &lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;vendor/**&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#72F1B8&quot;&gt;          script&lt;/span&gt;&lt;span style=&quot;color:#B6B1B1&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;            - &lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;composer install --ignore-platform-reqs&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;      - &lt;/span&gt;&lt;span style=&quot;color:#72F1B8&quot;&gt;step&lt;/span&gt;&lt;span style=&quot;color:#B6B1B1&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#72F1B8&quot;&gt;          name&lt;/span&gt;&lt;span style=&quot;color:#B6B1B1&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; Run tests&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#72F1B8&quot;&gt;          image&lt;/span&gt;&lt;span style=&quot;color:#B6B1B1&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; php:7.2-cli&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#72F1B8&quot;&gt;          script&lt;/span&gt;&lt;span style=&quot;color:#B6B1B1&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;            - &lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;ln -f -s .env.pipeline .env&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;            - &lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;php artisan key:generate&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;            - &lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;php artisan migrate&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;            - &lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;php artisan passport:keys&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;            - &lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;printf &quot;\n&quot; | php artisan passport:client --password&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;            - &lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;vendor/bin/phpunit -c tests/phpunit.xml --testsuite Unit --no-coverage&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;            - &lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;vendor/bin/phpunit -c tests/phpunit.xml --testsuite Feature --no-coverage&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;            - &lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;vendor/bin/phpunit -c tests/phpunit.xml --testsuite Domain --no-coverage&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#72F1B8&quot;&gt;          services&lt;/span&gt;&lt;span style=&quot;color:#B6B1B1&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;            - &lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;postgres&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#72F1B8&quot;&gt;  branches&lt;/span&gt;&lt;span style=&quot;color:#B6B1B1&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FF8B39&quot;&gt;    &apos;{master,dev-sprint-*}&apos;&lt;/span&gt;&lt;span style=&quot;color:#B6B1B1&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;      - &lt;/span&gt;&lt;span style=&quot;color:#72F1B8&quot;&gt;step&lt;/span&gt;&lt;span style=&quot;color:#B6B1B1&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#72F1B8&quot;&gt;          name&lt;/span&gt;&lt;span style=&quot;color:#B6B1B1&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; Install dependencies&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#72F1B8&quot;&gt;          image&lt;/span&gt;&lt;span style=&quot;color:#B6B1B1&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; composer&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#72F1B8&quot;&gt;          caches&lt;/span&gt;&lt;span style=&quot;color:#B6B1B1&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;            - &lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;composer&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#72F1B8&quot;&gt;          artifacts&lt;/span&gt;&lt;span style=&quot;color:#B6B1B1&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;            - &lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;vendor/**&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#72F1B8&quot;&gt;          script&lt;/span&gt;&lt;span style=&quot;color:#B6B1B1&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;            - &lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;composer install --ignore-platform-reqs&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;      - &lt;/span&gt;&lt;span style=&quot;color:#72F1B8&quot;&gt;step&lt;/span&gt;&lt;span style=&quot;color:#B6B1B1&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#72F1B8&quot;&gt;          name&lt;/span&gt;&lt;span style=&quot;color:#B6B1B1&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; Run tests&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#72F1B8&quot;&gt;          image&lt;/span&gt;&lt;span style=&quot;color:#B6B1B1&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; php:7.2-cli&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#72F1B8&quot;&gt;          script&lt;/span&gt;&lt;span style=&quot;color:#B6B1B1&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;            - &lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;ln -f -s .env.pipeline .env&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;            - &lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;php artisan key:generate&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;            - &lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;php artisan migrate&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;            - &lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;php artisan passport:keys&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;            - &lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;printf &quot;\n&quot; | php artisan passport:client --password&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;            - &lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;vendor/bin/phpunit -c tests/phpunit.xml --testsuite Unit --no-coverage&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;            - &lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;vendor/bin/phpunit -c tests/phpunit.xml --testsuite Feature --no-coverage&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;            - &lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;vendor/bin/phpunit -c tests/phpunit.xml --testsuite Domain --no-coverage&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#72F1B8&quot;&gt;          services&lt;/span&gt;&lt;span style=&quot;color:#B6B1B1&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;            - &lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;postgres&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#72F1B8&quot;&gt;definitions&lt;/span&gt;&lt;span style=&quot;color:#B6B1B1&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#72F1B8&quot;&gt;  caches&lt;/span&gt;&lt;span style=&quot;color:#B6B1B1&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#72F1B8&quot;&gt;    composer&lt;/span&gt;&lt;span style=&quot;color:#B6B1B1&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; /tmp&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#72F1B8&quot;&gt;  services&lt;/span&gt;&lt;span style=&quot;color:#B6B1B1&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#72F1B8&quot;&gt;    postgres&lt;/span&gt;&lt;span style=&quot;color:#B6B1B1&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#72F1B8&quot;&gt;      image&lt;/span&gt;&lt;span style=&quot;color:#B6B1B1&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; postgres:10.5&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#72F1B8&quot;&gt;      environment&lt;/span&gt;&lt;span style=&quot;color:#B6B1B1&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#72F1B8&quot;&gt;        POSTGRES_DB&lt;/span&gt;&lt;span style=&quot;color:#B6B1B1&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; database&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#72F1B8&quot;&gt;        POSTGRES_USER&lt;/span&gt;&lt;span style=&quot;color:#B6B1B1&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; root&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#72F1B8&quot;&gt;        POSTGRES_PASSWORD&lt;/span&gt;&lt;span style=&quot;color:#B6B1B1&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; root&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;With Bitbucket Pipelines handling our continuous integration testing workflow, every time some sneaky bug tried to enter our codebase, the pipeline would fail, informing the author of the commit via e-mail, warning to check the pipeline logs and apply the necessary correction to the code submitted.&lt;/p&gt;
&lt;p&gt;As long as we continued to add tests for every new feature, bug fix, and improvement, the pipeline would take care of checking every test case for possible problems. This had a very positive impact in our team workflow and improved our code quality because lesser bugs were merged into the codebase. It helped the team shift a little bit more from a reactive to a more preventive position. It’s better for the pipeline to catch the bugs and break, than our customers’ catch the bugs, lose work and then lose those clients!&lt;/p&gt;
</content:encoded><category>Articles</category><category>CI/CD</category></item><item><title>Running a smooth Docker stack for Web Development</title><link>https://josepostiga.com/writing/running-a-smooth-docker-stack-for-web-development/</link><guid isPermaLink="true">https://josepostiga.com/writing/running-a-smooth-docker-stack-for-web-development/</guid><description>Docker is the best way to build, share and run applications in the cloud. There’re no doubts about that! You literally only have to configure your infrastructure once, programmatically, and can run…</description><pubDate>Wed, 12 Jun 2019 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;Docker is the best way to build, share and run applications in the cloud. There’re no doubts about that! You literally only have to configure your infrastructure once, programmatically, and can run on every cloud provider. It’s amazingly fast, too. No wonder that everyone is crazy about this technology and are using it to support their most critical business services.&lt;/p&gt;
&lt;p&gt;Surely you’ve also heard, and read, about teams using Docker in their development process, right? That you can get up and running, on any project, without messing around with your computer and not being worried about installing different (or specific) versions of a software language or any other dependency you might need. You simply &lt;code&gt;docker-compose up&lt;/code&gt;and all services/dependencies are spawn and ready to use. Everything gets to run on an isolated container.&lt;/p&gt;
&lt;p&gt;I’ve been using Docker for development for a little more than two years, at the time of writing this article, and I’d like to share with you some details that’ll make your experience with Docker, for development, a very smooth one. But before I dump all the knowledge to you, we’ll start slow, by breaking my path to the final implementation into small parts, so you can understand where my decisions came from.&lt;/p&gt;
&lt;p&gt;Let’s get to it, shall we?&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Note: All examples will be oriented with web development in mind, but I think you can extrapolate to your situation, specifically.&lt;/em&gt;&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;part-1-with-great-dockerfiles-comes-great-responsibility&quot;&gt;&lt;strong&gt;Part 1: With great Dockerfiles, comes great responsibility&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;This is not an introduction to Docker or Dockerfiles. You have the official &lt;a href=&quot;https://docs.docker.com/engine/reference/builder/&quot;&gt;documentation&lt;/a&gt; that has in-depth information about it. However, I’ll tell you this: Dockerfiles contains additional commands (steps) that are called to assemble a Docker image with configurations, dependencies and other things you might need to run your container. However, you should avoid using them for as long as you possibly can.&lt;/p&gt;
&lt;p&gt;It’s not that these files are complicated because they’re not, it’s just that, as soon as you create a Dockerfile, you’re taking responsibility about managing that specific image definition. It’s not a decision you should take lightly. Dockerfiles, like any other system of its kind, need to be revisited from time to time and updated because, for example, a library you added has a new version available.&lt;/p&gt;
&lt;p&gt;To avoid having this responsibility, you should first check for an official image on &lt;a href=&quot;https://hub.docker.com/&quot;&gt;Docker Hub&lt;/a&gt;! Let others have to worry about dependency management and update. You’ll want to use your time to generate value, not worrying about dependencies versions being outdated, or even worrying about vulnerabilities on those dependencies. Docker Hub has a lot of images for you to work with. Not only has many images created by community members, but also has official images, supported by the very companies and groups that develop the underlying dependencies. For example, you can find official images for NGINX, PHP, Composer, Yarn, NodeJS, and a lot more!&lt;/p&gt;
&lt;p&gt;However, for those cases when you really have to create one, try to use it as little as possible. The next sections will show you how.&lt;/p&gt;
&lt;h3 id=&quot;choose-a-base-image-wisely&quot;&gt;&lt;strong&gt;Choose a base image wisely&lt;/strong&gt;&lt;/h3&gt;
&lt;p&gt;A Dockerfile requires that you define a base image, which to apply your changes upon. This can be an O.S. version (Ubuntu 19.10, Debian 9, Fedora, Mint, etc.) or you can even use an image that already has a dependency installed (PHP 7.3, NGINX, MySQL, etc.) which already have an underlying O.S. definition and all configurations needed to run that dependency.&lt;/p&gt;
&lt;p&gt;For example, when creating a PHP Dockerfile, I’ll try to use the most recent, stable, version needed for my situation. So, supposing I need to use PHP 7.2 (CLI), I’ll start my Dockerfile with:&lt;/p&gt;
&lt;pre class=&quot;astro-code synthwave-84&quot; style=&quot;background-color:#262335;color:#bbbbbb; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;plaintext&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;FROM php:7.2-cli&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Every command I add next will be run on top of this PHP 7.2 image, and have all dependencies needed to have it running without problems.&lt;/p&gt;
&lt;p&gt;By using a base image that already has almost everything I need, I’m also limiting my responsibility. I don’t have to worry about every command it takes to install PHP and I don’t have to worry about managing or updating it. If by any chance, there’s a new version of that base image, all I have to do is run the docker build command to fetch all updates available, directly related to the base image.&lt;/p&gt;
&lt;h3 id=&quot;condense-as-many-commands-as-possible&quot;&gt;&lt;strong&gt;Condense as many commands as possible&lt;/strong&gt;&lt;/h3&gt;
&lt;p&gt;To execute a command, after defining the base image, you use the &lt;code&gt;RUN&lt;/code&gt; directive. This runs the given command during the image build process, while the final image is being compiled, and corresponds to a layer. Each layer, upon being executed, is cached. This prevents the &lt;code&gt;docker build&lt;/code&gt; process to run every command, every time you execute it, saving you (sometimes a lot of) computation time.&lt;/p&gt;
&lt;p&gt;So, if every &lt;code&gt;RUN&lt;/code&gt; directive can correspond to a cached layer, it should make sense to use as few as possible, speeding up the compiling time. Well, not so fast! You need to use it with care, because every time you change the statement, the build process will re-execute the entire modified &lt;code&gt;RUN&lt;/code&gt; directive, even if the only thing you changed was the order of the arguments. So, if you have a “big” &lt;code&gt;RUN&lt;/code&gt; command, and change it, the cache is invalidated and you’ll have to wait that it finishes executing all work defined on that modified &lt;code&gt;RUN&lt;/code&gt; directive and every one after.&lt;/p&gt;
&lt;p&gt;To avoid having this problem, often, you have to find a sweet spot between the number of &lt;code&gt;RUN&lt;/code&gt; directives and the amount of work done on each. I tend to separate mines in three sections: package installs, package configurations and packages activations.&lt;/p&gt;
&lt;h3 id=&quot;keep-your-images-on-a-diet&quot;&gt;&lt;strong&gt;Keep your images on a diet&lt;/strong&gt;&lt;/h3&gt;
&lt;p&gt;The whole point of using Docker is to keep the dependencies at a minimum, and decoupled from your host computer. However, this line of thinking is not only applicable to the containers. You should start applying, at least the “keep dependencies at a minimum” part, with your Dockerfiles. Images are a very important part of your Docker setup: without images, you can’t have containers! They are two parts of a whole: the bigger your image’s size, the bigger the container size.&lt;/p&gt;
&lt;p&gt;Remember that the only thing that your host and your containers share, is the kernel. Everything that you install or copy onto your image will add up to its final size. Every &lt;code&gt;RUN&lt;/code&gt; directive that has a package install command (&lt;code&gt;apt-get install&lt;/code&gt;or &lt;code&gt;apk install&lt;/code&gt;) will be saved on the image. If you’re not careful, your image can become very heavy, very quickly. You might not even install that many things and still see your images reach one gigabyte of size, or even more.&lt;/p&gt;
&lt;p&gt;One of the main enablers of that situation is the package manager’s cache system. You see, when you have to install software, a general step required is to run &lt;code&gt;apt-get update&lt;/code&gt; (supposing you’re running Ubuntu as a base image) before running the command to install the software you need. This is because that command is responsible to download all package’s information list, available on every repository registered on the O.S. That list contains the repositories where the software is so that the package manager can download it and install it. The “real” problem is that after downloading that information, it’s cached.&lt;/p&gt;
&lt;p&gt;That behavior is very welcome if you’re running that on your host machine, avoiding having to download that information every time you try to update your system, but in the context of a Docker image, that’s useless! After you install all the software you need, that cache is only occupying precious space as it’s not needed to run the, already installed, software. By removing that cache information, you can save a lot of space.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;part-2-containers-and-networks&quot;&gt;&lt;strong&gt;Part 2. Containers and networks&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;Again, this is not an introduction to Docker networks. You have the official &lt;a href=&quot;https://docs.docker.com/network/&quot;&gt;documentation&lt;/a&gt; for in-depth information about it. Networking can be tricky, but it’s essential that you have a general understanding of how containers do networking.&lt;/p&gt;
&lt;p&gt;When you spawn a container via &lt;code&gt;docker run&lt;/code&gt; you can define a network by adding &lt;code&gt;--network={your-network-name-here}&lt;/code&gt; (or the shortcut &lt;code&gt;-n&lt;/code&gt;) and this will configure access, to this new container, to that network. This means that this container will have access to all other containers that also may be connected to the same network. But what about if you spawn a container without defining an explicit network? Well, one might think that this container won’t have access to anything, that’ll run in complete isolation. But that’s not always the case.&lt;/p&gt;
&lt;p&gt;All containers that are spawn without a network definition are connected, automatically, to the default &lt;code&gt;bridge&lt;/code&gt; network. So, in fact, if you start two containers without defining a network, those containers will be able to communicate with each other through that default &lt;code&gt;bridge&lt;/code&gt; network. However, contrary to user-generated networks, which supports service discovery (calling other containers by their defined name), those two containers can only communicate only via their IP address.&lt;/p&gt;
&lt;p&gt;This type of nuance can be very handy and it’s even more interesting if you think about using it for connecting to database instances! As long as your exposed ports don’t collide, you can then use the bounded, default, localhost port (0.0.0.0 or 127.0.0.1), specifying the exposed, mapped to host, port and connect to your database via a DBMS (pgAdmin, DBeaver, MySQL Workbench or any other of your liking). Pretty neat, I think! You can spin up two containers, one with your database instance and another with your app, and get them working together without even thinking about creating a user-defined network, without any &lt;code&gt;docker-compose&lt;/code&gt; files and any other type of orchestration method being needed.&lt;/p&gt;
&lt;p&gt;But when you do use a &lt;code&gt;docker-compose&lt;/code&gt; file, there are a lot more interesting things you can do. You can define many networks, their drivers, force IP addresses, group different services into different networks and even define aliases for the same instances on different networks. So, an NGINX container can be called &lt;code&gt;load-balancer&lt;/code&gt; on a network, and be called &lt;code&gt;nginx-lb&lt;/code&gt; on another. It’s the exact same instance, but with different names on each of those networks.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;part-3-permissions-and-usergroup-mappings&quot;&gt;&lt;strong&gt;Part 3. Permissions and user/group mappings&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;There’s something really inconvenient in running commands through containers: any file created gets associated, by default, with the user and group 0 (the &lt;code&gt;root&lt;/code&gt; user/group mapping). This means that you can’t edit or delete them, on your host computer, without using &lt;code&gt;sudo&lt;/code&gt; or running a &lt;code&gt;chown&lt;/code&gt; command to remap the file’s permissions to your own user. This might not sound very important but since I develop a lot with PHP, using &lt;code&gt;composer&lt;/code&gt; can get messy as the &lt;code&gt;vendor&lt;/code&gt; directory gets totally owned by &lt;code&gt;root&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;You might think it’s fine because, after all, &lt;code&gt;composer&lt;/code&gt; is a package manager and external, third-party, packages are not to be edited locally. Ok, that’s fair, but imagine you use a script that generates PHP classes. Let’s say, like me, you work with Laravel, which has the &lt;code&gt;artisan&lt;/code&gt; command line tool, that helps me generate not only classes but a lot more resource files to speed up your work. As soon as I run &lt;code&gt;php artisan make:controller SomeController&lt;/code&gt; I won’t be able to edit it without, first, do a &lt;code&gt;sudo chown {your username}: SomeController&lt;/code&gt; to give write access to that file. Pretty inconvenient, right? Luckily this can be avoided pretty easily!&lt;/p&gt;
&lt;p&gt;Docker supports the mapping of personalized users/groups to which the container will run as! We can use it as a command parameter when running &lt;code&gt;docker run&lt;/code&gt;. The parameter’s name signature is &lt;code&gt;--user {user}:{group}&lt;/code&gt; and, by adding it, we’re explicitly saying that the command is being run by that user, under that group. With this, if we map to our own user/group values, it’ll associate the files to our account, enabling us to fully work with them as if they were generated directly on our host machine.&lt;/p&gt;
&lt;p&gt;However, there’s a catch. Or two, in this case: 1. It only takes numbers for both user and group so you have to know, in advance, what’s yours; 2. It has no validation, whatsoever, for those numbers so, technically, you can use any number combination for user:group and still get the container to work. However, this has the same result as running as &lt;code&gt;root&lt;/code&gt;, since you wouldn’t be able to edit without elevated access…&lt;/p&gt;
&lt;p&gt;Don’t worry! There’s an easy way of using this properly without ever think about it. If you inspect the &lt;code&gt;id&lt;/code&gt; command, available on your machine, you’ll notice you have two options to get the ID and GROUP of the currently, logged in, user account. You can use that to programmatically get the correct values.&lt;/p&gt;
&lt;p&gt;Since bash commands can take sub-commands and evaluates them first, you can use &lt;code&gt;id -u&lt;/code&gt; to get the user and &lt;code&gt;id -g&lt;/code&gt; to get the group, before the main &lt;code&gt;docker run&lt;/code&gt; command gets executed. So, you can run any docker container with your user:group mapping with the following partial: &lt;code&gt;docker run --user $(id -u):$(id -g) {the rest of your command here}&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Now, you can run &lt;code&gt;composer&lt;/code&gt;, &lt;code&gt;artisan&lt;/code&gt; or any other command and have all the generated files correctly associated with your user/group. You don’t ever have to &lt;code&gt;chown&lt;/code&gt; your way through those files, again, to be able to edit them on your IDE or code editor of choice.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;lets-play&quot;&gt;&lt;strong&gt;Let’s play!&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;Did you think I’ve forgotten about why you’re reading this article? Of course not! Let’s see how we can get a smooth docker stack installed and configured on our computer.&lt;/p&gt;
&lt;h3 id=&quot;starting-with-infrastructure-architecture&quot;&gt;&lt;strong&gt;Starting with infrastructure architecture&lt;/strong&gt;&lt;/h3&gt;
&lt;p&gt;Like every new (tech) project, specifically infrastructure-related projects, we need to think, first, about how should we structure things. When I started to use Docker, I thought that I’d use a simple docker-compose file on the root of my project and be done with it. The infrastructure is project bounded, it’s related and tightly coupled to it, so it made sense to manage the infrastructure that way. It seemed simple, too.&lt;/p&gt;
&lt;p&gt;However, I was not thinking about what to do with the Dockerfiles, with service-related configuration files (e.g.: NGINX conf files or PHP’s modules’ ini files). To handle this noise, I started using a &lt;code&gt;.docker&lt;/code&gt; folder with everything inside, except the docker-compose file, which remained on the project root. This sounded liked a nice way to gently organize all my docker related files away from my project’s files, but it could still be versioned with the latter. Although there were many more files to manage, I would only have to worry about it once, so it still was “simple enough”.&lt;/p&gt;
&lt;p&gt;Everything was fine until I started deploying things. All my infrastructure related files were deployed attached to my code. Some sort of inception was going on, where I was creating a stack that’ll deploy an application that had all infrastructure related files inside, too. I thought that, although having the infrastructure definition on the project repository looked like I was helping others deploying and testing my work faster, the truth is that I was assuming that they’d use Docker, too.&lt;/p&gt;
&lt;p&gt;They could be using other development environments, like virtual machines or even have all the dependencies installed on the host machine, but they would still have to download all my infrastructure files. It didn’t felt clean, so I decided to separate my infrastructure files from my project’s, completely, and started to think about how could I manage it in a simple, eloquent, way. I needed to find a solution that would be easy to maintain, to version and to be simple enough to be rebuilt on another computer, if necessary.&lt;/p&gt;
&lt;p&gt;I found myself creating a dedicated folder for this on my system account’s home directory (in Linux is &lt;code&gt;/home/{username}&lt;/code&gt;) named &lt;code&gt;Infrastructure&lt;/code&gt;. Inside this folder I have:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;A folder for each different, personalized, Docker Image (for PHP, NGINX and other I needed to tailor to my needs);&lt;/li&gt;
&lt;li&gt;A folder called &lt;code&gt;Stacks&lt;/code&gt; containing dedicated &lt;code&gt;docker-compose&lt;/code&gt; files, each corresponding to a project;&lt;/li&gt;
&lt;li&gt;A folder called &lt;code&gt;Volumes&lt;/code&gt; containing all data that I need to persist from my running containers (like the database container’s data);&lt;/li&gt;
&lt;li&gt;A folder called &lt;code&gt;Scripts&lt;/code&gt; containing utility scripts for running containers’ commands through the console (for example, running Composer or PHP).&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Here’s a tree description of the folder:&lt;/p&gt;
&lt;pre class=&quot;astro-code synthwave-84&quot; style=&quot;background-color:#262335;color:#bbbbbb; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;plaintext&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;├── Nginx&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;│   ├── certificates&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;│   ├── conf&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;│   ├── docker-compose.yml&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;│   └── nginx.conf&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;├── PHP&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;│   └── 7.2&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;│       ├── cli&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;│       │   ├── conf&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;│       │   │   └── xdebug.ini&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;│       │   └── Dockerfile&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;│       └── fpm&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;│           ├── conf&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;│           │   └── xdebug.ini&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;│           └── Dockerfile&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;├── Scripts&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;│   ├── composer&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;│   ├── dep&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;│   ├── mkdocs&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;│   ├── mysql&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;│   ├── php&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;│   ├── php5.6&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;│   ├── phpcs&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;│   ├── php-cs-fixer&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;│   ├── phpinsights&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;│   ├── psql&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;│   ├── redis-cli&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;│   └── yarn&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;├── Stacks&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;├── Volumes&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;└── install.sh&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This structure allows me to version the whole folder, except the &lt;code&gt;Volumes&lt;/code&gt; folder (database data should not be versioned) so I can quickly check it out on another computer, run the &lt;code&gt;install.sh&lt;/code&gt; script and have the exact same structure and scripts available in a very short time. That file has five execution steps:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Creates all Docker networks that my stacks use;&lt;/li&gt;
&lt;li&gt;Pulls all latest images versions that my containers use from Docker HUB;&lt;/li&gt;
&lt;li&gt;Copies the Scripts folder’s scripts to my &lt;code&gt;/usr/local/bin&lt;/code&gt; folder, allowing me to use them globally on my computer;&lt;/li&gt;
&lt;li&gt;Installs globally required composer packages, like PHPUnit, PHP-CS-Fixer and others alike;&lt;/li&gt;
&lt;li&gt;Boots the NGINX container, that acts as the reverse-proxy.&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&quot;one-nginx-container-to-rule-them-all&quot;&gt;&lt;strong&gt;One NGINX container to rule them all&lt;/strong&gt;&lt;/h3&gt;
&lt;p&gt;Another detail on my infrastructure configuration is that I only use one NGINX container to serve all my (web) projects. If you’ve read any tutorial, on the web, about using Docker for development you’ll remember the service definition for a HTTP server (either NGINX, Apache or Caddy) declared on your project’s docker-compose file. There’s no need for that, really.&lt;/p&gt;
&lt;p&gt;The reality is that if you follow those tutorials recommendations, you’ll be repeating yourself over and over, again, by copying and pasting the same server configuration, on every project you have. Unless you have a very specific need for that, you’ll most likely use the same HTTP server, with the same configuration for every project you work on.&lt;/p&gt;
&lt;p&gt;Here’s a better way: use one, persistent, container. What do I mean with a “persistent” is a container that has the &lt;code&gt;restart&lt;/code&gt;directive property to &lt;code&gt;unless-stopped&lt;/code&gt;. This marks the container to be permanently up, even if some error occurs or the computer gets powered down. The Docker daemon will always try to reboot the container as fast as possible after it stops unintentionally.&lt;/p&gt;
&lt;p&gt;Take, for example, the following NGINX docker-compose definition:&lt;/p&gt;
&lt;pre class=&quot;astro-code synthwave-84&quot; style=&quot;background-color:#262335;color:#bbbbbb; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;yaml&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#72F1B8&quot;&gt;version&lt;/span&gt;&lt;span style=&quot;color:#B6B1B1&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#FF8B39&quot;&gt; &quot;3.7&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#72F1B8&quot;&gt;services&lt;/span&gt;&lt;span style=&quot;color:#B6B1B1&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#72F1B8&quot;&gt;    nginx-lb&lt;/span&gt;&lt;span style=&quot;color:#B6B1B1&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#72F1B8&quot;&gt;        container_name&lt;/span&gt;&lt;span style=&quot;color:#B6B1B1&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; nginx&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#72F1B8&quot;&gt;        image&lt;/span&gt;&lt;span style=&quot;color:#B6B1B1&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; nginx&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#72F1B8&quot;&gt;        ports&lt;/span&gt;&lt;span style=&quot;color:#B6B1B1&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;            - &lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;80:80&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;            - &lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;443:443&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;            - &lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;8080:8080&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;            - &lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;8082:8082&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#72F1B8&quot;&gt;        volumes&lt;/span&gt;&lt;span style=&quot;color:#B6B1B1&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;            - &lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;./nginx.conf:/etc/nginx/nginx.conf:ro&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;            - &lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;./certificates:/etc/nginx/certificates:ro&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;            - &lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;./conf:/etc/nginx/conf.d:ro&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;            - &lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;~/Code:/var/www/html&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#72F1B8&quot;&gt;        restart&lt;/span&gt;&lt;span style=&quot;color:#B6B1B1&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; unless-stopped&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#72F1B8&quot;&gt;        networks&lt;/span&gt;&lt;span style=&quot;color:#B6B1B1&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#72F1B8&quot;&gt;            web&lt;/span&gt;&lt;span style=&quot;color:#B6B1B1&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#72F1B8&quot;&gt;networks&lt;/span&gt;&lt;span style=&quot;color:#B6B1B1&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#72F1B8&quot;&gt;    web&lt;/span&gt;&lt;span style=&quot;color:#B6B1B1&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#72F1B8&quot;&gt;        external&lt;/span&gt;&lt;span style=&quot;color:#B6B1B1&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#F97E72&quot;&gt; true&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;With this configuration, all I need to do to serve a new project is a new configuration file in the &lt;code&gt;conf&lt;/code&gt; folder (which is mapped on the volumes section) and restart the container, besides having the source code on the &lt;code&gt;Code&lt;/code&gt; folder. After this, the NGINX will have all subsequent requests to my new project routed to the proper project container, to be handled.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;If you noted the volume mapping of my entire &lt;code&gt;Code&lt;/code&gt; folder, is because of, unfortunately, a limitation in the NGINX itself, that requires the reading the file, first, to interpret the configuration rules and calculate which server/location blocks to route the request to.&lt;/em&gt;&lt;/p&gt;
&lt;h3 id=&quot;spinning-up-a-projects-container&quot;&gt;&lt;strong&gt;Spinning up a project’s container&lt;/strong&gt;&lt;/h3&gt;
&lt;p&gt;Having our reverse-proxy setup is nice, but we’re still missing the project container instance, so that the requests are processed. Here’s an example docker-compose file for spinning a project’s container:&lt;/p&gt;
&lt;pre class=&quot;astro-code synthwave-84&quot; style=&quot;background-color:#262335;color:#bbbbbb; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;yaml&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#72F1B8&quot;&gt;version&lt;/span&gt;&lt;span style=&quot;color:#B6B1B1&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#FF8B39&quot;&gt; &quot;3.7&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#72F1B8&quot;&gt;services&lt;/span&gt;&lt;span style=&quot;color:#B6B1B1&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#72F1B8&quot;&gt;    awesome-project&lt;/span&gt;&lt;span style=&quot;color:#B6B1B1&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#72F1B8&quot;&gt;        build&lt;/span&gt;&lt;span style=&quot;color:#B6B1B1&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; ../../PHP/7.2/fpm&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#72F1B8&quot;&gt;        image&lt;/span&gt;&lt;span style=&quot;color:#B6B1B1&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; josepostiga/php:7.2-fpm&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#72F1B8&quot;&gt;        user&lt;/span&gt;&lt;span style=&quot;color:#B6B1B1&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#FF8B39&quot;&gt; &quot;1000:1000&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#72F1B8&quot;&gt;        expose&lt;/span&gt;&lt;span style=&quot;color:#B6B1B1&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;            - &lt;/span&gt;&lt;span style=&quot;color:#F97E72&quot;&gt;9000&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#72F1B8&quot;&gt;        volumes&lt;/span&gt;&lt;span style=&quot;color:#B6B1B1&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;            - &lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;~/Code:/var/www/html&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#72F1B8&quot;&gt;        restart&lt;/span&gt;&lt;span style=&quot;color:#B6B1B1&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; unless-stopped&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#72F1B8&quot;&gt;        networks&lt;/span&gt;&lt;span style=&quot;color:#B6B1B1&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;            - &lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;web&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;            - &lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;app&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#72F1B8&quot;&gt;networks&lt;/span&gt;&lt;span style=&quot;color:#B6B1B1&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#72F1B8&quot;&gt;    app&lt;/span&gt;&lt;span style=&quot;color:#B6B1B1&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#72F1B8&quot;&gt;    web&lt;/span&gt;&lt;span style=&quot;color:#B6B1B1&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#72F1B8&quot;&gt;        external&lt;/span&gt;&lt;span style=&quot;color:#B6B1B1&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#F97E72&quot;&gt; true&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Contrary to what you may find on various online articles, there’s no HTTP server service definition. Like I said, there’s no need, since we already have it prepared to handle many projects.&lt;/p&gt;
&lt;p&gt;But let’s break this file, shall we? This file defines that we’ll have a PHP 7.2 container, that’ll be executing under a mapped user within system’s ID/GROUP 1000 (remember these section, from before?), that exposes port 9000 to the host. Also, it has the host’s &lt;code&gt;Code&lt;/code&gt; folder mapped to the container’s &lt;code&gt;/var/www/html&lt;/code&gt; folder (that’s where your code will exist), will always restart unless we issue a command to stop it (voluntarily) and has access to two networks: the &lt;code&gt;web&lt;/code&gt; and &lt;code&gt;app&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Take a moment to sink this information in…&lt;/p&gt;
&lt;p&gt;Have you wondered why it has two networks defined? Allow me to explain: it’s to separate and isolate access to services that only concerns this stack. For example, the database container should not be on the &lt;code&gt;web&lt;/code&gt; network, because there’s another container, the NGINX one, that also has access to that network. Does it makes sense to have them both on the same layer? No. We’re simply talking about development environment, here, but it’s not difficult to imagine a similar stack deployed on production. Having unrelated services accessing the same network is a bad habit, because anyone with access to your NGINX container can, too, have access to your database container.&lt;/p&gt;
&lt;p&gt;It’s a good habit to think about proper boundaries on your services and limit access where it’s not needed. So, the &lt;code&gt;web&lt;/code&gt;network allows the NGINX container communicate with this PHP container and the &lt;code&gt;app&lt;/code&gt; network allows this PHP container to access other, more reserved, services (like a database). You can add as many networks as you may see fit. Also, since the &lt;code&gt;app&lt;/code&gt; network is not marked as &lt;code&gt;external&lt;/code&gt;, Docker will have it namespaced to this stack, only, and even if you have the same name on any other project, they will not be able to access each other’s services. It’s a neat security feature, built-in with Docker itself.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;all-together-now&quot;&gt;&lt;strong&gt;All together, now!&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;Ok, now that we have both the reverse proxy and a project’s container to serve, we need to understand how that all fits together and enable communications between the two services.&lt;/p&gt;
&lt;p&gt;When a request comes to NGINX, it’ll scan it to determine which domain it needs to route the request to the correct container. This happens on, what NGINX calls it, the server blocks. That’s why I’ve mapped a &lt;code&gt;conf&lt;/code&gt; folder on the NGINX container: that’s the folder that will contain all the dedicated projects configuration files. Here’s an example of such file:&lt;/p&gt;
&lt;pre class=&quot;astro-code synthwave-84&quot; style=&quot;background-color:#262335;color:#bbbbbb; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;plaintext&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;server {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;    server_name awesome-project.test;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;    listen 80;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;    root /var/www/html/awesome-project/public;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;    location / {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;        try_files $uri $uri/ /index.php?$query_string;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;    location = /favicon.ico { log_not_found off; access_log off; }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;    location = /robots.txt { log_not_found off; access_log off; }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;    error_page 404 /index.php;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;    location ~ \.php$ {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;        set $upstream awesome-project:9000;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;        fastcgi_split_path_info ^(.+\.php)(/.+)$;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;        fastcgi_pass $upstream;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;        include fastcgi_params;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;As you can see, this server block configuration file is set to handle requests for an &lt;code&gt;awesome-project.test&lt;/code&gt; domain. So, when a request comes from that domain, the NGINX container will look on the defined root folder for any file that matches the first &lt;code&gt;location&lt;/code&gt; definition. Assuming that it finds one that matches one of the patterns set, it’ll then scan all of the remaining &lt;code&gt;location&lt;/code&gt; definitions (on this example file, there’s one more) and if it can match the pattern (which is looking for any file ending in &lt;code&gt;.php&lt;/code&gt;), then it executes the corresponding block instructions. And is in this second &lt;code&gt;location&lt;/code&gt;block that all the magic happen.&lt;/p&gt;
&lt;p&gt;First and foremost, we’re setting a &lt;code&gt;container:port&lt;/code&gt; mapping in a variable, &lt;code&gt;$upstream&lt;/code&gt;. This is a very important part of the configuration, which avoids NGINX to malfunction, and enter a restart loop, if the container happens to not been started yet. If that would happen, all other projects that it may be responsible to handle wouldn’t be processed!&lt;/p&gt;
&lt;p&gt;After calcuating, and successfully resolving the project’s container, NGINX compiles the path info and request, passing it to the destination container, through the defined port. After this, the PHP container will pick up the call, execute the code and return the response back to NGINX to be outputted to the user.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;extra-points-utility-scripts-for-daily-usage&quot;&gt;&lt;strong&gt;Extra points: utility scripts for daily usage&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;Remember the &lt;code&gt;Scripts&lt;/code&gt; folder? As I’ve said before, that folder contains several scripts I use to perform a lot of common tasks on my day-to-day work. By copying them to a &lt;code&gt;bin&lt;/code&gt; folder, I can simulate the behaviour of any program as if it was installed on my computer, but, in fact, I’m running them in isolation, through a Docker container.&lt;/p&gt;
&lt;p&gt;For example, the command to run Composer, which is a dependency manager for PHP, is the following:&lt;/p&gt;
&lt;pre class=&quot;astro-code synthwave-84&quot; style=&quot;background-color:#262335;color:#bbbbbb; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;bash&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#848BBD;font-style:italic&quot;&gt;#!/bin/sh&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FE4450&quot;&gt;docker&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; run&lt;/span&gt;&lt;span style=&quot;color:#F97E72&quot;&gt; --rm&lt;/span&gt;&lt;span style=&quot;color:#F97E72&quot;&gt; -ti&lt;/span&gt;&lt;span style=&quot;color:#F97E72&quot;&gt; --user&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; $(&lt;/span&gt;&lt;span style=&quot;color:#FE4450&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color:#F97E72&quot;&gt; -u&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;$(&lt;/span&gt;&lt;span style=&quot;color:#FE4450&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color:#F97E72&quot;&gt; -g&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#36F9F6&quot;&gt;\&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F97E72&quot;&gt;    --volume&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; ~/.config/composer:/tmp&lt;/span&gt;&lt;span style=&quot;color:#36F9F6&quot;&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F97E72&quot;&gt;    --volume&lt;/span&gt;&lt;span style=&quot;color:#FF7EDB&quot;&gt; $SSH_AUTH_SOCK&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;:/ssh-auth.sock&lt;/span&gt;&lt;span style=&quot;color:#36F9F6&quot;&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F97E72&quot;&gt;    --volume&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; /etc/passwd:/etc/passwd:ro&lt;/span&gt;&lt;span style=&quot;color:#36F9F6&quot;&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F97E72&quot;&gt;    --volume&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; /etc/group:/etc/group:ro&lt;/span&gt;&lt;span style=&quot;color:#36F9F6&quot;&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F97E72&quot;&gt;    --volume&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; $(&lt;/span&gt;&lt;span style=&quot;color:#36F9F6&quot;&gt;pwd&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;:/app&lt;/span&gt;&lt;span style=&quot;color:#36F9F6&quot;&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F97E72&quot;&gt;    --env&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; SSH_AUTH_SOCK=/ssh-auth.sock&lt;/span&gt;&lt;span style=&quot;color:#36F9F6&quot;&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;    composer&lt;/span&gt;&lt;span style=&quot;color:#FF7EDB;font-style:italic&quot;&gt; $@&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;With this, I can run any composer command exactly as I would if I installed it on my computer, but without needing to install PHP and all it’s required dependencies. I just do &lt;code&gt;composer install&lt;/code&gt; or &lt;code&gt;composer update&lt;/code&gt; and be done with the task. This script can even access my SSH keys to authenticate the requests on private repositories.&lt;/p&gt;
&lt;p&gt;Here’s another example, this time for running Yarn, a dependency manager for Javascript based projects:&lt;/p&gt;
&lt;pre class=&quot;astro-code synthwave-84&quot; style=&quot;background-color:#262335;color:#bbbbbb; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;bash&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#848BBD;font-style:italic&quot;&gt;#!/bin/sh&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FE4450&quot;&gt;docker&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; run&lt;/span&gt;&lt;span style=&quot;color:#F97E72&quot;&gt; --rm&lt;/span&gt;&lt;span style=&quot;color:#F97E72&quot;&gt; -ti&lt;/span&gt;&lt;span style=&quot;color:#F97E72&quot;&gt; --user&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; $(&lt;/span&gt;&lt;span style=&quot;color:#FE4450&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color:#F97E72&quot;&gt; -u&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;$(&lt;/span&gt;&lt;span style=&quot;color:#FE4450&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color:#F97E72&quot;&gt; -g&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#36F9F6&quot;&gt;\&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F97E72&quot;&gt;    --volume&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; $(&lt;/span&gt;&lt;span style=&quot;color:#36F9F6&quot;&gt;pwd&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;:/usr/src/app&lt;/span&gt;&lt;span style=&quot;color:#36F9F6&quot;&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F97E72&quot;&gt;    -w&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; /usr/src/app&lt;/span&gt;&lt;span style=&quot;color:#36F9F6&quot;&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;    node&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; yarn&lt;/span&gt;&lt;span style=&quot;color:#FF7EDB;font-style:italic&quot;&gt; $@&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And I run it with a simple &lt;code&gt;yarn {my command here}&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;This works absolutely perfect and without any hassle whatsoever. If I end up not need a script, anymore, I simply remove it from my computer with a simple &lt;code&gt;rm {script file path}&lt;/code&gt; and that’s it! No unnecessary dependencies lying around on my computer.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;thats-it&quot;&gt;&lt;strong&gt;That’s it!&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;Well done! You now have the necessary information to be able to create a smooth infrastructure, just like me! You’ve learned how to put different containers to communicate with each other, how to use a single NGINX container to reverse-proxy, and serve, as many projects as you need and, on top of that, you learned that you can use containers to run your everyday scripts and not needing to worry if its installed on your current working computer.&lt;/p&gt;
&lt;p&gt;Hope you’ve enjoyed the article. If you have any question, feel free to contact me on &lt;a href=&quot;https://twitter.com/josepostiga&quot;&gt;Twitter&lt;/a&gt;. I’m more than happy to help you with any difficulty you may have while applying the knowledge available on this article.&lt;/p&gt;
</content:encoded><category>Articles</category><category>Docker</category></item><item><title>Using Deployer on a Docker container</title><link>https://josepostiga.com/writing/using-deployer-on-a-docker-container/</link><guid isPermaLink="true">https://josepostiga.com/writing/using-deployer-on-a-docker-container/</guid><description>A few days back I had the need to run Deployer, a deployment tool for PHP, on an isolated container. This was to avoiding keeping it, as a dependency, on a project that needed to be constantly tested…</description><pubDate>Sat, 08 Jun 2019 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;A few days back I had the need to run &lt;a href=&quot;https://deployer.org/&quot;&gt;Deployer&lt;/a&gt;, a deployment tool for PHP, on an isolated container. This was to avoiding keeping it, as a dependency, on a project that needed to be constantly tested on a PHP version not supported by a version of the tool that needed to be run.&lt;/p&gt;
&lt;p&gt;I couldn’t simply remove the dependency, because it’s used to deploy the project to production, and I didn’t want to have it installed directly, and globally (using composer), on my computer. So, I simply created a Docker image that would have that tool pre-installed and configured, and simply execute a script that would spin up a container, run the desired command, and then self-remove after the work is done.&lt;/p&gt;
&lt;p&gt;After I got it working as expected, I thought it would be useful for others, too, so I published it on Docker Hub. You can get to the page, &lt;a href=&quot;https://hub.docker.com/r/josepostiga/deployer&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Now you too can deploy your projects without having to install Deployer either globally on your computer or as a project dependency. The only thing you need is to run the container on the same folder where your &lt;code&gt;deploy.php&lt;/code&gt; file is and everything should work as expected.&lt;/p&gt;
&lt;p&gt;If you have any questions of feedback, feel free to contact me.&lt;/p&gt;
</content:encoded><category>Journal</category><category>Docker</category></item><item><title>My interview on Ubuntu Portugal Podcast</title><link>https://josepostiga.com/writing/my-interview-on-ubuntu-portugal-podcast/</link><guid isPermaLink="true">https://josepostiga.com/writing/my-interview-on-ubuntu-portugal-podcast/</guid><description>It’s no surprise to anyone who knows me that I’ve been very disappointed with Apple’s Macintosh products. The hardware has gotten next-to-zero valuable updates, except on the prices (got higher,…</description><pubDate>Sat, 01 Jun 2019 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;It’s no surprise to anyone who knows me that I’ve been very disappointed with Apple’s Macintosh products. The hardware has gotten next-to-zero valuable updates, except on the prices (got higher, every year). Since I work mainly with web technologies, I’m exposed to Linux environments, on a daily basis, and one thing I’ve noticed is how good it has become, either for everyday work, and for gaming! In fact, it has come to a point that made possible for me to transition all my personal machines to the Linux Ubuntu distro.&lt;/p&gt;
&lt;p&gt;This complete change sparked the interest of the nice people at Ubuntu Portugal Podcast and they invited me to chat a little about the whys and hows of this complete change. You can listen to the episode &lt;a href=&quot;https://podcastubuntuportugal.org/ep-56-laravel-dingo/&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;If you like the episode, be sure to leave your love on their &lt;a href=&quot;https://twitter.com/podcastubuntupt&quot;&gt;twitter&lt;/a&gt; account.&lt;/p&gt;
</content:encoded><category>Journal</category></item><item><title>Hard reviews, JSON Schema and stream!</title><link>https://josepostiga.com/writing/hard-reviews-json-schema-and-stream/</link><guid isPermaLink="true">https://josepostiga.com/writing/hard-reviews-json-schema-and-stream/</guid><description>Hey there. How was your day? So, today, was the Sprint Retrospective. We digressed about all situations, good and bad, about this sprint. I won’t share details, of course, but we did talk about what…</description><pubDate>Fri, 15 Feb 2019 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;Hey there. How was your day?&lt;/p&gt;
&lt;p&gt;So, today, was the Sprint Retrospective. We digressed about all situations, good and bad, about this sprint. I won’t share details, of course, but we did talk about what I shared in yesterday’s article: too much optimism. Everybody agreed on being more realistic. By the end of the retrospective, we came up with a pretty solid plan so that it won’t happen again. We’re always learning, we’r enot perfect. But we’re still an awesome Team. 🐱‍🏍&lt;/p&gt;
&lt;p&gt;After that, Gonçalo presented the Team with a tech talk about JSON Schema. I’ve never really took the time to be familiar with the RFCs presented, but I was very impressed about the potentialities of integrating this with our API. If I had to bet money I would bet that Gonçalo is already investigating about how to do it, gradually. 😏&lt;/p&gt;
&lt;p&gt;On another topic, I’m very tempted to start a streaming channel on Twitch, every Saturday afternoon, were I’d be working on pet projects or other programming related stuff. I’ve always fantasised about streaming myself working. However, if I do it, it’ll be completely in portuguese, my main language. I think portuguese audience needs content on our mother language and I’m willing to do it, just for the sake of it.&lt;/p&gt;
&lt;p&gt;What you think? Would you be interested in watching me work and interact with me? I have to admit, in advance, that I don’t have the best equipment to stream (I only have a very low budget webcam) so the sound and video quality will be a little low, at least for the first few episodes while I see if it sparks any real interest of the portuguese public.&lt;/p&gt;
&lt;p&gt;Anyway, to finish today’s blog post, I have to talk about this daily blog posts. I got to say I was not expecting that anyone would find interest in reading this. I don’t plan the content of these articles. I just… Write! However, I’ve been receiving nice feedback from a few readers. It’s nice to know. I accept critiques, also, so if you have anything to say, ping me on &lt;a href=&quot;https://twitter.com/josepostiga&quot;&gt;Twitter&lt;/a&gt;.&lt;/p&gt;
</content:encoded><category>Journal</category></item><item><title>Developers and story points</title><link>https://josepostiga.com/writing/developers-and-story-points/</link><guid isPermaLink="true">https://josepostiga.com/writing/developers-and-story-points/</guid><description>Hey there! How was your day? Another interesting conversation between the Team, at Infraspeak, today. We discussed why our story points’ estimates were constantly off. We program each Sprint to…</description><pubDate>Thu, 14 Feb 2019 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;Hey there! How was your day?&lt;/p&gt;
&lt;p&gt;Another interesting conversation between the Team, at Infraspeak, today. We discussed why our story points’ estimates were constantly off. We program each Sprint to fulfill around 130 story points (team wise for a cycle of 3 weeks for a total of 8 enginners split between backend, frontend, mobile and integrations). This should not be too much, but we’re always falling (very) short against our own estimates.&lt;/p&gt;
&lt;p&gt;While analyzing our Burndown Chart, Gonçalo noticed that we barely pulled the work line down, even though we have a lot of bugs, features, and an awesome Epic coming out this Sprint (the report me, Ricardo and João have been working). Looks like the Team had an overly optimistic sprint planning. You know how programmers are when it comes to planning and estimating: it’s all very quick, simple changes, but we keep missing the details, where we invest most of the time. Another problem is the fact that we haven’t mentalized, yet, that the issue is not really closed after opening the pull request and yet, maybe unconsciously, we think the work is done, and that now is time for the reviewers and QA people to deal with the rest. And that’s simply not true…&lt;/p&gt;
&lt;p&gt;So, we decided to change this, for good. Starting at next sprint, we’ve decided to check, at every daily stand-up, everyone’s tasks, especially those that are, or passed, the Code Review stage, to force, sort of speak, each one of us to be more sensible and try to close as many tasks as possible during the sprint and not on the last day, which has been the norm so far.&lt;/p&gt;
&lt;p&gt;I even proposed that we began to be a little more pessimistic in our poker planning (that planning phase were we attribute points to each task to be done) but the rest of the Team though that was not necessary. I still think it’s something we should do because we can always have a bug to fix or other unplanned situation and a little extra time to do it helps so to not disturb the current plan.&lt;/p&gt;
&lt;p&gt;Let’s see what’s going to happen.&lt;/p&gt;
</content:encoded><category>Journal</category></item><item><title>Sprint’s final sprint</title><link>https://josepostiga.com/writing/sprints-final-sprint/</link><guid isPermaLink="true">https://josepostiga.com/writing/sprints-final-sprint/</guid><description>Hey there, how was your day? Today I continued my work on the report class. I don’t think I’ve said this before but this is the main feature to be dispatched this Sprint (the Epic). I started talking…</description><pubDate>Wed, 13 Feb 2019 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;Hey there, how was your day?&lt;/p&gt;
&lt;p&gt;Today I continued my work on the report class. I don’t think I’ve said this before but this is the main feature to be dispatched this Sprint (the Epic). I started talking with João, my team leader, about my difficulties until today, mainly because of the domain logic I’m still lacking. He, graciously, made himself available to help me and Ricardo, by supervising and helping us, ad-hoc, with the domain logic necessary to unlock us. Always with the sensibility to not do anything for us, besides consulting. This is key.&lt;/p&gt;
&lt;p&gt;I haven’t seen this in a long time. It shows that there’s attention to not giving us all the answers, right away, but to make sure that we solidify our knowledge about the domain. With his help and high coordination from the team, we were able to push most of the necessary features for the report. Tomorrow will be the day to finish the last section, still missing and create the pull request for code review and testing.&lt;/p&gt;
&lt;p&gt;One thing I’ve been able to do was to keep doing TDD and it helped me keeping track of problems in between iterations from the first solution to final refactor.&lt;/p&gt;
&lt;p&gt;I can’t wait to finish this task and get feedback from the code review. If there’s one thing that has been happening is that I’ve been learning a lot working with this team.&lt;/p&gt;
&lt;p&gt;Btw, we’re hiring! Check the positions here: &lt;a href=&quot;http://home.infraspeak.com/pt-pt/empregos&quot;&gt;http://home.infraspeak.com/pt-pt/empregos&lt;/a&gt;&lt;/p&gt;
</content:encoded><category>Journal</category></item><item><title>Reactive VS Proactive</title><link>https://josepostiga.com/writing/reactive-vs-proactive/</link><guid isPermaLink="true">https://josepostiga.com/writing/reactive-vs-proactive/</guid><description>Hey there! How was your weekend? Ready for another week full of opportunities? I had an amazing discussion with my colleague Gonçalo, today. We discussed when to be proactive and when to be reactive…</description><pubDate>Tue, 12 Feb 2019 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;Hey there! How was your weekend? Ready for another week full of opportunities?&lt;/p&gt;
&lt;p&gt;I had an amazing discussion with my colleague Gonçalo, today. We discussed when to be proactive and when to be reactive when it comes to software maintenance. I’m all about proactiveness. He was a little of both.&lt;/p&gt;
&lt;p&gt;My arguments were that, if we detected a situation that still isn’t a big problem, we should always plan to implement the necessary solution to avoid it becoming a big problem. He mostly agreed but said that when working on a business, the primary objective is to deliver value to the customer, to allow for the company to capture more investment and, when there’s a little more time, or the problem starts to really bit our asses, then it’s when it’s addressed.&lt;/p&gt;
&lt;p&gt;He continued his arguments, saying that while some situations require immediate (sometimes urgent) attention, there’re others that can be dealt somewhere in the future, when there’s time to do it properly. With this said, he was more inclined to be more reactive while keeping an eye to the situations that could potentially escalate to real problems.&lt;/p&gt;
&lt;p&gt;Interesting ten minutes of discussion. The conclusion is that we can’t be black and white when it comes to decisions that not only affect the product but also affect the business and, so, must be moderated and strategically planned. I understand, and respect, Gonçalo’s thinking, agree to some extent, too, and accept that’s a consequence of doing business, but I know that this only means that the situations will only be dealt when there’s really no more options available (aka, to little to late).&lt;/p&gt;
&lt;p&gt;I, however, stand by my initial arguments.&lt;/p&gt;
&lt;p&gt;To avoid real problems down the road, one must handle the situations as soon as they appear. That’s why I develop with a TDD approach, for example. The time I spend creating the tests, now, will save me time, tomorrow, by keeping me away from potential regression bugs.&lt;/p&gt;
&lt;p&gt;Speaking of time and TDD, I continued developing the report class and I, finally, was able to let Ricardo access my current work branch and go ahead with the part of the integration he’s been waiting to do. This taks was not planned to take this long, but we all know there’s work that we think it’s going to be a relatively simple one, and then, only when you’re working on it, is when you notice that it’s more complicated than expected.&lt;/p&gt;
&lt;p&gt;I must admit that a great part of the time invested was me creating missing factory classes and developing the necessary unit and feature tests, as well as being the first time I’m really digging in the domain logic. I’m confident that, event knowing that the Sprint ends this Thursday, I’ll be able to finish it on time. 🤞&lt;/p&gt;
</content:encoded><category>Journal</category><category>TDD</category></item><item><title>Structures and clean code</title><link>https://josepostiga.com/writing/structures-and-clean-code/</link><guid isPermaLink="true">https://josepostiga.com/writing/structures-and-clean-code/</guid><description>Hey there! How was your weekend? Ready for another week full of opportunities? Today I started my day reading the powerful, insightful and intriguing book “Clean Code”, by Robert C. “Uncle Bob”…</description><pubDate>Mon, 11 Feb 2019 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;Hey there! How was your weekend? Ready for another week full of opportunities?&lt;/p&gt;
&lt;p&gt;Today I started my day reading the powerful, insightful and intriguing book “Clean Code”, by Robert C. “Uncle Bob” Martin. I’m still a couple chapters in but I’m already hooked on the premise of analysing code and understanding the common pitfalls of programming. The level of details and narrative shows a lot of commitment to trying to make us (programmers) more thoughtful on our daily work. I sure am learning something new at each paragraph.&lt;/p&gt;
&lt;p&gt;With all this inspiration. as soon as I entered the office, I went deep on that reporting class I’ve been working since last week. Now that I have the foundations (the “world”, as I referred on my last post), I rapidly added the tests necessary to validate the structure of that report. However, something were to keep me occupied for the most part of the morning: configurations.&lt;/p&gt;
&lt;p&gt;I had been having trouble configuring PHPstorm to run my test suite directly on it. If you have PHPstorm and have a test class opened, you can click on the green arrow, on the left side of the test function’s name, and let the IDE run the test through PHPUnit and output the result. After the first run (which should fail) you can rapidly re-execute it by clicking ctrl+F5 (on Windows/Linux). This workflow is better than going to the console, accessing the history to show past executed commands and run the command to test a function/entire class. And so, I spent the next hour and a half configuring a remote PHP interpreter with Docker, configuring PHPUnit to use a custom configuration file (under the tests folder) and going back and forth with little mistakes, along the way.&lt;/p&gt;
&lt;p&gt;After I got it to work properly, I started creating the different tests for each important part of the report’s response structure. I knew I could use two special functions, for this: “assertJsonStructure()” and “assertJsonFragment()”. I’ve never used them much, before, but the work I was doing was a perfect use case for these functions.&lt;/p&gt;
&lt;p&gt;By using the “assertJsonStructure()”, I can validate that a given response has the required structure, by checking if the defined keys are present. On the other hand, “assertJsonFragment()” validates that the response contains the given information, by checking not only the keys but also its values. &lt;/p&gt;
&lt;p&gt;As you can see, the “AssertJsonStructure()” is checking the response of the “getJson()” for the existence of the keys I defined as required. Now note that I’m not checking the keys’ values, but only that the structure is as defined. The values are checked on the “assertJsonFragment()” where it’s checked that the response has the given fragment somewhere. Alone, these assertions are prone to false positives but together they make a pretty good enforcing of the necessary structure of the response. Pretty neat, I think!&lt;/p&gt;
&lt;p&gt;I’m yet to finish this, but I can say I’m halfway through it. The best of all, I’ve been refactoring my solution along the way, and the tests let me do it with confidence that I won’t break anything. Awesome!&lt;/p&gt;
&lt;p&gt;But let’s talk about another thing, now: HUB. I’ve worked on it, this weekend. I finally finished the feature tests for the user’s profile update and also finished the create and update part of the CRUD functionality. I’m on the delete part, the last one before finishing this module. Another thing I’ve done, too, is to change the project, a little bit. I will be creating this as an API first software (or headless, one term you might already hear of). This decision will remove the need to think of a design to ship with the product when I release it to the World (MIT licensed). This way, anyone can create the frontend on their preferred technology. Also, as a bonus, when I finish the API part, I can practice the frontend part myself, as a separate project.&lt;/p&gt;
</content:encoded><category>Journal</category></item><item><title>Small, firm, steps</title><link>https://josepostiga.com/writing/small-firm-steps/</link><guid isPermaLink="true">https://josepostiga.com/writing/small-firm-steps/</guid><description>Hey there! What have you been up to? I passed all day working on a report class, which will be responsible to fetch, and process, all maintenance work done in a building (or a set of buildings). It…</description><pubDate>Sat, 09 Feb 2019 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;Hey there! What have you been up to?&lt;/p&gt;
&lt;p&gt;I passed all day working on a report class, which will be responsible to fetch, and process, all maintenance work done in a building (or a set of buildings). It has been a challenge, not for the task, itself, but the domain logic I need to know before even start to make the queries.&lt;/p&gt;
&lt;p&gt;The most part of my day was about understanding all the dependencies associated with an entity, how their operator permissions influence the model scopes and how to associate them. I identified a few factories that needed to be created and got to the end of the day with a working first feature test: checking that the route was reachable. It looks simples but, to that simple test to work, all the “world” needed to be mapped and set up before the assertion runs and that was the bulk of the work.&lt;/p&gt;
&lt;p&gt;Monday I’ll be solely focused on the queries and JSON response to pass the task back to my teammate Ricardo, which will be responsible to connect it to the view that’ll be used to generate the PDF.&lt;/p&gt;
&lt;p&gt;I could have gone much faster if I skipped all the testing part, and some would say it was ok to do that, but it was not! I understand that shipping features is very important, but I can’t jeopardise the quality of the code, especially when I still don’t master all the domain logic, or I risk injecting bugs or not catch other people’s bugs before being pushed to production. It’s best to be a little slow, at first, but then get a quality solution that works as designed and is tested.&lt;/p&gt;
&lt;p&gt;On another topic, I read a very good article about MVP (Minimum Viable Product), where the author explained why he hated MVP, as well as customers hates it, too! He showed some very good points and I think you should read it, too. You can access the article here: &lt;a href=&quot;https://blog.asmartbear.com/slc.html&quot;&gt;https://blog.asmartbear.com/slc.html&lt;/a&gt;&lt;/p&gt;
</content:encoded><category>Journal</category></item><item><title>Normalization and mocks</title><link>https://josepostiga.com/writing/normalization-and-mocks/</link><guid isPermaLink="true">https://josepostiga.com/writing/normalization-and-mocks/</guid><description>I finally finished all my tasks regarding the implementation of the code sniffers and fixers on all my teammates’ computers and advanced to other, more challenging tasks. The one I’m currently…</description><pubDate>Fri, 08 Feb 2019 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;I finally finished all my tasks regarding the implementation of the code sniffers and fixers on all my teammates’ computers and advanced to other, more challenging tasks. The one I’m currently working on is related to reports generation.&lt;/p&gt;
&lt;p&gt;Since reports are a very sensitive part of our software, I started unit testing a specific report class, making sure that it behaves as expected, returning the required, basic, information (like the report’s name, configuration) and got to the part of ensuring the right methods are called to generate a PDF. I stopped… The report classes use a third-party library to handle the generation of the PDF file and, to generate a file, at the very least, one method needed to be called. How could I ensure that that method was, in fact, called, without testing the third party code, itself?&lt;/p&gt;
&lt;p&gt;Like I said before, I’m not an expert on TDD, but I know enough to answer this: we Mock that behaviour, creating the expectation required to ensure that a certain method(s) is(are) called. On this particular case, I needed to ensure that some options were set and that the method to load a view, to be generated as a PDF, was called. So I started mocking the behaviour, setting the required expectations.&lt;/p&gt;
&lt;p&gt;When I tried to run the test, it broke… But, why? Going through the output of the error, I got the feedback that the class was being mocked more than once. Ok, but how? I went finding more information about the error message returned, on our lord and saviour Google. It turned out that Laravel Façades already have it activated when running in a test environment. Always learning, hein? I thought it’s pretty cool. After removing the mocking definition, the “Mockery::mock(Foo::class)” part, tests went green! Right on time to commit the work in progress and leave for the day.&lt;/p&gt;
&lt;p&gt;On our beloved HUB project, as I promised, I have advanced to the next part of the development of the users’ module. I switched from unit tests to feature tests, where I began testing the creation of a user account. While doing this, I started implementing the repository class, too.&lt;/p&gt;
&lt;p&gt;It’s incredible how little code can test so many parts of the software: the existence of the correct endpoint, the request validated input, the lack of errors on session, the correct redirection to the users’ index page, that it only may be done by someone logged in and that the record is, in fact, saved to the persistent layer (thus, it tests that the repository class does communicate to this layer). Perfect!&lt;/p&gt;
&lt;p&gt;Of course, it’s incomplete. It’s a work in progress and, so far, I only implemented the save method. Laravel’s Service Container makes dependency injection so easy it’s hard to belive that just by type-hinting the correct model class, in the constructor, is enough to connect it to the repository class and use the underlying behaviour.&lt;/p&gt;
&lt;p&gt;Tomorrow I’ll work through the rest of this users’ module. 🤓&lt;/p&gt;
</content:encoded><category>Journal</category></item><item><title>Keep calm and TDD</title><link>https://josepostiga.com/writing/keep-calm-and-tdd/</link><guid isPermaLink="true">https://josepostiga.com/writing/keep-calm-and-tdd/</guid><description>Today was a very calm day. I finally confirmed that the code sniffers and fixers are configured on all of my teammates’ computers. I continue observing how they’re reacting to the new development…</description><pubDate>Thu, 07 Feb 2019 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;Today was a very calm day. I finally confirmed that the code sniffers and fixers are configured on all of my teammates’ computers. I continue observing how they’re reacting to the new development process, with the pull requests, code reviews and PSR-2 compliant code. So far, so good. I’m really proud of their effort. 👌&lt;/p&gt;
&lt;p&gt;The most noteworthy part of the day was right after lunch when my colleague Luis Bessa came to me to ask me about how to start using TDD. I tried to give him a crash course about the thinking process: first, break the problem in little steps, then stub any dependencies that are required to exist for the test to run (for example, any entity and/or relations) and then using the right assertions for the required result. During this crash course, I showed him some examples of unit and feature tests, explaining, line by line, what was happening. Finally, I referred him to Laracasts, a very good project with several courses about TDD.&lt;/p&gt;
&lt;p&gt;Besides this, I haven’t had time to advance on the HUB project, unfortunately. However, I promise I will have news tomorrow! 🤞&lt;/p&gt;
</content:encoded><category>Journal</category></item><item><title>The first feedback</title><link>https://josepostiga.com/writing/the-first-feedback/</link><guid isPermaLink="true">https://josepostiga.com/writing/the-first-feedback/</guid><description>Today was an interesting day. I found out I already have a (very) small audience! I’ve been aware that a few of my colleagues, including my CTO, Luis Martins, have been reading my posts. He (Luis),…</description><pubDate>Wed, 06 Feb 2019 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;Today was an interesting day. I found out I already have a (very) small audience! I’ve been aware that a few of my colleagues, including my CTO, Luis Martins, have been reading my posts. He (Luis), in fact, call to my attention on a tech detail (an error regarding my statement about low performant table views) it felt good to know that he cared enough to correct me. It felt really good.&lt;/p&gt;
&lt;p&gt;Regarding my working day, it was one of those days that nothing really special happened. I spent most of my day reviewing pull requests and pressing my team leader, João, to finish the review on mine. I did have time, however, to watch how my teammates are reacting to the new code review process. It’s funny to see them adjusting and be mad with the extra steps and waiting time between reviews and merge. When I say mad, I’m not saying on a bad connotation. It’s the normal friction with change. They might not see, yet, how their life will be easier, and their work will start to be deployed with more quality and bugs will be prevented. However, if they’re like this with this basic change, let’s wait when we get to the point where tests will need to exist on every PR. 😂&lt;/p&gt;
&lt;p&gt;Nevertheless, I’m really proud of them. Besides all the “noise”, they’re really trying to adjust as quickly as possible. Kudos to them! 👌 This is what separates script kiddies from real programmers: how far are they willing to go for the greater good. So far, I’m not disappointed.&lt;/p&gt;
&lt;p&gt;On another topic, I’ve not made any advances on the HUB project, since today I needed to handle a situation regarding my utility contract. Small details that consume a lot of time. Time that I already have very little…&lt;/p&gt;
&lt;p&gt;Let’s hope tomorrow is a more interesting day!&lt;/p&gt;
</content:encoded><category>Journal</category></item><item><title>Documentation and self-doubting</title><link>https://josepostiga.com/writing/documentation-and-self-doubting/</link><guid isPermaLink="true">https://josepostiga.com/writing/documentation-and-self-doubting/</guid><description>The main tasks assigned to me are associated with documenting and helping my teammates implement code sniffers and fixers, to help keep our codebase in line with the current PSR-2 standard. So, as…</description><pubDate>Mon, 04 Feb 2019 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;The main tasks assigned to me are associated with documenting and helping my teammates implement code sniffers and fixers, to help keep our codebase in line with the current PSR-2 standard. So, as part of that work, I’ve been updating our internal documentation with the steps required to implement the necessary tools and processes so that everyone can configure them on their IDE/Code Editor.&lt;/p&gt;
&lt;p&gt;The tools we’ll be using are PHP CodeSniffer (phpcs) and PHP Code Beautifier and Fixer (phpcbf) and, since we use Docker in development, I needed to make sure those commands can be used both for every IDE/Code Editor, currently in use on our team, and through the terminal.&lt;/p&gt;
&lt;p&gt;It was a fun work to do, because I had to learn about how Sublime Text’s Phpcs plugin works, which order of arguments it uses and use shell scripts to run the command on a Docker container. The same for Visual Studio Code, although for this one I learnt that there’s no “native” script that could be used to handle the shell scripts so I had to find a workaround with “Save and Run” plugin, which executes commands after a file is saved.&lt;/p&gt;
&lt;p&gt;I learnt how to properly use the dirname script to fetch the file to handle and map, as a volume, to a PHP docker container with PHP CodeSniffer installed. I thought it would be much harder than actually was.&lt;/p&gt;
&lt;p&gt;In the end, I manage to see it quickly implemented on, at least, my team mate’s Ricardo dev environment. It worked flawlessly. And, now, is fully documented, which will benefit any other new team member that’d join us, in the future. He/She just needs to follow the steps and have it properly configured in no time!&lt;/p&gt;
&lt;p&gt;You probably have heard of this, before, but documentation is very important. It consumes a lot of time, for sure, but it helps not only to consolidate our knowledge but can be used as a reference for other people. It makes all the difference, be it whatever type of project. Document everything!&lt;/p&gt;
&lt;p&gt;On another topic, I’d like to update you all on the HUB project. I had a little discussion with myself, regarding how to properly unit test a class that relies on relations with other classes. All because I had some input, from a few colleagues, telling me that I should not test what I did not own. They were talking about the screenshot I shared on a previous post, where I was almost testing the Collection class’ behaviour (which was a little overkill) but I transported that feedback to the work I was doing (testing the existence of a certain set of relations) and was doubting myself. Would it be best to do it or should I trust that the relations were there and fully functional?&lt;/p&gt;
&lt;p&gt;After thinking about it, I got to the conclusion that it makes perfect sense to test, even in unit testing, that the required relations do, in fact, exist, and even that they return the right instance of the objects (e.g.: a Collection).&lt;/p&gt;
&lt;p&gt;You might think I was too involved in details but, as the saying goes: “The Devil is in the details”.&lt;/p&gt;
</content:encoded><category>Journal</category></item><item><title>It’s Friday and I’m thinking about repositories!</title><link>https://josepostiga.com/writing/its-friday-and-im-thinking-about-repositories/</link><guid isPermaLink="true">https://josepostiga.com/writing/its-friday-and-im-thinking-about-repositories/</guid><description>Everybody loves Friday, right? I’ve no special reaction to Friday, really. I love what I do, so I’m always enjoying my days. However, weekends are when I spend a little more time studying and…</description><pubDate>Sat, 02 Feb 2019 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;Everybody loves Friday, right? I’ve no special reaction to Friday, really. I love what I do, so I’m always enjoying my days. However, weekends are when I spend a little more time studying and training. I think that continue improving and challenging ourselves is very important to keep being relevant in our work. Especially if you want to work your way up on your career. But I digress…&lt;/p&gt;
&lt;p&gt;Since today I needed to leave the office in the afternoon, I don’t have many updates to share. I finally get to see my colleagues really try to change their work process and use work branches and pull requests to privilege the sharing of knowledge. Already saw a lot of exchange happening between them. I really hope that they get used to this new process because the big results will only come a few months from now when they realize that their domain knowledge improved.&lt;/p&gt;
&lt;p&gt;Changing subjects, and on a more personal level, I’m still working on HUB, although I haven’t touched the subject in about two days. I was doubting that the unit tests were not being well done because I was creating some tests to guarantee that required relations to other models exist. In my mind, that was a violation of testing in isolation. However, after exposing my doubts to the Laravel Portugal Community, they quickly told me I was overreacting. So this project is still under heavy development. I’m about to start the first feature tests for the Users model.&lt;/p&gt;
&lt;p&gt;Talking about models, I’ve been recently thinking about Models and Repositories. If you don’t know, Repositories (from the Repositories Pattern) are classes that the main objective is to abstract the persistent layer. This way, you can exchange the persistent layer drivers without needing to change anything else on your application. Just swap the concrete implementation injected as a dependency to the related repositories and you’re golden. It’s a pretty awesome pattern to follow.&lt;/p&gt;
&lt;p&gt;So, without much surprise, HUB will have the repository pattern implemented. Besides abstraction, I can control the data flowing from the application to the persistent layer, and vice-versa, which will help me keep my models clean. Also, if needed, I can apply other types of logic against the data, without polluting the models, like a cache system.&lt;/p&gt;
&lt;p&gt;Let’s see how this weekend goes, in terms of more excited news about this project.&lt;/p&gt;
</content:encoded><category>Journal</category></item><item><title>Thematic day and a football match</title><link>https://josepostiga.com/writing/thematic-day-and-a-football-match/</link><guid isPermaLink="true">https://josepostiga.com/writing/thematic-day-and-a-football-match/</guid><description>Today was one of those nice and quiet days, where nothing really notorious happens. It was a thematic day (like a hackathon), dedicated to resolving a type of issues that have not a significant…</description><pubDate>Thu, 31 Jan 2019 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;Today was one of those nice and quiet days, where nothing really notorious happens. It was a thematic day (like a hackathon), dedicated to resolving a type of issues that have not a significant impact on our customer’s day-to-day work, but that we know that must be dealt with, sometime in the future.&lt;/p&gt;
&lt;p&gt;Today’s theme was translations. We were given a spreadsheet that had all the various inconsistencies and errors on our translations (keys missing, grammar errors, etc.) and we dedicated all day dealing with that. I decided to start a little late on that, and prioritized other tasks that were planned for me: clean dead branches from the repositories and create the new develop branch for this sprint, and run a sniffer (PHPCS) and a fixer (PHPCBF) to normalize and correct all violations of the PSR2 standard, on the main project’s repository. There were a lot but mostly was blank lines where there shouldn’t be other issues alike (like “else” statements on new lines instead of in front of the closing brace of the “if”).&lt;/p&gt;
&lt;p&gt;However, now, we can be assured that the entire project is PSR2 compliant and I can skip to the next phase: document how to integrate the sniffer and the fixer into every body’s IDE/text editor to avoid that further violations enter our repository. It looks like an unimportant task, but it’ll bring tremendous benefits to the team coding style and overall code quality. It’s a nice step in the right direction and shows our commitment to the quality of our product.&lt;/p&gt;
&lt;p&gt;After the workday, we head over to an indoor soccer field, where we enjoyed a nice match and developed a friendly game between peers. It was really cool to see the Team on a more casual scene. Not that we’re much more serious, but it’s a little different when we’re not in a work environment.&lt;/p&gt;
&lt;p&gt;Oh, before I forget, Infraspeak launched an awesome video, that the Team made to celebrate the closing of a round of investment. I think it came off as a really cool video. See for yourself:&lt;/p&gt;
&lt;div class=&quot;video&quot;&gt;&lt;iframe src=&quot;https://www.youtube-nocookie.com/embed/-2_jpT_jqdM&quot; title=&quot;YouTube video player&quot; loading=&quot;lazy&quot; allow=&quot;accelerometer; encrypted-media; gyroscope; picture-in-picture&quot; allowfullscreen&gt;&lt;/iframe&gt;&lt;/div&gt;
</content:encoded><category>Journal</category></item><item><title>BadMethodCallException and table views are performing poorly</title><link>https://josepostiga.com/writing/badmethodcallexception-and-table-views-are-performing-poorly/</link><guid isPermaLink="true">https://josepostiga.com/writing/badmethodcallexception-and-table-views-are-performing-poorly/</guid><description>Yesterday, after I published the daily blog post, I received a few e-mails regarding a pull request I made. The specific commit removed a call to Auth::login() since my tests were throwing an…</description><pubDate>Wed, 30 Jan 2019 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;Yesterday, after I published the daily blog post, I received a few e-mails regarding a pull request I made. The specific commit removed a call to Auth::login() since my tests were throwing an exception about method “login” not being found through the call to the Auth façade. We all make mistakes and I trusted that my test was right and, thus, removed the call without checking further the reason why. Stupid mistake, rightly caught by Gonçalo, which I selected as one of two reviewers, which broke the authentication with OAuth tokens.&lt;/p&gt;
&lt;p&gt;It was late, and since it was not yet on production (was on a dev branch), it could wait for the next day. So, the day came and the first thing I did after reaching the office was figuring out why that was happening. I checked everything! Which guard Laravel was configured to load, the data that was passing to the methods. Somehow, the logic was breaking, according to the stack trace, when the Macroable trait was handling the call to the login method (which, when using a façade, is called using the magic method &lt;code&gt;__call&lt;/code&gt;). I was not getting why, so I called Gonçalo to help me understand since I’ve never gone this deep on the framework internals.&lt;/p&gt;
&lt;p&gt;Even he was not understanding why it was not working, until he remembered to search for every login method call, on every project’s classes. While analysing the search results, he remembered that we had forced the injection of the login driver to use to “api” every time we call “$this-&amp;gt;actingAs()” to mock an authentication as a specific user.&lt;/p&gt;
&lt;p&gt;Laravel has, by default, two main authentication mechanisms: Session and API. However, when using the Laravel Passport package, to support OAuth authentications, we get another driver: “passport”. So, when the Auth façade was called, when using oauth tokens, Laravel will need to use the “passport” driver but, since we forced the “api” driver to be used, everything got messed up! Removing this forcing fixed the problem, tests got back to green and I even checked the authentication methods manually.&lt;/p&gt;
&lt;p&gt;Everyone messes up, sometimes. 🤷‍♂️&lt;/p&gt;
&lt;p&gt;In between this debug session, I attend the second phase of the sprint #51 planning. While discussing the issues we were planning, a colleague of mine, Gedielson (we call him Jedi), was talking about poor performance in our tables views and that we should create the SQL statements directly on our code. I’ll be honest by saying that I don’t know much about table’s views, but the feedback I had, from other professionals, was that it would never perform worst than creating the queries within our codebase. In fact, using views, we would be transferring complexity to the DBMS layer and, thus, simplifying the access to that views’ data because, then, we could use basic select statements.&lt;/p&gt;
&lt;p&gt;With that in mind, I questioned him about his statement and he explained to me that the problem was not the access of the data (the select part) but the use of views with joins to other tables and sub-queries and that was the culprid, making the database work with unnecessary effort and should be optimized using raw queries. [1]&lt;/p&gt;
&lt;p&gt;That made complete sense to me. Always learning! 😏&lt;/p&gt;
&lt;p&gt;We finish the day making the last tests against the features and improvements made during sprint #50 and deployed to production! 🚀 Sprint #50 finished with success. Now, let’s go to sprint #51!&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;[1] I was called to attention, by my colleague (and CTO) Luis, that update operations, on Table Views, don’t exist. I misunderstood the conversation I had with Jedi, when he talked about making operations on the views, when he was refering to Joins and not updates (duh). Always learning! Thank you, Luis. (edited on Feb 5 2019).&lt;/p&gt;
</content:encoded><category>Journal</category></item><item><title>Think twice</title><link>https://josepostiga.com/writing/think-twice/</link><guid isPermaLink="true">https://josepostiga.com/writing/think-twice/</guid><description>Two major things happened today: I did overpass the difficulty I talked about, on yesterday’s daily blog post, and the Team discussed the strategy for the next 3 weeks. Regarding yesterday’s problem,…</description><pubDate>Mon, 28 Jan 2019 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;Two major things happened today: I did overpass the difficulty I talked about, on yesterday’s daily blog post, and the Team discussed the strategy for the next 3 weeks.&lt;/p&gt;
&lt;p&gt;Regarding yesterday’s problem, one of my team leaders, Gonçalo, helped me find a possible solution to execute PHP CodeSniffer on a Docker container, within Sublime Text. He found this pretty quickly, which made me a little mad at myself since I, practically, wasted almost an afternoon trying to do, basically, the same thing he showed me, but I was not using the absolute path to the script. 🤦‍♂&lt;/p&gt;
&lt;p&gt;Anyway, I was relieved that we had found a solution in time to document the implementation to the rest of the Team before the start of Sprint #51. Speaking of which…&lt;/p&gt;
&lt;p&gt;Today was the first of two days that the Team at Infraspeak dedicates to designing the next sprint. I don’t know if I’ve already told you that but a Sprint is a period of time (in our case, three weeks) when we create new features and improvements to our maintenance management software. The main goal for this Sprint is to create a new type of report, regarding technical interventions in our customers’ buildings. Bogas, our designer, did a wonderful job at designing the mockups that we’ll use. Our team leaders, João and Gonçalo, presented the Epics to the Team and we began planning and classifying the issues. It was pretty neat to see how much everyone cares for the product and the UX that’ll be implemented to the customer to use.&lt;/p&gt;
&lt;p&gt;On another topic, remember that I talked about starting the development of a small pet project, a few articles back? Yep, I’ve started it! I called it HUB and it’s going to be my interpretation of an Enterprise Social Network software. It’ll handle the users and departments management, projects and respective tasks, allow co-workers to share updates on different newsfeeds, have a few specific reports to gather data for analysis and have minor notifications about new developments on projects and departments.&lt;/p&gt;
&lt;p&gt;I won’t get in too much detail, right now, and it’s not the project that matters the most. The main reason for this pet project is improving my skills as a developer. So, I set some ground rules for the development approach I’d take: TDD. Yep, Test-Driven Development! I want to be more familiar with TDD and nothing beats experience. I’m not that unfamiliar with it, because I’ve been practising it for the last year but, as they say: “Practice makes perfect” and I know that I need to be better at this.&lt;/p&gt;
&lt;p&gt;Right now, I’ve done most of the unit test of the first module I’m developing: Co-Workers and Departments Directory.&lt;/p&gt;
&lt;p&gt;So far, so good. I’ve already made like 8 tests and 21 assertions. Seeing everything pass is an awesome sensation and I’ve already learned a lot! All this are “only” unit tests, testing how a user account behaves, which required properties are needed and making sure they really exist within the object.&lt;/p&gt;
&lt;p&gt;With this method, I can ensure that the User object has the required basic info I defined when designing the whole co-worker management system. If any of these properties behave differently or cease to exist, this test will error out and warn me that I may be breaking a lot of functionality, unintentionally. Amazing!&lt;/p&gt;
&lt;p&gt;I’ll try to continue to advance on this on a daily basis, too, so it’s probably safe to say that’ll be one of the topics on these daily blog posts.&lt;/p&gt;
</content:encoded><category>Journal</category></item><item><title>A very busy start of 2019</title><link>https://josepostiga.com/writing/a-very-busy-start-of-2019/</link><guid isPermaLink="true">https://josepostiga.com/writing/a-very-busy-start-of-2019/</guid><description>Last month I announced that I’d be changing companies, leaving TBFiles and join Infraspeak. Since that, a lot more has changed in my life. First, I’ve also changed to a new house, in a neighbouring…</description><pubDate>Sun, 27 Jan 2019 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;Last month I announced that I’d be changing companies, leaving TBFiles and join Infraspeak. Since that, a lot more has changed in my life.&lt;/p&gt;
&lt;p&gt;First, I’ve also changed to a new house, in a neighbouring city. This move is a long time in the making, as I needed something with better conditions, to allow for a better quality of life. Even with the housing market inflated, I manage to found a 4 bedroom house with plenty of room for everybody and, even, to have a home office, where I plan to develop some interesting open-source projects.&lt;/p&gt;
&lt;p&gt;Before I speak about those projects, I’d like to share my experience at Infraspeak. Even though I’m still at the honeymoon phase (I’m with them, only, since the beginning of this month), but I can say that this was a very good transition for me. I’m surrounded by a very smart group of professionals, which I’m very excited to learn from and, I hope, teach something, too. The product is very good and has a real impact on the life of their users and that’s something important for me, knowing that my efforts, and work, will help people enjoy their work and be more productive and efficient.&lt;/p&gt;
&lt;p&gt;Now, about those projects. I’ve been a little away from the community, for the last month an a half, and that is “killing” me. I really want to get back to contributing to open source. So, without further ado, I want to share that I’m starting the development of a little project that I’ve been thinking about. With this, I’m thinking about blogging about it. However, the real objective is not the project itself, but is the learning and development of my own capacities as a web developer. If you learn with me, that’ll be even better!&lt;/p&gt;
</content:encoded><category>Journal</category><category>Career</category></item><item><title>I’m moving away from TBFiles</title><link>https://josepostiga.com/writing/im-moving-away-from-tbfiles/</link><guid isPermaLink="true">https://josepostiga.com/writing/im-moving-away-from-tbfiles/</guid><description>If you follow my work, you know I’ve been working on a company called TBFiles since the first trimester of this year. However, on January 2019, I’ll start working on another company: Infraspeak. In…</description><pubDate>Sat, 08 Dec 2018 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;If you follow my work, you know I’ve been working on a company called TBFiles since the first trimester of this year. However, on January 2019, I’ll start working on another company: Infraspeak.&lt;/p&gt;
&lt;p&gt;In spite of the short term I’ve been working for TBFiles, I really enjoyed it. I’ve had the opportunity to work on a big project, for a well knowm Portuguese travel agency, as weel as working on another couple of strategic, internal, services which, in a matter of fact, the CEO decided to invest and make them a top priority for the company, for the next year. However a very good job opportunity came to my attention and I couldn’t say no to it.&lt;/p&gt;
&lt;p&gt;Just to be clear, it’s not a simple matter of payment upgrade! As I’ve written before (check this article), money is not the main condition for my departure. Deciding to join Infraspeak was not a easy decision but I couldn’t let an opportunity to specialize as a Senior Backend Developer, instead of continuing as a Full Stack Web Developer. This position suits me the best and was one of the main reasons that led me to sign for them.&lt;/p&gt;
&lt;p&gt;I really liked working in TBFiles and I thank all of the people that works there, as they’ve made me feel very comfortable. All my colleagues are really interesting and friendly people, with lots of knowledge and they’re very supporting: no matter your level of expertize, they just focus on making you a better developer. Their soft-skills are really on point. That’s one of the main reasons that this team has mamange to deliver every single project ahed of time. It was the first time I saw that happening! Every sprint was meticulously fulfilled. 👏&lt;/p&gt;
&lt;p&gt;Now it’s time to focus on a new chapter of my career. Let’s see how this goes! 🤳&lt;/p&gt;
</content:encoded><category>Journal</category><category>Career</category></item><item><title>There’s more to me than money: a Career!</title><link>https://josepostiga.com/writing/theres-more-to-me-than-money-a-career/</link><guid isPermaLink="true">https://josepostiga.com/writing/theres-more-to-me-than-money-a-career/</guid><description>This is a question which I’ve discussed, many times, with colleagues and friends, and I think it’s such an interesting topic that I wanted to share my opinion with you and, in return, I’d appreciate…</description><pubDate>Tue, 31 Jul 2018 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;This is a question which I’ve discussed, many times, with colleagues and friends, and I think it’s such an interesting topic that I wanted to share my opinion with you and, in return, I’d appreciate if you shared yours. So, please, feel free to comment.&lt;/p&gt;
&lt;p&gt;Although the answer seems petty easy to predict, I would never decide only based on money. Yes, it takes a great part on my decision process, but there’s three more parameters I’ll also evaluate: 1. What’s the main vision, the mission and culture? 2. What kind of problems and challenges are they solving? 3. How does this company contributes to my own professional objectives?&lt;/p&gt;
&lt;p&gt;The answers to this questions are as important as how much will they pay me. Let me explain…&lt;/p&gt;
&lt;h2 id=&quot;the-vision-the-mission-and-the-culture&quot;&gt;&lt;strong&gt;The Vision, The Mission And The Culture&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;Lately, I’ve been hooked on &lt;a href=&quot;https://startwithwhy.com/&quot;&gt;Simon Sinek&lt;/a&gt;’s videos, on YouTube (if you don’t know him, I highly recommend you watch some of his videos). He talks about how important it is for a company’s vision (and mission) to be palpable, and how it effects their employees. He says that a well defined, tangible, goal, where people can clearly imagine that vision coming true, would make them feel more motivated to help achieve that goal.&lt;/p&gt;
&lt;p&gt;That’s why this is the first thing I analyse, when I look at an offer. I try to know and understand what’s the vision, where does this company wants to go and how can I add value to that? Where do I fit? If I don’t feel good about the culture in place, I will simply decline, period.&lt;/p&gt;
&lt;p&gt;No money in the World would make me wake up to “just” do my job. I want to be working on something that has meaning, that has a positive impact in the World. I want to be able to say “I contributed to that!” to my friends and family. I want to be proud of me and my work.&lt;/p&gt;
&lt;h2 id=&quot;the-problems-and-challenges-ahead&quot;&gt;&lt;strong&gt;The Problems And Challenges Ahead&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;The second thing I tend to look is the type of company that I’m evaluating: is it a Design Agency, a Consultancy Agency, a SaaS Company? This let’s me filter out offers from companies on which I’d take no pleasure working on.&lt;/p&gt;
&lt;p&gt;To avoid that, I tend to prefer a company that has a mix of mature projects and gives the liberty of exploring and trying new things. Bonus points if they encourage their employees work on side projects and present them as possible new solutions for the company, or it’s clients, to benefit from.&lt;/p&gt;
&lt;h2 id=&quot;so-how-does-this-all-fit-into-my-master-plan&quot;&gt;&lt;strong&gt;So, How Does This All Fit Into My Master Plan?&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;My main career objective is to be a Team Leader. It’s an awesome title to have, but that comes with big responsibilities. Being a team leader requires more than hard skills on whichever area you’re trying to lead on. It requires exceptional soft skills, like empathy and people management, for example.&lt;/p&gt;
&lt;p&gt;I definitely know I’m not yet ready to take that kind of responsibility, but I work very hard, everyday, to improve myself to, eventually, fulfill that objective. That means that I can take advantage of making myself available to be wherever it’ll help me gain the necessary experience to get to where I want to be and I may even be comfortable in getting a little pay cut if that represents a step closer to my main career objective.&lt;/p&gt;
&lt;p&gt;Again, like I said at the beginning of this article, money is still an important metric, specially for exclusion purposes. However, I found out that focusing on being a better you, on finding your true purpose and keeping doing what you love the most, will make you a more rich and fulfilled person. Happiness is king here, and I keep saying that we must position ourselves, in life, on where we really love to be, and do what we really love to do.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Because money will always follow your passion.&lt;/strong&gt; It’ll always be a part of the equation or, at the very least, a result of it.&lt;/p&gt;
</content:encoded><category>Articles</category><category>Career</category></item><item><title>How I managed to control chaos with Laravel</title><link>https://josepostiga.com/writing/how-i-managed-to-control-chaos-with-laravel/</link><guid isPermaLink="true">https://josepostiga.com/writing/how-i-managed-to-control-chaos-with-laravel/</guid><description>Automatizing fetching, normalizing and storing information from different online sources without breaking a sweat.</description><pubDate>Thu, 14 Jun 2018 00:00:00 GMT</pubDate><content:encoded>&lt;h2 id=&quot;a-little-of-context&quot;&gt;&lt;strong&gt;A little of context&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;At the time of writing this post, I’m a Full-Stack Web Developer @ TBFiles, a Portuguese company with operations also in Angola and Mozambique. Our core business is dematerialization, workflow design and optimization of documents and digital processes. We help our customers transferring offline information (documents, forms, processes in general). By using digital processes, instead of physical documents, our customers save time, space (because they don’t have to deal with physical archives) and keeps all information accessible through a single application, in a friendly, searchable and scalable way.&lt;/p&gt;
&lt;p&gt;This kind of service, however, requires that we support data collection and extraction using different technologies (like FTP, e-mail and third-party web-services) with very distinctive nuances that comes with each customer having its own ways of organizing information.&lt;/p&gt;
&lt;h2 id=&quot;the-chaos&quot;&gt;&lt;strong&gt;The Chaos&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;Up until now, whenever a new customer subscribed to our “Digital Archive” product, our team would have to create a specific PHP script that would connect to whichever systems this customer uses, import the required data to index, deal with the specific logic of extracting and saving in our infrastructure and then display that information in our application. This work could take some time, depending on the client’s specifications, number and type of systems we’d need to handle and if our team would need to coordinate with third-party tech teams, to number a few…&lt;/p&gt;
&lt;p&gt;This was manageable but, as everything else, when we got to a serious number of customers using this service, this type of workflow began to backfire.&lt;/p&gt;
&lt;p&gt;One might ask: “But didn’t anyone in that team thought about scaling when developing the service?”. To which I answer: “Of course! But there’s something called Management, it’s friend Delivery Date and their lawyer called Pressure”. Jokes aside, the first step taken was to create this fast, so it could be tested and proved to be a viable business.&lt;/p&gt;
&lt;p&gt;Having proved that, in fact, it was a good product, our team gathered to discuss how we could manage the chaos that was starting to be. And we needed to move fast, because Management’s lawyer (The Pressure) never left the building, and we found out that Deliver Date had a twin…&lt;/p&gt;
&lt;h2 id=&quot;getting-the-party-started&quot;&gt;&lt;strong&gt;Getting The Party Started!&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;After a quick team brainstorming, we came to the conclusion that we had to develop a two step process: a Collector, for fetching information, and an Extractor, to handle data extraction and send it to our main application’s persistent layer, to be available to our customers.&lt;/p&gt;
&lt;p&gt;I was put in charge of developing the Collector part, and another colleague was in charge of developing the Extractor. I was pretty excited! I was the newest member of the team and already got assigned this kind of responsibility. I immediately got to work.&lt;/p&gt;
&lt;p&gt;The requirements for the Collector were: * It must be capable of connecting to all the data sources that the company currently supports (e-mail inboxes, FTP file repositories and Shared Directories) and save all found information, structuring it in a normalized way and storing it for posterity. * It must have a web UI to allow non tech users to access and configure data buckets (a repository of a type of data, e.g.: an e-mail bucket), set rules that would allow the system to know exactly what to import and a few post-import actions for clean-up work afterwards. * It must have an API layer to allow other internal services to access data for specific processing and other business logic that may be needed.&lt;/p&gt;
&lt;p&gt;That’s it. Those three bullet points were the main requisites for my part of the system. Deliver Date was set for two weeks after initial kick-off.&lt;/p&gt;
&lt;h2 id=&quot;choosing-the-tool-for-the-job&quot;&gt;&lt;strong&gt;Choosing The Tool For The Job&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;Two weeks was a challenge… I needed to get my part done, and then test the result alongside my colleague’s. To be able to deliver a good, robust application it immediately came to my mind the Laravel framework. I didn’t even think twice: I’ve had used it successfully on another project, before this one, and loved the experience, thanks to it’s fluent syntax, well documented interface and awesome community. And the benchmarks were impressive, too.&lt;/p&gt;
&lt;p&gt;OK, I can do this!&lt;/p&gt;
&lt;h2 id=&quot;laravel-new-collector&quot;&gt;&lt;strong&gt;Laravel New Collector&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;Yep, let’s start talking about the implementation.&lt;/p&gt;
&lt;p&gt;Before starting to code, I got myself thinking a little more about how to handle e-mails. I knew that for FTP and shared folders (we have other services that scans physical documents and makes them available in shared folders) I could simply use Flysystem, which comes out-of-the-box with Laravel. However, e-mail accessing and handling is not straightforward as one might think. I though: “There must be a package for that!”. So, like every other super dev, I went to GitHub and searched a bit about available projects that could handle some of the heavy lifting of handling IMAP connections.&lt;/p&gt;
&lt;p&gt;I quickly found IMAP, by David de Boer. Exactly what I needed: a nice, tested library to handle IMAP connections, message search and retrieval and attachments download through a very straightforward API. The examples clearly showed me I could definitely use this without much work on my end. Awesome!&lt;/p&gt;
&lt;p&gt;While Composer was doing it’s thing, I was thinking about how I could make everything configurable in a simple way. I needed to add a UI layer so that an authenticated user could configure the different connections, rules for data validation and some actions for cleaning up already handled data.&lt;/p&gt;
&lt;p&gt;The term Buckets came to my mind, influenced by the AWS S3 Buckets. Indeed it’s a very simple term to describe a resource that holds contents. A Bucket would only have one type of data, would contain it’s rules to filter out data that would not conform to some business rules and would also contain the actions to be executed after the filtered data was imported to our systems.&lt;/p&gt;
&lt;h2 id=&quot;the-ui-layer&quot;&gt;&lt;strong&gt;The UI Layer&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;I’m not a designer. I definitely can’t draw nothing useful, even if my life depended upon it… Luckily, projects like Bootstrap exists and can help anyone like me on that matter. Also, I found out a UI project called Tabler, which I could use to handle my “original design”.&lt;/p&gt;
&lt;p&gt;So I created the normal index, edit and create panels for managing Buckets and associating them to our already existing customers’ table. In the next two days I created the necessary panels for managing the Buckets’ rules and actions. Also, I made the necessary listing and showing panels for the e-mails that would be imported, and a download link for each attachment they could possible have associated.&lt;/p&gt;
&lt;p&gt;I’ve also added a button for starting and stopping the buckets process job. And that’s the interesting part of this article.&lt;/p&gt;
&lt;h2 id=&quot;getting-to-the-fun-stuff&quot;&gt;&lt;strong&gt;Getting To The Fun Stuff&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;By the end of the first week of work, I’d have all my controllers, models and views prepared to receive the data from the sources defined in the Buckets.&lt;/p&gt;
&lt;p&gt;One thing I made sure was done right was the encryption of all Bucket’s configuration, because it’ll be holding access information to our customers’ data. That’s a pretty sensible information to be holding in plain text, so I used the encrypt() and decrypt() methods that Laravel has at our disposal. I’d encrypt the data before saving it to the database and decrypt it only when accessing them.&lt;/p&gt;
&lt;p&gt;After this, I stepped back and thought a little more about how the system was going to work. I definitely knew I’d need to use queuable classes to make the application as snappy as possible, by sending the real work to be handled on the background. But how to best approach this? How should my system handle that? To help me think, I picked up my notepad and came up with this workflow: * A scheduled command should query for all the active Buckets that were eligible for processing. * For each active Bucket found, a new Process Job should be dispatched to connect to the source defined. * For each data (should it be a message, a file or other supported media) the respective Process Job should get the Bucket’s rules and only process the data that passed every rule. * If one of the rules were not correctly validated, this data would be ignored by the Process Job. * Finally, the Process Job would import a normalized version of the fetched data, check for attachments (in case of an email) and download them to the disk for archiving purposes. In case there were any PDF file we’ll need to extract the text and save it to a persistent layer to show on our application. * At the very end, the Process Job would execute every action defined in the Bucket’s configuration.&lt;/p&gt;
&lt;p&gt;After getting the workflow straighten up, I created a new Laravel command which would query, every minute, which Buckets were suppose to be processed and dispatch a job for each one, like this:&lt;/p&gt;
&lt;pre class=&quot;astro-code synthwave-84&quot; style=&quot;background-color:#262335;color:#bbbbbb; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;php&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;&amp;lt;?&lt;/span&gt;&lt;span style=&quot;color:#F97E72&quot;&gt;php&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;namespace&lt;/span&gt;&lt;span style=&quot;color:#FE4450&quot;&gt; App\Console\Commands&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;use&lt;/span&gt;&lt;span style=&quot;color:#FE4450&quot;&gt; App\Bucket&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;use&lt;/span&gt;&lt;span style=&quot;color:#FE4450&quot;&gt; App\Jobs\ProcessEmailBuckets&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;use&lt;/span&gt;&lt;span style=&quot;color:#FE4450&quot;&gt; App\Jobs\ProcessFtpBuckets&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;use&lt;/span&gt;&lt;span style=&quot;color:#FE4450&quot;&gt; App\Jobs\ProcessNfsBuckets&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;use&lt;/span&gt;&lt;span style=&quot;color:#FE4450&quot;&gt; Illuminate\Console\Command&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;class&lt;/span&gt;&lt;span style=&quot;color:#FE4450&quot;&gt; Collector&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt; extends&lt;/span&gt;&lt;span style=&quot;color:#D50&quot;&gt; Command&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#848BBD;font-style:italic&quot;&gt;    /**&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#848BBD;font-style:italic&quot;&gt;     * The name and signature of the console command.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#848BBD;font-style:italic&quot;&gt;     *&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#848BBD;font-style:italic&quot;&gt;     * &lt;/span&gt;&lt;span style=&quot;color:#FEDE5D;font-style:italic&quot;&gt;@var&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D;font-style:italic&quot;&gt; string&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#848BBD;font-style:italic&quot;&gt;     */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;    protected&lt;/span&gt;&lt;span style=&quot;color:#FF7EDB&quot;&gt; $signature&lt;/span&gt;&lt;span style=&quot;color:#FFFFFFEE&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#FF8B39&quot;&gt; &apos;collector&apos;&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#848BBD;font-style:italic&quot;&gt;    /**&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#848BBD;font-style:italic&quot;&gt;     * The console command description.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#848BBD;font-style:italic&quot;&gt;     *&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#848BBD;font-style:italic&quot;&gt;     * &lt;/span&gt;&lt;span style=&quot;color:#FEDE5D;font-style:italic&quot;&gt;@var&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D;font-style:italic&quot;&gt; string&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#848BBD;font-style:italic&quot;&gt;     */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;    protected&lt;/span&gt;&lt;span style=&quot;color:#FF7EDB&quot;&gt; $description&lt;/span&gt;&lt;span style=&quot;color:#FFFFFFEE&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#FF8B39&quot;&gt; &apos;Initializes the processing of buckets&apos;&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#848BBD;font-style:italic&quot;&gt;    /**&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#848BBD;font-style:italic&quot;&gt;     * Execute the console command.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#848BBD;font-style:italic&quot;&gt;     *&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#848BBD;font-style:italic&quot;&gt;     * &lt;/span&gt;&lt;span style=&quot;color:#FEDE5D;font-style:italic&quot;&gt;@param&lt;/span&gt;&lt;span style=&quot;color:#FE4450;font-style:italic&quot;&gt; Bucket&lt;/span&gt;&lt;span style=&quot;color:#848BBD;font-style:italic&quot;&gt; $buckets&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#848BBD;font-style:italic&quot;&gt;     * &lt;/span&gt;&lt;span style=&quot;color:#FEDE5D;font-style:italic&quot;&gt;@return&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D;font-style:italic&quot;&gt; mixed&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#848BBD;font-style:italic&quot;&gt;     */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;    public&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt; function&lt;/span&gt;&lt;span style=&quot;color:#36F9F6&quot;&gt; handle&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#FE4450&quot;&gt;Bucket&lt;/span&gt;&lt;span style=&quot;color:#FF7EDB&quot;&gt; $buckets&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;    {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FF7EDB&quot;&gt;        $buckets&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#36F9F6&quot;&gt;freeForProcess&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;()&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#36F9F6&quot;&gt;get&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;()&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#36F9F6&quot;&gt;each&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#FF7EDB&quot;&gt;$bucket&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;            if&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#FF7EDB&quot;&gt;$bucket&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#FF7EDB&quot;&gt;type&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt; ===&lt;/span&gt;&lt;span style=&quot;color:#FF8B39&quot;&gt; &apos;email&apos;&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FE4450&quot;&gt;                ProcessEmailBuckets&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color:#36F9F6&quot;&gt;dispatch&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#FF7EDB&quot;&gt;$bucket&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#36F9F6&quot;&gt;onQueue&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#FF8B39&quot;&gt;&apos;collector&apos;&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;            } &lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;elseif&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#FF7EDB&quot;&gt;$bucket&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#FF7EDB&quot;&gt;type&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt; ===&lt;/span&gt;&lt;span style=&quot;color:#FF8B39&quot;&gt; &apos;ftp&apos;&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FE4450&quot;&gt;                ProcessFtpBuckets&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color:#36F9F6&quot;&gt;dispatch&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#FF7EDB&quot;&gt;$bucket&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#36F9F6&quot;&gt;onQueue&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#FF8B39&quot;&gt;&apos;collector&apos;&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;            } &lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;elseif&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#FF7EDB&quot;&gt;$bucket&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#FF7EDB&quot;&gt;type&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt; ===&lt;/span&gt;&lt;span style=&quot;color:#FF8B39&quot;&gt; &apos;nfs&apos;&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FE4450&quot;&gt;                ProcessNfsBuckets&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color:#36F9F6&quot;&gt;dispatch&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#FF7EDB&quot;&gt;$bucket&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#36F9F6&quot;&gt;onQueue&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#FF8B39&quot;&gt;&apos;collector&apos;&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;            }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;        });&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Nothing fancy. To avoid any overlaps I scheduled this Collector command using the &lt;code&gt;withoutOverlapping()&lt;/code&gt; method chained, like this:&lt;/p&gt;
&lt;pre class=&quot;astro-code synthwave-84&quot; style=&quot;background-color:#262335;color:#bbbbbb; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;php&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#848BBD;font-style:italic&quot;&gt;/**&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#848BBD;font-style:italic&quot;&gt; * Define the application&apos;s command schedule.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#848BBD;font-style:italic&quot;&gt; *&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#848BBD;font-style:italic&quot;&gt; * &lt;/span&gt;&lt;span style=&quot;color:#FEDE5D;font-style:italic&quot;&gt;@param&lt;/span&gt;&lt;span style=&quot;color:#FE4450;font-style:italic&quot;&gt;  \Illuminate\Console\Scheduling\Schedule&lt;/span&gt;&lt;span style=&quot;color:#848BBD;font-style:italic&quot;&gt;  $schedule&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#848BBD;font-style:italic&quot;&gt; * &lt;/span&gt;&lt;span style=&quot;color:#FEDE5D;font-style:italic&quot;&gt;@return&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D;font-style:italic&quot;&gt; void&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#848BBD;font-style:italic&quot;&gt; */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;protected&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt; function&lt;/span&gt;&lt;span style=&quot;color:#36F9F6&quot;&gt; schedule&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#FE4450&quot;&gt;Schedule&lt;/span&gt;&lt;span style=&quot;color:#FF7EDB&quot;&gt; $schedule&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FF7EDB&quot;&gt;    $schedule&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#36F9F6&quot;&gt;command&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#FF8B39&quot;&gt;&apos;collector&apos;&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#36F9F6&quot;&gt;everyMinute&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;()&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#36F9F6&quot;&gt;withoutOverlapping&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This takes care of the first two bullet points, previously listed above. So far, so good. I got the ProcessFtpBuckets and ProcessNfsBuckets Job classes working in little time, thanks to the awesome Flysystem support.&lt;/p&gt;
&lt;p&gt;But, while I was coding the ProcessEmailBuckets Job class, I started thinking about the fact that it should not be aware of the concrete implementation of the IMAP library. To avoid falling in a common trap, and to keep me from messing my Future Self’s life, I created the repository class EmailServiceRepository to be used as a wrapper for the IMAP library, with a few simple methods that would enable the job class to deal with the mailbox connections. Here’s the interface that defined my implementation:&lt;/p&gt;
&lt;pre class=&quot;astro-code synthwave-84&quot; style=&quot;background-color:#262335;color:#bbbbbb; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;php&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;&amp;lt;?&lt;/span&gt;&lt;span style=&quot;color:#F97E72&quot;&gt;php&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;namespace&lt;/span&gt;&lt;span style=&quot;color:#FE4450&quot;&gt; App\Repositories\Contracts&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;interface&lt;/span&gt;&lt;span style=&quot;color:#FE4450&quot;&gt; EmailServiceInterface&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#848BBD;font-style:italic&quot;&gt;  /**&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#848BBD;font-style:italic&quot;&gt;   * Connects to server and authenticates.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#848BBD;font-style:italic&quot;&gt;   *&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#848BBD;font-style:italic&quot;&gt;   * &lt;/span&gt;&lt;span style=&quot;color:#FEDE5D;font-style:italic&quot;&gt;@param&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D;font-style:italic&quot;&gt; string&lt;/span&gt;&lt;span style=&quot;color:#848BBD;font-style:italic&quot;&gt; $server&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#848BBD;font-style:italic&quot;&gt;   * &lt;/span&gt;&lt;span style=&quot;color:#FEDE5D;font-style:italic&quot;&gt;@param&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D;font-style:italic&quot;&gt; string&lt;/span&gt;&lt;span style=&quot;color:#848BBD;font-style:italic&quot;&gt; $username&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#848BBD;font-style:italic&quot;&gt;   * &lt;/span&gt;&lt;span style=&quot;color:#FEDE5D;font-style:italic&quot;&gt;@param&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D;font-style:italic&quot;&gt; string&lt;/span&gt;&lt;span style=&quot;color:#848BBD;font-style:italic&quot;&gt; $password&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#848BBD;font-style:italic&quot;&gt;   * &lt;/span&gt;&lt;span style=&quot;color:#FEDE5D;font-style:italic&quot;&gt;@return&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D;font-style:italic&quot;&gt; self&lt;/span&gt;&lt;span style=&quot;color:#848BBD;font-style:italic&quot;&gt; $this&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#848BBD;font-style:italic&quot;&gt;   */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;  public&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt; function&lt;/span&gt;&lt;span style=&quot;color:#36F9F6&quot;&gt; connect&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color:#FF7EDB&quot;&gt; $server&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color:#FF7EDB&quot;&gt; $username&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color:#FF7EDB&quot;&gt; $password&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#848BBD;font-style:italic&quot;&gt;  /**&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#848BBD;font-style:italic&quot;&gt;   * List all available mailboxes.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#848BBD;font-style:italic&quot;&gt;   *&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#848BBD;font-style:italic&quot;&gt;   * &lt;/span&gt;&lt;span style=&quot;color:#FEDE5D;font-style:italic&quot;&gt;@return&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D;font-style:italic&quot;&gt; array&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#848BBD;font-style:italic&quot;&gt;   */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;  public&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt; function&lt;/span&gt;&lt;span style=&quot;color:#36F9F6&quot;&gt; listMailboxes&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#848BBD;font-style:italic&quot;&gt;  /**&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#848BBD;font-style:italic&quot;&gt;   * Lists all messages.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#848BBD;font-style:italic&quot;&gt;   *&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#848BBD;font-style:italic&quot;&gt;   * &lt;/span&gt;&lt;span style=&quot;color:#FEDE5D;font-style:italic&quot;&gt;@param&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D;font-style:italic&quot;&gt; string&lt;/span&gt;&lt;span style=&quot;color:#848BBD;font-style:italic&quot;&gt; $mailbox&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#848BBD;font-style:italic&quot;&gt;   * &lt;/span&gt;&lt;span style=&quot;color:#FEDE5D;font-style:italic&quot;&gt;@param&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D;font-style:italic&quot;&gt; array&lt;/span&gt;&lt;span style=&quot;color:#848BBD;font-style:italic&quot;&gt; $filters&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#848BBD;font-style:italic&quot;&gt;   * &lt;/span&gt;&lt;span style=&quot;color:#FEDE5D;font-style:italic&quot;&gt;@return&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D;font-style:italic&quot;&gt; mixed&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#848BBD;font-style:italic&quot;&gt;   */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;  public&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt; function&lt;/span&gt;&lt;span style=&quot;color:#36F9F6&quot;&gt; getEmails&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color:#FF7EDB&quot;&gt; $mailbox&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;array&lt;/span&gt;&lt;span style=&quot;color:#FF7EDB&quot;&gt; $filters&lt;/span&gt;&lt;span style=&quot;color:#FFFFFFEE&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; []);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#848BBD;font-style:italic&quot;&gt;  /**&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#848BBD;font-style:italic&quot;&gt;   * Creates normalized message metadata.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#848BBD;font-style:italic&quot;&gt;   *&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#848BBD;font-style:italic&quot;&gt;   * &lt;/span&gt;&lt;span style=&quot;color:#FEDE5D;font-style:italic&quot;&gt;@param&lt;/span&gt;&lt;span style=&quot;color:#FE4450;font-style:italic&quot;&gt; Message&lt;/span&gt;&lt;span style=&quot;color:#848BBD;font-style:italic&quot;&gt; $message&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#848BBD;font-style:italic&quot;&gt;   * &lt;/span&gt;&lt;span style=&quot;color:#FEDE5D;font-style:italic&quot;&gt;@return&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D;font-style:italic&quot;&gt; array&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#848BBD;font-style:italic&quot;&gt;   */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;  public&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt; function&lt;/span&gt;&lt;span style=&quot;color:#36F9F6&quot;&gt; normalize&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#FE4450&quot;&gt;Message&lt;/span&gt;&lt;span style=&quot;color:#FF7EDB&quot;&gt; $message&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#848BBD;font-style:italic&quot;&gt;  /**&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#848BBD;font-style:italic&quot;&gt;   * Downloads attachment to disk and return normalized metadata.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#848BBD;font-style:italic&quot;&gt;   *&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#848BBD;font-style:italic&quot;&gt;   * &lt;/span&gt;&lt;span style=&quot;color:#FEDE5D;font-style:italic&quot;&gt;@param&lt;/span&gt;&lt;span style=&quot;color:#FE4450;font-style:italic&quot;&gt; Attachment&lt;/span&gt;&lt;span style=&quot;color:#848BBD;font-style:italic&quot;&gt; $attachment&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#848BBD;font-style:italic&quot;&gt;   * &lt;/span&gt;&lt;span style=&quot;color:#FEDE5D;font-style:italic&quot;&gt;@param&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D;font-style:italic&quot;&gt; string&lt;/span&gt;&lt;span style=&quot;color:#848BBD;font-style:italic&quot;&gt; $baseFolder&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#848BBD;font-style:italic&quot;&gt;   * &lt;/span&gt;&lt;span style=&quot;color:#FEDE5D;font-style:italic&quot;&gt;@return&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D;font-style:italic&quot;&gt; array&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#848BBD;font-style:italic&quot;&gt;   */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;  public&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt; function&lt;/span&gt;&lt;span style=&quot;color:#36F9F6&quot;&gt; downloadAttachment&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#FE4450&quot;&gt;Attachment&lt;/span&gt;&lt;span style=&quot;color:#FF7EDB&quot;&gt; $attachment&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color:#FF7EDB&quot;&gt; $baseFolder&lt;/span&gt;&lt;span style=&quot;color:#FFFFFFEE&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#FF8B39&quot;&gt; &apos;attachments&apos;&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#848BBD;font-style:italic&quot;&gt;  /**&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#848BBD;font-style:italic&quot;&gt;   * Marks given messages as read.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#848BBD;font-style:italic&quot;&gt;   *&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#848BBD;font-style:italic&quot;&gt;   * &lt;/span&gt;&lt;span style=&quot;color:#FEDE5D;font-style:italic&quot;&gt;@param&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D;font-style:italic&quot;&gt; string&lt;/span&gt;&lt;span style=&quot;color:#848BBD;font-style:italic&quot;&gt; $mailbox&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#848BBD;font-style:italic&quot;&gt;   * &lt;/span&gt;&lt;span style=&quot;color:#FEDE5D;font-style:italic&quot;&gt;@param&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D;font-style:italic&quot;&gt; string&lt;/span&gt;&lt;span style=&quot;color:#848BBD;font-style:italic&quot;&gt; $messagesNumbers&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#848BBD;font-style:italic&quot;&gt;   * &lt;/span&gt;&lt;span style=&quot;color:#FEDE5D;font-style:italic&quot;&gt;@return&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D;font-style:italic&quot;&gt; mixed&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#848BBD;font-style:italic&quot;&gt;   */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;  public&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt; function&lt;/span&gt;&lt;span style=&quot;color:#36F9F6&quot;&gt; markAsRead&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color:#FF7EDB&quot;&gt; $mailbox&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color:#FF7EDB&quot;&gt; $messagesNumbers&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#848BBD;font-style:italic&quot;&gt;  /**&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#848BBD;font-style:italic&quot;&gt;   * Marks given messages as unread.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#848BBD;font-style:italic&quot;&gt;   *&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#848BBD;font-style:italic&quot;&gt;   * &lt;/span&gt;&lt;span style=&quot;color:#FEDE5D;font-style:italic&quot;&gt;@param&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D;font-style:italic&quot;&gt; string&lt;/span&gt;&lt;span style=&quot;color:#848BBD;font-style:italic&quot;&gt; $mailbox&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#848BBD;font-style:italic&quot;&gt;   * &lt;/span&gt;&lt;span style=&quot;color:#FEDE5D;font-style:italic&quot;&gt;@param&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D;font-style:italic&quot;&gt; string&lt;/span&gt;&lt;span style=&quot;color:#848BBD;font-style:italic&quot;&gt; $messagesNumbers&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#848BBD;font-style:italic&quot;&gt;   * &lt;/span&gt;&lt;span style=&quot;color:#FEDE5D;font-style:italic&quot;&gt;@return&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D;font-style:italic&quot;&gt; mixed&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#848BBD;font-style:italic&quot;&gt;   */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;  public&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt; function&lt;/span&gt;&lt;span style=&quot;color:#36F9F6&quot;&gt; markAsUnRead&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color:#FF7EDB&quot;&gt; $mailbox&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color:#FF7EDB&quot;&gt; $messagesNumbers&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#848BBD;font-style:italic&quot;&gt;  /**&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#848BBD;font-style:italic&quot;&gt;   * Moves message to given mailbox path.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#848BBD;font-style:italic&quot;&gt;   *&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#848BBD;font-style:italic&quot;&gt;   * &lt;/span&gt;&lt;span style=&quot;color:#FEDE5D;font-style:italic&quot;&gt;@param&lt;/span&gt;&lt;span style=&quot;color:#FE4450;font-style:italic&quot;&gt; Message&lt;/span&gt;&lt;span style=&quot;color:#848BBD;font-style:italic&quot;&gt; $message&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#848BBD;font-style:italic&quot;&gt;   * &lt;/span&gt;&lt;span style=&quot;color:#FEDE5D;font-style:italic&quot;&gt;@param&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D;font-style:italic&quot;&gt; string&lt;/span&gt;&lt;span style=&quot;color:#848BBD;font-style:italic&quot;&gt; $mailbox&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#848BBD;font-style:italic&quot;&gt;   * &lt;/span&gt;&lt;span style=&quot;color:#FEDE5D;font-style:italic&quot;&gt;@return&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D;font-style:italic&quot;&gt; void&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#848BBD;font-style:italic&quot;&gt;   */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;  public&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt; function&lt;/span&gt;&lt;span style=&quot;color:#36F9F6&quot;&gt; move&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#FE4450&quot;&gt;Message&lt;/span&gt;&lt;span style=&quot;color:#FF7EDB&quot;&gt; $message&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color:#FF7EDB&quot;&gt; $mailbox&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#848BBD;font-style:italic&quot;&gt;  /**&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#848BBD;font-style:italic&quot;&gt;   * Deletes given message.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#848BBD;font-style:italic&quot;&gt;   *&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#848BBD;font-style:italic&quot;&gt;   * &lt;/span&gt;&lt;span style=&quot;color:#FEDE5D;font-style:italic&quot;&gt;@param&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D;font-style:italic&quot;&gt; int&lt;/span&gt;&lt;span style=&quot;color:#848BBD;font-style:italic&quot;&gt; $messageNumber&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#848BBD;font-style:italic&quot;&gt;   * &lt;/span&gt;&lt;span style=&quot;color:#FEDE5D;font-style:italic&quot;&gt;@param&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D;font-style:italic&quot;&gt; string&lt;/span&gt;&lt;span style=&quot;color:#848BBD;font-style:italic&quot;&gt; $mailbox&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#848BBD;font-style:italic&quot;&gt;   */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;  public&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt; function&lt;/span&gt;&lt;span style=&quot;color:#36F9F6&quot;&gt; delete&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;int&lt;/span&gt;&lt;span style=&quot;color:#FF7EDB&quot;&gt; $messageNumber&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color:#FF7EDB&quot;&gt; $mailbox&lt;/span&gt;&lt;span style=&quot;color:#FFFFFFEE&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#FF8B39&quot;&gt; &apos;INBOX&apos;&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now I could, if needed, swap the concrete implementation, at any point in the future, without ever needing to change the Process Job class, as long as I respect that Interface.&lt;/p&gt;
&lt;h2 id=&quot;rules--actions&quot;&gt;&lt;strong&gt;Rules &amp;amp; Actions&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;Not all communications are to be imported, because it may be SPAM, irrelevant to the Bucket scope and, so, are not to be made available. To handle those cases, I created a simple rule based validation system and post-import actions (for cleaning up, afterwards).&lt;/p&gt;
&lt;p&gt;The rules, which are defined through the UI, basically consists on saying that the Bucket only cares for specific data. For example, a Bucket could be configured to only archive communications sent from a specific e-mail address. That rule configuration would set the ProcessEmailBuckets class to ignore any message that was not be sent by that e-mail.&lt;/p&gt;
&lt;p&gt;Rules could be configured to check for the sender address, the receivers’ addresses, keywords on the subject and/or body, if it has attachments and others… They can even be stacked together, meaning that a message would only be imported if it passes all the rules defined for that Bucket. Calm down… It looks a lot more complicated than it really is. Here’s the validator method, for clarification:&lt;/p&gt;
&lt;pre class=&quot;astro-code synthwave-84&quot; style=&quot;background-color:#262335;color:#bbbbbb; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;php&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#848BBD;font-style:italic&quot;&gt;/**&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#848BBD;font-style:italic&quot;&gt; * Validates given message against import rules.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#848BBD;font-style:italic&quot;&gt; *&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#848BBD;font-style:italic&quot;&gt; * &lt;/span&gt;&lt;span style=&quot;color:#FEDE5D;font-style:italic&quot;&gt;@param&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D;font-style:italic&quot;&gt; array&lt;/span&gt;&lt;span style=&quot;color:#848BBD;font-style:italic&quot;&gt; $message&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#848BBD;font-style:italic&quot;&gt; * &lt;/span&gt;&lt;span style=&quot;color:#FEDE5D;font-style:italic&quot;&gt;@return&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D;font-style:italic&quot;&gt; mixed&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#848BBD;font-style:italic&quot;&gt; */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;protected&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt; function&lt;/span&gt;&lt;span style=&quot;color:#36F9F6&quot;&gt; validate&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;array&lt;/span&gt;&lt;span style=&quot;color:#FF7EDB&quot;&gt; $message&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;    return&lt;/span&gt;&lt;span style=&quot;color:#FE4450;font-weight:bold&quot;&gt; $this&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#FF7EDB&quot;&gt;bucket&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#36F9F6&quot;&gt;rules&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;()&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#36F9F6&quot;&gt;get&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;()&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#36F9F6&quot;&gt;every&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#FF7EDB&quot;&gt;$rule&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;use&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#FF7EDB&quot;&gt;$message&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;        switch&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#FF7EDB&quot;&gt;$rule&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#FF7EDB&quot;&gt;validator&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;            case&lt;/span&gt;&lt;span style=&quot;color:#FF8B39&quot;&gt; &apos;all&apos;&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;                return&lt;/span&gt;&lt;span style=&quot;color:#F97E72&quot;&gt; true&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;                break&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;            case&lt;/span&gt;&lt;span style=&quot;color:#FF8B39&quot;&gt; &apos;sender&apos;&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;                return&lt;/span&gt;&lt;span style=&quot;color:#36F9F6&quot;&gt; str_contains&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#FF7EDB&quot;&gt;$message&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color:#FF8B39&quot;&gt;&apos;from&apos;&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;], &lt;/span&gt;&lt;span style=&quot;color:#FF7EDB&quot;&gt;$rule&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#FF7EDB&quot;&gt;param&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;                break&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;            case&lt;/span&gt;&lt;span style=&quot;color:#FF8B39&quot;&gt; &apos;receiver&apos;&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;                return&lt;/span&gt;&lt;span style=&quot;color:#36F9F6&quot;&gt; str_is&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#FF7EDB&quot;&gt;$message&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color:#FF8B39&quot;&gt;&apos;to&apos;&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;], &lt;/span&gt;&lt;span style=&quot;color:#FF7EDB&quot;&gt;$rule&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#FF7EDB&quot;&gt;param&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;                break&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;            case&lt;/span&gt;&lt;span style=&quot;color:#FF8B39&quot;&gt; &apos;subject&apos;&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;                return&lt;/span&gt;&lt;span style=&quot;color:#36F9F6&quot;&gt; str_contains&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#FF7EDB&quot;&gt;$message&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color:#FF8B39&quot;&gt;&apos;subject&apos;&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;], &lt;/span&gt;&lt;span style=&quot;color:#FF7EDB&quot;&gt;$rule&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#FF7EDB&quot;&gt;param&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;                break&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;            case&lt;/span&gt;&lt;span style=&quot;color:#FF8B39&quot;&gt; &apos;body&apos;&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;                return&lt;/span&gt;&lt;span style=&quot;color:#36F9F6&quot;&gt; str_contains&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#FF7EDB&quot;&gt;$message&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color:#FF8B39&quot;&gt;&apos;body&apos;&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;], &lt;/span&gt;&lt;span style=&quot;color:#FF7EDB&quot;&gt;$rule&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#FF7EDB&quot;&gt;param&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;                break&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;            case&lt;/span&gt;&lt;span style=&quot;color:#FF8B39&quot;&gt; &apos;attachments&apos;&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;                return&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt; !&lt;/span&gt;&lt;span style=&quot;color:#36F9F6&quot;&gt;empty&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#FF7EDB&quot;&gt;$message&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color:#FF8B39&quot;&gt;&apos;attachments&apos;&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;]);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;                break&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;            default&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;                return&lt;/span&gt;&lt;span style=&quot;color:#F97E72&quot;&gt; false&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;    });&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Following the same logic, actions, which are also defined through the UI, configures the work to be done, by the ProcessEmailsBuckets class, after importing a message, successfully. Actions could be one of the follow: marking a message as read/imported, move a message to another mailbox, and delete the message from the source. This will ensure that the source would stay organized and optimized for the next run. Here’s how I implemented this:&lt;/p&gt;
&lt;pre class=&quot;astro-code synthwave-84&quot; style=&quot;background-color:#262335;color:#bbbbbb; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;php&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#848BBD;font-style:italic&quot;&gt;/**&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#848BBD;font-style:italic&quot;&gt; * Executes after process actions defined.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#848BBD;font-style:italic&quot;&gt; *&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#848BBD;font-style:italic&quot;&gt; * &lt;/span&gt;&lt;span style=&quot;color:#FEDE5D;font-style:italic&quot;&gt;@param&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D;font-style:italic&quot;&gt; array&lt;/span&gt;&lt;span style=&quot;color:#848BBD;font-style:italic&quot;&gt; $message&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#848BBD;font-style:italic&quot;&gt; */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;protected&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt; function&lt;/span&gt;&lt;span style=&quot;color:#36F9F6&quot;&gt; executeActions&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;array&lt;/span&gt;&lt;span style=&quot;color:#FF7EDB&quot;&gt; $message&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FE4450;font-weight:bold&quot;&gt;  $this&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#FF7EDB&quot;&gt;bucket&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#36F9F6&quot;&gt;actions&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;()&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#36F9F6&quot;&gt;get&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;()&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#36F9F6&quot;&gt;each&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#FF7EDB&quot;&gt;$action&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;use&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#FF7EDB&quot;&gt;$message&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;      if&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#FF7EDB&quot;&gt;$action&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#FF7EDB&quot;&gt;type&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt; ===&lt;/span&gt;&lt;span style=&quot;color:#FF8B39&quot;&gt; &apos;flag_as_seen&apos;&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FE4450;font-weight:bold&quot;&gt;          $this&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#FF7EDB&quot;&gt;repository&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;              -&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#36F9F6&quot;&gt;markAsRead&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FE4450;font-weight:bold&quot;&gt;                  $this&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#FF7EDB&quot;&gt;bucket&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#FF7EDB&quot;&gt;connection&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color:#FF8B39&quot;&gt;&apos;mailbox&apos;&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;],&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FF7EDB&quot;&gt;                  $message&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color:#FF8B39&quot;&gt;&apos;number&apos;&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;              );&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;      } &lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;elseif&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#FF7EDB&quot;&gt;$action&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#FF7EDB&quot;&gt;type&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt; ===&lt;/span&gt;&lt;span style=&quot;color:#FF8B39&quot;&gt; &apos;move&apos;&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FF7EDB&quot;&gt;          $message&lt;/span&gt;&lt;span style=&quot;color:#FFFFFFEE&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#FE4450;font-weight:bold&quot;&gt; $this&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#FF7EDB&quot;&gt;repository&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;              -&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#36F9F6&quot;&gt;getEmails&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FE4450;font-weight:bold&quot;&gt;                  $this&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#FF7EDB&quot;&gt;bucket&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#FF7EDB&quot;&gt;connection&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color:#FF8B39&quot;&gt;&apos;mailbox&apos;&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;], &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;                  [&lt;/span&gt;&lt;span style=&quot;color:#FF8B39&quot;&gt;&apos;number&apos;&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#FF7EDB&quot;&gt; $message&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color:#FF8B39&quot;&gt;&apos;number&apos;&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;]]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;              );&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;              &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FE4450;font-weight:bold&quot;&gt;          $this&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#FF7EDB&quot;&gt;repository&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#36F9F6&quot;&gt;move&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#FF7EDB&quot;&gt;$message&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#FF7EDB&quot;&gt;$action&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#FF7EDB&quot;&gt;param&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;      } &lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;elseif&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#FF7EDB&quot;&gt;$action&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#FF7EDB&quot;&gt;type&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt; ===&lt;/span&gt;&lt;span style=&quot;color:#FF8B39&quot;&gt; &apos;delete&apos;&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FE4450;font-weight:bold&quot;&gt;          $this&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#FF7EDB&quot;&gt;repository&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;              -&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#36F9F6&quot;&gt;delete&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FE4450;font-weight:bold&quot;&gt;                  $this&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#FF7EDB&quot;&gt;bucket&lt;/span&gt;&lt;span style=&quot;color:#FEDE5D&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#FF7EDB&quot;&gt;connection&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color:#FF8B39&quot;&gt;&apos;mailbox&apos;&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;], &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FF7EDB&quot;&gt;                  $message&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color:#FF8B39&quot;&gt;&apos;number&apos;&lt;/span&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;              );&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;      }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;  });&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#BBBBBB&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Another little nuance I needed to handle was extracting text from PDFs. So, if the ProcessEmailBuckets Job class detected a PDF file/attachment, not only would it download and archive it, but it should dispatch another job class, called ScanPdfAttachments.&lt;/p&gt;
&lt;p&gt;This class would run a third-party software called PdfToText, installed on the server, that takes the PDF file path, as input, and outputs it’s text. The ScanPdfAttachments class would, then, take that output and save it to a column associated to the PDF file, on our database. The Extractor, then, could use this text to gather relevant business data.&lt;/p&gt;
&lt;p&gt;I need to refer that this was as simple as pull a package named pdf-to-text, from a well known company called Spatie (they develop a lot of great packages), and call a simple static method they provide: Pdf::getText().&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;By the way, this reminds me I need to send a postcard to them, for using their package!&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 id=&quot;last-save&quot;&gt;&lt;strong&gt;Last Save!&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;Awesome! Now I have my Collector ready for action! It successfully allows the creation of buckets, define their rules and actions, and access to the data imported through a Web UI, I have the Process Jobs running in the background and I have an API layer so my colleague could get the normalized data from my Collector and deal with specific customers’ business extraction rules and data delivery.&lt;/p&gt;
&lt;p&gt;And now, we don’t need to create a new script for each customer that subscribes our “Digital Archive” service. We simply create the necessary Buckets, set the rules for the data import and normalization, and carry on with our life, knowing that the Collector will be actively listening for data to be fetched and make it available to other internal systems, like the Extractor.&lt;/p&gt;
&lt;p&gt;And all of this was made in about two weeks, thanks to the Laravel framework, which allowed me to abstract common needs and focus on my main problem. Tests included!&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;notes-from-the-author&quot;&gt;&lt;strong&gt;Notes From The Author&lt;/strong&gt;&lt;/h3&gt;
&lt;p&gt;Thank you very much for reading this!&lt;/p&gt;
&lt;p&gt;As you may notice, I’ve not revealed many of the technical details, nor have I revealed several other parts of the system. I have a very strict contract with my current employer that doesn’t allow me to show you all the bits and pieces behind this project. If you got disappointed by that, I’m really sorry…&lt;/p&gt;
&lt;p&gt;What I wanted to show you, however, was my process of thinking, tools chosen and the reasons behind my decisions. Everyone can make the same, or even better, solution on other languages and/or frameworks. The interesting, and the hard, part is the process of thinking, the ability to break down a big problem into smaller ones and not losing focus on the main goal.&lt;/p&gt;
</content:encoded><category>Articles</category><category>Laravel</category></item></channel></rss>