Deployment
Relevant source files
The following files were used as context for generating this wiki page:
The Ever Demand platform is a monorepo managed with Lerna, comprising multiple projects including a backend API, an admin website, and various storefronts (web and mobile). Deployment strategies vary depending on the component and the target environment, ranging from local development execution to production deployments on servers using PM2, AWS, or static site hosting like GitHub Pages.
This document outlines the different deployment and execution methods for the platform's key components, as derived from the project's configuration and scripts. The platform utilizes environment-specific configurations, build tools like Webpack and Angular CLI, and process managers to ensure flexibility and robustness across environments.
Local Development Setup
Running the platform locally involves bootstrapping all package dependencies, building the projects, and then running each service individually. The process is managed by yarn and lerna scripts defined in the root package.json.
Sources: package.json
Initial Setup Flow
The following diagram illustrates the one-time setup process for a new developer.
Sources: package.json:15-17
Running Services
After the initial setup, individual services can be started using dedicated yarn scripts. It is crucial to build shared modules (@ever-platform/common, @ever-platform/common-angular) before running applications that depend on them. The backend API server should also be running for the frontend applications to function correctly.
The following table summarizes the main scripts for running each part of the platform.
| Script | Description |
|---|---|
yarn run:server | Builds and starts the backend API server. |
yarn run:server:dev | Starts the backend API server in development mode with file watching. |
yarn run:admin | Starts the Admin Angular web application. |
yarn run:shopweb | Starts the Shop Angular web application. |
yarn run:shopexpo | Starts the Shop React Native (Expo) mobile application. |
yarn run:merchant | Starts the Merchant Ionic tablet application. |
yarn run:carrier | Starts the Carrier Ionic mobile application. |
Sources: package.json:28-34
Backend Deployment (@ever-platform/core)
The backend API is a NestJS application designed for production deployment. The recommended setup involves using PM2 as a process manager for clustering and fault tolerance. The project also contains configuration for deployment to AWS Elastic Beanstalk.
Sources: README.md:92, packages/core/README.md:6
PM2 Process Management
For production, the backend is started via PM2. This provides features like clustering to leverage multiple CPU cores, automatic restarts on crashes, and log management. The packages/shop-web-angular/package.json includes a start:server:pm2 script, which indicates a production-like startup process.
Sources: packages/shop-web-angular/package.json:28, packages/core/README.md:40
AWS Elastic Beanstalk
The repository includes configuration files for deploying the backend to AWS Elastic Beanstalk, although the details of the AWS configuration are in folders like .ebextensions which are not fully detailed in the provided context. The entry point for an AWS deployment is specified as pm2bootstrap.ts.
Sources: packages/core/README.md:30-31, packages/core/README.md:38
Frontend Deployment
Frontend applications have distinct build and deployment processes based on their frameworks.
Angular Web Shop (shop-web-angular)
The Angular-based web shop can be deployed as a static site to services like GitHub Pages. This process is automated via a custom Webpack configuration.
Sources: packages/shop-web-angular/package.json:52-54
GitHub Pages Deployment
A dedicated Webpack configuration (webpack.github-deploy.js) and associated scripts handle the deployment to a gh-pages branch.
The deployment flow is as follows:
The deployment script uses the gh-pages npm package to publish the contents of the build output directory. Key steps include:
- Determining the repository name by executing
git remote show origin. - Modifying the Webpack configuration to prepend the repository name to the
baseUrl, ensuring that all asset paths are correct when served from a subdirectory on GitHub Pages (e.g.,https://user.github.io/repo-name/). - Creating a
.nojekyllfile in the output directory to prevent GitHub Pages from running the site through Jekyll. - Publishing the build artifacts to the
gh-pagesbranch of theoriginremote.
Sources: packages/shop-web-angular/config/webpack.github-deploy.js:12,25,48, packages/shop-web-angular/config/github-deploy/index.js:17-25,60-67
Mobile Apps (Expo & Flutter)
The mobile applications are not "deployed" in the traditional sense but are run on simulators/emulators or physical devices during development.
- Expo (
shop-mobile-expo): This React Native app is run using the Expo CLI. After installing dependencies, the developer runsyarn run startto start the Metro bundler. The app can then be opened in the Expo Go app on a mobile device. - Flutter (
shop-mobile-flutter): This app is developed using the Flutter SDK. Developers need to set up their environment according to the official Flutter documentation, after which they can run the app on a connected device or simulator.
Sources: packages/shop-mobile-expo/README.md
Environment Configuration
Before any build or deployment, environment-specific configuration files are generated. Scripts like configure.ts in the admin-web-angular and shop-mobile-expo packages read variables from a .env file and create environment.ts (for development) or environment.prod.ts (for production) files.
This process injects environment-specific values like API endpoints, API keys, and feature flags into the application at build time.
The diagram below shows the configuration generation flow for the Angular admin app.