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.json
file, and runnpm install
. This will not juse install thenode_modules
at 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 start
which 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.json
file, 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-management
runs 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
addReducer
which other component are using to register thereduce
in 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
cart
runs on8081
- this is component has small cart functionlity and cart component, which is exposed and avilable to be used by
host
app. This component use thestate-management
(viagateway
) to register cart related redux slice, and letstate-management
handle redux state at global store.
- this is component has small cart functionlity and cart component, which is exposed and avilable to be used by
product
runs 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,host
app 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-gateway
runs 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 fact9090
will 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 -
host
runs on8080
- this is final product, which use all above components to get the final product.
- when running on local machine using
npm run
from root, we are usinglerna
(https://lerna.js.org/) to start all these components parallel. and launching browser forlocalhost:8080
(host
app only). host
app will use the exposed components fromcart
,product
andstate-management
viagateway
and 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 -d
from root directory) onlygateway
port9090
andhost
app port8080
are expose, not internal parts -cart, product & state-management
#react #redux #TypeScript #Javascript #docker #microfrontend #cart #create-mf-app #create-react-app #cra