<?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 Omal Perera on Medium]]></title>
        <description><![CDATA[Stories by Omal Perera on Medium]]></description>
        <link>https://medium.com/@omalperera?source=rss-50e1e03eeb0c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*FJuxf8Fclm_7Gb-XCwcoJA.jpeg</url>
            <title>Stories by Omal Perera on Medium</title>
            <link>https://medium.com/@omalperera?source=rss-50e1e03eeb0c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 22:54:13 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@omalperera/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[Supercharge your React-native app with GraphQL Codegen: Strongly typed, hassle-free data fetching]]></title>
            <link>https://medium.com/ascentic-technology/supercharge-your-react-native-app-with-graphql-codegen-strongly-typed-hassle-free-data-fetching-ac262999af65?source=rss-50e1e03eeb0c------2</link>
            <guid isPermaLink="false">https://medium.com/p/ac262999af65</guid>
            <category><![CDATA[graphql]]></category>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[react-native]]></category>
            <dc:creator><![CDATA[Omal Perera]]></dc:creator>
            <pubDate>Tue, 31 Oct 2023 08:30:34 GMT</pubDate>
            <atom:updated>2023-10-31T08:30:34.811Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*sQKaVWRu5YCCZ7ZzRcx7XQ.jpeg" /><figcaption><a href="https://www.freepik.com/free-ai-image/rocket-takes-off-from-desert-with-mountains-background_40739893.htm#query=apollo&amp;position=15&amp;from_view=search&amp;track=sph">Image By Sketchepedia</a></figcaption></figure><p>As we all know, graphQL is a query language for APIs that enables more efficient and precise data retrieval. It allows clients to request exactly the data they need, eliminating over-fetching or under-fetching. GraphQL offers a strongly typed schema, defining what data can be queried, and allows for complex, nested queries in a single request. It’s a versatile and flexible technology, well-suited for modern, data-driven applications, and enables developers to iterate on the client side without requiring changes on the server.</p><p>Nowadays, TypeScript is our preferred choice for many JavaScript projects, offering numerous advantages such as type safety, enhanced code quality, improved documentation, reduced bugs, and more.</p><h4>GraphQL Code Generator</h4><p>GraphQL Code Generator (<a href="https://the-guild.dev/graphql/codegen">GraphQL Codegen</a>) is a tool and code generation framework that automates the process of generating code from your GraphQL schema and operations. GraphQL is a query language for your API, and GraphQL Codegen helps streamline the development process by generating strongly typed code for your API.</p><p>Here’s how GraphQL Codegen works and what it can do:</p><ol><li><strong>Schema-first development: <br></strong>GraphQL Codegen typically starts with a GraphQL schema definition. You define your data types, queries, mutations, and subscriptions in a schema file. GraphQL Codegen can then generate code for your server and client based on this schema.</li><li><strong>Type-safe code:</strong><br>GraphQL Codegen generates code in various programming languages (eg: JavaScript, TypeScript, Java, Go) that enforces type safety. This means that you can work with your GraphQL data and queries without worrying about type-related runtime errors.</li><li><strong>Client-side code generation:</strong><br>For client applications, GraphQL Codegen can generate code to create GraphQL queries and mutations. This eliminates the need to write these queries manually, reducing errors and speeding up development.</li><li><strong>Integrations with build tools:</strong><br>GraphQL Codegen can be integrated into your build process, ensuring that generated code is always up-to-date with your schema and queries. It can be used with tools like Webpack, Babel, and others.</li><li><strong>Integrations with build tools:</strong><br>GraphQL Codegen supports various GraphQL libraries, such as Apollo Client, Relay, and many server frameworks. This makes it a versatile tool that can be adapted to your project’s requirements.</li></ol><h3>Let’s configure GraphQL codegen</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/540/1*EaW3wPh4oBKTv2e-5oxB2g.gif" /><figcaption>Image courtesy — <a href="https://giphy.com/gifs/BoschGlobal-coding-home-office-remote-working-umYMU8G2ixG5mJBDo5">giphy.com</a></figcaption></figure><p>Let’s take a look at how to set up the required configurations. This article focuses on doing it in a React Native project (which is almost similar to React projects as well). If you’re interested in using GraphQL Codegen in other languages, you can visit <a href="https://the-guild.dev/graphql/">https://the-guild.dev/graphql/</a> codegen for instructions.</p><blockquote>If you want to skip the RN project initialization and graphQL initialization, you can directly refer to Step 6 and onwards.</blockquote><h4><strong>Step 1 — Creating a base react-native project</strong></h4><ol><li>I’m assuming that you’ve already set up your React Native development environment on your local machine. If not, you can visit the official React Native <a href="https://reactnative.dev/docs/environment-setup?guide=native#creating-a-new-application">documentation</a> for step-by-step instructions.</li><li>Now, let’s run the following command to create a new project</li></ol><pre>npx react-native@latest init RnGql</pre><h4>Step 2 — Checking newly created app is running correctly</h4><ol><li>Navigate to the project directory and run the project to ensure everything is working smoothly with your React Native project.</li></ol><pre>cd RnGql <br>react-native run-android</pre><h4>Step 3 — Let’s start with initiating a graphQL client</h4><ol><li>We will use the Apollo client to make GraphQL requests in our RN application npm i @apollo/client</li><li>For this demonstration, we’ll be using <strong>AniList</strong>, a free GraphQL service where we can request sample anime data. You can find more information at <a href="https://anilist.gitbook.io/anilist-apiv2-docs/overview/graphql/getting-started">https://anilist.gitbook.io/anilist-apiv2-docs/overview/graphql/getting-started</a>.</li><li>Create a folder named src in your project directory. <br>Move the App.tsx file into the src folder and update the import statement in index.js.</li><li>Inside the src folder, create a new folder called animeList (for later use).</li><li>Let’s define a GraphQL client. Create a new directory called network within the src folder. <br>Inside the network directory, create a new file named graphqlClient.ts and add the following lines.<br>Add another folder called queries inside network folder for later use.</li></ol><pre>import {ApolloClient, InMemoryCache} from &#39;@apollo/client&#39;;<br><br>export const client = new ApolloClient({<br>  uri: &#39;https://graphql.anilist.co&#39;,<br>  cache: new InMemoryCache(),<br>});</pre><p>so at the end of this step, your files folder structure should be as follows.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/568/1*RtuBJ63zOJO6rxjmIDA97A.png" /><figcaption>The newly added network directory and the graphqlClient file.</figcaption></figure><h4>Step 4— Build up a simple query &amp; add it to our project</h4><p>Now, we’re going to create a simple query to retrieve a list of anime data from AniList. Go to <a href="https://anilist.co/graphiql">https://anilist.co/graphiql</a> and write a query to fetch 10 anime items. To keep things straightforward, we’ll only retrieve 2 properties per item.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cg_sdf_xJKqVAsi9otxvqw.png" /><figcaption>creating a simple query in <a href="https://anilist.co/graphiql">https://anilist.co/graphiql</a>, which we can use in the project</figcaption></figure><p>Incorporating the above query into our React native codebase and generating the required code using GraphQL Codegen involves a few steps:</p><ol><li>Inside the queries directory, craft a new file named anime.graphql <em>(</em><strong><em>remember to include the ‘.graphql’ extension, which aids in recognizing query files during code generation)</em></strong><em>.</em></li><li>Copy and paste the query we crafted in the previous step into this file. Additionally, we have given a name and the ability to pass variables to the query.</li></ol><pre>query GetAnimeList($page: Int, $perPage: Int) {<br>  Page(page: $page, perPage: $perPage) {<br>    media {<br>      id<br>      title {<br>        userPreferred<br>      }<br>      seasonYear<br>    }<br>  }<br>}</pre><h4>Step 5 — Develop a simple view component to render data</h4><ol><li>Create a file named animeListView.tsx in animeList folder we created in step 3 earlier.</li><li>Add the following code to animeListView.tsx <br>Note: we are running our component with a fixed constant array as our graphQL codegen is still not fully configured. we will be replacing this in the final step.</li></ol><pre>import React from &#39;react&#39;;<br>import {FlatList, StyleSheet, Text, View} from &#39;react-native&#39;;<br><br>// still codegen is under configuration. so defining a sample array to test the component<br>const animeList = {<br>  Page: {<br>    media: [<br>      {<br>        id: 1,<br>        title: {<br>          userPreferred: &#39;Cowboy Bebop&#39;,<br>        },<br>        seasonYear: 1998,<br>      },<br>      {<br>        id: 5,<br>        title: {<br>          userPreferred: &#39;Cowboy Bebop: Tengoku no Tobira&#39;,<br>        },<br>        seasonYear: 2001,<br>      },<br>    ],<br>  },<br>};<br><br>const AnimeListViewComponent = () =&gt; {<br>  const renderAnimeItem = item =&gt; {<br>    return (<br>      &lt;View style={styles.itemContainer}&gt;<br>        &lt;Text&gt;{item.title?.userPreferred}&lt;/Text&gt;<br>        &lt;Text&gt;{item.seasonYear}&lt;/Text&gt;<br>      &lt;/View&gt;<br>    );<br>  };<br><br>  return (<br>    &lt;View style={styles.contentContainer}&gt;<br>      &lt;FlatList<br>        data={animeList.Page.media}<br>        renderItem={({item}) =&gt; renderAnimeItem(item)}<br>        refreshing={false}<br>      /&gt;<br>    &lt;/View&gt;<br>  );<br>};<br><br>export default AnimeListViewComponent;<br><br>const styles = StyleSheet.create({<br>  contentContainer: {<br>    flex: 1,<br>    flexDirection: &#39;column&#39;,<br>  },<br>  itemContainer: {<br>    flex: 1,<br>    flexDirection: &#39;row&#39;,<br>    marginVertical: 5,<br>    marginHorizontal: 15,<br>    justifyContent: &#39;space-between&#39;,<br>  },<br>});</pre><p>And replace the code in App.tsx as below.</p><blockquote>Don&#39;t forget to wrap the component tree with a &lt;ApolloProvider client={client}</blockquote><pre>import React from &#39;react&#39;;<br>import {SafeAreaView} from &#39;react-native&#39;;<br>import AnimeListViewComponent from &#39;./animeList/animeListView&#39;;<br>import {ApolloProvider} from &#39;@apollo/client&#39;;<br>import {client} from &#39;./network/graphqlClient&#39;;<br><br>function App(): JSX.Element {<br>  return (<br>    &lt;ApolloProvider client={client}&gt;<br>      &lt;SafeAreaView /&gt;<br>      &lt;AnimeListViewComponent /&gt;<br>    &lt;/ApolloProvider&gt;<br>  );<br>}<br><br>export default App;</pre><h4>Step 6 — Real codegen configuration</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*bGwNKyqINUY4UJF-iNmlrw.gif" /></figure><p>To accomplish this, we’ll need the assistance of the following additional development dependencies for this task.</p><ol><li><strong>@graphql-codegen/cli</strong>: CLI tool for generating code based on GraphQL schemas and operations.</li><li><strong>@graphql-codegen/typescript</strong>: designed to generate TypeScript code from your GraphQL schema</li><li><strong>@graphql-codegen/typescript-graphql-request</strong>: creates functions and code that help you send queries, mutations, and subscriptions to a GraphQL server.</li><li><strong>@graphql-codegen/typescript-operations: </strong>this is a template plugin</li><li><strong>@graphql-codegen/typescript-react-apollo</strong>: this is a template plugin (we can specify different templates. As I mentioned in the very beginning code gen support for many frameworks and languages. If our requirement is to go with relay instead of Apollo, we can generate compatible code by adjusting these template plugins)</li></ol><p>install the above dev dependencies.</p><pre>npm install -D @graphql-codegen/cli @graphql-codegen/typescript @graphql-codegen/typescript-graphql-request @graphql-codegen/typescript-operations @graphql-codegen/typescript-react-apollo</pre><p>Create a new file named graphql.config.yml in the project root directory. Then, include the following code. For further information about the configuration file, you can refer to the documentation here. (<a href="https://the-guild.dev/graphql/config/docs/user/usage">https://the-guild.dev/graphql/config/docs/user/usage</a>).</p><pre>schema:<br>  - &#39;https://graphql.anilist.co&#39;<br>documents:<br>  - &#39;./src/**/*.graphql&#39;<br>generates:<br>  ./src/network/queries/__generated__/graphql.ts:<br>    plugins:<br>      - typescript<br>      - typescript-operations<br>      - typescript-react-apollo</pre><p>here we have Instructed the Codegen CLI tool to scan all *.graphql files within the source directory, generate code based on provided templates, and save it to the src/network/queries/__generated__/graphql.ts</p><p>As the final step of our configurations, add the following line to the Package.json file. This will help to run the codegen tool from CLI.</p><pre>&quot;scripts&quot;: {<br>    ..., <br>    &quot;generate-gql-queries&quot;: &quot;graphql-codegen --config graphql.config.yml&quot;<br>  },</pre><p>Now run the above-added script in your terminal in the root directory using</p><pre>npm run generate-gql-queries</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JYBgJ3gxcdt9H7mR3nbRyw.png" /><figcaption>Executing codegen command in terminal and get the success response.</figcaption></figure><p>If you can see the results above. Congratulations! 🎉🎉🎉</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/498/1*KowWujusMfDjlkjeeOFEBg.gif" /></figure><h4>Step 7 — Check the generated code</h4><p>Now if you check the src/network/quaries folder, there will be a newly generated file with all generated codes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/564/1*6uQottvo01uy6iDXtI_nGw.png" /><figcaption>codegen output</figcaption></figure><p>If you explore the graphql.ts file. You’ll find a complete set of generated type definitions and queries, along with examples illustrating how to use them.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*X3uI8ITkobl9UVHEoVfsAQ.png" /><figcaption>Generated code, type definitions from codegen</figcaption></figure><p>The challenging part is behind you. Now, all that’s left is to use the generated items in your React Native project</p><p>To utilize the generated code in your React Native project, you have access to code blocks for <strong>useQuery</strong> hook, <strong>useLazyQuery</strong> hook, and the plain <strong>query document</strong>. You’re free to use them as you see fit.</p><ol><li>using <strong>useQuery </strong>hook</li></ol><pre>import { useGetAnimeListQuery } from &#39;../network/queries/__generated__/graphql&#39;;<br>  <br>const {data, loading, error} = useGetAnimeListQuery({<br>    variables: {<br>      page: 1,<br>      perPage: 10,<br>    },<br>  });</pre><p>2. using<strong> useLazyQuery</strong> hook</p><pre>import { useGetAnimeListLazyQuery } from &#39;../network/queries/__generated__/graphql&#39;;<br>    <br>const [getAnimeList, {data, loading, error}] = useGetAnimeListLazyQuery({<br>  variables: {<br>    page: 1,<br>    perPage: 10,<br>  },<br>});<br><br>const onRefresh = () =&gt; {<br>  getAnimeList();<br>};</pre><p>3. using plain <strong>query document</strong></p><pre>import { GetAnimeListDocument } from &#39;../network/queries/__generated__/graphql&#39;;<br>import {client} from &#39;../network/graphqlClient&#39;;<br><br>    <br>const fetchAnimeList = async () =&gt; {<br>  const {data, loading, error} = await client.query({<br>    query: GetAnimeListDocument,<br>    variables: {<br>      page: 1,<br>      perPage: 10,<br>    },<br>  });<br>};</pre><p>This is how it will be used in our example component.</p><pre>import React from &#39;react&#39;;<br>import {FlatList, StyleSheet, Text, View} from &#39;react-native&#39;;<br>import {<br>  GetAnimeListDocument,<br>  useGetAnimeListLazyQuery,<br>  useGetAnimeListQuery,<br>} from &#39;../network/queries/__generated__/graphql&#39;;<br>import {client} from &#39;../network/graphqlClient&#39;;<br><br>const AnimeListViewComponent = () =&gt; {<br>  /* Method 1 - Using useQuery */<br>  const {data, loading, error} = useGetAnimeListQuery({<br>    variables: {<br>      page: 1,<br>      perPage: 10,<br>    },<br>  });<br><br>  /* Method 2 - Using useLazyQuery */<br>  // const [getAnimeList, {data, loading, error}] = useGetAnimeListLazyQuery({<br>  //   variables: {<br>  //     page: 1,<br>  //     perPage: 10,<br>  //   },<br>  // });<br><br>  //   const onRefresh = () =&gt; {<br>  //     getAnimeList();<br>  //   };<br><br>  /* Method 3 - If you are using the query document */<br>  // const fetchAnimeList = async () =&gt; {<br>  //   const {data, loading, error} = await client.query({<br>  //     query: GetAnimeListDocument,<br>  //     variables: {<br>  //       page: 1,<br>  //       perPage: 10,<br>  //     },<br>  //   });<br>  // };<br><br>  const renderAnimeItem = item =&gt; {<br>    return (<br>      &lt;View style={styles.itemContainer}&gt;<br>        &lt;Text&gt;{item?.title?.userPreferred}&lt;/Text&gt;<br>        &lt;Text&gt;{item?.seasonYear}&lt;/Text&gt;<br>      &lt;/View&gt;<br>    );<br>  };<br><br>  return (<br>    &lt;View style={styles.contentContainer}&gt;<br>      &lt;FlatList<br>        data={data?.Page?.media || []}<br>        renderItem={({item}) =&gt; renderAnimeItem(item)}<br>        refreshing={loading}<br>        //onRefresh={onRefresh} //uncomment if you use &#39;Method 2 - useLazyQuery&#39;<br>      /&gt;<br>    &lt;/View&gt;<br>  );<br>};<br><br>export default AnimeListViewComponent;<br><br>const styles = StyleSheet.create({<br>  contentContainer: {<br>    flex: 1,<br>    flexDirection: &#39;column&#39;,<br>  },<br>  itemContainer: {<br>    flex: 1,<br>    flexDirection: &#39;row&#39;,<br>    marginVertical: 5,<br>    marginHorizontal: 15,<br>    justifyContent: &#39;space-between&#39;,<br>  },<br>});</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ykrhzLTzglfwDPdzjQd4uw.png" /></figure><p>And also now you have the type definitions too.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8kg9EZ2pU23bUsuHmf3ngA.png" /><figcaption>How codegen provides type definitions.</figcaption></figure><h3>That is it!</h3><p>In conclusion, GraphQL Codegen is a powerful tool that streamlines the development process in TypeScript-based React Native projects. By automating the generation of strongly typed GraphQL code, it enhances code quality, reduces errors, and boosts developer productivity. Whether you’re building a complex mobile app or a simple prototype, integrating GraphQL Codegen ensures that your data-fetching code remains type-safe and maintainable, allowing you to focus on creating outstanding user experiences in your applications.</p><p><strong>Codebase</strong>: <a href="https://github.com/OmalPerera/RnGql">https://github.com/OmalPerera/RnGql</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ac262999af65" width="1" height="1" alt=""><hr><p><a href="https://medium.com/ascentic-technology/supercharge-your-react-native-app-with-graphql-codegen-strongly-typed-hassle-free-data-fetching-ac262999af65">Supercharge your React-native app with GraphQL Codegen: Strongly typed, hassle-free data fetching</a> was originally published in <a href="https://medium.com/ascentic-technology">Ascentic Technology</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[One codebase for React and React-native with Nx monorepos]]></title>
            <link>https://medium.com/ascentic-technology/one-codebase-for-react-and-react-native-with-nx-monorepos-5e876ed829c2?source=rss-50e1e03eeb0c------2</link>
            <guid isPermaLink="false">https://medium.com/p/5e876ed829c2</guid>
            <category><![CDATA[nx]]></category>
            <category><![CDATA[monorepo]]></category>
            <category><![CDATA[nx-workspace]]></category>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Omal Perera]]></dc:creator>
            <pubDate>Sat, 28 Oct 2023 04:58:45 GMT</pubDate>
            <atom:updated>2023-10-28T04:58:45.411Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TohMPpzQ71vGhekcXs_sXg.png" /><figcaption>Image from <a href="https://www.voiceflow.com/blog/how-monorepos-can-help-improve-your-productivity">https://www.voiceflow.com/blog/how-monorepos-can-help-improve-your-productivity</a></figcaption></figure><p>A <em>monorepo</em> is a single repository containing multiple distinct projects, with well-defined relationships. This shouldn’t be confused with <em>monolithic architecture</em>, which is a software development practice for writing self-contained applications.</p><p>Monorepo is a technical concept; Using it for your project depends on your tech stack, requirements, team arrangement, release pipeline, and many other factors. Therefore, it is always advised to analyze your system and feasibility before making a decision. This informative article, ‘<a href="https://semaphoreci.com/blog/what-is-monorepo"><strong>What is monorepo? (and should you use it?)</strong></a>’, highlights some key reasons to both love and hate monorepos.</p><p>Today we will be focusing on how to maintain and share code between react and react native projects using <a href="https://nx.dev/getting-started/intro">Nx workspace</a>.</p><h3>Why monorepo?</h3><h4>Simple use-case</h4><p>For this article, our objective is to develop a React Native mobile app and a React web app using TypeScript. Both the mobile and web projects will feature a simple counter app, and we will employ Redux for state management.</p><p><strong>Analysing the requirement</strong></p><p>Upon reviewing the straightforward requirement above, we can glean insights regarding code reusability. It’s evident that we cannot reuse or share the view layer components between React and React Native. However, the remainder of our TypeScript utility functions, type definitions, models, theming, service layer implementations, reducers, store, and related actions can be shared between the web and mobile applications.</p><p>In order to implement this, Nx provides robust support for easily scaffolding projects, resolving files and modules, running, building, and more.</p><h3>Let’s get started with Nx</h3><h4>Step 1 — Setting up Nx workspace</h4><p>First, you should install Nx globally by using the following command. If you encounter any errors, you can refer to the official installation instructions available <a href="https://nx.dev/getting-started/installation">here</a>.</p><pre>npm install -g nx@latest</pre><p>Nx offers convenient plugins for both VSCode and JetBrains IDEs. By installing these plugins in either <a href="https://marketplace.visualstudio.com/items?itemName=nrwl.angular-console">VSCode</a> or <a href="https://plugins.jetbrains.com/plugin/21060-nx-console">JetBrains</a>, you can streamline your workflow and reduce your reliance on CLI commands. You can find the official installation instructions <a href="https://nx.dev/core-features/integrate-with-editors">here</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZYHlx3Dp4tJ0mWhIKArx2w.png" /><figcaption>Install Nx Console to VSCode from the marketplace.</figcaption></figure><h4>Step 2 — Creating a Workspace &amp; Generating React Native &amp; React Apps</h4><p>Now, let’s proceed to create an Nx workspace, as demonstrated in the GIF below. We will create a workspace (I have named it “m-repo”) and a React Native project called “mobile.”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/746/1*9KjDsY0vG4ecOcZzKu1G5Q.gif" /></figure><p>After following the steps above, your workspace structure should look like this, with the React Native app codebase located inside the ‘apps/mobile’ directory.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/699/1*np-HJzAWOpUznE3eiedPEA.png" /></figure><p><strong>Creating the React Project in the Same Workspace</strong></p><p>To add a React project to the Nx workspace, use the ‘generate’ command. Navigate to the Nx button in VSCode, and follow the steps shown in the GIF below. Specify the directory as apps/webApp since we’re creating our React app inside the ‘apps’ folder. Additionally, set the end-to-end test runner to ‘none’ to keep things simple, as we don&#39;t need an end-to-end test project at this time.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/664/1*cMvS6k9GOQFRRAThOOaWEQ.gif" /><figcaption>Generating a React project using ‘generate’ command in nx workspace</figcaption></figure><p><strong>Run the React-native apps and React app</strong></p><p>Navigate to the Nx plugin button and select the options shown below to run the specific app.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/699/1*REcXZZNOwFrOHJ3f3vlfXw.png" /><figcaption>use these options to run the apps</figcaption></figure><p><strong>How to remove a project from Nx workspace?</strong></p><p>The recommended way to delete or remove a generated project in Nx workspace is through the plugin or command. Manually deleting the project folder is not a safe approach and can lead to project corruption.<br>You can find the specific project under the ‘Projects’ section in the Nx plugin pane and remove it by right-clicking on the project to access the deletion option.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/758/1*q7p1ncqIjsdi5cZppZPMgA.gif" /><figcaption>Removing a project. (mobile-e2e project removed from Nx)</figcaption></figure><h4>Step 3 — Creating a Shared project and use it in mobile and web projects.</h4><p>Now, it’s time to create a shared project for common store since our goal is to share them between the web and mobile applications. To keep things organized, we’ll place this library inside a ‘shared’ folder in the project root, anticipating the need for more common projects as the project progresses.</p><p>For this task, you can utilize the same ‘generate’ Nx option to create a project. However, this time, it will be a library, not an application as before. Detailed steps can be found in the following GIF.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/744/1*BvXvmbMXARK1X9nWIWZmUg.gif" /></figure><p>To ensure everything is working smoothly, let’s import and utilize the store library in both React Native and React. If you inspect shared/store/lib/store.ts you will find a simple function that returns the string ‘store’. We will now integrate this into our mobile and web apps.</p><p><strong>Import and usage in mobile projects</strong></p><p>To integrate the shared module into your mobile project, Change the content of apps/mobile/src/app/App.tsx as follows. In line number 3 we have imported our pre-created shared module. This is made possible through the configurations in tsconfig.base.json at the project root (as illustrated in the image below). Nx automatically includes the relative path of the shared project, which Metro will resolve during the build process.</p><pre>//apps/mobile/src/app/App.tsx<br>import React from &#39;react&#39;;<br>import { SafeAreaView, StyleSheet, View, Text } from &#39;react-native&#39;;<br>import { store } from &#39;@m-repo/store&#39;; //This is how import works<br><br>export const App = () =&gt; {<br>  return (<br>    &lt;&gt;<br>      &lt;SafeAreaView /&gt;<br>      &lt;View&gt;<br>        &lt;Text style={styles.textLg}&gt;Welcome Mobile&lt;/Text&gt;<br>        &lt;Text style={styles.textLg}&gt;<br>          {&#39;From shared module -&gt; &#39; + store()}<br>        &lt;/Text&gt;<br>      &lt;/View&gt;<br>    &lt;/&gt;<br>  );<br>};<br>const styles = StyleSheet.create({<br>  textLg: {<br>    fontSize: 24,<br>    padding: 24,<br>  },<br>});<br><br>export default App;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/878/1*XsRbAoYCLSyRV0o-RiNm_g.png" /><figcaption>tsconfig.base.json — Automatically added record when a library is created. @m-repo/store can be used in import statements instead of relative paths</figcaption></figure><p><strong>Import and usage in Web projects</strong></p><p>You can import the shared store string into your React project just as we did for React Native above. Replace the code in apps/webApp/src/app/app.tsx with the following code.</p><pre>// apps/webApp/src/app/app.tsx<br>import { store } from &#39;@m-repo/store&#39;;<br><br>export function App() {<br>  return (<br>    &lt;div&gt;<br>      &lt;h1&gt;<br>        &lt;span&gt;Hello there&lt;/span&gt;<br>      &lt;/h1&gt;<br>      &lt;span&gt;{&#39;From shared module -&gt; &#39; + store()}&lt;/span&gt;<br>    &lt;/div&gt;<br>  );<br>}<br><br>export default App;</pre><p>Now you can run the projects and check whether all is good up to now.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/931/1*l6J5TyJCB6X49XXTYSNmJw.png" /><figcaption>running of 2 apps should show a similar result.</figcaption></figure><p>If you can see the string ‘store’ that we imported from the shared module, congratulations! 🎉 .<br>This marks the foundation for code sharing, and the next steps involve implementing the planned features.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/345/1*yeQJrJZ8fjQ20hyzodDMjQ.gif" /></figure><h3>Okay, what is next?</h3><p>Comparing with the initial requirements and what we have built so far, we have accomplished the following:</p><ul><li>Created an Nx workspace.</li><li>Developed two separate projects for React Native and React.js.</li><li>Established a simple shared module used in both mobile and web projects.</li></ul><p>What remains to be done?</p><ul><li>Set up and configure the Redux store and reducers.</li><li>Create a simple UI in both projects and connect the store.</li></ul><h4><strong>Setting up a common store</strong></h4><p>Firstly, We need to install Redux-related dependencies in the root project.</p><pre>npm i redux react-redux @reduxjs/toolkit</pre><p>Create a new file named ‘counterReducer.ts’ in shared/store/src/lib/ and add the following code to create a simple store slice for storing our counter value. The updateCounteraction will be called from the component to update the value.”</p><pre>// shared/store/src/lib/counterReducer.ts<br>import { createSlice } from &#39;@reduxjs/toolkit&#39;;<br><br>export type TcounterReducer = {<br>  counterValue: number;<br>};<br><br>const INITIAL_STATE: TcounterReducer = {<br>  counterValue: 0,<br>};<br><br>const counterSlice = createSlice({<br>  name: &#39;counter&#39;,<br>  initialState: INITIAL_STATE,<br>  reducers: {<br>    updateCounter: (state, action) =&gt; {<br>      state.counterValue = action.payload;<br>    },<br>  },<br>});<br><br>export const { updateCounter } = counterSlice.actions;<br>export const counterReducer = counterSlice.reducer;</pre><p>It’s time to create the store. Open the shared/store/src/lib/store.ts file and replace its content with the following code. In this step, we configure our store. <br>For this demonstration, we won’t be injecting any middleware. If you plan to use different types of middleware for mobile and web, it’s advisable to configure separate stores for each project, while still sharing reducer slices.</p><pre>// shared/store/src/lib/store.ts<br>import { combineReducers } from &#39;redux&#39;;<br>import { configureStore } from &#39;@reduxjs/toolkit&#39;;<br>import { counterReducer } from &#39;./counterReducer&#39;;<br><br>const rootReducer = combineReducers({<br>  counterReducer: counterReducer,<br>});<br><br>export const store = configureStore({<br>  reducer: rootReducer,<br>});<br><br>export type RootState = ReturnType&lt;typeof store.getState&gt;;</pre><p>lastly, we should expose these via the shared/store/src/index.ts so that we can import using @m-repo/store statement.</p><pre>// shared/store/src/index.ts<br>export * from &#39;./lib/store&#39;;<br>export * from &#39;./lib/counterReducer&#39;;</pre><h4>Adding a simple UI and using the shared store</h4><p><strong>Let&#39;s do the mobile-first.</strong></p><p>Create a new file named ‘CounterComponent.ts’ in apps/mobile/src/app/features/ and add the following code, which creates the UI for a simple counter app. This code includes a function that renders ‘+’ and ‘-’ buttons, as well as a text component to display the current counter value. when the button is pressed, an incremented or decremented value will be passed to the action we created in the “counterReducer”.</p><pre>// apps/mobile/src/app/features/CounterComponent.ts<br>import React from &#39;react&#39;;<br>import {<br>  SafeAreaView,<br>  StyleSheet,<br>  View,<br>  Text,<br>  TouchableOpacity,<br>} from &#39;react-native&#39;;<br>import { useDispatch, useSelector } from &#39;react-redux&#39;;<br>import { RootState, updateCounter } from &#39;@m-repo/store&#39;;<br><br>export const CounterComponent = () =&gt; {<br>  const dispatch = useDispatch();<br>  const counterValue = useSelector(<br>    (state: RootState) =&gt; state.counterReducer.counterValue<br>  );<br><br>  const renderButton = (operation: &#39;+&#39; | &#39;-&#39;) =&gt; {<br>    return (<br>      &lt;TouchableOpacity<br>        style={styles.btnBg}<br>        onPress={() =&gt; {<br>          dispatch(<br>            updateCounter(<br>              operation === &#39;+&#39; ? counterValue + 1 : counterValue - 1<br>            )<br>          );<br>        }}<br>      &gt;<br>        &lt;Text style={styles.btnTxt}&gt;{operation}&lt;/Text&gt;<br>      &lt;/TouchableOpacity&gt;<br>    );<br>  };<br><br>  return (<br>    &lt;&gt;<br>      &lt;SafeAreaView /&gt;<br>      &lt;View style={styles.container}&gt;<br>        {renderButton(&#39;-&#39;)}<br>        &lt;Text style={styles.counterTxt}&gt;{counterValue}&lt;/Text&gt;<br>        {renderButton(&#39;+&#39;)}<br>      &lt;/View&gt;<br>    &lt;/&gt;<br>  );<br>};<br>const styles = StyleSheet.create({<br>  container: {<br>    flexDirection: &#39;row&#39;,<br>    justifyContent: &#39;space-evenly&#39;,<br>    alignItems: &#39;center&#39;,<br>    marginVertical: 40,<br>  },<br>  btnBg: {<br>    backgroundColor: &#39;#FE9505&#39;,<br>    height: 76,<br>    width: 76,<br>    justifyContent: &#39;center&#39;,<br>    alignItems: &#39;center&#39;,<br>    borderRadius: 38,<br>  },<br>  btnTxt: {<br>    fontSize: 32,<br>    fontWeight: &#39;600&#39;,<br>    color: &#39;white&#39;,<br>  },<br>  counterTxt: {<br>    fontSize: 32,<br>  },<br>});<br><br>export default CounterComponent;</pre><p>Next, we need to wrap our entire component tree with the ‘react-redux’ provider. To do that, open ‘App.tsx’ and replace the existing code with the following code. As you can see the ‘store’ is imported from @m-repo/store .</p><pre>// apps/mobile/src/app/App.tsx<br>import React from &#39;react&#39;;<br>import CounterComponent from &#39;./features/CounterComponent&#39;;<br>import { Provider } from &#39;react-redux&#39;;<br>import { store } from &#39;@m-repo/store&#39;;<br><br>export const App = () =&gt; {<br>  return (<br>    &lt;Provider store={store}&gt;<br>      &lt;CounterComponent /&gt;<br>    &lt;/Provider&gt;<br>  );<br>};<br><br>export default App;</pre><p><strong>Adding the React js web UI and integrating the shared store</strong></p><p>Create a new file named ‘counterComponent.tsx’ in apps/webApp/src/app/ and add the following code.</p><pre>// apps/webApp/src/app/counterComponent.tsx<br>import { RootState, updateCounter } from &#39;@m-repo/store&#39;;<br>import { useSelector, useDispatch } from &#39;react-redux&#39;;<br><br>const CounterComponent = () =&gt; {<br>  const dispatch = useDispatch();<br>  const counterValue = useSelector(<br>    (state: RootState) =&gt; state.counterReducer.counterValue<br>  );<br><br>  const renderButton = (operation: &#39;+&#39; | &#39;-&#39;) =&gt; {<br>    return (<br>      &lt;button<br>        style={styles.btnBg}<br>        onClick={() =&gt; {<br>          dispatch(<br>            updateCounter(<br>              operation === &#39;+&#39; ? counterValue + 1 : counterValue - 1<br>            )<br>          );<br>        }}<br>      &gt;<br>        &lt;span style={styles.btnTxt}&gt;{operation}&lt;/span&gt;<br>      &lt;/button&gt;<br>    );<br>  };<br><br>  return (<br>    &lt;div style={styles.container}&gt;<br>      {renderButton(&#39;-&#39;)}<br>      &lt;span style={styles.counterTxt}&gt;{counterValue}&lt;/span&gt;<br>      {renderButton(&#39;+&#39;)}<br>    &lt;/div&gt;<br>  );<br>};<br><br>export default CounterComponent;<br><br>const styles = {<br>  btnBg: {<br>    backgroundColor: &#39;#FE9505&#39;,<br>    width: 76,<br>    height: 76,<br>    borderRadius: 38,<br>    borderWidth: 0,<br>  },<br>  counterTxt: {<br>    fontSize: &#39;32px&#39;,<br>  },<br>  btnTxt: {<br>    fontSize: &#39;32px&#39;,<br>    fontWeight: &#39;bold&#39;,<br>    color: &#39;white&#39;,<br>  },<br>  container: {<br>    display: &#39;flex&#39;,<br>    justifyContent: &#39;space-evenly&#39;,<br>    alignItems: &#39;center&#39;,<br>  },<br>};</pre><p>Same as we did in react-native app.tsx, we need to wrap the entire component tree with a react-redux provider as below. You can replace the code in apps/webApp/src/app/app.tsx</p><pre>// apps/webApp/src/app/app.tsx<br>import { Provider } from &#39;react-redux&#39;;<br>import CounterComponent from &#39;./counterComponent&#39;;<br>import { store } from &#39;@m-repo/store&#39;;<br><br>export function App() {<br>  return (<br>    &lt;Provider store={store}&gt;<br>      &lt;CounterComponent /&gt;<br>    &lt;/Provider&gt;<br>  );<br>}<br><br>export default App;</pre><p>That is it! Now we can run our applications to check the behavior.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/860/1*Q0hQclnHS6RIT5zS6KM2NQ.gif" /><figcaption>React-naive app (left side) and the React web (right side), which share the same code for ‘redux-store’ in a single repository</figcaption></figure><h3>Things we learned today</h3><p>In this article, we successfully developed both a React.js web application and a React Native app within a single repository using Nx. This structure enables us to conveniently store our common business logic in technology-independent libraries, which can be easily linked to both our React web and React Native mobile applications.</p><p>The directory and file names used in this article can be customized to fit your project’s requirements. For instance, the ‘shared’ folder can be renamed to anything that suits your needs. And also, Nx is not limited to React and React Native, but it also supports many other languages and frameworks.</p><p>Thank you for being with us throughout the article and for sharing your thoughts and experiences.</p><p><strong>Codebase</strong>: <a href="https://github.com/OmalPerera/m-repo">https://github.com/OmalPerera/m-repo</a></p><h4>For further reading</h4><ol><li><strong>Misconceptions about Monorepos: Monorepo != Monolith : </strong><a href="https://blog.nrwl.io/misconceptions-about-monorepos-monorepo-monolith-df1250d4b03c">https://blog.nrwl.io/misconceptions-about-monorepos-monorepo-monolith-df1250d4b03c</a></li><li><strong>What is monorepo? (and should you use it?) : </strong><a href="https://semaphoreci.com/blog/what-is-monorepo">https://semaphoreci.com/blog/what-is-monorepo</a></li><li><strong>Guide to Monorepos for Front-end Code</strong>: <a href="https://www.toptal.com/front-end/guide-to-monorepos">https://www.toptal.com/front-end/guide-to-monorepos</a></li><li><strong>Why Nx</strong> : <a href="https://nx.dev/getting-started/why-nx">https://nx.dev/getting-started/why-nx</a></li><li><strong>Share code between React Web &amp; React Native Mobile with Nx:</strong> <a href="https://blog.nrwl.io/share-code-between-react-web-react-native-mobile-with-nx-fe5e22b5a755">https://blog.nrwl.io/share-code-between-react-web-react-native-mobile-with-nx-fe5e22b5a755</a></li><li><strong>Step-by-Step Guide to Creating an Expo Monorepo with Nx :</strong> <a href="https://blog.nrwl.io/step-by-step-guide-to-creating-an-expo-monorepo-with-nx-30c976fdc2c1">https://blog.nrwl.io/step-by-step-guide-to-creating-an-expo-monorepo-with-nx-30c976fdc2c1</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5e876ed829c2" width="1" height="1" alt=""><hr><p><a href="https://medium.com/ascentic-technology/one-codebase-for-react-and-react-native-with-nx-monorepos-5e876ed829c2">One codebase for React and React-native with Nx monorepos</a> was originally published in <a href="https://medium.com/ascentic-technology">Ascentic Technology</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Case study: AI/AR-based Virtual Try-on for e-commerce]]></title>
            <link>https://medium.com/ascentic-technology/case-study-ai-ar-based-virtual-try-on-for-e-commerce-8d1a3d6ad6a6?source=rss-50e1e03eeb0c------2</link>
            <guid isPermaLink="false">https://medium.com/p/8d1a3d6ad6a6</guid>
            <category><![CDATA[fashion]]></category>
            <category><![CDATA[virtual-try-on]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[ar]]></category>
            <category><![CDATA[ecommerce]]></category>
            <dc:creator><![CDATA[Omal Perera]]></dc:creator>
            <pubDate>Tue, 05 Sep 2023 07:05:18 GMT</pubDate>
            <atom:updated>2023-09-05T07:05:18.347Z</atom:updated>
            <content:encoded><![CDATA[<h3>What is Virtual Try-On (VTO)</h3><p>Virtual Try-On enables consumers to superimpose digital representations of products onto their real-world environment using their smartphones, tablets, or other AR-enabled devices. This technology is commonly used in the fashion and beauty industries, where users can try on clothing, accessories, eyewear, makeup, and even hairstyles virtually. It has several advantages for e-commerce</p><p>1. Enhanced customer engagement<br>2. Reduced purchase uncertainty<br>3. Improved personalization<br>4. Increased sales and conversion rates<br>5. Social sharing, viral marketing, and Competitive advantage</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/980/1*LqvVWmY9bxyNjZxTHE0PHA.jpeg" /><figcaption>A model uses FXGear’s virtual fitting room FXMirror to virtually try on a garment. / Courtesy of <a href="https://www.fxgear.net/">FXGear</a></figcaption></figure><h3><strong>Forecasting the future of the Virtual Try-On market</strong></h3><p>The global virtual fitting room market grew significantly, reaching USD 3.78 billion in 2022. This upward trend is projected to continue with a strong compound annual growth rate of 24.1% from 2023 to 2030 according to <a href="https://www.fortunebusinessinsights.com/industry-reports/virtual-fitting-room-vfr-market-100322">fortunebusinessinsights.com</a>. The market’s expansion can be attributed to the increasing adoption of Virtual Reality (VR) and Augmented Reality (AR) technologies in virtual fitting room solutions, providing users with a heightened sense of realism and engagement during the online shopping experience.</p><p>Moreover, businesses across various industries are actively exploring ways to integrate VR shopping experiences into their physical storefronts and online platforms, recognizing the potential benefits of enhanced user engagement and satisfaction. The incorporation of VR and AR technologies enhances the overall purchasing experience for consumers, enabling them to visualize products better before deciding.</p><h3><strong>Few big steps in the e-commerce world with Virtual try-on.</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Q1Rldofe-IcaVB0ruYVkmQ.jpeg" /><figcaption>Image courtesy — <a href="https://corporate.walmart.com/newsroom/2022/09/15/walmart-levels-up-virtual-try-on-for-apparel-with-be-your-own-model-experience">https://corporate.walmart.com</a></figcaption></figure><p>A prominent example of this trend is <strong>Walmart Inc</strong>. In March 2022, Walmart launched a cutting-edge virtual try-on tool. This tool empowers customers to virtually try on clothing items through a personalized virtual model that aligns with their individual body type, hair colour, and skin tone. The success of this initiative has been a driving force behind the market’s growth, as it addresses common concerns related to online apparel shopping, such as fitness and suitability.</p><p><strong>Adidas’s</strong> new virtual try-on feature in its iOS app aims to help shoppers pick out new shoe styles without setting foot in a shoe store in an effort to improve the customer experience.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FkHiI-oQvB5c&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DkHiI-oQvB5c&amp;image=http%3A%2F%2Fi.ytimg.com%2Fvi%2FkHiI-oQvB5c%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/c0d3f564437a80ce02d03054f7b54f6d/href">https://medium.com/media/c0d3f564437a80ce02d03054f7b54f6d/href</a></iframe><h3><strong>How does it actually work?</strong></h3><p>There are several approaches that have been used in these applications, and let’s have a look at a couple of them in brief.</p><h4><strong>1. Overlying a pre-designed asset on a 2D/3D model using AR</strong></h4><p>The following are some screenshots from <a href="https://wanna.fashion/">Wanna wear app</a> which uses a similar technology.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7gHTn9i6aFG8-R0yg3AbTg.png" /><figcaption>Collection of screenshots from the Wanna wear app</figcaption></figure><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FzYKiUxnumKM%3Fstart%3D7%26feature%3Doembed%26start%3D7&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DzYKiUxnumKM&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FzYKiUxnumKM%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/2b8f07a6d602c136f87ad9e8104e383e/href">https://medium.com/media/2b8f07a6d602c136f87ad9e8104e383e/href</a></iframe><p>The following will be the foundation approach for such an implementation. But always keep in mind that it will be a huge development effort to build up an accurate solution on top of these foundation steps.</p><ol><li>Real-time user pose detection.</li><li>Transform 3D digital garment assets according to the posture.</li><li>Map to body landmarks and inpainting</li><li>Applying on top of AR-detected character</li></ol><p>Let’s discuss some challenges in the above implementation.</p><h4><strong>Posture detection</strong></h4><p>Posture detection and tracking the body landmarks are critical components of AR applications that aim to interact with users in a more natural and intuitive way. Python, a popular programming language, can be combined with Human Pose Estimation techniques to achieve this functionality. ARKit, Apple’s AR development framework, offers powerful tools for creating immersive AR experiences on iOS devices. By utilizing ARKit’s capabilities and integrating them with Python libraries for Human Pose Estimation, apps can track and identify the key points of a person’s body in real-time. These body landmarks include the position of joints like elbows, wrists, knees, and ankles, enabling the AR application to interpret the user’s posture and movements.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/772/1*JJCbfzhTySIqKr1L5pDkpQ.png" /><figcaption><a href="https://github.com/google/mediapipe/blob/master/docs/solutions/pose.md">Media pipe</a> is a popular python library to work with body landmarks</figcaption></figure><h4>Designing, transforming digital assets to match the 2D/3D model</h4><p>To ensure a realistic and immersive try-on experience, designers and developers employ various techniques, including computer vision, image processing, and machine learning algorithms when preparing digital media resources.</p><p>The process is far more complex than creating a static 3D object, as resource objects such as clothing items, accessories, or cosmetics should support human movements and be accurately mapped to fit the user’s body or face in real-time.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*51RkYtjZeraHs9VUKrP67A.png" /><figcaption>Managing digital 3D assets from Vyking Studio to use in its apps — <a href="https://www.vyking.io/">https://www.vyking.io/</a></figcaption></figure><h4>2. TryOnDiffusion — for 2D images</h4><p>Using <a href="https://tryondiffusion.github.io/">try-on diffusion</a> for virtual try-on is a cutting-edge approach that revolutionizes the way users experience products in the digital world. Try-on diffusion leverages advanced computer vision and machine learning techniques to seamlessly integrate virtual objects into real-world environments, creating a more realistic and immersive try-on experience.</p><p>Very recently (June 2023) <a href="https://blog.google/products/shopping/ai-virtual-try-on-google-shopping/">Google has released</a> a new virtual try-on tool using generative artificial intelligence is available through its search engine. It is only usable on women’s tops to start.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*E-74iUWL1OfK2dxNZabnUQ.jpeg" /><figcaption>A selection of three different models wearing the same shirt. With Google’s virtual try-on feature, users can select models ranging from size XXS to 4XL, with different skin tones, body shapes, and hair types. Image courtesy: <a href="https://www.retaildive.com/news/google-generative-artificial-intelligence-virtual-try-on-tool/653076/">https://www.retaildive.com</a></figcaption></figure><p>Beneath the surface, it uses a <a href="https://blog.google/products/shopping/virtual-try-on-google-generative-ai">generative AI model</a> that can take just one clothing image and accurately reflect how it would drape, fold, cling, stretch, and form wrinkles and shadows on a diverse set of real models in various poses. It supports people ranging in sizes XXS-4XL representing different skin tones (using the <a href="https://blog.google/products/search/monk-skin-tone-scale/">Monk Skin Tone Scale</a> as a guide), body shapes, ethnicities, and hair types.</p><p>The biggest advantage of this approach is the ability to work without pre-designed dedicated overlay images of clothing or accessories.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dzDdPYhzYuPn8gcdqua2cw.png" /><figcaption>diffusion model sends images to their own neural network (a U-net) to generate the output: a photorealistic image of the person wearing the garment. <a href="https://blog.google/products/shopping/virtual-try-on-google-generative-ai/">https://blog.google/</a></figcaption></figure><p>In today’s market, there are several web and mobile app solutions demonstrating successful AR/AI virtual try-on implementations. Companies like <a href="https://wanna.fashion/">Wanna</a>, <a href="https://www.reactivereality.com/">Reactive Reality</a>, <a href="https://www.vyking.io/">Vyking</a>, <a href="http://www.fxmirror.net/en/features">FxMirror,</a> <a href="https://ar.snap.com/lens-studio">SnapChat AR</a> are just a few examples of such platforms.</p><p>Each of these solutions comes with their own set of capabilities, and limitations, and their performance, accuracy, reliability, and features vary significantly. As such, they each take a unique approach tailored to the products they cater to.</p><p>As discussed earlier, some solutions support only 2D images of models which give you a more accurate silhouette, while others enable real-time application of 3D body mapping, but don’t ensure 100% accuracy.</p><p>Consequently, choosing the most suitable solution for your business will heavily depend on your specific requirements.</p><h3><strong>Finally…</strong></h3><p>Applications of virtual try-on for day-to-day activities are on a rapid growth trajectory, with VR and AR technologies playing a critical role in enhancing user experiences.</p><p>As discussed previously, there are several approaches where current solutions are based and we can expect a lot more new developments to be introduced in the future. As companies invest more in virtual shopping solutions, the market is set to grow significantly, catering to the changing preferences of tech-savvy consumers and shaping the future of retail. Remember, the future of shopping is at our fingertips!</p><p>Thanks for reading! If you have had any encounters with virtual try-on implementations, your insights would be invaluable to us. Feel free to let me know your opinions, suggestions, or any interesting experiences you may have had.</p><p><strong>Reference</strong></p><ol><li><a href="https://vogue-try-on.github.io/">https://vogue-try-on.github.io/</a></li><li><a href="https://tryondiffusion.github.io/">https://tryondiffusion.github.io/</a></li><li>Snapchat Lens Studio, asset creation <a href="https://www.youtube.com/watch?v=g4bxByrHFGY">https://www.youtube.com/watch?v=g4bxByrHFGY</a></li><li><a href="https://ar.snap.com/lens-studio">https://ar.snap.com/lens-studio</a></li><li><a href="https://wanna.fashion/blog/virtual-try-on-technology-for-luxury-industry">https://wanna.fashion/blog/virtual-try-on-technology-for-luxury-industry</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8d1a3d6ad6a6" width="1" height="1" alt=""><hr><p><a href="https://medium.com/ascentic-technology/case-study-ai-ar-based-virtual-try-on-for-e-commerce-8d1a3d6ad6a6">Case study: AI/AR-based Virtual Try-on for e-commerce</a> was originally published in <a href="https://medium.com/ascentic-technology">Ascentic Technology</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Crafting AR apps with React Native]]></title>
            <link>https://medium.com/ascentic-technology/crafting-ar-apps-with-react-native-a9040cf40042?source=rss-50e1e03eeb0c------2</link>
            <guid isPermaLink="false">https://medium.com/p/a9040cf40042</guid>
            <category><![CDATA[ar]]></category>
            <category><![CDATA[viroreact]]></category>
            <category><![CDATA[augmented-reality]]></category>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <dc:creator><![CDATA[Omal Perera]]></dc:creator>
            <pubDate>Thu, 10 Aug 2023 08:26:26 GMT</pubDate>
            <atom:updated>2023-08-10T08:26:26.454Z</atom:updated>
            <content:encoded><![CDATA[<p>Augmented Reality (AR) is an emerging technology that enhances the ability to present computer-generated content along with the real world. It combines digital image processing, 3D graphics, artificial intelligence, and various other fields to create its enhanced capabilities.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*h6OlJL3yfx20s6-50tWf4w.jpeg" /><figcaption>This is a real photo taken from Google Maps&#39; newest AR integration, currently limited to private-alpha users. Photo credit: <a href="https://twitter.com/nickbastone">Nick Bastone</a></figcaption></figure><h4><strong>What is under the hood?</strong></h4><p>There are several popular AR development libraries and frameworks available for mobile app development. To the date, most of them rely on ARKit and ARCore SDKs provided by Apple and Google respectively.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AYDgTXUK_sh_fdCOyrFfQw.png" /></figure><p>iOS ARKit and Android ARCore are two native SDKs that utilize the device’s camera, motion sensors, and processing power to overlay virtual objects onto the real world, creating interactive and realistic AR content.</p><p>These were initially released in mid-2017 and the following are some common features/capabilities for AR development.</p><h4><strong>1. World Tracking</strong></h4><ul><li>Uses the device’s camera to track the movement of the device and detect features in the environment, such as flat surfaces and objects.</li></ul><h4><strong>2. Scene Understanding</strong></h4><ul><li>Understanding the surrounding environment, including recognizing horizontal and vertical planes, and estimating lighting conditions.</li></ul><h4>3. Motion Tracking</h4><ul><li>Tracks the device’s orientation and movement, allowing virtual objects to remain stable and aligned with the physical environment as the user moves the device.</li></ul><h4><strong>4. Face Tracking</strong></h4><ul><li>Accurately recognize and track facial features</li></ul><h4>5. Image and Object Recognition</h4><ul><li>Can recognize and track specific 2D images or 3D objects in the real world.</li></ul><h3><strong>React-native AR libraries</strong></h3><p><a href="https://github.com/viromedia/viro">Viro-react</a> is one of the popular libraries for react-native AR development when compared with other options. It uses native AR capabilities on both iOS and Android platforms and ensures a high-quality and immersive experience for users with comprehensive support for 3D models, animations, physics, and user interactions.</p><p>Documentation: [<a href="https://viro-community.readme.io/docs/overview">https://viro-community.readme.io/docs/overview</a> ]</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mUx788LZAgVPd2CUnsGqCw.png" /></figure><p>Following are some key milestones in Viro-react in brief</p><ul><li>Initial release on March 2016 aiming VR by a startup called ‘Viro-Media’</li><li>AR Integration, as AR technology gained traction</li><li>Open-Sourced: In August 2018 under MIT License.</li><li>Viro Media was acquired by Facebook in November 2019</li></ul><h3><strong>Let’s do some code</strong></h3><p>If this is your first-time trying AR with react-native, I recommend you use the <a href="https://github.com/OmalPerera/viro-react-starter-kit">StarterKit</a> first. <br>(It is the best way to experience the features without spending time on initial configs and searching 3D objects).</p><pre>git clone https://github.com/OmalPerera/viro-react-starter-kit.git<br><br>cd viro-react-starter-kit<br><br>npm install or yarn install <br><br>npx pod-install </pre><h3><strong>Running the code</strong></h3><p>You need a physical mobile device to run the app. AR is not runnable on simulators as it heavily depends on device sensors.</p><p>We can run the app using the following commands according to the ReadMe file.</p><pre>&gt; npx react-native run-android or npx react-native run-ios </pre><p>But I prefer to open the app in Xcode (by clicking viro-react-starter-kit &gt; ios &gt; myviroapp.xcworkspace file) as it is easy to identify any build time issues (if any).</p><p>Possible errors at the first run</p><ul><li>Not having a matching development team in Xcode while trying to run on a physical iPhone<br><strong>Fix</strong>: Select your Team from the dropdown and add a bundle Identifier in ‘signing &amp; Capabilities’.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/414/1*IF3MKK5m6xbTsvxpGLzqbw.gif" /><figcaption>Rendering AR Text element in Viro-react</figcaption></figure><p>Congratulations! You completed the 1st milestone. 🎉</p><h3><strong>Let’s try to understand the code</strong></h3><p>The starting point is <a href="https://viro-community.readme.io/docs/scene-navigation)">&lt;ViroARSceneNavigator&gt;</a> inside the render method in App.js.</p><pre>const HelloWorldSceneAR = () =&gt; {<br>  return (<br>    &lt;ViroARScene&gt;<br>      &lt;ViroText<br>        text={text}<br>        scale={[0.5, 0.5, 0.5]}<br>        position={[0, 0, -1]}<br>        style={styles.helloWorldTextStyle}<br>      /&gt;<br>    &lt;/ViroARScene&gt;<br>  );<br><br>};<br><br>export default () =&gt; {<br>  return (<br>    &lt;ViroARSceneNavigator<br>      autofocus={true}<br>      initialScene={{<br>        scene: HelloWorldSceneAR,<br>      }}<br>      style={styles.f1}<br>    /&gt;<br>  );<br>};</pre><p>&lt;ViroARSceneNavigator&gt; handles the transitions between &lt;ViroScene&gt; objects. It enables the 3D equivalent of a navigation stack.</p><p>&lt;ViroARScene&gt; contains all the ViroReact elements, such as UI controls, 3D objects, lights, etc. So, it’s actually where we need to arrange our digital AR media according to our requirements.</p><p>For example, if the requirement is to show a 3D dragon on the flow, the steps will be;<br>1. Position the dragon correctly on the Scene<br>2. Attach the Scene to &lt;ViroARSceneNavigator&gt;</p><p>Here is how positioning works in a Scene:<br>As mentioned above &lt;ViroARScene&gt; is a 3D space. By default, the camera is positioned at [0, 0, 0] and looks in the direction [0, 0, -1]</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0pBWti95CxgqUOpMFJNQzg.png" /><figcaption>How positioning works in a viro scene.</figcaption></figure><h3><strong>Positioning a 3D Object</strong></h3><pre>&lt;ViroARScene onTrackingUpdated={onInitialized}&gt;<br>  &lt;ViroAmbientLight color={&#39;#aaaaaa&#39;} /&gt;<br>   &lt;Viro3DObject<br>      source={objects_3D.pug_animated.obj}<br>      type={objects_3D.pug_animated.type}<br>      position={objects_3D.pug_animated.position}<br>      scale={objects_3D.pug_animated.scale}<br>      rotation={[0, 0, 0]}<br>      animation={{...objects_3D.pug_animated.animation, run: true}}<br>      dragType=&quot;FixedToWorld&quot;<br>      onDrag={() =&gt; {}}<br>    /&gt;<br>&lt;/ViroARScene&gt;</pre><p>&lt;ViroAmbientLight&gt; is a light object that emits ambient light that affects all objects equally.</p><p>&lt;Viro3DObject&gt; can be used to render any 3D objects. The behavior of any Viro components can be controlled by passing props as we do with normal react-native components. All the props are well explained in the <a href="https://viro-community.readme.io/docs/viro3dobject">Viro-Community documentation</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/414/1*5N3_Wq8LX9pyebiAtJdT4g.gif" /><figcaption>Rendering 3D objects in react-native using viro-react</figcaption></figure><h3><strong>Adding 360 background to viroARScene</strong></h3><p>Replace the existing &lt;Viro3DObject&gt; component with the following code block.</p><pre>&lt;ViroARScene onTrackingUpdated={onInitialized}&gt;<br>  &lt;ViroAmbientLight color={&#39;#aaaaaa&#39;} /&gt;<br>   &lt;Viro360Image source={objects_3D.diving_360.background} /&gt;<br>&lt;/ViroARScene&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/414/1*kHwMRSSyKKw5dlNENByJdQ.gif" /><figcaption>360-degree background image to viroARScene</figcaption></figure><h3><strong>Image recognition</strong></h3><p>Image recognition is a key component of AR: it enables you to interpret the real world and respond to it accordingly. Let’s work on a simple example.</p><p>Here we will try to identify a real-world 2D or 3D object and render a 3D object on it.</p><p>We can use the <a href="https://viro-community.readme.io/docs/image-recognition">&lt;ViroARImageMarker&gt;</a> component for real-world object identification. And also, we should provide a reference image that Viro will recognize and track. (used <a href="https://viro-community.readme.io/docs/viroartrackingtargets">ViroARTrackingTargets</a> for it)</p><pre>const HelloWorldSceneAR = () =&gt; {<br>  return (<br>    &lt;ViroARImageMarker target={&#39;pug2D_img&#39;}&gt;<br>      &lt;Viro3DObject<br>        source={objects_3D.pug_animated.obj}<br>        type={objects_3D.pug_animated.type}<br>        position={objects_3D.pug_animated.position}<br>        scale={objects_3D.pug_animated.scale}<br>        rotation={[0, 0, 0]}<br>        animation={{...objects_3D.pug_animated.animation, run: true}}<br>        dragType=&quot;FixedToWorld&quot;<br>        onDrag={() =&gt; {}}<br>      /&gt;<br>    &lt;/ViroARImageMarker&gt;<br>    );<br>};<br><br>export default () =&gt; {<br>  return (<br>    &lt;ViroARSceneNavigator<br>      autofocus={true}<br>      initialScene={{<br>        scene: HelloWorldSceneAR,<br>      }}<br>      style={styles.f1}<br>    /&gt;<br>  );<br>};<br><br>ViroARTrackingTargets.createTargets({<br>  pug2D_img: {<br>    source: objects_3D.pug_animated.img,<br>    orientation: &#39;Up&#39;,<br>    physicalWidth: 0.12, // real world width in meters<br>  },<br>});</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JPPjR4NbPHpCY66FYvX3rQ.gif" /><figcaption>Recognize a given image and render a 3D object with viro-react</figcaption></figure><h3><strong>What is next?</strong></h3><p>So far, we have used a few components from Viro-react (ViroARScene, Viro360Image, Viro3DObject, ViroAmbientLight, ViroARImageMarker, etc.) but there are a huge number of components in the Viro-react library that provide different experiences.</p><p>In order to build a rich AR experience, these components need to be combined and place hierarchically in scenes, as we did in the Image Recognition section.</p><p>Keep in mind that Viro-react is one of the many options available for building AR apps in React-native. It is a mature and stable library which has both capabilities and limitations, especially when compared with native SDKs such as Apple ARKit and AR-core on Android.</p><h3><strong>Wrap up</strong></h3><p>With viro-react, we have seen how AR can seamlessly blend physical and digital environments. As you know, technology is evolving rapidly and the potential for innovation seems boundless. It keeps pushing the limits of what’s possible and making the virtual world more tangible and interactive than ever before.</p><p>Thanks for reading! Let me know in the comment if you found this information useful and applicable to your projects.</p><h3><strong>Resources</strong></h3><p>Full code is available in: <a href="https://github.com/OmalPerera/viro-react-starter-kit/">https://github.com/OmalPerera/viro-react-starter-kit/</a></p><ul><li><a href="https://blog.viromedia.com/">VR &amp; AR App Development Blog - Viro Media</a></li><li><a href="https://github.com/viromedia/viro">GitHub - viromedia/viro: ViroReact: AR and VR using React Native</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a9040cf40042" width="1" height="1" alt=""><hr><p><a href="https://medium.com/ascentic-technology/crafting-ar-apps-with-react-native-a9040cf40042">Crafting AR apps with React Native</a> was originally published in <a href="https://medium.com/ascentic-technology">Ascentic Technology</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[KERBEROS in ‘point form’]]></title>
            <link>https://medium.com/@omalperera/kerberos-in-point-form-9c9c44f734b2?source=rss-50e1e03eeb0c------2</link>
            <guid isPermaLink="false">https://medium.com/p/9c9c44f734b2</guid>
            <category><![CDATA[kerberos]]></category>
            <category><![CDATA[security]]></category>
            <category><![CDATA[computer-system]]></category>
            <category><![CDATA[distributed-systems]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <dc:creator><![CDATA[Omal Perera]]></dc:creator>
            <pubDate>Fri, 09 Mar 2018 04:04:31 GMT</pubDate>
            <atom:updated>2018-03-13T10:02:57.512Z</atom:updated>
            <content:encoded><![CDATA[<p>Let’s have a glimpse on Kerberos, a security approach for Distributed Systems. For your understandability, I’m using simple points to explain the notation in this article.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/807/1*LHj32Lt63Y-t4Fq38ZqL3w.png" /><figcaption>Kerberos for Distributed System Security</figcaption></figure><h3>Summary</h3><ul><li>A protocol for authentication</li><li>Developed at MIT in the mid 1980’s</li><li>Uses tickets to authenticate</li><li>Avoids saving passwords locally</li><li>Avoids sending passwords over the internet</li><li>Involves a trusted third party</li><li>Built on symmetric-key cryptography</li></ul><h3>Why does this really require this option?</h3><ul><li>Kerberos is mature</li><li>Kerberos meets the requirements of modern distributed systems</li><li>Kerberos is architecturally sound</li><li>Kerberos is already in place</li></ul><h3>Authenticating using Kerberos</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/865/1*k7YAdNK7dhnaDaXgjtK8mw.png" /><figcaption>Kerberos — Authentication mechanism</figcaption></figure><p>Step 1 — Hello, I’m Bob. Can I have a ticket for getting tickets.</p><p>Step 2 — Yes, Here is your Ticket Granting Ticket (TGT). It is encrypted with your(Bob’s) secret key.</p><p>Step 3 — Here is my TGT. Can I have a ticket for Service ‘x’ in server 1 ?</p><p>Step 4 — yes sure, Here is your ticket for service ‘x’</p><p>Step 5 — Here is my ticket. Can I use service ‘x’</p><p>Step 6 — yes, Welcome! I’m the service ‘x’</p><h3>Deeper into its Components</h3><p><strong>Key Distribution Center (KDC)</strong></p><ul><li>One Kerberos server for one region</li><li>Key Distribution Center contains the Authentication Service, Ticket-Granting Service and master database for Kerberos.</li><li>All the services are implemented as a single daemon</li></ul><p><strong>Authentication Server</strong></p><ul><li>Handles <strong>user authentication</strong> / verifying that principals are correctly identified</li><li>Consists Servers in the KDC + security clients</li><li>Security server accesses the registry database to perform queries then <strong>updates and to validate user logins</strong></li></ul><p><strong>Ticket Granting Service (TGT)</strong></p><ul><li>Once authenticated, a principal will be granted a TGT and a <strong>ticket session key</strong></li><li>Your credentials = ticket + its associated key</li><li>Credentials are <strong>stored in a credentials cache</strong>, a file in a directory in the principle</li></ul><p><strong>Kerberos Database</strong></p><ul><li>Database contains all of the realm’s Kerberos principals their passwords &amp; other administrative information about each principal</li><li>The <strong>master KDC</strong> contains the <strong>primary copy of the database</strong>, <br> which it <strong>propagates at regular intervals </strong>to the slave KDCs</li></ul><p><strong>Kerberos Utility Programs</strong></p><ul><li>OpenVMS provides different user interface programs such as original UNIX style, DCL version, X Windows version</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1003/1*q7mIob2voeGbpxtXDQLX_Q.png" /></figure><h3>Applications of Kerberos</h3><ul><li>Microsoft Windows</li><li>Email, FTP, network file systems, other applications have been kerberized</li><li>Local authentication</li><li>Authentication for network protocols</li><li>Secure windows systems</li></ul><h3><strong>Advantages</strong></h3><ul><li>Passwords are never sent across the network unencrypted</li><li>Client and application services mutually authenticated</li><li>Tickets have a limited lifetime</li><li>Authentication through Authentication Service has to happen only once</li><li>Sharing secret keys is more efficient than public keys</li></ul><h3>Disadvantages</h3><ul><li>Single point of failure. it requires continuous availability of a central server</li><li>Only provides authentication for clients and services</li><li>Vulnerable to users making poor password choices</li><li>Has strict time requirements</li></ul><p><em>IImage Copyrights : </em><a href="http://www.freepik.com/"><em>www.freepik.com</em></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9c9c44f734b2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Lets Setup Apache Kafka locally]]></title>
            <link>https://medium.com/@omalperera/lets-setup-apache-kafka-locally-cde7e45d68f1?source=rss-50e1e03eeb0c------2</link>
            <guid isPermaLink="false">https://medium.com/p/cde7e45d68f1</guid>
            <category><![CDATA[big-data]]></category>
            <category><![CDATA[data-streaming]]></category>
            <category><![CDATA[kafka]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[apache-kafka]]></category>
            <dc:creator><![CDATA[Omal Perera]]></dc:creator>
            <pubDate>Fri, 10 Nov 2017 08:18:35 GMT</pubDate>
            <atom:updated>2017-11-17T13:40:17.240Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*8GbrXbHdH5uPGMb5epWhrg.png" /></figure><p>This Guide is basically for the linux based OS. Directories in the Kafka setup can be slightly different in the windows setup.</p><p>Mainly we deal with the /bin folder.</p><ul><li>For mac — kafka_2.10–0.10.2.0/bin/</li><li>For Windows — kafka_2.10–0.10.2.0\bin\windows\</li></ul><p><strong>Note</strong> : Every command must be executed in a separate terminal or console except for creating the topic and ending a server.</p><h3>Step 1 — Download the source code &amp; extract it</h3><ul><li>Download Kafka from <a href="https://www.apache.org/dyn/closer.cgi?path=/kafka/1.0.0/kafka_2.10-0.10.2.0.tgz">here</a></li><li>Navigate to the downloaded directory and untar the kafka_2.10–0.10.2.0.tar<br> tar -xzf kafka_2.10–0.10.2.0.tgz<br> cd kafka_2.10–0.10.2.0</li></ul><h3>Step 2 — Starting the Server</h3><p>You first need to start a ZooKeeper serve, since Kafka uses Zookeeper for the tasks such as Electing a controller, Topic configuration, ACLs &amp; for many more.</p><ul><li>As you are now in the kafka_2.10–0.10.2.0 directory execute the following command<br>bin/zookeeper-server-start.sh config/zookeeper.properties</li><li>Starting the Kafka Server<br> bin/kafka-server-start.sh config/server.properties</li></ul><h3>Step 3 — Creating a Topic</h3><ul><li>Creating a topic located at zookeeper at the localhost:2181 named <strong><em>“mytopic”</em></strong> with a single partition &amp; single replica.</li></ul><pre>bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic mytopic</pre><ul><li>To ensure that our topic is created, execute following command<br> bin/kafka-topics.sh --list --zookeeper localhost:2181</li></ul><h3>Step 4 — Running the Producer</h3><ul><li>This is for feed the mytopic Topic (do it in a separate console)</li></ul><pre>bin/kafka-console-producer.sh --broker-list localhost:9092 --topic mytopic</pre><ul><li>You can send messages to the Kafka cluster from the console even except the standard file inputs. just type the message in the console.<br> This is a Sample message</li></ul><h3>Step 5 — Running the Consumer</h3><p>This is for listen to the producer at that port (do it in a separate terminal).</p><ul><li>Following command will listens for the topic inputs and outputs<br>bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic mytopic--from-beginning</li><li>If you type messages into the producer terminal you should see them appear in the consumer terminal.</li></ul><h3>Step 6 — Stopping the Kafka Server</h3><p>bin/kafka-server-stop.sh</p><h3>Step 7 — Stopping the Zookeeper Server</h3><p>bin/zookeeper-server-stop.sh</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kQXkMQTrMrG4VJ3KZehaqA.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cde7e45d68f1" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>