Pushbots
Frontend Stack
Agenda
- Legacy stack
- Integrating a UI framework (MPA)(Current)
- Building a full SPA (Current)
- Scaling SPA
Legacy Stack
Laravel + jQuery
View
AJAX and JS Logic
Problems
- Hard to maintain the code
- Hard to add new features
- Hard to test
- bundle size is big
- no real frontend dev environment
Solution one
Organize the code into small components (files)
// composer/what.blade.php
// extend composer layout
@extends('layouts.dashboard.composer')
// adding styles
@section('styles')
<link href="composer/what.css" rel="stylesheet">
@stop
// html content
@section('content')
<div class="composer__what">
.......
</div>
@stop
// adding js logic
@section('scripts')
<script src="composer/what.js"></script>
@stop
Solution Two
Do the same but with a frontend framework
Multi page app with react
Server-side routing and page-shell
// laravel route
Route::get('push/{id}', ['as' => 'app.push', 'uses' => 'ApplicationController@push']);
// blade view (page shell)
@extends('layouts.app_dashboard')
@section('content')
<script>
var pageData = {!! json_encode($data) !!}
</script>
<div id="composer" data-app-id="{{$data['app']['_id']}}">
</div>
@stop
//js code to load composer code
const composer = document.getElementById("composer");
if (typeof composer !== "undefined" && composer !== null) {
const Composer = Loadable({
loader: () =>
import(/* webpackChunkName: "/js/composer" */ "./Pages/Composer/index.jsx"),
loading: ComposerPlaceHolder
});
render(<Composer />, composer);
}Benefits
- Progressive migration for code base
- Adding new feature while migration is easy
Problems
- No shared state
- Loading all common asset on each page (react/redux/etc)
- No direct way to share a component between all pages (Account settings modal)
Text
SPA
- A separation between the backend and frontend
- Focus only on frontend development
- One state for all apps
- Full Client-side UI routing
- Easy to scale and add a new feature
- Code splitting per route/component
- No style issues (
jss ) - Easy to testing UI component (jest)
- Shared component and helpers
- Small bundle size
- Easy to upgrade and scale
- Custom build system with
webpack - Best react and frontend practices
Current Frontend stack
React (UI Components)
JSS (Styling solution)
Redux (State management)
React Router (UI Routing)
React loadable (Lazy load/code splitting)
Material (UI Components)
Formik/Yup (UI Validation)
Axios (Http Client)
Jest (Unit testing)
Cypress (E2E testing)
Webpack/npm scripts (Build system)
and more on demand
Code overview
NEXT
Separate API and Frontend Servers
- Decoupling backend and frontend development
- Scale them differently
- Server-side rendering for react
- Fast build times
Decouple logic from UI (SDKs)
- Easy to change entire UI layer if we need
- DRY coding for any new projects
- Easy to test logic separate from UI
A/B Testing / Addon based App
- Enable/Disable Dashboard feature based on conditions for a specific segment of users
Practices
- Read and understand the business
- Search/discuss an implementation
- Prototype the features
- Follow project structure
- Organize and solidify your code
- Add test ids for UI testing
- Test your components/utils
- Document your code
- Extract potential common components
- Document the concept and usage on https://www.nuclino.com/
- Share what you learned with us
Steps to add a new feature
- Read and understand the business
- Search/discuss an implementation
- Prototype the features
- Follow project structure
- Organize and solidify your code
- Add test ids for UI testing
- Test your components/utils
- Document your code
- Extract potential common components
- Document the concept and usage on https://www.nuclino.com/
- Share what you learned with us
Steps to add a new feature
- Create a pull request on github
- Add 2 reviews
- CircleCI will run e2e tests
- Fix failed tests if found
- Resolve reviews/confilicts
- Push your Code
- All green
Per review
- Research and business (amr)
- API Implementation (Abdallah/omr)
- SDKs Implementation (abdallah)
- Dashboard implementation (Salama,Hassan,Bassel)
- Testing (Amal)
- Live
- Marketing (amr/sayed/abdelrahman)
- Enhance/analyze(Moatasm)
Feature Shipping
Questions
Pushbots frontend
By Salama Ashoush
Pushbots frontend
- 95