Frontend Architecture
Relevant source files
The following files were used as context for generating this wiki page:The Ever Demand platform utilizes a "Headless Commerce" architecture, where the backend exposes a set of APIs consumed by multiple, distinct frontend applications. This approach allows for a flexible and decoupled system, with each frontend tailored to a specific user role or platform and built with the most suitable technology. The entire frontend ecosystem is managed within a single monorepo.
The architecture is comprised of several applications for different user roles, including administrators, customers, merchants, and carriers. These applications are built using a variety of modern web and mobile frameworks such as Angular, Ionic, React Native, and Gatsby, demonstrating a polyglot approach to frontend development.
Monorepo and Tooling
The project is structured as a monorepo, managed by Lerna and Yarn Workspaces. This setup facilitates code sharing, centralized dependency management, and streamlined build processes across the various frontend and backend packages.
Sources: package.json:195-207
"workspaces": {
"packages": [
"libs/*",
"apps/*",
"tools",
"packages/*",
"packages/plugins/*"
],
"nohoist": [
"**/@types/jasmine",
"**/@types/jasminewd2",
"**/@nebular",
"**/@angular*/**",
"**/@ngtools/**"
]
}
Sources: package.json:195-207
The root package.json contains scripts to bootstrap, build, and run all applications simultaneously or individually.
| Script | Description |
|---|---|
yarn bootstrap | Installs all dependencies for all packages using Lerna. |
yarn build:all | Builds all common modules and applications in the correct order. |
yarn run:admin | Starts the Admin Web App. |
yarn run:shopmobile | Starts the Shopping Mobile App (Ionic). |
yarn run:shopweb | Starts the Shopping Web App (Angular). |
Sources: package.json:26-51
Application Overview
The platform includes several frontend applications, each serving a specific purpose and built with a distinct technology stack.
The diagram below illustrates the different frontend applications and the technologies they are built upon.
Sources: README.md:30-36, README.md:80-92
| Application | Description | Technology Stack |
|---|---|---|
| Admin Website | A comprehensive web interface for managing all platform features and settings. | Angular 9.1, ngx-admin |
| Shopping Website | A customizable e-commerce website for customers to make purchases. | Angular 9.1, Angular Starter |
| Shopping Website (WIP) | An alternative shopping website. | Gatsby, React |
| Shopping Mobile App | A mobile app for customers to place on-demand orders. | Ionic 5, Angular |
| Shopping Mobile App (WIP) | An alternative mobile shopping app. | React Native, Expo |
| Merchant Tablet App | An app for merchants to manage orders, track inventory, and organize deliveries. | Ionic 5, Angular |
| Carrier Mobile App | A mobile app for carriers/drivers to manage deliveries. | Ionic 5, Angular |
Sources: README.md:30-36, README.md:80-92
Angular-Based Applications
Angular is the primary framework for the web applications and the foundation for the Ionic mobile apps.
Admin Web App (admin-web-angular)
Built upon the ngx-admin template, this application provides a rich user interface for platform administration.
Configuration & Dependencies
The build process is configured in angular.json. It defines entry points, assets, global styles, and scripts.
- Styles: Includes global styles from
bootstrap,roboto-fontface,@fortawesome/fontawesome-free,nebular/theme, andleaflet. - Scripts: Injects third-party libraries like
pace-js(for loading indicators),tinymce(rich text editor), andecharts/chart.js(for data visualization).
Sources: packages/admin-web-angular/angular.json:48-77
Module Architecture & Initialization
The application's root module, AppModule, orchestrates the initialization of core services and features.
The diagram below shows the key modules imported by the AppModule.
The application uses APP_INITIALIZER tokens to ensure critical services are loaded before the application starts. This includes:
serverConnectionFactory: Verifies connection to the backend services.googleMapsLoaderFactory: Asynchronously loads the Google Maps API.maintenanceFactory: Checks the application's maintenance status.serverSettingsFactory: Loads server-side settings.
Sources: packages/admin-web-angular/src/app/app.module.ts:100-125
Shop Web App (shop-web-angular)
This application is the customer-facing e-commerce website, built using the angular-starter template and a custom Webpack configuration.
Custom Webpack Configuration
The project uses a custom Webpack setup defined in packages/shop-web-angular/config/webpack.common.js to gain more control over the build process.
Key features of the Webpack configuration include:
- Module Replacement: The
NormalModuleReplacementPluginis used to replace backend-specific libraries likemongooseandtypeormwith browser-compatible placeholders, preventing build errors. - HTML Generation:
HtmlWebpackPluginandHtmlElementsPluginare used to generate theindex.htmlfile and inject necessary tags and metadata. - Script Optimization:
ScriptExtHtmlWebpackPluginenhances theindex.htmlby addingasync,preload, andprefetchattributes to script tags for optimized loading.
The flow below outlines the custom Webpack build process.
A notable implementation detail is the replacement of Node.js-specific modules for the browser environment.
// packages/shop-web-angular/config/webpack.common.js:110-126
new NormalModuleReplacementPlugin(
/^mongoose$/,
// For some reason, it does not work well with mongoose-placeholder.ts, so we reference JS here
// it's anyway placeholder so we don't really care much about content to be in sync with TS (for now at least)
require.resolve(
`${nodeModulesPath}/@ever-platform/common-angular/build/mongoose-placeholder.js`
)
),
new NormalModuleReplacementPlugin(
/^typeorm$/,
// For some reason, it does not work well with typeorm-placeholder.ts, so we reference JS here
// it's anyway placeholder so we don't really care much about content to be in sync with TS (for now at least)
require.resolve(
`${nodeModulesPath}/@ever-platform/common-angular/build/typeorm-placeholder.js`
)
),
Sources: packages/shop-web-angular/config/webpack.common.js:110-126
Ionic & React Applications
The platform also includes mobile apps built with Ionic and is experimenting with React-based alternatives.
Ionic Mobile Apps
The shop-mobile-ionic, carrier-mobile-ionic, and merchant-tablet-ionic applications are built with Ionic 5 and Angular. Their project structure and build configurations, defined in their respective angular.json files, follow standard @ionic/angular-toolkit conventions. They are configured as PWAs with service worker support enabled for production builds.
Sources: packages/merchant-tablet-ionic/angular.json:71-72
React-based Apps (WIP)
- Gatsby Shop (
shop-web-gatsby): A work-in-progress alternative to the Angular shop, built with Gatsby. Its dependencies includereact,gatsby,@material-ui/core,styled-components, and@apollo/clientfor data fetching.
Sources: packages/shop-web-gatsby/package.json:30-53 - Expo Mobile Shop (
shop-mobile-expo): A work-in-progress React Native app using the Expo framework. It also uses Apollo Client for GraphQL communication.
Sources: packages/shop-mobile-expo/README.md:20-22
Data Layer: Apollo GraphQL Client
The primary mechanism for communication with the headless backend is GraphQL, implemented via the Apollo Client. The setup in admin-web-angular serves as a representative example for all frontend applications.
The AppModule configures the Apollo client to handle both standard HTTP requests and real-time WebSocket subscriptions.
This sequence diagram shows how a GraphQL request is processed.
The configuration uses an ApolloLink.split to route operations based on their type:
- Subscriptions are sent over a
WebSocketLink. - Queries and Mutations are sent over an
HttpLink.
An authLink middleware intercepts each request to inject the user's authentication token into the headers.
// packages/admin-web-angular/src/app/app.module.ts:153-182
const authLink: ApolloLink = setContext((_, { headers }) => {
// get the authentication token from local storage if it exists
const token = store.token;
// return the headers to the context so httpLink can read them
return {
headers: {
...headers,
authorization: token ? `Bearer ${token}` : '',
},
};
});
apollo.create({
link: authLink.concat(
ApolloLink.split(
(operation) => {
const operationAST = getOperationAST(
operation.query,
operation.operationName
);
return (
!!operationAST &&
operationAST.operation === 'subscription'
);
},
ws,
http
)
),
// ...
});
Sources: packages/admin-web-angular/src/app/app.module.ts:153-182
Summary
The frontend architecture of Ever Demand is a robust, flexible system that leverages a headless commerce paradigm. By using a monorepo with Lerna and Yarn, it efficiently manages a diverse set of applications built on multiple frameworks like Angular, Ionic, and React. This poly-framework approach allows for the creation of highly specialized user experiences for different roles within the e-commerce ecosystem, all while communicating with a unified backend via a sophisticated GraphQL data layer powered by Apollo Client.