• Stars
    star
    270
  • Rank 152,189 (Top 3 %)
  • Language
    TypeScript
  • License
    Other
  • Created over 4 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Form builder for the Singapore Government


Contributor Covenant Build Status Coverage Status

Table of Contents

Contributing

We welcome all contributions, bug reports, bug fixes, documentation improvements, enhancements, and ideas to code open sourced by the Government Technology Agency of Singapore. Contributors will also be asked to sign a Contributor License Agreement (CLA) to ensure that everybody is free to use their contributions.

IMPORTANT NOTE TO ALL CONTRIBUTORS

Before contributing, please read CONTRIBUTING.md. In particular, we strongly encourage contributors to please first discuss the change you wish to make via GitHub issue, email, or any other method with the repository owners beforehand. Otherwise, we may not be able to review or accept your PR.

Features

FormSG is a form builder application built, open sourced and maintained by the Open Government Products team of the Singapore Government Technology Agency to digitise paper processes.

Notable features include:

  • 19 different form field types, including attachments, tables, email and mobile
  • Verified email and mobile phone fields via integrations with Twilio and AWS SES
  • Automatic emailing of submissions for forms built with Email Mode
  • Encryption for data collected on forms built with Storage Mode
  • (Singapore government agencies only) Citizen authentication with SingPass
  • (Singapore government agencies only) Citizen authentication with sgID
  • (Singapore government agencies only) Corporate authentication with CorpPass
  • (Singapore government agencies only) Automatic prefill of verified data with MyInfo
  • Webhooks functionality via the official FormSG JavaScript SDK and contributor-supported FormSG Ruby SDK
  • Variable amount and Itemised payments on forms with stripe integration

Local Development (Docker)

Prerequisites

Install docker and docker-compose.

First Setup

To install the relevant npm packages, run the following in the root direcory:

npm install

To prevent breaking changes to webpack4 introduced in node 17 and above, enable the --openssl-legacy-provider flag:

export NODE_OPTIONS=--openssl-legacy-provider

If you are on Mac OS X, you may want to allow Docker to use more RAM (minimum of 4GB) by clicking on the Docker icon on the toolbar, clicking on the "Preferences" menu item, then clicking on the "Resources" link on the left.

Running Locally

Run the following shell commands to build the Docker image from scratch. This will usually take 10 or so minutes. These commands runs the backend services specified under docker-compose.yml and the React frontend on the native host.

npm run build:frontend
npm run dev

After the Docker image has finished building, the React application can be accessed at localhost:3000. The backend API server can be accessed at localhost:5001.

If there are no dependency changes in package.json or changes in the src/app/server.ts file, you can run

docker-compose up

which does not rebuild the Docker image from scratch. This command usually only takes ~15 seconds to finish starting up the image.

Adding dependencies

Run npm install as per usual.

For backend, run

docker-compose up --build --renew-anon-volumes

which will rebuild the backend Docker image and not reuse the existing node_modules volume.

As frontend project is currently not using Docker, no other steps are required.

Accessing email locally

We use MailDev to access emails in the development environment. The MailDev UI can be accessed at localhost:1080 when the Docker container runs.

Environment variables

Docker-compose looks at various places for environment variables to inject into the containers. The following is the order of priority:

  • Compose file
  • Shell environment variables
  • Environment file
  • Dockerfile

FormSG requires some environment variables to function. More information about the required environment variables are in DEPLOYMENT_SETUP.md.

We provide a .template-env file with the secrets blanked out. You can copy and paste the variables described into a self-created .env file, replacing the required values with your own.

Trouble-shooting

You can consult TROUBLESHOOTING.md for common issues that developers face and how to resolve them.

Testing

The docker environment has not been configured to run tests. Thus, you will need to follow the following local build guide to get tests running locally.

Testing Prerequisites

The team uses macOS for development.

Make you sure have the following node version & package manager on your machine:

  • "node": ">=18.12.1"
  • "npm": ">=8.19.2"
  • "mongo": ">=4.0.0"

Run

nvm install 18
npm install
pip install "localstack[full]"

to install node modules and Localstack locally to be able to run tests. Note that localstack[full] is only compatible with Python 3.7 and above.

Running tests

Unit tests

npm run test

will build the backend and run our backend unit tests. The tests are located at __tests__/unit/backend.

If the backend is already built, you can run

npm run test-ci

Frontend tests are located at frontend/__tests__. They can be run with

npm run test:frontend

End-to-end tests

npm run test:e2e-v2

will build both the frontend and backend then run our end-to-end tests. The tests are located at __tests__/e2e. You will need to stop the Docker dev container to be able to run the end-to-end tests.

If you do not need to rebuild the frontend and backend, you can run

npx playwright test

Cross-browser testing

This project is tested with BrowserStack.

Architecture

The architecture overview is here.

MongoDB Scripts

Scripts for common tasks in MongoDB can be found here.

Support

Please contact FormSG ([email protected]) for any details.

Database Alternatives

Migrating from Mongoose ODM to Prisma ORM

FormSG uses Mongoose as the Object-Document Mapping (ODM) to MongoDB. This means that our code is strongly coupled with MongoDB as Mongoose solely supports it.

In order to use a different database with FormSG you will have to first migrate from Mongoose to other object modelling libraries. One of which is Prisma.

Prisma is an Object-Relational Mapping (ORM) library that can also be used as the object model for MongoDB. Prisma is compatible with various other relational databases like Cockroach DB.

Follow this guide by Prisma to migrate from Mongoose.

