Jakub SowiΕ„ski

Software Architect

🌐 soofka.pl  |  🐦 @pansoofka

πŸ“…

7 days

⏱️

30 minutes





Service-Oriented
Architecture

Micro Frontends:
extending service-oriented architecture to frontend development

πŸ—ΊοΈ

  • πŸ‘‰ What is Micro Frontend? πŸ“Œ

  • πŸ‘‰ What is Micro Frontend for?

  • πŸ‘‰ How does it work?

  • πŸ‘‰ How do we create one?

πŸ”Ž "Microfrontend"
in Google searches

πŸ€–
Micro
Frontend

πŸ€–πŸ€–πŸ€–
Micro
Frontend
Architecture

πŸ—ΊοΈ

  • πŸ‘‰ What is Micro Frontend?

  • πŸ‘‰ What is Micro Frontend for? πŸ“Œ

  • πŸ‘‰ How does it work?

  • πŸ‘‰ How do we create one?

πŸ•΅πŸ‘©β€πŸŽ¨πŸ§™

Small, autonomous teams
with customer focus

πŸ”­ Reduced scope

⚑⚑⚑
Speed and agility

of development

🎨 Progressive refactoring

Architecture is
a tool ⛏️

🏁
Start with monolith

Fragmentation

πŸ‘ expectations vs reality πŸ‘Ž

πŸ—ΊοΈ

  • πŸ‘‰ What is Micro Frontend?

  • πŸ‘‰ What is Micro Frontend for?

  • πŸ‘‰ How does it work? πŸ“Œ

  • πŸ‘‰ How do we create one?

Server-Side Includes:
HTML template


<html lang="en" dir="ltr">
  <head>
    <meta charset="utf-8">
    <title>Feed me</title>
  </head>
  <body>
    <h1>🍽 Feed me</h1>
    <!--# include file="$PAGE.html" -->
  </body>
</html>
                    

Server-Side Includes: server


server {
    listen 8080;
    server_name localhost;

    root /usr/share/nginx/html;
    index index.html;
    ssi on;

    rewrite ^/$ http://localhost:8080/browse redirect;

    location /browse {
      set $PAGE 'browse';
    }
    location /order {
      set $PAGE 'order';
    }
    location /profile {
      set $PAGE 'profile'
    }
}
                    

Templating Engine: routes


routeMap:
  "/": "/index.html"
  "/thiscompany": "/companyHub/pages/thisCompany.html"
  "/jobs": "/companyHub/pages/jobs.html"
  "/contacts": "/companyHub/pages/contacts.html"
  "/reviews": "/companyHub/pages/reviews.html"
                    

Templating Engine: template


<fragment id="ch-background-image" slot="ch-background-image"
    timeout="30000" async></fragment>

<fragment id="ch-meta-data-header" slot="ch-header"
    timeout="30000" async></fragment>

<fragment id="ch-jobs" slot="ch-block-main"
    timeout="30000"></fragment>

<fragment id="ch-assets" slot="ch-block-end"
    timeout="30000" async></fragment>
                    

Templating Engine: fragments


fragments:
  ch-assets: http://localhost:8080/assetslinks

  ch-background-image: http://localhost:8080/v1/background
    /companyId/{companyId}/lang/{langName}/?{additionalParams}

  ch-jobs: http://localhost:8080/v1/jobs/companyId/{companyId}
    /lang/{langName}/?{additionalParams}

  ch-meta-data-header: http://localhost:8080/v1/header
    /companyId/{companyId}/lang/{langName}/?{additionalParams}
                    

Templating Engine:
other responsibilities

  • πŸ‘‰ standard libraries

  • πŸ‘‰ tracking

  • πŸ‘‰ a/b tests

PubSub: Subscribe


import {
  PubSub,
  CANDIDATE_PROFILE_EVENTS,
} from '@stepstone/pub-sub';

class LoginModal extends React.Component {
  public componentDidMount() {
    PubSub.subscribe(
      CANDIDATE_PROFILE_EVENTS.SHOW_LOGIN_MODAL,
      (msg, data) => { /* ... */ }
    );
  }
}
                    

PubSub: Publish


                        PubSub.publish('CANDIDATE_PROFILE_SHOW_LOGIN_MODAL');
                    

Native events


    PubSub.subscribe(...);
                        

    PubSub.publish(...);
                        

    element.addEventListener(...);
                        

    element.dispatchEvent(...);
                        

CustomEvent API: availability

