Broadening implementation options of a .NET platform by adding a JavaScript SDK

A presentation at Microsoft Build in May 2019 in Seattle, WA, USA by Anastasiya Flynn

Slide 1

Slide 1

Slide 2

Slide 2

Slide 3

Slide 3

Agenda

  • Architecture
  • Developer Experience
  • Supporting multiple frameworks

Slide 4

Slide 4

Our (Microsoft) story

Slide 5

Slide 5

Sitecore

1,000 Employees 50+ Countries 1,400 Partners 18,000+ Developers (C#, .NET, Windows) We offer a web-based CMS platform. Our ‘thing’ is personalization.

Slide 6

Slide 6

A website page is a hierarchy of UI components

Slide 7

Slide 7

Editing pages

  • Authors assemble components
  • Authors control layout

Slide 8

Slide 8

Editing pages

  • Authors assemble components
  • Authors control layout

Slide 9

Slide 9

Personalization

  • Update banner content based on user’s persona
  • Show personalized notification based on user’s cart content

Localization - Change social buttons based on user’s country

A/B Testing - Switch between 2 CTA styles to test which one drives more click-through

Personalization - Show personalized notification based on user’s cart content

Bottom line: page composition is not known at development-time

Slide 10

Slide 10

What does this mean for application architecture?

Bottom line: page composition is not known at development-time

Slide 11

Slide 11

MVC Workflow

  • JS layer depends on HTML produced by MVC Views
  • JS devs have to coordinate changes with back-end devs

Slide 12

Slide 12

Why did we want to -change- evolve?

Slide 13

Slide 13

Client implementation vs Platform

Slide 14

Slide 14

Front-end framework benefits

Faster performance - Faster, more efficient DOM reloading that makes sites/apps feel more responsive; DOM updates only when needed Easier maintenance - Well-defined patterns for setting up project, components, testing, etc Component re-use - Component-based design: Representing site content through self-contained components is the norm Robust data management - Application state is managed within the framework’s data models instead of scattered throughout the DOM Ecosystem - Big community of JS devs, huge ecosystem of tools and open-source libraries

Slide 15

Slide 15

So what's the issue?

Slide 16

Slide 16

The challenge with front-end frameworks

Developers control component layout

Slide 17

Slide 17

Component composition

React vs Angular vs Vue

Slide 18

Slide 18

JavaScript Services (JSS) to the rescue!

Slide 19

Slide 20

Slide 20

Three-year journey (and counting)

  • Initial POC proposal
  • POC
  • alpha
  • Tech preview
  • General availability

Slide 21

Slide 21

Initial idea

  • Render JS app server-side
  • Unplug from .NET
  • Clear FE/BE separation
  • Editor works

Slide 22

Slide 22

Placeholders in React components

Slide 23

Slide 23

Architecture (editor mode)

  • JS controller from POC ultimately became an independent REST service so it can be accessed from any context
  • JS layer physically decoupled from back-end layer (received data via HTTP post)

Slide 24

Slide 24

What if...

What if we could totally disconnect front-end development from .NET and Windows dependencies?

Slide 25

Slide 25

Disconnected development

Slide 26

Slide 26

Disconnected development

Manifest data – locally defined static files (yaml or json) created by front-end devs are used to generate a “data manifest”. Define component schemas and content for later export to DB.

Local development – Use webpack-dev-server and create-react-app’s proxy feature to spin up a mock layout service.

Develop on a Mac without a VM

Slide 27

Slide 27

Sample App

Slide 28

Slide 28

JS controls data layer

  • JS devs push code to source control
  • Manifest generated on integration env
  • Integration env runs import tasks

Slide 29

Slide 29

Architecture (editor mode)

Slide 30

Slide 31

Slide 31

Architecture (end-user mode)

  • Biggest hurdle in headless proxy architecture is cookies
  • Using http-proxy-middleware

Slide 32

Slide 32

Tech preview - Go beyond React

Support multiple frameworks

  • Add Angular, Vue, React Native parity
  • Build app samples and Style Guides

Developer experience improvements

  • Add command line interface
  • Implement GraphQL

Solution complexity grows

  • Automate testing

Slide 33

Slide 33

“Being able to clone a repo, run npm install, and run a watch/browser syncing task and get right to work… That’s my jam! THAT feels like a modern, well done FED workflow”

Front-end devs love automation 🤖

Slide 34

Slide 34

Command Line Interface

JSS CLI (command-line interface) delivers a modern developer experience Before CLI, we deployed individual scripts to /bin Used for:

  • Creating new apps
  • Adding components
  • Disconnected development
  • App deployment
  • Data import to platform

Create a new JSS app is seconds with 3 commands

Slide 35

@AnastasiyaFlynn

Slide 36

Slide 36

Command Line Interface - Used Yargs

https://github.com/yargs/yargs/blob/master/docs/advanced.md#providing-a-command-module

Slide 37

Slide 37

Starter Kits

JSS has sample starter kits for each front-end framework

  • Provide an implementation starting point
  • Provide most common functionality such as routing and internationalization.

Each starter is based on popular starters

  • create-react-app
  • vue-cli
  • angular-cli

Starters serve as live documentation on patterns and best practices Supporting the starters – need to stay up to date with the various libraries Starters used for e2e testing

Slide 38

Slide 38

Automated e2e test suite

Cypress – testing library for anything that runs in the browser

Smokey (the e2e testing bear) Custom PowerShell scripts that we created in response to having to do a lot of manual testing.

Slide 39

Slide 39

GraphQL

  • Query language for your API.
  • Designed to support the frontend
  • Offers amazing tooling
  • Strongly typed, self-documenting
  • Avoids over-fetching or under-fetching

Allows front-end devs to work more independently @AnastasiyaFlynn

Slide 40

Slide 40

GraphQL Example

Slide 41

Slide 41

Monorepo

We started with a small number of packages A lot of manual maintenance As solution grew, we made the decision to move to a monorepo

Monorepo benefits

  • Simplified organization
  • Simplified dependencies
  • Tooling
  • Cross-project changes

Monorepo cons

  • Tags less useful
  • Potential performance issues

Slide 42

Slide 42

Monorepo powered by lerna.js

Lerna – a tool for managing JS projects with multiple packages https://github.com/lerna/lerna

Manage your project using one of two modes: Fixed or Independent.

Slide 43

Slide 43

Monorepo powered by lerna.js

lerna publish

  • lerna will prompt you to update the package(s) version, choose accordingly between major/minor/patch
  • lerna will publish the packages to npm
  • lerna will also update package.json files for the samples and packages
  • Commit updates and push to master as part of a tag commit, in which a tag will also be added for the version that was published.

Slide 44

Slide 44

TypeScript

Iterative process during Tech Preview Initiated by community feedback Wanted TS users to have an easy time consuming our libraries.

Benefits

  • Intellisense
  • Easier for TS consumers
  • Our codebase reached the point of complexity where having inter-library contracts and type checking was super useful

Slide 45

Slide 45

Documentation – make it searchable

https://community.algolia.com/docsearch/

Slide 46

Slide 46

Summary

Slide 47

Slide 47

Overhead of supporting multiple frameworks

  • Build frameworkagnostic manifest generation
  • Refactoring to monorepo
  • Custom automed e2e tests
  • Overhead of framework + cli dependency upgrades
  • Supporting the starter apps, Normalizing scripts
  • More documentation needed

Slide 48

Slide 48

Focus on developer experience

In building our JS layer, we wanted to make sure we are building something that JS devs will actually want to use.

Slide 49

Slide 49

Focus on developer experience

Intuitive to use

  • CLI
  • TypeScript definitions
  • Comprehensive, searchable docs
  • Quick start guide

Empowering

  • GraphQL integration
  • Manifest-driven data-modeling

Supports independent workflow

  • No need to learn Sitecore
  • Any framework
  • Any OS
  • Work without installing Sitecore

Slide 50

Slide 50

Want to learn more about our SDK?

Repository https://github.com/Sitecore/jss Free developer trial https://www.sitecore.com/trial Docs https://jss.sitecore.com/docs

Slide 51

Slide 51