The guide has 4 primary steps:

  1. Install Prisma CLI
  2. Introspect the current MongoDB for the data model
    1. For this section, Prisma’s introspection should be able to create prisma models that will replace your server.model.ts for each collection
    2. Additionally, as Prisma is relational, you could add relations between the various documents. One good relation to add will be form many to one user on the [form.email](http://form.email) field.
  3. Install Prisma Client
  4. Replace Mongoose Queries with Prisma Client
    1. This step will likely take the most refactoring efforts
    2. This will include most files in formsg/src ending with service.ts
    3. Including test files ending with service.spec.ts

Replacing MongoDB with CockroachDB

Thereafter, you could set up CockroachDB which is a distributed SQL DB. Follow the quick start guide by CockroachDB to create a CockroachDB Serverless cluster.

To replace the local development instance, you can follow this guide. As FormSG uses Docker for local development, you will have to replace the mongoDB container from docker-compose.yml to the cockroachDB version.

Then connect to CockroachDB by changing the DB url in .env to the one from your CockroachDB DATABASE_URL="YOUR_COCKROACH_DB_URL".

For local development, if the DB is replaced as above, you should not need to modify the ports as it will still be hosted on localhost:27017.

Other Prisma supported DBs

MongoDB can be replaced with other various relational databases supported by Prisma in this list.

Other potential DB migrations

It is also possible to migrate from Mongoose to Ottoman, which is another ODM.

The process will be simpler than migrating to Prisma, but Ottoman is more restrictive and can only be used together with Couchbase, which is also a noSQL DB like MongoDB.

Refer to this guide to migrate from Mongoose to Ottoman and then replace MongoDB with Couchbase.

Acknowledgements

FormSG acknowledges the work done by Arielle Baldwynn to build and maintain TellForm, on which FormSG is based.

Contributions have also been made by:
@RyanAngJY
@jeantanzy
@pregnantboy
@namnguyen08
@zioul123
@JoelWee
@limli
@tankevan

More Repositories

1

GoGovSG

The official link shortener of the Singapore Government
TypeScript
93
star
2

mockpass

A mock SingPass/CorpPass/MyInfo server for dev purposes
CSS
83
star
3

postmangovsg

Templated message sending for public officers
TypeScript
60
star
4

design-system

The Design System used at Open Government Products
TypeScript
37
star
5

ts-template

A template repository for TypeScript projects in Open Government Products
TypeScript
36
star
6

starter-kit

A technical kit to quickly build new products
TypeScript
36
star
7

engineering-practices

29
star
8

ColouriseSG

A deep learning colouriser prototype specifically for old Singaporean photos.
27
star
9

formsg-javascript-sdk

JavaScript SDK for integrating with FormSG
TypeScript
26
star
10

spcp-auth-client

Integrates SingPass and CorpPass SAML into your node.js application
JavaScript
25
star
11

queuesg

Queue is a simple queue management system that utilises Trello as a backend admin, for a quick and simple way to create pop-up queues
JavaScript
19
star
12

askgovsg

Answers from the Singapore Government
TypeScript
16
star
13

credits-generator

Attributes the authors of your first-level package.json dependencies
JavaScript
15
star
14

myinfo-gov-client

A lightweight client to easily call MyInfo
TypeScript
14
star
15

checkfirst

Don't Know? CheckFirst. A tool to build eligibility checkers and calculators for Singapore Government policies
TypeScript
12
star
16

plumber

Automate your pipelines, streamline your workflows.
TypeScript
11
star
17

sgid-client

The official TypeScript/JavaScript SDK for sgID
TypeScript
11
star
18

petitionsgovsg

Where citizens push for change that matters
TypeScript
10
star
19

cbdc-smart-contracts

Smart contracts for the CBDC collaboration
TypeScript
10
star
20

countries-regions-codes

Utility for converting between nationality codes
TypeScript
7
star
21

lambda-virus-scanner

A Lambda-hosted service that scans files for viruses with ClamAV, bucketing them into clean or quarantine S3 buckets
TypeScript
4
star
22

isomer

Monorepo for Isomer Next
TypeScript
4
star
23

starter-kit-dd

A demo of Starter Kit integrated with Datadog APM and RUM
TypeScript
4
star
24

sgid-client-python

The official Python client for sgID.
Python
3
star
25

postmangovsg-guide

Guide for PostmanSG
3
star
26

mui-select-button

A React button with select dropdown menu using Material-UI
TypeScript
2
star
27

carparks-near-me

JavaScript
2
star
28

letters

TypeScript
2
star
29

redeem-ce

A platform for digital monetary vouchers, as well as associated processes and bookkeeping
TypeScript
2
star
30

formsg-ruby-sdk

Ruby SDK for integrating with form.gov.sg webhooks
Ruby
1
star
31

terraform-template

Repo to get a terraform infra running for OGP products
HCL
1
star
32

sgID-attribution

1
star
33

formsg-intl

A modified version of FormSG, suitable for other organisations
TypeScript
1
star
34

formsg-on-cdk

Public CDK (and CloudFormation) templates to deploy FormSG on AWS
TypeScript
1
star
35

xinyao-stack

A Remix stack for the Singapore Government
TypeScript
1
star
36

spotlightsg

TypeScript
1
star
37

officesg-maps

HTML
1
star
38

.github

GitHub community health files for Open Government Products
1
star
39

tfpg-jobs

The jobs directory for the Tech for Public Good hiring drive of the Singapore Government
TypeScript
1
star
40

memos

TypeScript
1
star
41

eslint-config-opengovsg

ESLint rules for Open Government Products, part of the Singapore Government
JavaScript
1
star
42

sgID-microsite

JavaScript
1
star
43

q-rstu

A React Native app wrapping around CPF e-cashier
JavaScript
1
star
44

rdsproxy-test

C
1
star
45

emergency

TypeScript
1
star
46

formsg-python-sdk

Python SDK for integrating with FormSG
Python
1
star