PubSub vs CustomEvent API


    PubSub.subscribe(
      'myEvent',
      (msg, data) => { /* ... */ }
    );
                        

    PubSub.publish('myEvent');
                        

    element.addEventListener(
      'myEvent',
      (msg, data) => { /* ... */ }
    );
                        

    element.dispatchEvent(
      new CustomEvent('myEvent')
    );
                        

Alternative for communication

πŸ—ΊοΈ

  • πŸ‘‰ What is Micro Frontend?

  • πŸ‘‰ What is Micro Frontend for?

  • πŸ‘‰ How does it work?

  • πŸ‘‰ How do we create one? πŸ“Œ

Standardization and automation

Automated project
creation
βš™οΈβš™οΈβš™οΈ

  • πŸ“¦ code repository

  • πŸ”¨ build plan

  • 🎯 deployment plan

πŸ”¨ Build

🎯 Deployment

πŸ’€ App skeleton

  • πŸ‘‰ code style

  • πŸ‘‰ code samples

  • πŸ‘‰ build and deployment scripts

πŸ’€ App skeleton

πŸ” Standard tech stack

  • πŸ‘‰ easy to switch teams and projects

  • πŸ‘‰ easy to share knowledge and solutions

  • πŸ‘‰ better performance

Frontend vendor package

  • βš›οΈ React

  • βš›οΈ React DOM

  • πŸ“œ polyfills

  • πŸ“š other common libraries

πŸ–ŒοΈ Styling

πŸ–ŒοΈ Styling with SASS

πŸ–ŒοΈ Styling with SASS: issues

  • πŸ“œ over 100 versions in 1 year

  • πŸ‹οΈ repository of 135 megabytes

πŸ–ŒοΈ Styling with CSS-in-JS

πŸ–ŒοΈ Styling with CSS-in-JS: component


import styled from '@stepstone/dresscode-react';

const Example = styled.section`
    padding: 0 ${(props) => props.theme.spacings.spacingXS};
    background-color: ${(props) => props.theme.colors.accent};
    font-size: ${(props) => props.theme.typography.fontSizeM};
`;
                    

πŸ–ŒοΈ Styling with CSS-in-JS:
Theme Provider


import {
  ThemeProvider,
  getThemeVariables
} from '@stepstone/dresscode-react';

const theme = getThemeVariables('stepstone');

ReactDOM.render(
  <ThemeProvider theme={theme}>
    <Example/>
  </ThemeProvider>
  document.getElementById('root')
);
                    

πŸ–ŒοΈ Styling with CSS-in-JS: theme


{
    "breakpoints": {
        "screenXSMax": "767px",
        "screenSMax": "767px",
        "screenMMin": "768px",
        // ...
    },
    "colors": {
        "black": "#222222",
        "grey": "#8e97a4",
        "white": "#ffffff",
        // ...
    },
    // ...
}
                    

πŸ“š Library of components

πŸ“š Library of components

(monorepo)

πŸ“š Library of components

(monorepo)

βš”οΈ Battle test

πŸ“š Adding components

  • 1. βš”οΈ battle test

  • 2. πŸ™‹β€β™€οΈ propose

  • 3. πŸ“‹ review

  • 4. πŸ™ merge and release

  • 5. πŸ”„ replace

πŸ“š Atomic design

πŸ“š Atomic design



πŸ‘¨β€πŸ’»

πŸ“š

πŸ‘©β€πŸŽ¨

πŸ“š

πŸ‘¨β€πŸ’»πŸ‘©β€πŸŽ¨

πŸ“š

βœ”οΈ Testing

Tests pyramid

πŸ”¨ Build

  • πŸ‘‰ run unit tests

  • πŸ‘‰ check code coverage

  • πŸ‘‰ run performance and accessibility tests

Tests pyramid

βœ”οΈ Automated Tests Framework

βœ”οΈ Additional testing

πŸ’‚ Custodian

πŸ’‚ Custodians of ATF

πŸ’‚ In need for custodian

  • πŸ‘‰ templating engine

  • πŸ‘‰ application skeleton and related processes

  • πŸ‘‰ common styling

  • πŸ‘‰ library of components

  • πŸ‘‰ end-to-end tests

  • πŸ‘‰ tracking

  • πŸ‘‰ a/b tests

πŸ’‚ Custodians of frontend

πŸ—ΊοΈ

  • πŸ‘‰ What is Micro Frontend?

  • πŸ‘‰ What is Micro Frontend for?

  • πŸ‘‰ How does it work?

  • πŸ‘‰ How do we create one?

πŸ‘

πŸ‘Ž

πŸ“š Learning resources

πŸ“š This presentation

πŸ’™


🌐 soofka.pl  |  🐦 @pansoofka