This is the source code of the erpjs, the headless serverless ERP and CRM for the cloud written in TypeScript running on Node.js and in a browser as an Angular single page application.
It can run on your local computer, in a containerized environment like Kubernetes (K8) on Google Cloud, Microsoft Azure or IBM Cloud or even as a serverless function in AWS.
Auth0 is used for the authentication so with paid plans you can achieve Single Sign On with G Suite, Office 365 or Salesforce.com (SFDC) while still running free on the plain old username + password.
You can download the source code and own the ERP&CRM. You can explore the source code and find out how we used Nx, NestJS, TypeORM, GraphQL and Angular to both build the backend that can run in AWS Lambda and a sample frontend application that can be immediately used to run a business.
You can run the ERP&CRM in your own cloud provided by AWS and both keep your data safe and prevent bad things happening by having all your important data on your laptop or own server.
This is a monorepo of the erpjs API server (backend) and a sample Angular web client (frontend) together with some libraries like @erpjs/model, the business core of erpjs.
This is the business core of the ERP/CRM. Stored in libs/model:
-
services (e.g.
BankAccountServiceorLeadService). The services contains the core business logic like:-
SalesInvoiceServicemakes sure VATs are applied if necessary, the grand total is rounded and is ready to be posted with the correct currency rate -
ProspectServicecorrectly convertsSuspectModeltoProspectModelwhen needed
-
-
entity interfaces (e.g.
AccountModelorCustomerModel). What are the basic minimum attributes entities need to have. -
jobs (e.g.
SalesInvoiceJob). Repeatable jobs that e.g. assign document numbers to invoices. -
args. The interface for a new entity to be created through the service.
-
Injector to be able to make calls between services.
This library contains only the business code, no persistence, minimum dependencies.
Never import like import { ... } from '@erp/model here, always use the relative paths or the @erpjs/model
will not build.
This is the implementation of @erpjs/model in NestJS. Implements the entity persistence using TypeORM.
The main backend serving the GraphQL requests from the client
and running jobs like invoicing, downloading currency rates etc. Stored in apps/api.
The default implementation uses PostgreSQL, but any TypeORM supported relation database should work (MySQL, MariaDB, CockroachDB, Microsoft SQL Server, Oracle).
The server is tested on Heroku and AWS Lambda.
The sample frontend written in Angular with Clarity Design System calling the API using GraphQL.
- Node.JS 10 for running the API server; switch with commands like
nvm use v10.18.1, also note we are now not node 13.5 compatible - Auth0 tenant created and setup following Setup Auth0 for erpjs.
- for the mobile application you have to install NativeScript e.g.
npm install -g nativescript
Run npm i to install the dependencies.
Build frontend with AUTH0_DOMAIN=<domain>.auth0.com AUTH0_CLIENT_ID=<clientid> AUTH0_AUDIENCE='@erpjs' API='<api server url>' npm run build erp.
Obtain the AUTH0_* variables from the Setup Auth0 for erpjs guide
for the SPA application (do not use the machine-machine API ones).
Run ng build [project name] to build the project. The build artifacts will be stored in the dist/ directory. Use the --prod flag for a production build.
Run AUTH0_DOMAIN=AAAAA.eu.auth0.com AUTH0_CLIENT_ID=CLIENTID AUTH0_CLIENT_SECRET=SECRET ng serve api for a dev API server.
Navigate to http://localhost:3333/api/hello. The app will automatically reload if you change any of the source files.
Run ng serve erp for a dev server. Navigate to http://localhost:4200/.
The app will automatically reload if you change any of the source files.
Run ng test to execute the unit tests via Jest.
Run nx affected:test to execute the unit tests affected by a change.
Run ng e2e to execute the end-to-end tests via Cypress.
Run nx affected:e2e to execute the end-to-end tests affected by a change.
Run nx dep-graph to see a diagram of the dependencies of your projects.
Visit the Nx Documentation to learn more.
ng build model
npm publish ~/dev/erp/dist/libs/model/ --access public
docker pull postgres:12
docker stop pg-docker; docker run --rm --name pg-docker -e POSTGRES_PASSWORD=HlohIn14563 -e POSTGRES_DB=gt2 -d -p 5432:5432 postgres:12
set AWS environment variable on the lambda to 1 for the GraphQLModule automatic schema generation to work.
AUTH0_DOMAIN=AAAAA.eu.auth0.com AUTH0_CLIENT_ID=CLIENTID AUTH0_CLIENT_SECRET=SECRET npm run build api-sls
AUTH0_DOMAIN=AAAAA.eu.auth0.com AUTH0_CLIENT_ID=CLIENTID AUTH0_CLIENT_SECRET=SECRET cp serverless.yml ./dist/apps/api-sls/ && cp auth_config_server.json ./dist/apps/api-sls/ && (cd ./dist/apps/api-sls/ && npm i && sls deploy)
Open Serveless Dashboard, locate the erpjs service, find any/ API endpoint
and try to access /api/hello on the URL.
The API is the path to the API endpoint ending with the stage (e.g. /dev).
heroku restart --app erpjs && heroku pg:reset DATABASE --app erpjs
AUTH0_DOMAIN=AAAAA.eu.auth0.com AUTH0_CLIENT_ID=CLIENTID AUTH0_CLIENT_SECRET=SECRET ./heroku_deploy_api.sh
Access the health check.
The API is https://erpjs.herokuapp.com.
Run npm run start.nativescript.mobile.android.
If you have Signing for "nativescriptmobile" requires a development team. you need
to go to the project Targets and choose the team (you need to create the development team in advance).
When running on the real device, you will get the error about Untrusted developer.
Go to Setting -> General -> Device Management and "Trust" the developer used.
if the "Device Management" option is not present, reinstall the application.

