This is an example to demonstrate how to use a micro-frontend framework to write comprehensive structure from utils to services to components to pages. This is not meant to be a full-fledge project since many data and business plans are still vague.
This application consists of four widgets:
- Chart
- Positions
- Order Book
- Order Entry Ticket
This is based on a micro-frontend framework called bit. Ensure bit is installed and PATH is linked so it can be executed in CLI.
bit install
bit compile
bit start
Navigate to pages/dashboard from side menu
Bit framework has been around for a while, and has a strong community surrounding it. It emphasizes on modularisation of all parts in the project, bringing developer's focus on separation of concern in each module no matter the size. With each module, it also standardizes: documentation, composition, testing and also adds a relations table as a bonus. This brings ease of understanding for modules between developers and is clear to see how thorough the developer has been with the module.
Storybook has always been great but it:
- does not create package of each module
- generate documentation page as user-friendly
- strictly limits to components
I've chosen to go with the Angular approach of singleton services because:
- updates are slow using store, causing many re-renders easily
- works better when each module is separated, meaning a container may not even have a page level to hold the store provider
- unlike redux, dispatched events does not get caught by all redux listeners. This approach is more of a pubSub method where events only distributes to subscribers. This reduce processing concerns in other unrelated components
- since it is a pubSub handling, receiver receiving event does not automatically equate to re-rendering components
Of course whenever we stray away from the typical approach, there'll be some downsides like a lack of standardized structuring. The standard will be something the team has to agree on or have base classes services must extend to lock certain structures. I think with the advantage of streamlining data distribution and thus maximizing performance in a resource intensive setup like this, it definitely outweighs a conventional library like Redux.
The reason for choosing lightweight-chart is due to the company behind it. TradingView has one of the most comprehensive stock charts available for free. On top of that, it is very easy to implement as to something more low-level like d3.js. Since lightweight-chart already specializes in trading charts, it absolutely fits the current project's needs.
In this requirement scope, Formik (or any form library) may be a bit of an overkill. With that said, sometimes it is just good to standardize somethings while you're at it. Always good to also add some client-side validations using Yup.
Since this is a small size project, and we're storing small items, we don't need to worry too much on where we store these small things like layout and positions. I've chosen to use js-cookie to ease my get/set handling.
Caching is very important in here since the returning data is big and there can be many repeated fetches. I choose to use SWR for component level fetching and the good old fetch for service level API calls like this.
There aren't much in here, but framer-motion is a great react animation library that defines the entry and exit animation as well as other states all using its props. It is clean and readable way to define these animation as to the alternatives such as Reanimated 2
- since this involves using a third-party (Alpha Vantage) library for quote information, we must be aware we are only allowed: 5 API calls per minute, and 500 API calls a day
- since third-party (Alpha Vantage) library is very limited, I chose to simulate order book and position's current prices
- order form type and price doesn't actually take effect. This is because it requires an order system for matching buyers to sellers and watching trigger targets (ie. stop limits)
- positions PL & MV are simulated
- only the ui section has test & documentations, for example purposes