A demo app showing how truely microfrontend app is created. To see the real world scenario, run via docker, and see how we have hidden the internal lib/package (cart, product) behind gateway/proxy.
- React
- Redux (https://redux-toolkit.js.org/)
- Webpack + babel
- Typescript
- fast-gateway
- Lerna
- Docker ( optional )
- pull the code to your machine.
- go the root directory where you have
lerna.jsonfile, and runnpm install. This will not juse install thenode_modulesat root, but also for child packages -api-gateway, cart, products, state-management and host(this may take some time, installing for all childs) - at same directory level run
npm startwhich will start all child and will launch the host in default browser http://localhost:8080
- pull the code to your machine.
- go the root directory where you have
lerna.jsonfile, and rundocker compose up -d - once all services are up and started, open https://localhost:8080.
This monorepo has 5 components/packages which works together to make a product listing and cart functionality.
state-managementruns on8090- this is all about handling the state in redux for all, being as component, it can easily manage the state of all the other component, we have expose a function
addReducerwhich other component are using to register thereducein global store.
- this is all about handling the state in redux for all, being as component, it can easily manage the state of all the other component, we have expose a function
cartruns on8081- this is component has small cart functionlity and cart component, which is exposed and avilable to be used by
hostapp. This component use thestate-management(viagateway) to register cart related redux slice, and letstate-managementhandle redux state at global store.
- this is component has small cart functionlity and cart component, which is exposed and avilable to be used by
productruns on8082- 3rd component in stack, which is responsible for product fetching and listing. it also use the
state-management(viagateway) to store the list of product to store. This also expose component which has product listing,hostapp will this component to list the product in final page.
- 3rd component in stack, which is responsible for product fetching and listing. it also use the
api-gatewayruns on9090- this one is used to hide the above 3 behind gateway. so on real production server, there will not be any direct access to ports -
8090,8081&8082, in fact9090will be considered as single point, and nobody knows how many micro frontends are running behind this gateway.
- this one is used to hide the above 3 behind gateway. so on real production server, there will not be any direct access to ports -
hostruns on8080- this is final product, which use all above components to get the final product.
- when running on local machine using
npm runfrom root, we are usinglerna(https://lerna.js.org/) to start all these components parallel. and launching browser forlocalhost:8080(hostapp only). hostapp will use the exposed components fromcart,productandstate-managementviagatewayand will render full page.- when running on local machine, all ports are accessible, though host app is using those via
gateway - when running via docker (
docker compose up -dfrom root directory) onlygatewayport9090andhostapp port8080are expose, not internal parts -cart, product & state-management
#react #redux #TypeScript #Javascript #docker #microfrontend #cart #create-mf-app #create-react-app #cra

