<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Ali Afsah-Noudeh on Medium]]></title>
        <description><![CDATA[Stories by Ali Afsah-Noudeh on Medium]]></description>
        <link>https://medium.com/@aliafsah1988?source=rss-ad76ef429ff4------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*xm6Ng77NMRArmUD3</url>
            <title>Stories by Ali Afsah-Noudeh on Medium</title>
            <link>https://medium.com/@aliafsah1988?source=rss-ad76ef429ff4------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 22:21:18 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@aliafsah1988/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[I packaged my Figma-to-React Claude Code setup as a plugin. Here’s why and how]]></title>
            <link>https://medium.com/@aliafsah1988/i-packaged-my-figma-to-react-claude-code-setup-as-a-plugin-heres-why-and-how-4f239170d5b5?source=rss-ad76ef429ff4------2</link>
            <guid isPermaLink="false">https://medium.com/p/4f239170d5b5</guid>
            <category><![CDATA[anthropic-claude]]></category>
            <category><![CDATA[design-systems]]></category>
            <category><![CDATA[claude-code]]></category>
            <category><![CDATA[ai]]></category>
            <dc:creator><![CDATA[Ali Afsah-Noudeh]]></dc:creator>
            <pubDate>Sun, 28 Jun 2026 11:39:50 GMT</pubDate>
            <atom:updated>2026-06-28T11:39:50.454Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="Figma-to-React Claude Code pipeline." src="https://cdn-images-1.medium.com/max/720/1*rB6KsyS97czqPdF-LDX1Ng.jpeg" /></figure><p><a href="https://medium.com/@aliafsah1988/how-to-turn-claude-code-into-a-figma-to-react-pipeline-that-visually-verifies-its-own-work-030246f600a9"><em>Two posts ago</em></a><em> I built a Figma-to-React pipeline with Claude Code. </em><a href="https://medium.com/@aliafsah1988/your-ai-coding-agent-is-only-as-good-as-your-design-system-6055e4667fa9"><em>One post ago</em></a><em> I explained why the design system is what makes it work. Both ended with “clone my repo.” This is the post that fixes that.</em></p><h3>The problem with “clone my repo”</h3><p>My first two posts in this series both ended the same way. Clone the repo. Run my bootstrap script. Copy the patterns into your own project.</p><p>That’s a lot of friction.</p><p>If all you wanted was my agents, hooks, and skills, you had to take the whole demo with them. My FastAPI backend. My Next.js app. My design system. None of that is yours. You just wanted the harness.</p><p>The bootstrap script helped. But it still assumed you were sitting inside my repo. That’s fine for reading. It’s bad for adoption.</p><p>So I packaged the whole thing as a Claude Code plugin. Now you install it into your own project with one command. This post is about what that changes.</p><h3>What a Claude Code marketplace actually is</h3><p>Let me explain it the way I explained MCP in the first post.</p><p>A plugin bundles agents, skills, commands, and hooks into one installable unit. A marketplace is just a place Claude Code can install plugins from. It can be a public registry or your own GitHub repo.</p><p>So instead of copying files one by one, a developer points Claude Code at the marketplace and runs install. They get the whole harness in their project. No cloning. No hand-copying. No bootstrap script.</p><p>This is the natural next step of the committed-template pattern from the first post.</p><h3>What’s in the plugin</h3><p>The pieces are the same ones from the first two posts. Nothing new to learn. Now they just ship as a unit.</p><ul><li>The figma-impl agent. The keystone. Pulls real tokens from Figma, maps them to the design system, implements the feature, and visually verifies its own work in a real browser.</li><li>The design-system-check linter agent. The fast Haiku one. Catches direct @mui/* imports, hardcoded hex values, and custom UI duplicates.</li><li>The code-reviewer, test-writer, and other agents. Each with a narrow tool whitelist, so the blast radius stays small.</li><li>The hooks. Auto-prettier on write. Auto-typecheck on edit. The env-file blocker on read.</li><li>The /commit and /pr skills. Both with disable-model-invocation, so the model can prepare the work but only you can publish it.</li></ul><p>If you read <a href="https://medium.com/@aliafsah1988/how-to-turn-claude-code-into-a-figma-to-react-pipeline-that-visually-verifies-its-own-work-030246f600a9">the first post</a>, this is that whole .claude directory. The difference is you no longer copy it. You install it.</p><h3>How you install it</h3><p>While using claude code, add the marketplace once (points Claude Code at this repo):</p><pre>/plugin marketplace add aliafsahnoudeh/figma-to-code-claude-pipeline</pre><p>Install a specific plugin from it:</p><pre>/plugin install taskflow-pipeline@taskflow</pre><p>Update later:</p><pre>/plugin update taskflow-pipeline@taskflow</pre><h3>What ships, and what you tune</h3><p>The plugin ships the harness. The agents, the hooks, the skills. That part is fully portable. It works in any project.</p><p>The design system is portable too, just in a different way. It ships as packages. In this repo the design system is already a pnpm workspace with two packages, one for the theme and one for the components. You can publish those to npm or install them straight from GitHub. More packages can follow later as the system grows.</p><p>Here’s the real split. The plugin you install and use as-is. The design system packages you install and then tune. The structure comes for free. The token values are yours. Your brand purple is not my brand purple. Your spacing scale is not mine. So you install the packages, then point the tokens at your Figma.</p><p>In other words, almost none of this has to be hand-copied anymore. The harness installs. The design system installs. The only thing left that’s truly yours is the token values, and that’s exactly the part that should be.</p><h3>Where this leaves the series</h3><p>Three posts now, and they fit together.</p><p>The <a href="https://medium.com/@aliafsah1988/how-to-turn-claude-code-into-a-figma-to-react-pipeline-that-visually-verifies-its-own-work-030246f600a9">first post</a> builds the pipeline. The MCP servers, the agent prompt, the hooks that close the loop.</p><p>The <a href="https://medium.com/@aliafsah1988/your-ai-coding-agent-is-only-as-good-as-your-design-system-6055e4667fa9">second post</a> builds the design system that makes the pipeline reliable. The token contract, the wrapper pattern, the linter that keeps it honest.</p><p>This post packages all of it so your team can actually adopt it in one command.</p><p>Build the pipeline. Build the design system. Then ship it as a plugin and let the agent loose.</p><p><strong><em>The full repo, MIT-licensed:</em></strong> <a href="https://github.com/aliafsahnoudeh/figma-to-code-claude-pipeline"><strong><em>github.com/aliafsahnoudeh/figma-to-code-claude-pipeline</em></strong></a><strong><em>.</em></strong></p><p><em>I write about AI and software engineering on</em> <a href="https://medium.com/@aliafsah1988"><em>Medium</em></a><em>. Take a look at my other posts if this was useful, the first two in this series are linked above. I’m also</em> <a href="https://www.linkedin.com/in/aliafsahnoudeh/"><em>on LinkedIn</em></a><em>. Happy to hear your thoughts and ideas, and always open to talk about technical stuff.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4f239170d5b5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Your AI coding agent is only as good as your design system]]></title>
            <link>https://medium.com/@aliafsah1988/your-ai-coding-agent-is-only-as-good-as-your-design-system-6055e4667fa9?source=rss-ad76ef429ff4------2</link>
            <guid isPermaLink="false">https://medium.com/p/6055e4667fa9</guid>
            <category><![CDATA[design-systems]]></category>
            <category><![CDATA[frontend-development]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[software-engineering]]></category>
            <dc:creator><![CDATA[Ali Afsah-Noudeh]]></dc:creator>
            <pubDate>Thu, 14 May 2026 09:18:43 GMT</pubDate>
            <atom:updated>2026-06-28T10:49:01.388Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9lMoPIi5XQlkhrcxQRNJ9g.png" /></figure><p><em>Why a thin wrapper around MUI (or other component libraries), plus a JSON token contract, turns LLM frontend codegen from “plausible but wrong” into something you’d actually merge.</em></p><h3><strong>A quick experiment</strong></h3><p>Open your favorite AI coding assistant. Paste a Figma screenshot of a card component. Ask it to generate the React.</p><p>Look at what comes back. Read it carefully.</p><p>If your project is using stock MUI, plain TailwindCSS, or any component library where the model has thousands of props to choose from, you’ll see something like this:</p><ul><li>The padding is hardcoded as `p: 2` or `padding: ‘16px’` — no token, no semantic meaning.</li><li>The primary color is `#6366F1` written as a literal hex string.</li><li>The button uses `variant=”contained”` with no `color` prop, falling back to MUI’s default theme.</li><li>The font sizes are guessed from the screenshot. They’re close. They’re never right.</li><li>There’s a `Typography` import you didn’t ask for, sized in `rem`.</li><li>The model invented a prop.Except your design system doesn’t allow both. It just silently picked one:</li></ul><pre>&lt;Card elevation={2} variant=&quot;outlined&quot;&gt;</pre><p>Now try the same prompt against a project where the design system is built specifically as a target for AI codegen. The Figma color resolves to `primary.main`. The padding becomes `theme.spacing(2)`. The button becomes :</p><pre>&lt;Button color=&quot;primary&quot; variant=&quot;contained&quot; /&gt;</pre><p>from your wrapped component, with no extra props because the wrapper doesn’t expose any. Every value traces back to a token in a JSON file the model can read.</p><p>Same model. Same Figma frame. Different design system. Wildly different output quality.</p><p>This post is about why that difference exists, and how to deliberately design the second outcome.</p><p>The pipeline I’m describing lives in a public demo repo:</p><p><a href="https://github.com/aliafsahnoudeh/figma-to-code-claude-pipeline"><strong>github.com/aliafsahnoudeh/figma-to-code-claude-pipeline</strong></a></p><p>If you read ‘<a href="https://medium.com/@aliafsah1988/how-to-turn-claude-code-into-a-figma-to-react-pipeline-that-visually-verifies-its-own-work-030246f600a9">How to turn Claude Code into a Figma-to-React pipeline that visually verifies its own work</a>’ — about turning Claude Code into a Figma-to-React pipeline with MCP servers, agents, and hooks — this is the half I deliberately glossed over: <strong><em>why the design system is the hidden bottleneck of AI frontend codegen</em></strong>, and what to build instead.</p><h3><strong>The core idea: tokens are a shared vocabulary</strong></h3><p>Every “translate Figma to code” tool faces the same fundamental problem. Figma describes a design in one vocabulary (frames, fills, auto-layout, variables). React code describes a UI in another (components, props, CSS-in-JS, MUI’s `sx`). Without a shared vocabulary in between, the model has to invent a mapping from one to the other on every single request.</p><p>LLMs are <strong><em>bad</em></strong> at consistent invention. They’re <strong><em>excellent</em></strong> at lookups.</p><p>A token-driven design system gives the model a lookup table:</p><pre>Figma fill `#6366F1` → token `primary.main` → &lt;Box sx={{ color: &#39;primary.main&#39; }} /&gt;</pre><p>Once that mapping exists, the model stops guessing. It also stops drifting between sessions — the same Figma color produces the same code today as it will tomorrow, because both runs perform the same lookup.</p><p>The slogan: <strong>if your design system has tokens, your AI inherits them for free. If it doesn’t, your AI is guessing every time.</strong></p><h3><strong>The architecture</strong></h3><p>The flow, as documented in `<a href="https://github.com/aliafsahnoudeh/figma-to-code-claude-pipeline/blob/main/design-system/CLAUDE.md">design-system/CLAUDE.md</a>`:</p><pre>JSON tokens → zod validation → MUI theme → component overrides → consumer apps</pre><p>Three tiers of tokens, named by what they describe rather than where they’re used:</p><p>- <strong>Foundation</strong> — spacing, radius, typography, breakpoints, z-index</p><p>- <strong>Semantic</strong>— palette, elevation</p><p>- <strong>Components</strong> — button sizes, field sizes, dialog, table</p><p>Concrete files in the repo:</p><p>- Tokens: `<a href="https://github.com/aliafsahnoudeh/figma-to-code-claude-pipeline/blob/main/design-system/packages/themes/src/tokens/global.json">global.json</a>`, `<a href="https://github.com/aliafsahnoudeh/figma-to-code-claude-pipeline/blob/main/design-system/packages/themes/src/tokens/taskflow.json">taskflow.json</a>`</p><p>- Schema (zod): `<a href="https://github.com/aliafsahnoudeh/figma-to-code-claude-pipeline/blob/main/design-system/packages/themes/src/schema/tokenSchema.ts">tokenSchema.ts</a>`</p><p>- Tokens → MUI theme: `<a href="https://github.com/aliafsahnoudeh/figma-to-code-claude-pipeline/blob/main/design-system/packages/themes/src/createTheme.ts">createTheme.ts</a>`</p><p>- Wrapped components: `<a href="https://github.com/aliafsahnoudeh/figma-to-code-claude-pipeline/tree/main/design-system/packages/components/src">packages/components/src/</a>` — Button, Card, TextField, Dialog, Table, and 60+ others, all wrapping MUI</p><p>`<a href="https://github.com/aliafsahnoudeh/figma-to-code-claude-pipeline/blob/main/design-system/packages/themes/src/tokens/taskflow.json">taskflow.json</a>` only overrides the values that differ from `<a href="https://github.com/aliafsahnoudeh/figma-to-code-claude-pipeline/blob/main/design-system/packages/themes/src/tokens/global.json">global.json</a>` (it has `meta.extends: “global”`). The merge is deep, validated by zod, and <strong><em>then</em></strong> fed into MUI’s `createTheme`. Every consumer app sees a single coherent theme that came from a checked-in JSON file.</p><p>This is the part designers and engineers can both read. A designer doesn’t need to know what `createTheme` does; they need to know that `primary.main` is the brand purple. An engineer doesn’t need to memorize the brand purple; they need to know to use `primary.main`. And the AI agent, sitting between them, just needs to look up which is which.</p><h3><strong>The wrapper pattern: small, curated, JSDoc’d</strong></h3><p>This is where most design systems fail at AI codegen. They wrap nothing, expose everything, and rely on docs to keep teams aligned. That’s fine for a human reviewer who can spot the wrong import. It’s a disaster for an LLM that doesn’t know which prop is the “blessed” one.</p><p>I keep seeing the same failure mode in real projects. The AI writes code that looks right but is subtly off. Wrong elevation values. Hardcoded hex strings. MUI’s default theme leaking through because the components expose too much. The fix is never to prompt harder. It’s to wrap the components tighter and give the model a tokens file it can actually read. Output gets better in the same session.</p><p>The wrapper pattern is the answer. Here’s `<a href="https://github.com/aliafsahnoudeh/figma-to-code-claude-pipeline/blob/main/design-system/packages/components/src/Button.tsx">Button.tsx</a>` from the demo repo, simplified:</p><pre>export type ButtonColor =<br>| &quot;primary&quot; | &quot;secondary&quot; | &quot;error&quot; | &quot;warning&quot; | &quot;info&quot; | &quot;success&quot;;<br>export type ButtonVariant = &quot;contained&quot; | &quot;outlined&quot; | &quot;text&quot;;<br>export type ButtonSize = &quot;small&quot; | &quot;medium&quot; | &quot;large&quot;;<br>export interface ButtonProps {<br>  /** Button content */<br>  children: React.ReactNode;<br>  /** @default &#39;primary&#39; */<br>  color?: ButtonColor;<br>  /** @default &#39;contained&#39; */<br>  variant?: ButtonVariant;<br>  /** @default &#39;medium&#39; */<br>  size?: ButtonSize;<br>  loading?: boolean;<br>  // … cherry-picked, JSDoc&#39;d props only<br>   sx?: SxProps&lt;Theme&gt;;<br>}<br>export const Button = React.forwardRef&lt;HTMLButtonElement, ButtonProps&gt;(/* … */);</pre><p>Compare this to stock MUI’s `Button`, which exposes around 30 props directly and inherits dozens more through props spreading. The wrapped version exposes about 10. Each one has a JSDoc comment. Defaults are explicit. There’s no `{ …rest }` pass-through.</p><p>The non-negotiables, copied from `<a href="https://github.com/aliafsahnoudeh/figma-to-code-claude-pipeline/blob/main/design-system/CLAUDE.md">design-system/CLAUDE.md</a>`:</p><p>1. <strong>Never prefix components. </strong>Export `Button`, not `MyButton` or `TaskflowButton`.</p><p>2. <strong>Always wrap MUI.</strong> Never build from scratch.</p><p>3. <strong>Curate the API.</strong> Cherry-pick MUI props. No `{ …rest }` pass-through.</p><p>4. <strong>Token-driven.</strong> Sizing and colors come from tokens via `createTheme.ts` overrides.</p><p>5. <strong>`sx` is allowed but discouraged.</strong> Tokens cover the 90% case.</p><p>6. TypeScript strict, JSDoc on all public props.</p><p>7. WCAG 2.1 AA.</p><p>8. Named exports only.</p><p>Why this matters for AI implementation:</p><ul><li><strong>A small curated API is easier for an LLM to use correctly than the full MUI surface area.</strong> It physically can’t hallucinate `&lt;Button confusingExperimentalProp /&gt;` because the type system rejects it and the IDE tells the model the prop doesn’t exist.</li><li><strong>JSDoc on every prop</strong> gives the model a built-in docstring it sees at autocomplete time.</li><li><strong>All sizing and colors flow from tokens</strong>, so when the model writes `&lt;Button size=”medium”&gt;`, the spacing, radius, and font-size match Figma’s “medium button” spec automatically — no extra `sx` overrides, no hardcoded pixels.</li></ul><p>You’re not just building a design system. You’re building <strong>a contract</strong> that designers, engineers, and the AI agent all read the same way.</p><h3><strong>The Figma ↔ token mapping table</strong></h3><p>The single most useful artifact in the whole repo, from [`web/CLAUDE.md`](https://github.com/aliafsahnoudeh/figma-to-code-claude-pipeline/blob/main/web/CLAUDE.md):</p><pre>| Need              | Token (MUI `sx`)                |<br>| - -               | - -                             |<br>| Black / White     | `common.black` / `common.white` |<br>| Primary text      | `text.primary`                  |<br>| Secondary text    | `text.secondary`                |<br>| Disabled text     | `text.disabled`                 |<br>| Page background   | `background.default`            |<br>| Card / surface bg | `background.paper`              |<br>| Brand primary     | `primary.main`                  |<br>| Error / Success   | `error.main` / `success.main`   |<br>| Divider           | `divider`                       |<br>| Hover bg          | `action.hover`                  |</pre><p>Inside `<a href="https://github.com/aliafsahnoudeh/figma-to-code-claude-pipeline/blob/main/design-system/packages/themes/src/tokens/taskflow.json">taskflow.json</a>`, `primary.main` resolves to `#6366F1`. So a Figma fill of `#6366F1` becomes `primary.main` becomes:</p><pre>&lt;Box sx={{ color: &quot;primary.main&quot; }} /&gt;</pre><p><strong>Zero hex values in app code.</strong></p><p>This table lives in the CLAUDE.md file that auto-loads into every Claude Code session working in `<a href="https://github.com/aliafsahnoudeh/figma-to-code-claude-pipeline/tree/main/web">web/</a>`. Both the human and the AI read the same vocabulary, in the same place, every time.</p><p>`web/CLAUDE.md` also lists what’s <strong><em>forbidden</em></strong> in the consumer app:</p><p>- Direct `@mui/*` imports</p><p>- Hardcoded `#…`, `rgb()`, `hsl()` values in `sx`</p><p>- Custom button / input / dialog reimplementations</p><p>These prohibitions are enforced by a fast Haiku-powered linter agent — `<a href="https://github.com/aliafsahnoudeh/figma-to-code-claude-pipeline/blob/main/.claude/agents/design-system-check.md">design-system-check.md</a>` — that scans changed files and flags violations. Cheap to run on every change, fast enough to feel free.</p><h3><strong>Why curated APIs make LLM codegen reliable</strong></h3><p>The deeper principle behind the wrapper pattern: <strong>shrinking the surface area is the design move that makes AI codegen stable.</strong></p><p>Stock MUI exposes thousands of props across hundreds of components. Most of them you’ll never use. Many of them conflict with each other. Some of them silently override your theme. An LLM exploring this surface area is sampling from a probability distribution that includes a lot of plausible-but-wrong combinations.</p><p>A wrapped component with 10 cherry-picked props produces a much narrower distribution. The model can still generate wrong code — but the wrongness is constrained to the dimensions you actually care about. It can’t produce `&lt;Button experimentalNonsense /&gt;`. It can’t bypass your theme by passing inline styles. It can’t use a deprecated prop you removed three months ago. The type system literally rejects those outputs.</p><p>This is the same idea as building good tools for human engineers — narrow APIs are easier to use correctly than broad ones — but it’s <em>*more*</em> important when an LLM is the consumer, because the model can’t ask “is this the right way to do it?” before committing to an answer. By the time it’s typing the JSX, it’s already decided. Your job is to make sure the only decisions available are the right ones.</p><p>The same logic applies to your token JSON. If you have one source of truth for spacing — `theme.spacing(n)` — the model uses it consistently. If you have three sources of truth (`theme.spacing`, raw pixel values in `sx`, and a custom Tailwind config), the model picks one at random per file and you get drift.</p><h3><strong>The aspirational piece: closing the loop with Figma</strong></h3><p>There’s one part of this that isn’t yet automated, and I want to be honest about it: <strong>token sync from Figma to JSON is still manual.</strong></p><p>When a designer adds or changes a token in Figma, an engineer currently hand-edits `taskflow.json`. There’s a placeholder script at `<a href="https://github.com/aliafsahnoudeh/figma-to-code-claude-pipeline/blob/main/design-system/scripts/sync-figma-tokens.ts">design-system/scripts/sync-figma-tokens.ts</a>` that documents the intent — fetch tokens via the Figma API or <a href="https://tokens.studio/">Tokens Studio</a>, validate against the zod schema, write to the JSON files, open a PR. I haven’t shipped it yet.</p><p>Closing this loop is what would make the pipeline truly bidirectional: designer changes a token in Figma → CI fetches → zod validates → PR opens → engineers review → AI agent picks up the new token automatically the next time it generates code.</p><p>Today the loop is one-way: tokens flow from JSON to MUI to wrapped components to the AI’s mental model. Designers still have to ping engineers when they update Figma. It’s the largest gap in the system and the one I’d close next.</p><p>I want to be careful not to undersell this. On a stable team, manual sync is annoying but fine. On a fast-moving one it’s a real risk. In early-stage startups the Figma file and the codebase drift apart every week. The JSON goes stale fast. When that happens the AI is looking up the wrong values, and the whole contract quietly stops working. So for some teams this isn’t a nice-to-have. It’s the thing that decides if the system holds up at all.</p><h3><strong>What this is, distilled</strong></h3><p>A design system built as an AI contract has, in my experience, four essential properties:</p><p>1. <strong>A token JSON file as the single source of truth for design values</strong> — validated by a schema, deep-merged across themes, fed into your component library’s theming system. No design value lives anywhere else.</p><p>2. <strong>A thin wrapper layer over your component library</strong>, with a curated, JSDoc’d, type-safe prop interface per component. No `{ …rest }` spreading. No direct vendor imports allowed in app code.</p><p>3. <strong>A mapping table between Figma values and tokens</strong> — published in the same place humans and AI agents both read (CLAUDE.md, README, whatever your team’s convention is). The mapping is what turns translation into lookup.</p><p>4. <strong>A linter agent or rule that enforces token usage in app code.</strong> This is the part that keeps the contract honest over time. Without it, teams drift back to hardcoding within weeks. The first time someone is in a hurry, they paste a hex value and move on. The linter catches that on every PR, so the rules don’t rot. With enforcement, every PR is automatically design-system-compliant.</p><p>None of this is specific to MUI, to Claude Code, or to the demo repo. The same pattern works with shadcn, Mantine, Chakra, an in-house component library — anywhere you have a vendor library you can wrap and a theme system you can drive from JSON.</p><p>What changes when you have it: <strong>the AI stops guessing.</strong> A frontend implementation request becomes a series of lookups against a contract everyone agreed to. Your codebase stays consistent across sessions, across developers, across the inevitable churn of “let me try a different model this week.”</p><p>The slogan, again: <strong><em>if your design system has tokens, your AI inherits them for free. If it doesn’t, your AI is guessing every time.</em></strong></p><p>Build the contract. Wrap your library. Publish the mapping. Then go let the agent loose.</p><p><strong><em>The full demo repo, MIT-licensed</em></strong><em>: </em><a href="https://github.com/aliafsahnoudeh/figma-to-code-claude-pipeline"><strong>github.com/aliafsahnoudeh/figma-to-code-claude-pipeline</strong></a><em>.</em></p><p><strong><em>If you missed </em></strong><a href="https://medium.com/@aliafsah1988/how-to-turn-claude-code-into-a-figma-to-react-pipeline-that-visually-verifies-its-own-work-030246f600a9"><strong><em>the first post</em></strong></a><strong><em> in this series, it covers the other half: how the agent harness, MCP servers, and hooks compose into a Figma-to-React pipeline that visually verifies its own work.</em></strong></p><p><strong><em>I write about AI engineering and frontend architecture on </em></strong><a href="https://medium.com/@aliafsah1988"><strong><em>Medium</em></strong></a><strong><em>. I build production AI agent systems and design-system infrastructure for a living. If you’re hiring for senior or staff full-stack / AI engineering roles, I’m </em></strong><a href="https://www.linkedin.com/"><strong><em>on LinkedIn</em></strong></a><strong><em>.</em></strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6055e4667fa9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to turn Claude Code into a Figma-to-React pipeline that visually verifies its own work]]></title>
            <link>https://medium.com/@aliafsah1988/how-to-turn-claude-code-into-a-figma-to-react-pipeline-that-visually-verifies-its-own-work-030246f600a9?source=rss-ad76ef429ff4------2</link>
            <guid isPermaLink="false">https://medium.com/p/030246f600a9</guid>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[claude]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Ali Afsah-Noudeh]]></dc:creator>
            <pubDate>Mon, 04 May 2026 09:11:22 GMT</pubDate>
            <atom:updated>2026-05-04T09:11:22.697Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bNJQoFQ3BPJvo0o_KEEcug.png" /></figure><p><em>An MCP-driven agent harness with two design-loop tools, four scoped CLAUDE.md files, and hooks that block until the code type-checks.</em></p><h3><strong>The problem with “AI codegen for frontend”</strong></h3><p>Most AI coding assistants are fast at producing UI that <strong><em>looks</em></strong> right and slow at producing UI that <strong><em>matches the design</em></strong>. Drop a screenshot of a Figma frame into a chat window, ask for the React, and you’ll usually get something plausible — and subtly wrong everywhere it matters. Spacing eyeballed. Colors rounded to whatever hex felt close. Component picked from memory rather than your design system.</p><p>The model isn’t dumb. It’s just guessing, because the loop never closes. There’s no point at which the code is compared back to the design.</p><p>I spent some time turning <a href="https://www.anthropic.com/claude-code">Claude Code</a> into a frontend pipeline that closes that loop. Give it a Figma URL and a target route, and it will:</p><p>1. Pull the <strong>real design tokens </strong>(not pixels) from Figma via the Figma MCP server.</p><p>2. Map them to a token-driven, <a href="https://mui.com/material-ui/">MUI</a>-wrapped (it can be other component libraries) Design System.</p><p>3. Implement the feature in a Next.js app following our project conventions.</p><p>4. Open the page in a real browser via the Playwright MCP server, take a screenshot, and visually diff it against the Figma frame.</p><p>5. Iterate until the implementation matches.</p><p>The full demo repository is here:</p><p><a href="https://github.com/aliafsahnoudeh/figma-to-code-claude-pipeline"><strong>github.com/aliafsahnoudeh/figma-to-code-claude-pipeline</strong></a></p><p>This post walks through the four pieces that make it work: the MCP servers, the agent prompt, the hooks that act as guardrails, and the committed-template pattern that makes the whole setup reproducible. The next post in this series covers the design system half of the equation — why a token-driven, wrapped-MUI design system is what makes any of this fast and reliable. Without that, the agent is still guessing.</p><h3><strong>The four-ingredient recipe</strong></h3><p>Before going deep, here’s the whole thing at a glance:</p><ul><li><strong>Two MCP servers</strong> — Figma (read tokens, screenshots) and Playwright (drive a real browser)</li></ul><p>Why it matters? The agent can both <strong><em>see</em></strong> the design and <strong><em>see</em></strong> its own output. Without these the loop can’t close.</p><ul><li><strong>A specialized `figma-impl` agent</strong> with a strict 5-step process</li></ul><p>Why it matter? “Use tokens” is too easy to skip. A pre-baked extract → map → implement → verify loop forces the model through each step.</p><ul><li><strong>PostToolUse hooks</strong> that auto-format and auto-typecheck every file the agent writes</li></ul><p>Why it matter? The harness enforces conventions so the prompt doesn’t have to. The agent gets type errors shoved back at it until it fixes them.</p><ul><li><strong>A committed settings template + bootstrap script</strong></li></ul><p>Why it matter? Every developer (and every Claude session) ends up with the same MCPs, the same hooks, the same permissions — without forcing identical config on every machine.</p><p>Now let’s go through each.</p><h4><strong>1. The two MCP servers</strong></h4><p><a href="https://modelcontextprotocol.io/">Model Context Protocol</a> is the open standard Anthropic published for letting LLMs talk to external tools. Each MCP server exposes a typed set of tools that any MCP-aware client can call. Two of them turn Claude Code from “smart autocomplete” into “frontend implementer”.</p><p>Both are declared in `<a href="https://github.com/aliafsahnoudeh/figma-to-code-claude-pipeline/blob/main/.claude/settings.example.json">.claude/settings.example.json</a>`:</p><pre>&quot;mcpServers&quot;: {<br>  &quot;playwright&quot;: { &quot;command&quot;: &quot;npx&quot;, &quot;args&quot;: [&quot;-y&quot;, &quot;@playwright/mcp&quot;] },<br>  &quot;figma-local&quot;: {<br>    &quot;command&quot;: &quot;npx&quot;,<br>    &quot;args&quot;: [&quot;-y&quot;, &quot;figma-developer-mcp&quot;, &quot; - figma-api-key=YOUR_TOKEN&quot;, &quot; - stdio&quot;]<br>  }<br>}</pre><p><strong>Figma MCP — `figma-local`</strong></p><p>The Figma MCP server is what makes “translate Figma to code” deterministic. The agent uses these tools:</p><pre>| Tool                   | Returns                                           |<br>| - - - - - - - - - - - -|- - - - - - - - - - - - - - - - - - - - - - - - - -|<br>| `get_design_context`   | Code hints + structure + screenshot for a node    |<br>| `get_metadata`         | Detailed node properties - sizes, paddings, fills |<br>| `get_variable_defs`    | Figma variables → token map                       |<br>| `get_screenshot`       | A PNG of a specific node, for visual diffing      |<br>| `search_design_system` | Lookup against the linked design system in Figma  |</pre><p>The crucial property: <strong>these tools return real values, not pixels.</strong> A `get_metadata` call on a button doesn’t say “looks like 12 pixels of padding”; it says `paddingLeft: 12, paddingRight: 12`. The agent prompt explicitly instructs the model not to eyeball spacing or typography from screenshots — extract them from `get_metadata` and `get_variable_defs`, and <strong><em>only</em></strong> use the screenshot for the visual diff at the end.</p><p>One non-obvious gotcha: the ` — stdio` flag in the args is mandatory. Without it the server starts in HTTP mode and Claude Code can’t talk to it. The repo-wide `<a href="https://github.com/aliafsahnoudeh/figma-to-code-claude-pipeline/blob/main/CLAUDE.md">CLAUDE.md</a>` calls this out so the AI doesn’t reinvent the install incorrectly when it’s helping a new dev set up.</p><p><strong>Playwright MCP</strong></p><p>The Playwright MCP server gives the agent a real browser. The tools the agent uses:</p><p>- `browser_navigate(url)` — open a page</p><p>- `browser_resize(width, height)` — match the Figma frame’s dimensions exactly</p><p>- `browser_take_screenshot()` — capture the rendered output</p><p>- `browser_snapshot()` — accessibility-tree snapshot for assertions</p><p>- `browser_click`, `browser_fill_form`, `browser_evaluate` — exercise interactive flows</p><p>This is what closes the loop. After generating code, the agent boots the dev server, navigates to the route, resizes the viewport to match the Figma frame, takes a screenshot, calls `get_screenshot` on the same Figma node, and compares them. If the footer spacing is 24px instead of 16px, it sees the discrepancy and fixes it.</p><p>`<a href="https://github.com/aliafsahnoudeh/figma-to-code-claude-pipeline/blob/main/web/CLAUDE.md">web/CLAUDE.md</a>` makes Playwright verification mandatory for <strong><em>all</em></strong> frontend work — not just Figma implementations. If you change a component, you screenshot the result. It costs the agent maybe 10 seconds and removes an entire class of “looks fine in code, broken in the browser” bugs.</p><h4><strong>2. The `figma-impl` agent — process baked into the prompt</strong></h4><p>In Claude Code, an “agent” is a markdown file with YAML frontmatter that defines a sub-agent the parent session can delegate to. Each one has a name, a description, a tool whitelist (narrower than the parent’s), a model choice, and a prompt body.</p><p>The pattern across the agent roster in this repo: <strong>bake the process into the prompt, narrow the tool surface, pick the right model for the job.</strong></p><pre>| Agent                    | Model  | Purpose                                                                                   |<br>| - -                      | - -    | - -                                                                                       |<br>| `figma-impl`             | sonnet | Implement UI from a Figma URL - the keystone                                              |<br>| `design-system-component`| sonnet | Scaffold a new wrapped-MUI component                                                      |<br>| `design-system-check`    | haiku  | Fast linter - catches direct `@mui/*` imports, hardcoded hex values, custom UI duplicates |<br>| `code-reviewer`          | sonnet | Reviews staged + unstaged changes against project rules                                   |<br>| `test-writer`            | sonnet | Writes pytest async (backend) or Jest+RTL (web) tests                                     |<br>| `api-scaffold`           | sonnet | Scaffolds a new FastAPI resource with schemas, router, store, tests                       |</pre><p>Two things worth noting up front. First, the <strong>model split</strong>: fast lookups and lints use Haiku, substantive code generation uses Sonnet. Cheap when cheap is fine, capable where it matters. Second, the <strong>tool whitelists</strong> — the Figma agent has no git tools and no shell access beyond `Bash`, the design-system-check agent can only read and grep. The blast radius of any single agent is bounded by what you let it touch.</p><p><strong>The figma-impl prompt, dissected</strong></p><p>Here’s the frontmatter (the actual file has the tools comma-separated on one line — broken here for readability):</p><pre>name: figma-impl<br>description: Implements UI features from Figma designs with pixel-perfect accuracy…<br>tools: Read, Grep, Glob, Bash, Write, Edit,<br>mcp__figma-local__get_design_context,<br>mcp__figma-local__get_screenshot,<br>mcp__figma-local__get_metadata,<br>mcp__figma-local__get_variable_defs,<br>mcp__figma-local__search_design_system,<br>mcp__playwright__browser_navigate,<br>mcp__playwright__browser_snapshot,<br>mcp__playwright__browser_take_screenshot,<br>mcp__playwright__browser_resize,<br>mcp__playwright__browser_close<br>model: sonnet</pre><p>Notice what’s missing: no `Bash(git …)` patterns, no database tools, no destructive shell commands. This agent is safe to let loop on visual diffs because it can’t accidentally commit anything or drop a table.</p><p>The prompt body enforces a strict 5-step process:</p><p>1. <strong>Extract design data.</strong> Parse the Figma URL into `fileKey` + `nodeId`. Call `get_design_context`, `get_metadata`, `get_variable_defs`, `get_screenshot`. Document spacing, typography, colors, radius, shadows, layout, hierarchy. <strong><em>Real values, never eyeballed</em></strong><em>.</em></p><p>2. <strong>Map to the Design System. </strong>Read `<a href="https://github.com/aliafsahnoudeh/figma-to-code-claude-pipeline/blob/main/design-system/packages/components/src/index.ts">design-system/packages/components/src/index.ts</a>` first to see what’s available. Map Figma colors to design system tokens. Identify which design system components match Figma elements. (More on this in the next post — the design system is what makes step 2 a lookup instead of a guess.)</p><p>3. <strong>Implement.</strong> Follow the conventions in `<a href="https://github.com/aliafsahnoudeh/figma-to-code-claude-pipeline/blob/main/web/CLAUDE.md">web/CLAUDE.md</a>`: `@taskflow/components` only (no direct MUI imports), files under `domains/{domain}/components/`, hooks separated from JSX, `”use client”` only when needed.</p><p>4. <strong>Visual verification — mandatory.</strong> `pnpm dev`, `browser_navigate`, `browser_resize` to the Figma frame size, `browser_take_screenshot`. Then `get_screenshot` from Figma for the same node. Compare. <strong>If discrepancies, fix and repeat.</strong></p><p>5. <strong>Report. </strong>Components created/modified, tokens mapped (Figma value → token), unmappable elements, visual diff result.</p><p>The prompt ends with a hard rule list: no hardcoded hex values, must use design system components, must visually verify. These are stated as non-negotiables because in practice, without them, the model will skip step 4 about a third of the time. With them, it doesn’t.</p><p>That’s the keystone insight of agent design: <strong>the prompt encodes the process, not just the rules.</strong> Telling the model “you must use tokens” is too easy to forget. A 5-step procedure with a mandatory verification gate forces it through every step.</p><h4><strong>3. Hooks: the silent guardrails</strong></h4><p>CLAUDE.md files <strong><em>describe </em></strong>rules. Hooks <strong><em>enforce</em></strong> them. Hooks are commands that run before or after specific tool calls, and they can either pass through, log something, or <strong>block the tool call</strong> by exiting non-zero.</p><p>Three hooks are configured for this repo. Together they handle three different failure modes.</p><p><strong>Hook 1: `read_hook.js` — env file guard (PreToolUse)</strong></p><p>`<a href="https://github.com/aliafsahnoudeh/figma-to-code-claude-pipeline/blob/main/.claude/hooks/read_hook.js">.claude/hooks/read_hook.js</a>` is about 20 lines. Most of it is stdin plumbing. The actual check is two lines:</p><pre>const readPath = toolArgs.tool_input?.file_path || toolArgs.tool_input?.path || &quot;&quot;;<br>if (readPath.includes(&quot;.env&quot;)) {<br>  console.error(&quot;You cannot read the .env file&quot;);<br>  process.exit(2); // exit 2 BLOCKS the tool call<br>}</pre><p>Triggered on every `Read` and `Grep`, this is enough to keep the model from accidentally pulling secrets into context. Exit code 2 is the magic number — it tells Claude Code to block the call and surface the error message to the model so it knows <strong><em>why</em></strong> it was blocked.</p><p><strong>Hook 2: `tsc.js` — auto type-check (PostToolUse)</strong></p><p>`<a href="https://github.com/aliafsahnoudeh/figma-to-code-claude-pipeline/blob/main/.claude/hooks/tsc.js">.claude/hooks/tsc.js</a>` is the most consequential hook in the whole setup. After every `Write`, `Edit`, or `MultiEdit` on a `.ts` or `.tsx` file, it:</p><p>1. Detects the sub-project (`web/` or `design-system/`).</p><p>2. Runs that project’s `tsc — project tsconfig.json` (no emit).</p><p>3. If type-check fails, exits with status 2 — which surfaces the errors to the model and forces it to fix them before moving on.</p><p>This is the difference between “the agent generated TypeScript” and “the agent generated TypeScript that compiles.” The model can’t ignore type errors because the harness keeps shoving them back into its face.</p><p><strong>Hook 3: auto-prettier (PostToolUse)</strong></p><p>In `<a href="https://github.com/aliafsahnoudeh/figma-to-code-claude-pipeline/blob/main/.claude/settings.json">.claude/settings.json</a>`:</p><pre>{<br>  &quot;type&quot;: &quot;command&quot;,<br>  &quot;command&quot;: &quot;jq -r &#39;.tool_response.filePath // .tool_input.file_path // empty&#39; | xargs -I {} npx - yes prettier - write {} 2&gt;/dev/null || true&quot;,<br>  &quot;statusMessage&quot;: &quot;Formatting with Prettier…&quot;<br>}</pre><p>A one-liner. Pulls the written file path out of the tool payload, runs prettier on it, ignores errors. The model never produces unformatted code, and on the next read its context matches what’s actually on disk.</p><p><strong>The deeper point</strong></p><p>Hooks make conventions <strong>enforceable, not just documented</strong>. You don’t have to remind the model “remember to run prettier” — the harness runs it. You don’t have to remind it “fix the type errors” — the harness blocks until they’re fixed. CLAUDE.md <strong><em>describes</em></strong> rules; hooks <strong><em>enforce</em></strong> them.</p><p>The same idea applies to <a href="https://github.com/aliafsahnoudeh/figma-to-code-claude-pipeline/tree/main/.claude/skills">skills</a>, which are user-invokable slash commands. The two with side effects — `<a href="https://github.com/aliafsahnoudeh/figma-to-code-claude-pipeline/blob/main/.claude/skills/commit/SKILL.md">/commit</a>` and `<a href="https://github.com/aliafsahnoudeh/figma-to-code-claude-pipeline/blob/main/.claude/skills/pr/SKILL.md">/pr</a>` — set `disable-model-invocation: true` in their frontmatter, which means the model can prepare the work but can’t unilaterally publish it. Only the user triggers a commit or a PR. That’s a second safety pattern: scope autonomy by side-effect class, not by trust.</p><p><strong>4. The committed-template pattern</strong></p><p>Three settings files live in `.claude/`:</p><pre>| File                            | Status     | Purpose                                                           |<br>| - -                             | - -        | - -                                                               |<br>| `.claude/settings.json`         | Committed  | Minimal shared config: 1 MCP server + auto-prettier hook          |<br>| `.claude/settings.example.json` | Committed  | The real template - 2 MCPs, all hooks. Consumed by the bootstrap. |<br>| `.claude/settings.local.json`   | Gitignored | Per-developer materialized config                                 |</pre><p>The clever bit is the bootstrap script, `<a href="https://github.com/aliafsahnoudeh/figma-to-code-claude-pipeline/blob/main/scripts/init-claude.js">scripts/init-claude.js</a>`. What it does:</p><p>1. Reads `<a href="https://github.com/aliafsahnoudeh/figma-to-code-claude-pipeline/blob/main/.claude/settings.example.json">.claude/settings.example.json</a>`.</p><p>2. Replaces literal `$PWD` placeholders with the developer’s absolute path.</p><p>3. <strong>Merges</strong> with any existing `settings.local.json` instead of overwriting — user-added permissions are preserved across updates to the template.</p><p>4. Symlinks the user’s <em>global</em> Claude state (`~/.claude.json`, the auto-memory directory) into `.claude/dashboard/` so you can browse them without leaving the project.</p><p>The pattern is: <strong>committed template → optional environment-aware bootstrap → merged local file</strong>. Every dev (and every Claude session) gets the same MCPs, hooks, and conventions — without forcing identical permissions onto everyone’s machine. New team member runs `node scripts/init-claude.js`, swaps in their Figma token, and is configured identically to everyone else in five seconds.</p><p>For a solo developer this is overkill. For a team, it’s the difference between “the AI works for me but not for Cyrus” and “the AI works the same way for everyone.”</p><h3><strong>What an end-to-end session looks like</strong></h3><p>Here’s a real authoring loop, slightly compressed:</p><p>You: “Implement a ‘create task’ modal from</p><p>https://figma.com/design/&lt;fileKey&gt;/TaskFlow?node-id=&lt;nodeId&gt;</p><p>at /projects/p_website.”</p><p>Claude (figma-impl agent):</p><p>1. Calls get_design_context, get_metadata, get_variable_defs.</p><p>2. Reads design-system/packages/components/src/index.ts.</p><p>3. Maps:</p><p>Figma fill #6366F1 → primary.main</p><p>Figma 16px padding → theme.spacing(2)</p><p>Figma “Heading/H2” → &lt;Typography variant=”h2&quot;&gt;</p><p>Figma “Primary button” → &lt;Button color=”primary” variant=”contained” /&gt;</p><p>4. Creates web/src/domains/tasks/components/CreateTaskModal.tsx</p><p>(and CreateTaskModal.test.tsx — tests are mandatory).</p><p>→ Auto-prettier hook formats it on write.</p><p>→ tsc.js hook type-checks; if errors, agent fixes before moving on.</p><p>5. Boots Playwright: browser_navigate(“http://localhost:3000/projects/p_website&quot;),</p><p>browser_resize(1440, 900), browser_take_screenshot().</p><p>6. Calls get_screenshot from Figma for the same node.</p><p>7. Diff: footer spacing is 24px not 16px → fixes → re-screenshots.</p><p>8. Reports: 1 file created, 1 test, all colors mapped to tokens, visual diff matches.</p><p>You: /commit # only the user can trigger this</p><p>You: /pr # same — disable-model-invocation</p><p>The agent doesn’t ship anything. It prepares the work, verifies it against the design, and hands the side-effecting steps back to me.</p><h3><strong>Why this works (and where it doesn’t)</strong></h3><p>The reason this pipeline is fast and reliable, distilled:</p><p>1. <strong>The agent has both eyes open.</strong> Figma MCP lets it see the design as structured data. Playwright MCP lets it see its own output as a real rendered page. With only one of those, the loop never closes.</p><p>2. <strong>The process is in the prompt.</strong> “Use tokens” is too easy to skip. A 5-step prompt with a mandatory visual-verification gate forces the model through every step.</p><p>3. <strong>Hooks make rules enforceable.</strong> Auto-prettier on write, auto-tsc on edit, env-file blocker on read. The model doesn’t have to <strong><em>remember </em></strong>— the harness enforces.</p><p>4. <strong>Tool whitelists per agent bound the blast radius.</strong> The Figma agent can’t commit. The design-system-check agent can’t write code at all. Each agent gets exactly the surface area it needs.</p><p>5. <strong>`disable-model-invocation` on side-effecting skills is a second safety layer.</strong> The model can prepare a commit or a PR; only the user can publish.</p><p>What this pipeline <strong><em>doesn’t</em></strong> solve:</p><ul><li><strong>Figma → token sync is still manual.</strong> When designers add a token in Figma, an engineer hand-edits the JSON in `design-system/packages/themes/src/tokens/`. There’s a placeholder script for closing this loop with the Tokens Studio API; I haven’t shipped it yet.</li><li><strong>The agent occasionally needs nudging when Figma frames have weak naming.</strong> “Frame 247” gives it nothing to work with. Well-named layers with linked variables make it three times faster.</li><li><strong>”Visual diff” is human-judged comparison of two screenshots, not pixel-diffed.</strong> The agent describes the differences it sees and decides whether they’re significant. Most of the time that’s enough; occasionally I have to push back on what it considers “matching.”</li></ul><h3><strong>The next post: why your design system is the hidden bottleneck</strong></h3><p>I deliberately glossed over step 2 — “map to the design system” — in this post, because it’s the half of the story that deserves its own treatment. The pipeline above only works because the design system is built specifically as a target for AI codegen: a small curated API, every token JSON-defined and zod-validated, MUI wrapped underneath, every component cherry-picking only the props it actually wants to expose.</p><p>If you give an AI agent stock MUI plus a Figma frame, you’re asking it to invent a mapping every time. It will be plausible and inconsistent. If you give it a token-driven wrapper layer with a published vocabulary, you’ve turned the hardest part of the job into a lookup table — and LLMs are excellent at lookups.</p><p>That’s the next post. Until then, the full repository is at <a href="https://github.com/aliafsahnoudeh/figma-to-code-claude-pipeline"><strong>github.com/aliafsahnoudeh/figma-to-code-claude-pipeline</strong></a> — clone it, point it at one of your own Figma files, and let the agent close the loop.</p><p><em>I write about AI engineering and agent systems on </em><a href="https://medium.com/@aliafsah1988"><em>Medium</em></a><em>. I build production AI agent systems for a living . Personal AI projects (wildfire detection, multilingual RAG, an MCP server for Persian classical literature) are on my </em><a href="https://github.com/aliafsahnoudeh"><em>GitHub</em></a><em>. If you’re hiring for senior or staff AI / full-stack roles, I’m </em><a href="https://www.linkedin.com/"><em>reachable on LinkedIn</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=030246f600a9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to properly use Typescript, OOP and SOLID in modern web applications]]></title>
            <link>https://medium.com/@aliafsah1988/how-to-properly-use-typescript-oop-and-solid-in-modern-web-applications-e4ef88761154?source=rss-ad76ef429ff4------2</link>
            <guid isPermaLink="false">https://medium.com/p/e4ef88761154</guid>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[dependency-injection]]></category>
            <category><![CDATA[vuejs]]></category>
            <category><![CDATA[object-oriented-program]]></category>
            <dc:creator><![CDATA[Ali Afsah-Noudeh]]></dc:creator>
            <pubDate>Mon, 09 May 2022 09:58:46 GMT</pubDate>
            <atom:updated>2022-05-27T14:42:21.221Z</atom:updated>
            <content:encoded><![CDATA[<h3>The problem, the motivation and the goal</h3><p>In my opinion using <a href="https://www.typescriptlang.org/">Typescript</a> and object oriented programming paradigm is beneficial for medium to large and in general enterprise projects.</p><p>We can leverage many things like types and abstractions which can lead to loose coupling and it means more usability and more maintainability. These topics might seem fancy at first sight but they are important for big applications!</p><p>When I learned more about software architecture and tried to write better codes I was a backend developer. Later when I re-entered the client side world, I was confused how to organize my code as cleanly as I did in backend ones! Especially in JavaScript codebases I saw lots of failed attempts to use functional programming paradigm which were just violating every single principle of this paradigm. They were basically just using functions in a very bad and confusing way and most of them ended up making spaghettis!</p><p>I want to share what I’ve learned so far about how to leverage advanced techniques to improve a web client codebase quality.</p><p>To explain the implementation of each piece, I’ve created two SPAs with React.js and Vue.js and will refer to them in each step.</p><p>There is a link to each repository here:</p><p><a href="https://github.com/aliafsahnoudeh/react-oop-solid">React.js codebase</a></p><p><a href="https://github.com/aliafsahnoudeh/vue-oop-solid">Vue.js codebase</a></p><h3>A simple example for comparison</h3><p>Imagine that we have two pretty standard server-side and client-side code bases. No third parties, no specific complexity! Our backend is a simple CRUD server which exposes a RESTful api and our client application is a SPA with a couple of pages. But they are going to be big applications eventually! Implementation of object oriented programming and SOLID principles and advanced techniques like dependency injection are more obvious in our imaginary backend project! I think because we are usually dealing with one type of element, logical components. For instance in a node.js app, usually JavaScript and Typescript files which contain our logic. This logic can vary from listening to a port to working with a database but still one type of component.</p><p>On the other hand in the web client, we also have UI components and all things related to them. And that’s why it’s getting less obvious how we can leverage those mentioned techniques.</p><h3>The solution: Basic principles</h3><p>Finally I ended up just thinking about some important basic principles and by respecting them, tried to find my way to have a better code base incrementally. And here they are:</p><h3>1) Three layered architecture</h3><p>The base idea is to split everything into three layers, similar to MVVM or MVP. Everything related to UI should be in the <strong>presentation layer</strong>. Everything related to business and logic in the <strong>logic layer</strong> and everything related to data and state in the <strong>model layer</strong></p><ul><li>Presentation layer: views and ui-components</li><li>Logic layer: services and logical-components</li><li>Model layer: stores and types</li></ul><p>Look at these two examples:</p><p><a href="https://github.com/aliafsahnoudeh/react-oop-solid/tree/main/src">React.js project structure</a></p><figure><img alt="React.js code structure" src="https://cdn-images-1.medium.com/max/358/1*5DdDbKixGcO1R5izd7Ha8w.png" /></figure><p>and<a href="https://github.com/aliafsahnoudeh/vue-oop-solid/tree/main/src"> Vue.js project structure</a></p><figure><img alt="Vue.js code structure" src="https://cdn-images-1.medium.com/max/406/1*blHXsSWLskTI0xZWEEH0mA.png" /></figure><h3>2) Separated presentation</h3><p>Very simple but very important <a href="https://martinfowler.com/eaaDev/SeparatedPresentation.html">principle</a>. In the client side applications we need to <strong>separate our business logic from UI logic</strong>. Which means we need to keep everything related to UI inside our UI components and extract the business logic somewhere else which I’ll talk about very soon!</p><p>By doing this, we are making life easier for everyone including ourselves! UI components can focus on just UI logic. Things like what to show and when to render them, how to deal with user actions and so on.</p><h3>3) Separation of concerns</h3><p>We need to split UI and logical components to smaller pieces and each piece should do just one thing ideally. These small pieces can be reused all across our application. In a real world situation, a perfect result is probably impossible but we can at least try to be as close as possible to this goal.</p><p>In UI components:</p><p>By having a <strong>component based</strong> approach.</p><p>And in our logical components:</p><p>By using <strong>compositions</strong>.</p><p>By having these two approaches we can have reusability and more <strong>code coherence</strong>. So as a result we will have reusable pieces which can contain a very specific logic and keep all of the elements in the same place rather than split them in different places!</p><p>For example in a React.js application we can achieve it with <a href="https://reactjs.org/docs/hooks-custom.html#extracting-a-custom-hook"><strong>costume hooks</strong></a> and in Vue.js with <a href="https://vuejs.org/guide/extras/composition-api-faq.html"><strong>composition api</strong></a>. Both very clean and practical. If you haven’t tried them, I strongly suggest doing it. After properly using them, you will have a cleaner code which is much easier to test and maintain.</p><p><a href="https://github.com/aliafsahnoudeh/react-oop-solid/blob/main/src/logical-components/useCompnaies.ts">An example of custom hook in a React.js app.</a></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dea942c9843067857c2162af8ff3d299/href">https://medium.com/media/dea942c9843067857c2162af8ff3d299/href</a></iframe><p><a href="https://github.com/aliafsahnoudeh/vue-oop-solid/blob/main/src/logical-components/useCompanies.ts">An example of composition API in a Vue.js app</a>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7bb80171649079f5553601f944f54f1e/href">https://medium.com/media/7bb80171649079f5553601f944f54f1e/href</a></iframe><p>On top of that, the business logic can be isolated and just gives an abstraction to their consumers, in our case presentation layer.</p><h3>4) OOP</h3><p>Now that we have our reusable, testable and clean components, we need to think about the logic, the business logic.</p><p>First of all, based on our imaginary application we need to interact with a server. We definitely don’t want to mess it up with UI stuff. Also after receiving the data from the server or an action from the user, we might need to process some data or do some calculations/mappings.</p><p>I always divide this part into two pieces. I separate everything related to the outside world like API calls from the actual logic like calculations, mappings etc.</p><p>In an ideal world every single piece should solve a single problem and <strong>encapsulates</strong> what it’s doing from outside. On the other hand it should provide an <strong>abstraction</strong> to its consumers and show just necessary information. We can achieve this by using <strong>interfaces</strong>, <strong>IOC containers</strong> and <strong>dependency injection</strong>. Different elements will be coupled loosely to each other and be injected to the presentation layer. We can have this mechanism in one or multiple places. For instance if our application is big and we separated our code base into different modules based on business domains, and each module is maintained by a different team, we can have a separated injection unit for each module but keep the common stuff in the root.</p><p>Hopefully TypeScript provides interfaces. Also for the actual injection we have some tools as well! For instance we can use<a href="https://reactjs.org/docs/context.html"> context</a> in React.js or<a href="https://vuejs.org/guide/components/provide-inject.html"> provide/inject</a> in Vue.js.</p><p><a href="https://github.com/aliafsahnoudeh/react-oop-solid/blob/main/src/IocContainer.ts">An example of IOC container in TypeScript</a>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/71568789ba9f860f84d8b3a15a687c2c/href">https://medium.com/media/71568789ba9f860f84d8b3a15a687c2c/href</a></iframe><p><a href="https://github.com/aliafsahnoudeh/react-oop-solid/blob/main/src/services/index.ts">An example of injecting dependencies in a React.js app</a>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a68753ee0be66fcea2faf0eafdcf4ee2/href">https://medium.com/media/a68753ee0be66fcea2faf0eafdcf4ee2/href</a></iframe><p><a href="https://github.com/aliafsahnoudeh/react-oop-solid/blob/main/src/logical-components/useCompnaies.ts#L8">An example of using injected dependency in React.js</a>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ef109a22f0dd34c07897d89ee9e5363c/href">https://medium.com/media/ef109a22f0dd34c07897d89ee9e5363c/href</a></iframe><p><a href="https://github.com/aliafsahnoudeh/vue-oop-solid/blob/main/src/services/index.ts">An example of injecting dependencies in a Vue.js app</a>:<a href="https://github.com/aliafsahnoudeh/vue-oop-solid/blob/main/src/services/index.ts"> here</a>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5a8b527839fcb8c64271c74b0e9a84d1/href">https://medium.com/media/5a8b527839fcb8c64271c74b0e9a84d1/href</a></iframe><p>and<a href="https://github.com/aliafsahnoudeh/vue-oop-solid/blob/main/src/App.vue#L9"> Providing it here</a>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/be21a803a461ffc2977b165022b78ffa/href">https://medium.com/media/be21a803a461ffc2977b165022b78ffa/href</a></iframe><p><a href="https://github.com/aliafsahnoudeh/vue-oop-solid/blob/main/src/logical-components/useCompanies.ts#L13">An example of using injected dependency in Vue.js</a></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/92df926b6874be8b7bb18238cb8807fe/href">https://medium.com/media/92df926b6874be8b7bb18238cb8807fe/href</a></iframe><h3>5) Types and model layer</h3><p>Finally for our model layer, we can keep state of some specific actions inside the related compositions so we can make sure about code coherence. And also put the shared ones in our global state management. This state management can have different sub modules. For instance in React.js if we use<a href="https://github.com/pmndrs/zustand"> Zustand</a>, we can create multiple stores and keep related data in them. Or in Vue.js we can have our modules inside<a href="https://vuex.vuejs.org/"> Vuex</a> or<a href="https://pinia.vuejs.org/"> Pinia</a>.</p><p><a href="https://github.com/aliafsahnoudeh/react-oop-solid/blob/main/src/store/index.ts">An example of global state management in a React.js app</a>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/79e1ca587aff205ccf5948617daa85a5/href">https://medium.com/media/79e1ca587aff205ccf5948617daa85a5/href</a></iframe><p><a href="https://github.com/aliafsahnoudeh/vue-oop-solid/blob/main/src/store/index.ts">An example of global state management in a Vue.js app</a>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3944d95365a43ffbdccb36dd0c5c951d/href">https://medium.com/media/3944d95365a43ffbdccb36dd0c5c951d/href</a></iframe><p>Also I strongly suggest having a lot of types to leverage TypeScript more. And I think it’s beneficial to keep them in the central place to prevent confusion.</p><h3>One important note to mention</h3><p>At the beginning of my exploration in frontend/web code bases, sometimes I’ve over engineered some parts! Namely in the Presentation/UI layer. In both React.js and Vue.js applications I’ve tried to implement dependency injection in UI components to make them loosely coupled. And the result was a very confusing and complex codebase. So I’ve learned to stick with the library/framework’s best practices if they make scenes and combine them with my thoughts, not over write them!</p><h3>Summary</h3><p>Split the code base into three layers:</p><ol><li>Presentation / View: Put ui components and pages here.</li></ol><p>Use separated presentation, separation of concerns, component base approach and compositions.</p><p>2. Business / Logic: For keeping everything related to logic including server communications and calculations.</p><p>Use interfaces, IOC containers and dependency injection.</p><p>3. Model / Data: Put global state management and everything related to data here.</p><h3>At the end</h3><p>This is my personal opinion about how to use these techniques and organize a modern web code base. What do you think? :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e4ef88761154" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Use Vue.js inside React.js properly!]]></title>
            <link>https://medium.com/@aliafsah1988/how-to-usevue-js-inside-react-js-code-base-properly-3380f09b60f7?source=rss-ad76ef429ff4------2</link>
            <guid isPermaLink="false">https://medium.com/p/3380f09b60f7</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[vuejs]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[vue]]></category>
            <dc:creator><![CDATA[Ali Afsah-Noudeh]]></dc:creator>
            <pubDate>Thu, 30 Sep 2021 12:17:19 GMT</pubDate>
            <atom:updated>2021-09-30T12:42:06.220Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="use vue.js inside react.js" src="https://cdn-images-1.medium.com/max/500/1*Sw93emlTh2eQve5hNLcFmg.png" /><figcaption>Vue.js inside react.js</figcaption></figure><h3>Demand</h3><p>There are a couple of different scenarios for using a frontend library/framework inside another one. Like using a widget created by some other technologies or in our case migrating the code base.</p><p>So based on our company’s resources and our project’s requirements we have decided to migrate our codebase from <a href="https://reactjs.org/">React.js</a> to <a href="https://vuejs.org/">Vue.js</a></p><p>Our plan was to do this migration as smooth as possible in these steps:</p><ol><li>Write new components in Vue.js and use them in our current React.js codebase.</li><li>Refactor the old components to Vue.js as well.</li><li>Change the infrastructure of the codebase to Vue.js (things like routing, global state management, service layer and etc.)</li></ol><p>For doing such a thing I’ve learned a couple of ways which I want to talk about them here. Each approach has its own pros and cons and definitely I’m unable to bring all of these points to view, so I would be more that happy to hear your thoughts.</p><h3>1. Using the Vue component as a web component</h3><p>We can build our Vue component as a web components and use the build version inside our main application.</p><p><a href="https://github.com/aliafsahnoudeh/vue-in-react-web-component">Click here to see the sample source code</a></p><p>More information in <a href="https://medium.com/@pateldhruv020/using-vue-component-in-react-9161f30d29a0">this article</a>.</p><h3>Things to consider:</h3><ul><li>For building the vue components we can leverage vue-cli. We can easily create a new project with our desired features and then we just need to update our build script by setting the target to “wc”. Something like this:</li></ul><blockquote>$ vue-cli-service build — target wc — name &lt;component-name&gt; &lt;path to the component&gt;</blockquote><ul><li>We need to add Vue.js framework to our main codebase. Simply by adding a script tag to our html file (so <a href="https://vuejs.org/v2/guide/installation.html#CDN">via CDN</a>) and it’ll be available inside our window object. If we don’t, we’re going to get this error:</li></ul><blockquote>“Vue is not defined”</blockquote><ul><li>No extra changes needed to be done in webpack configs of our main codebase. Since we aren not importing any .vue file directly.</li><li>There is no need to add <strong>styles</strong> from vue component separately. It’ll be done through the build process and will be included in the JavaScript file. So by importing the common.js file, we are importing the styles too.</li></ul><h3>Pros</h3><ul><li>This approach would be very handy if we want to use a Vue.js widget inside a non-vue code base.</li></ul><h3>Cons</h3><ul><li>In our case we needed to have Vuex available to our Vue.js components and make it interactive with the state management of the main code base (mobx).</li></ul><h3>2. Using a third party library</h3><p><a href="https://github.com/akxcv/vuera">This library</a> wraps our component and make in usable in a react codebase.</p><h3>Pros</h3><ul><li>Implementation is easy and fast.</li></ul><h3>Cons</h3><ul><li>Some extra bytes on bundle size</li><li>Again, we couldn’t find a good way to use Vuex, so lesser flexibility.</li></ul><h3>3. Load Vue components directly with webpack</h3><p>Another way is to load our components directly inside the main application using webpack. So basically we will have .vue files beside our other types of files.</p><p><a href="https://github.com/aliafsahnoudeh/vue-in-react-directly">Click here for sample repository</a></p><h3>Things to consider:</h3><ul><li>Still we should include Vue.s in our project (as script to our html file or just install it via npm/yarn).</li><li>Since we are using .vue files directly in our application, we need to load them via webpack, so we config webpack. And they will be a part of our bundle as mentioned above.</li></ul><h3>Pros</h3><ul><li>We can use features like Vuex and pass them via main codes base the main vue instance. So it has a good flexibility.</li><li>There is no need for any extra build inside the vue project, since we are using .vue files directly inside our main code base and they are getting build via webpack there (one step build in one place).</li></ul><h3>Cons</h3><ul><li>We couldn’t find a way to use TypeScript properly in both code bases (if you know a solution, I would love to hear that 🙂 )</li><li>Linting could be a bit tricky since we have both react and vue components in our code base.</li></ul><h3>4. Using Vue components as library</h3><p>It has similarities with the first approach but in terms of building we need to build our whole vue project (and not just one component) as a library. For that we can leverage again vue-cli and use the lib as target. Something like this:</p><blockquote>$ vue-cli-service build — target lib — name vue-lib-components src/main.ts</blockquote><p><a href="https://github.com/aliafsahnoudeh/vue-in-react-library">Click here to see the sample repository</a></p><p>In the above example main.ts is the entry point of our project where we are exporting all of our components.</p><h3>Things to consider:</h3><ul><li>Vue.js should be added to our codebase (we need it in our vue-wrapper component which is a react component itself).</li></ul><h3>Pros</h3><ul><li>We can use features like Vuex and pass them via main codes base the main vue instance. So good flexibility again.</li><li>Proper working with TypeScript is easier. Since we have two separated projects.</li></ul><h3>Cons</h3><ul><li>We need to build the vue project for every change and then use the build version in the main code base (two step build in two different projects).</li></ul><p>We ended up using the last approach but I hope you can find the best solution for your need from the above options!</p><p>Cheers,</p><p>Ali</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3380f09b60f7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Deploy your Node.js + TypeScript backend for free on Heroku!]]></title>
            <link>https://medium.com/@aliafsah1988/deploy-your-node-js-typescript-backend-for-free-on-heroku-546d117c516a?source=rss-ad76ef429ff4------2</link>
            <guid isPermaLink="false">https://medium.com/p/546d117c516a</guid>
            <category><![CDATA[backend-development]]></category>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[expressjs]]></category>
            <category><![CDATA[heroku]]></category>
            <dc:creator><![CDATA[Ali Afsah-Noudeh]]></dc:creator>
            <pubDate>Wed, 01 Sep 2021 15:14:39 GMT</pubDate>
            <atom:updated>2021-09-01T15:23:55.299Z</atom:updated>
            <content:encoded><![CDATA[<h3>Demand</h3><p>I had a node.js monolith application which was created with Express.js and TypeScript. At some points running it locally wasn’t enough for me and I needed to deploy it on the internet. There were several providers but I didn’t want to spend money on this project at this stage. Maybe in the future but not now!</p><p>So I ended up with <a href="https://www.heroku.com/">Heroku</a>, it has a free (limited) plan for deploying applications which is very handy for your small projects. If you want to create a test application or if you have an app which is too young to spend money on it, Heroku makes total sense.</p><p>Just reading the <a href="https://devcenter.heroku.com/articles/deploying-nodejs">Heroku’s docs</a> or other related documents wasn’t enough for me so I ended up writing this article to share what I’ve learned. And I will try to make it as small and simple as possible.</p><p>Because my project was written with TypeScript I had to do a couple of small extra steps.</p><h3>Preparing the app</h3><p>For deploying this TypeScript application on any environment obviously we need to compile it to JavaScript first. Because at the end node.js should run it. tsc is doing the job for us but for making it work properly on Heroku we need to add it to postinstall script. Heroku runs this command automatically before deploying a new version. For that we just need to add this line to our package.json:</p><blockquote>“postinstall”: “tsc”</blockquote><p>After running this command the compiled version of our app will be placed in dist directory at the root of our application by default. Since Heroku does this compilation automatically on it’s environment we need to put this directory in our .gitignore file (to be sure it doesn’t go to the heroku’s server).</p><p>After that we need to add the start command. By running this command our compiled application (JavaScript files) will start running. Heroku will do this automatically on each deploy and for that it needs a start script. In my case the starting file of the application will be index.js inside the dist directory (which is the default entry point for TypeScript and I didn’t change it). So we need to add this line to our package.json file as well:</p><blockquote>“start”: “node dist/index.js”</blockquote><p>At the end we have to specify the node version that Heroku is going to use. So we just need to add “engines” property to our package.json. For instance something like this:</p><blockquote>“engines”: {</blockquote><blockquote>“node”: “14.x”</blockquote><blockquote>}</blockquote><p>Then we just need to add a file called “Procfile” to the root of our project with below content:</p><blockquote>worker: node dist/index.js</blockquote><p>By that we are informing heroku about the entry point of our application.</p><h3>Setup communicatio to heroku</h3><p>First we need to create an account on the heroku’s website and choose a plan. In my case the free one!</p><p>For interacting with our created account on heroku we can leverage heroku cli (you can find a suitable version bases on your OS <a href="https://devcenter.heroku.com/articles/heroku-cli">here</a>).</p><p>After installing that, by running this command in your terminal you can login to your account. It will redirct you to the browser to login.</p><blockquote>heroku login</blockquote><p>No that we have access to our herku account, we can create a new project. We need it for deploying:</p><blockquote>heroku create</blockquote><h3>Set env variables on heroku configs</h3><p>Probably our application is working with some environment variables. For having them on heroku server, we need to add them to heroku’s config. We can add them simply by heroku’s set command. More information <a href="https://devcenter.heroku.com/articles/config-vars">here</a>.</p><h3>Deploying</h3><p>Now it’s almost ready. Each time we run this command, the latest version of our codebase will be pushed to heroku’s servers and then it get compiled and deployed.</p><p>git push heroku &lt;name_of_the_branch&gt;</p><p>For example:</p><blockquote>git push heroku main</blockquote><p>For making everything even easier, you can put this command at your script like this:</p><blockquote>“deploy”: “git push heroku main”</blockquote><p>And done, your app is alive on the internet with a unique url!</p><h3>Sample repository</h3><p><a href="https://github.com/aliafsahnoudeh/node-express-typescript-heroku">https://github.com/aliafsahnoudeh/node-express-typescript-heroku</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=546d117c516a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What are Slots in Vue.js and when we should use them?]]></title>
            <link>https://medium.com/@aliafsah1988/what-are-slots-in-vue-js-and-when-we-should-use-them-5e3012963377?source=rss-ad76ef429ff4------2</link>
            <guid isPermaLink="false">https://medium.com/p/5e3012963377</guid>
            <category><![CDATA[vuejs]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[slot]]></category>
            <category><![CDATA[vue]]></category>
            <category><![CDATA[front-end-development]]></category>
            <dc:creator><![CDATA[Ali Afsah-Noudeh]]></dc:creator>
            <pubDate>Fri, 18 Sep 2020 12:31:43 GMT</pubDate>
            <atom:updated>2020-09-20T06:09:09.788Z</atom:updated>
            <content:encoded><![CDATA[<h3>What are Slots in Vue.js and when should we use them?</h3><h3><strong>Introduction</strong></h3><p>Vue.js implements the content distribution API using the &lt;slot&gt; element. It has some similarities to the <strong>children</strong> API of React.js.</p><p>So slots help us to <strong>distribute our content</strong> <strong>in other components</strong>. It’s specially useful when we want to create <strong>reusable widgets</strong>. In this approach we can make sure our distributed content will be exactly distributed inside the child component as we want.</p><h3><strong>A use case</strong></h3><p>I had a task to create a carousel for our landing page and this carousel should take totally different kinds of components (with different HTML layout and styling) as slides. But the frame which contains these slides should be the same. So same parent component but completely different Childs (content).</p><p>Even if I wanted to create a couple of carousels with the same group of slides (for example a carousel with images as children or the one with just videos), still this approach would be a great choice.</p><h3><strong>How to use it</strong></h3><p>Using the slot is very easy, we should just write the &lt;slot&gt; component (which is a <strong>reserved word</strong> in Vue.js) inside the child component’s template, where we want to receive data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/920/1*CW8myWhFMPgdoFKhbB1e4Q.png" /><figcaption>A child component uses slot.</figcaption></figure><p>This &lt;slot&gt; component is going to take over and renders the content we’re passing from outside (parent component). So it renders parts between opening and closing selectors of the child component in the parent component. So in the parent component:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/920/1*02BqeFvcG_87vDIbbk451Q.png" /><figcaption>A parent component passes data as slot to another component.</figcaption></figure><p>So basically it allows us to <strong>pass data from outside</strong> and <strong>render them in the child</strong> component. And this data can be anything!</p><h3><strong>Styling</strong></h3><p>The child component’s styling is applied to the data being passed in from outside (as slot).</p><p>So if we want to style your slot data, we should put our styles inside the child component and if we put these styles in the parent component (of-course if they’re not global!), they won’t work.</p><h3><strong>Compiling</strong></h3><p>For compiling a template (which means any Vue.js operation such using a state-variable or calling a method), the component where we have the code in it’s template (parent component) will be the one doing the changes.</p><p>So for example if you want to use some variable from your data object (from the Vue instance) you have to declare it where you wrote the code and not where it passed (in the child component).</p><p>It’s true that we pass it finally to the child but we write it in the parent and it would take care of vue.js operations.</p><p>In parent component:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/921/1*yKMu4rmtjvybnXkoSM__nQ.png" /><figcaption>Dynamic data as slot to another component.</figcaption></figure><p>And in Child:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/923/1*KKhyoLa3SmKPoOArS-K4Dg.png" /></figure><p>The result on your raw HTML:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/924/1*ZD2i8qmHUUpHlwNY7bh-AQ.png" /></figure><p>So as we can see, if we want to use some dynamic data or any other Vue.js operation (except for styling) we should write them on the parent component.</p><p>And we can say styling and compiling of a slot data are in opposite of each other. Styling in child, compiling in parent.</p><h3><strong>Rendering slots in different places of a child component</strong></h3><p>If we’re passing multiple components from parent to child and we want to render them in different places in our child component we should use the <strong>named slot</strong> feature of the Vue.js.</p><p>For that in the child component we just need to add an attribute called “name” and give it some name, and then in the parent component where we’re passing the content, we should add a new attribute called <strong>slot</strong> in our component (or selector). Slot is not an official HTML attribute and it was introduced by Vue.js and is going to be used by it. So Vue.js will render the component with slot attribute in the &lt;slot&gt; component of the child with the exact value.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/924/1*n1dGgvWGKxzFgyoEhTZLNg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/924/1*hgrMr_4HFI4h_vmvA9QMog.png" /></figure><h3><strong>Default behavior for an unnamed-slot</strong></h3><p>If you’re passing multiple components to a child component and for example if one of them is a named-slot and one of them is an unnamed-slot, by default Vue.js will treat the unnamed one as default slot and renders it in the &lt;slot&gt; component without name.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/922/1*5356YR4lRH05oDd6FHBJQA.png" /></figure><h3><strong>Default value for a slot</strong></h3><p>If we’re not sure that content will be passed to our child component or not, we can set up some default content to be displayed (in case of absence of that slot). For that we just need to write some data inside the opening and closing tags of &lt;slot&gt; in the child component.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/922/1*86dxjx1XKtcBWXWJ-PqoHQ.png" /></figure><h3><strong>Scoped Slots</strong></h3><p>Sometimes, it’s useful for slot content (in the parent component) to have access to data which is only available in the child component.</p><p>Imagine you have some variables in your data object of your child component and somehow you want to access them in your parent component. You might see this in some packages which you used as a dependency. In this scenario the author of that package can make more flexibility by sending some of its data to outside so you can use them where you called his/her component.</p><p>For that in your child component you should add:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/922/1*1pLUWJ45ZJb_4z6yz4sIng.png" /></figure><p>to the slot component. And then you can use it in the parent component :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/923/1*OFmsATJIQ5XtD8gGmroY6A.png" /></figure><p>Child component:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/927/1*Mmx-3IbEAw0luNzu-rOxFQ.png" /></figure><p>Parent component:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/922/1*iQcYx2TGVl_LJOVjsQCROQ.png" /></figure><h3><strong>Conclusion</strong></h3><p>I can say slots are very great tools for distributing in your project and components. But you should be careful to not overuse them, people don’t use <strong>Slots </strong>in Vue.js as often as they use <strong>Children </strong>in React.js.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5e3012963377" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Make a Vue.js library to keep our components]]></title>
            <link>https://medium.com/@aliafsah1988/make-a-vue-js-library-to-keep-our-components-62fde3659ea6?source=rss-ad76ef429ff4------2</link>
            <guid isPermaLink="false">https://medium.com/p/62fde3659ea6</guid>
            <category><![CDATA[vuejs]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[software-architecture]]></category>
            <category><![CDATA[vue]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Ali Afsah-Noudeh]]></dc:creator>
            <pubDate>Sat, 12 Sep 2020 12:56:37 GMT</pubDate>
            <atom:updated>2020-09-13T05:59:24.672Z</atom:updated>
            <content:encoded><![CDATA[<h3>Make a Vue.js library to keep your components</h3><h3><strong>Introduction</strong></h3><p>I was working on a project written with Nuxt.js (<a href="https://nuxtjs.org/">https://nuxtjs.org/</a>). As you know Nuxt.js is created on top of the Vue.js (<a href="https://vuejs.org/">https://vuejs.org/</a>), so they share the same component based approach. And based on that, we split the whole application into small and reusable components.</p><p>We didn’t use any ready-to-use UI library/framework for our components (such as Quasar, Vuetify) so all of our components were written by our team, because our UI designers were very detailed and we need to have flexibility and customization in any level to create pixel perfect user interfaces based on their designs.</p><p>We kept all of our components inside the components directory of our Nuxt.js app as it recommends.</p><h3><strong>A demand</strong></h3><p>After a while we had a demand to create a dashboard (admin panel) for our internal works and other activities which we couldn’t put them to the main website and it was better we kept them in a separate project. So we chose Vue.js again because it’s a stack of our main website (we tried to keep the same stack in our front-end projects as possible) and most importantly we needed lots of components on Vue.js which we already had on our main website and obviously we didn’t want to write them from the scratch (because it’s ridiculous!) and we definitely didn’t want to keep them in two separate places and make maintaining a disaster in the future. Imagine every single change and bug fix should be taken care of in two places!!! Impossible right! Or should I say stupid!</p><p>Long story short, we must put all of our components in a separated project and use it in our main website and newly created dashboard as a dependency. Which seems a best practice to me so far and many people do this around the globe.</p><p>So this new project should contain our components and these components should be used in other projects. So we have no pages here! There is no point to have some empty pages or some pages to just show a bunch of components and it’s a waste of energy and time (because we can use a storybook (<a href="https://storybook.js.org/">https://storybook.js.org/</a>) and I’m going to talk about it in another article). This led me to find out about vue library projects. These projects have no App.vue (as a starting point for a showable web application) and just contain a bunch of components, helpers, utils and other stuff to be shared and used in a couple of other projects. We can write proper tests for them and keep any related logic and functionality there. The upper layer (the other apps which use our projects) don’t need to know about our internal stuff and with a proper build they can use it like any other dependencies.</p><h3><strong>Solution</strong></h3><p>Fortunately for us, vue-cli (<a href="https://cli.vuejs.org/">https://cli.vuejs.org/</a>) made it very easy by a few steps which I’m going to explain here. It uses the Webpack (<a href="https://webpack.js.org/">https://webpack.js.org/</a>) behind the scenes and provides lots of useful tools.</p><p>Of Course there are other ways like using Webpack directly which is more flexible but we didn’t need that kind of flexibility and we were out of time.</p><p>If you don’t know about Webpack and how to configure it, I strongly recommend to take a deep look at it first. If you just use things like vue-cli and don’t learn about what they’re doing behind the scenes, it might get you away from basic stuff and deep knowledge which will cause you many problems in the future and it’s a poison for any kind of engineer.</p><h3><strong>How to create and use</strong></h3><p>Now the steps:</p><ol><li>Install vue-cli to use its tools and templates. By below command we’re going to install it globally on our machine:</li></ol><blockquote><em>npm install -g @vue/cli</em></blockquote><p>2. Create a new project with it:</p><blockquote><em>vue create [your-awesome-project]</em></blockquote><p>3. Set your required configurations:</p><p>I’m just choosing Babel (<a href="https://babeljs.io/">https://babeljs.io/</a>) and nothing more to have a very light project.</p><p>4. Go to your root directory and open the project with your preferred editor or IDE. I use VsCode (<a href="https://code.visualstudio.com/">https://code.visualstudio.com/</a>).</p><p>5. Run the project with just typing:</p><blockquote><em>npm run serve</em></blockquote><p>As you can see it’s a simple template to run a simple vue project.</p><p>6. Remove App.vue in the src folder. You don’t need it! Also you can get rid of logo.png in the assets folder and HelloWord.vue in components folder.</p><p>7. Create your first component.</p><p>I just created a simple component for this example.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/451/1*Rnk999ZKMWm88fj2aDNPQg.png" /><figcaption>Simple Component with Vue.js</figcaption></figure><p>It’s a button which takes a string as a prop (text) and shows it in it’s Inner Html.</p><p>8. Export this component to be used by others. For that:</p><p>Add an index.js file into components folder with just below content:</p><blockquote><em>import Button from ‘./Button’</em></blockquote><blockquote><em>export { Button }</em></blockquote><p>It will export Button.vue by name to the upper layer.</p><p>Then replace the content of the main.js in src folder with these:</p><blockquote><em>export * from ‘./components’</em></blockquote><p>By that we’re saying to main.js to export everything in components directory as named export. You can use any other way you prefer.</p><p>9. Replace your current build script in package.json with the line below:</p><blockquote>“build”: “vue-cli-service build — target lib — name ui-components src/main.js”</blockquote><p>By using — target we can specify the type of build we want (<a href="https://cli.vuejs.org/guide/build-targets.html">https://cli.vuejs.org/guide/build-targets.html</a>). Also we can declare a name and an entry point to start the building process and Webpack, in our case main.js.</p><p>When you run npm run build, this script is gonna build a folder (by default dist) inside your root directory by webpack and we told vue.js to make it as a library and not a website.</p><p>10. By running the build script, as you can see we have dist folder like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/379/0*A6oOfGDm6oxe7wXC" /></figure><p>Each file can be used in a different situation.</p><p>A lib build outputs:</p><ul><li>dist/[YOUR_LIBRARY].common.js: A CommonJS bundle for consuming via bundlers.</li><li>dist/[YOUR_LIBRARY].umd.js: A UMD bundle for consuming directly in browsers or with AMD loaders</li><li>dist/[YOUR_LIBRARY].umd.min.js: Minified version of the UMD build.</li><li>dist/[YOUR_LIBRARY].css: Extracted CSS file (can be forced into inlined by setting css: { extract: false } in vue.config.js)</li></ul><p>11. So if we want to use this project as a dependency package, we should use [YOUR_LIBRARY].common.js as the primary entry point to our project. For that we just need to set the main property in package.json:</p><blockquote>“main”: “./dist/vue-lib-sample.common.js”</blockquote><p>Note: If you’re using git, make sure you removed the dist folder from .gitignore file so you can have it on your remote repo.</p><p>13. Now we can use it as a npm package or anyway we want. In this example I’m going to use it directly as a local dependency in another project.</p><p>In my upper layer project I’m just installing our project as dependency with npm:</p><blockquote>npm add [PATH_OF_PROJECT]</blockquote><p>So my package.json will be updated like this:</p><blockquote>“dependencies”: {</blockquote><blockquote>…</blockquote><blockquote>“vue-lib-sample”: “file:[some_path]/vue-lib-sample”</blockquote><blockquote>}</blockquote><p>And as you can see it’s added to our node_modules:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/378/0*bJLyA5g-xInsW8QH" /></figure><p>Note: In this approach (local dependency) you might face some linting issues. In my case I didn’t use any linting in both projects.</p><p>Now we can use our Button component in any where we want!</p><p><strong>Conclusion</strong></p><p>It’s a good practice to keep your components in a separated project, and isolate them from outside. They’re going to be reusable and you just need to change them in just one place. Also by adding a storybook you can make life easier for the whole team, including developers, designers and everybody else.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/899/1*wSdX8rbFO6Anzybmr3a1Jw.png" /><figcaption>Vue.js usage of a vue library package</figcaption></figure><p>You can find relate repo here:</p><p><a href="https://github.com/aliafsah1988/vue-lib-sample">https://github.com/aliafsah1988/vue-lib-sample</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=62fde3659ea6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Hash Tables in JavaScript]]></title>
            <link>https://medium.com/@aliafsah1988/hash-tables-in-javascript-ff59b5f6d8d3?source=rss-ad76ef429ff4------2</link>
            <guid isPermaLink="false">https://medium.com/p/ff59b5f6d8d3</guid>
            <dc:creator><![CDATA[Ali Afsah-Noudeh]]></dc:creator>
            <pubDate>Fri, 06 Mar 2020 14:07:38 GMT</pubDate>
            <atom:updated>2020-03-06T14:07:38.981Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="Hash tables by Ali Afsahnoudeh" src="https://cdn-images-1.medium.com/max/786/1*H9WlYaKiyk2gcZb8GPeDmw.png" /></figure><h3><strong>Introduction</strong></h3><p>Hi I’m a software engineer who is working a lot with JavaScript in these days. This article is about what I learned and understand about <strong>hash table</strong> in general and it’s implementation in <strong>JavaScript</strong>.</p><h3><strong>What are Hash Tables?</strong></h3><p>Hash tables are data structures for storing key/value pairs. They also called dictionaries. They contain places called buckets or slots for keeping items. The number of these slots represents the length of our hash table. For example if we have a hash table of length 1000, it means it has 1000 slots/buckets to keep 1000 items.</p><h3><strong>Where we use them?</strong></h3><p>The run-time complexity of hash table’s actions are:</p><p>Insert: O(1)</p><p>Lookup: O(1)</p><p>Delete: O(1)</p><p>As you can see hash tables are very fast! They are used in compilers, code editors, dictionaries and lots of other places. Practically saying if you have some data with unique keys and you need a very fast look up, you should use hash tables (in some situations, the worst case scenario for insert and delete can be O(n) but since they rarely happen, we can stick with O(1)).</p><p>There are lots of famous interview questions that can be answered by hash tables. Like the first non-repetitive character in a string.</p><h3><strong>Where we can find them?</strong></h3><p>Most programming languages support hash tables under different names.</p><p>Java: HashMap</p><p>C# &amp; Python: Dictionary</p><p>JavaScript: Object and Map !</p><p>Yes! both maps and objects are hash tables and I’m going to talk about them more in JavaScript.</p><h3><strong>How Hash Tables work</strong></h3><p>When I was learned about hash tables I found out that they use an array to store items. On that moment I had couple of question. The most important ones was:</p><ol><li>What’s the point of using hash tables if they use Arrays for storing? We can simply use Arrays instead!</li></ol><p>2. If they are using an Array, how the run-time complexity of a hash table is O(1)?! For example, to find (lookup) an item it needs to iterate over all items (like searching an item in an Array by value) which is a operation of O(n).</p><p>But it’s not iterating over all items!</p><p>Hash tables has a mechanism call <strong>Hash Function</strong>. As the name explains, it’s a function that returns an index by giving it a key. And it’s <strong>deterministic</strong>, which means every time that we give it the same input it will return the same value. So for inserting, deleting or searching we give it a key(our key for data) and it will always return the same index for each individual key. And then our hash table goes directly to that index of it’s array and it’s a operation of O(1)!</p><figure><img alt="Hash function in a hash table" src="https://cdn-images-1.medium.com/max/240/1*pPrBzMrzNF4xGw5EHHxuvQ.png" /></figure><p>Imagine we have a list of students to store. Each has a unique student Id. So our key is student Id and our student object is the value. We passing this key/value pair to our hash table. It gets the key, pass it to hash function and hash function returns an index (for example 2). Then hash table stores the key/value pair in the given index (in our case 2). After that if we want to get that specific student, we just pass the student Id to hash table and our hash function gives us 2 as index again (because of it’s deterministic behavior).</p><h3><strong>Hash Tables in JavaScript</strong></h3><p>Before ECMAScript, when every thing in JavaScript world was less interested (imagine rock’n roll world without <strong>Jimi Hendrix</strong>, <strong>Zepplin </strong>or <strong>Pink Floyd</strong>!), people used objects for hash table scenarios. Because the key/value pair structure of objects and the fact that every key needs to be unique.</p><p>It’s great and solving most of the problems but it has it’s own down sides. For example:</p><ul><li>The keys of an Object must be either a String or a Symbol. It’s not usable for some scenarios that we need other types (like objects) as keys.</li><li>An Object has a prototype, so it contains default keys that could collide with your own keys if you’re not careful.</li><li>The keys of an Object are not ordered (in case you need ordered lists).</li><li>The number of items in an Object must be determined manually. It can’t tell you the length of it’s keys or items (properties).</li><li>Iterating over an Object requires obtaining its keys in some fashion and iterating over them. You need to use Object.keys() first to retrieve keys and then start to iterating.</li><li>Not optimized for frequent additions and removals of key-value pairs. In case you have lots of adding or removing items (which usually you have!).</li></ul><p>But after the Hendrix, sorry the ECMAScript, beside lots of other beauties and features, <strong>Maps </strong>was announced. A specific implementation of hash tables. It has lots of benefits instead of object, for using in hash table problems:</p><ul><li>A Map does not contain any keys by default. It only contains what is explicitly put into it.</li><li>A Map’s keys can be any value (including functions, objects, or any primitive).</li><li>The keys in Map are ordered. Thus, when iterating over it, a Map object returns keys in order of insertion.</li><li>The number of items in a Map is easily retrieved from its size property.</li><li>A Map is an iterable, so it can be directly iterated.</li><li>Performs better in scenarios involving frequent additions and removals of key-value pairs.</li></ul><p>Based on above information it’s recommended to use Maps if it’s supported in your project and your targeted browsers.</p><h3><strong>Set</strong></h3><p>There is another structure called <strong>Set</strong> which is similar to maps but contains just keys. Like maps, in sets keys are unique so a value in the Set may only occur once.</p><p>They are useful for solving lots of problems, for example if we need to remove duplicate items in a list , we can use sets.</p><h3><strong>At The End</strong></h3><p>I hope I could explain well what I learned about hash tables so far. I will be more that happy for any suggestion, correction and advice from anyone.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ff59b5f6d8d3" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>