Documentation - Open-Source Web App Starter Kit: Angular, Payload CMS, Nx & ExpressJs

Read the documentation directly in Notion.

binarystarter-angular Open Source - Installation

This is a step by step guide to install the angular starter, free and open-source.

Resources:

Prerequisites:

  • Install nodejs v20

1. Clone the starter repository

Run git clone https://github.com/binarystarter/binarystarter-angular.git <project_name>

2. Install modules

Change the directory to the newly created folder <project_name > ( cd <project_name> )

Run pnpm install and open the project in your favorite IDE.

3. Configure ExpressJs API server

Duplicate the apps/express/.env.local.example file and rename it to apps/express/.env.local.

Fill the environment variables with the desired configuration for your environment.

This is the environment variable used by the docker-compose.yml and the expressjs application.

Environment Variables Explained

Please pay careful attention to the keys marked with SECRET KEY. These are the keys that should always be kept secret and not committed or shared with anyone else.

  • api_url

development environment: can be

, considering that 8080 is the above set

  • api_port

production environment: needs to be the full domain pointing to the api node app - e.g.

or https://api.binarystarter.com

The URL pointing to the API app

  • api_port

The port where the expressjs should be served on.

  • app_allowed_headers

You can limit the allowed headers if you don’t need all to be available on services such as S3, API etc.

The allowed headers used for S3 buckets and potentially other places. The headers should be split by , . e.g. GET,POST,PUT.

  • app_auth

The authentication system used.

Valid value: passportjs

Currently, we only support passportjs. This is set so that we can add more auth options in the future, such as firebase authentication.

  • app_name

The name of the application. This is used internally for identifying resources in AWS, database naming or other usages.

  • app_stage

The stage, stack or environment - we refer to them interchangeably. The stage should match dev or prod

  • email_user

The email user.

The email is configured using Gmail initially. You can update the apps/express/src/main.ts and set your nodemailer transport.

You require 2FA to be activated and create a new app password.

FYI: In all our templates, the email is automatically setup using AWS SES. All you need to do is set SES and put the arn in the configuration file

  • email_from

The email address from which all system emails are sent from.

  • email_password

The email password

The email is configured using gmail initially. You can update the apps/express/src/main.ts and set your own nodemailer transport.

  • mongo_port

The port used by docker-compose to run mongodb.

  • mongo_db - SECRET KEY

The name you want to give to the mongo database.

  • mongo_password - SECRET KEY

The mongo database user password

  • mongo_username - SECRET KEY

The mongo user username

  • mongo_connectionString - SECRET KEY

The mongo connection string.

Locally, the connection string should look like this: mongodb://<mongo:username>:<mongo:password>@localhost:27017/<mongo:db>?authSource=admin

On production you can use multiple methods of hosting the mongo database: - Managed Cloud: MongoDB atlas, digitalocean MongoDB - in which case you get the connection string from them (e.g. mongodb+srv….) - Self hosted MongoDB - in which case you have to test using mongosh command on the mongo db server that you set up to double-check the connection.

  • payload_secret - SECRET KEY

Create a random string, maybe over 16 characters of all kinds. Treat this as a sensitive password that gives access to your whole CMS. This is used to encrypt a lot of things on the backend side. It’s called payload:secret because the open-source CMS used is called payload CMS.

  • payload_users_slug

The collection storing users is called the users slug. Default value is users.

3.2 Add web URL as shared constant

Duplicate the file at libs/shared-constants/src/lib/web-url.ts.example and rename it to web-url.ts. Set the web_url from above .env.local config as a value.

💡 I know, it’s not that pretty. We need this to share the URL with the payload react components. This cannot be done using dotenv because, in the browser, dotenv does not exist.

4. Configure Angular

4.1 Rename the project (optional)

Search in the entire project for binarystarter-angular and replace with your app name.

4.2 Environment Variables (optional)

This is optional initially. You can update later.

Development environment file: libs/default-theme/src/lib/environments/environment.development.ts

Production environment file: libs/default-theme/src/lib/environments/environment.production.ts

Fill them accordingly. There is no problem committing to git because we do not keep sensitive information in these files.

The environment.ts file is getting overwritten automatically using the fileReplacement settings under web/project.json configuration for each environment.

💡 Feel free to add as many environment files and configurations as you wish. Make sure to update the project.json files accordingly.

5. Run the applications

5.1 Temporarily allowing anyone to create an administrator account

This is needed in order for you to be able to create an administrator account the first time running the project.

Open the apps/express/src/payloadcms/UsersCollection.ts file, go to the roles field definition, and comment this line create: fieldAccessAdminOnly and hidden:true under admin key (see below).

💡 By default, users are not allowed to select any roles. This operation is done ONLY when creating your first administrator user.

5.2 Run the Web app

Read more about the CLI commands available at apps/web/project.json

Run in the terminal at the root level nx serve web

5.3 Run the Server App & Mongo database

💡 Make sure to have docker app opened

Run in the terminal at the root level

    
(starts the mongodb server inside a docker. Configuration can be found at apps/express/docker-compose.yml

Run in the terminal at the root level nx serve express

💡 Read more about the CLI commands available at apps/express/project.json

Wait for express and payload to run.

5.4 Create your administrator account 5.4.1 Navigate to localhost:8080/admin

5.4.2 Create the first user using the Administrator role.

5.4.3 Revert commented lines from above. (from step 5.1)

Next Steps

  • setup a gmail account for local development and add it under .env.local in order to be able to create new accounts. Each new account must be verified before logging in.
  • integration with github actions - automatic CICD and AWS resources creation using infrastructure as code.

More Information

Folder structure explained

CLI tool helps us manage the project applications and libraries.

You may be wondering why is this needed, and while there’s multiple reasons, a simple one that I love is the automatic tsconfig configurations for each library and application.

  • Whether you want to add or remove a new app, you can do it with one nx CLI command.
  • Whether you want to add or remove a new lib, you can do it with one nx CLI command.

No other manual updates of tsconfigs for other apps or libraries.

According to nx best practices, 80% of the code should live inside libs and 20% of the code in the apps.

Now that we explained a bit about the reasoning, we have the following folder structure:

  • apps/express is where our server lives. It contains two endpoints that extend the registration and authentication of payload cms. The authentication is done using JWT tokens stored in localstorage.

The initial reasoning was consistency between angular login, payload dashboard login, and a flutter application, everything configured from one configuration file (see pro version).

However, we all know that storing jwt in local storage is not the best option, so we are considering updating it to cookie-based, leaving it to your responsibility to have the server and frontend on the same domain.

Built with