Skip to content

Commit f2fbd53

Browse files
update frontend readme (canada-ca#2873)
1 parent 156eb9d commit f2fbd53

File tree

1 file changed

+60
-12
lines changed

1 file changed

+60
-12
lines changed

frontend/README.md

Lines changed: 60 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,48 +2,60 @@
22

33
This frontend is an example of a Single Page Application (SPA) on the [Web Platform](https://platform.html5.org).
44

5-
There are lots of ways to build an application, why a SPA? As more and more APIs are added to the Web Platform (known to most as "the browser") more and more code runs on the Web Platform rather than a server or a competing platform like IOS or Android. The langauge of the Web Platform is JavaScript and a SPA style application is the main way to create apps in the browser.
5+
There are lots of ways to build an application, why a SPA? As more and more APIs are added to the Web Platform (known to most as "the browser") more and more code runs on the Web Platform rather than a server or a competing platform like IOS or Android.
6+
The language of the Web Platform is JavaScript and a SPA style application is the main way to create apps in the browser.
67

7-
SPAs execute code in the browser on the users machine, which lets our applications handle spotty network connections, work offline entirely and avoid sending partial data to servers while filling out multi-stage forms. [Betting on the web](https://joreteg.com/blog/betting-on-the-web) lets us deliver web applications on a truly open platform that are powerful, accessible, and work on a huge range of devices.
8+
SPAs execute code in the browser on the users machine, which lets our applications handle spotty network connections, work offline entirely and avoid sending partial data to servers while filling out multi-stage forms.
9+
[Betting on the web](https://joreteg.com/blog/betting-on-the-web) lets us deliver web applications on a truly open platform that are powerful, accessible, and work on a huge range of devices.
810

911
Specific to this project, the SPA architecture allows for dynamic behaviour that is needed for us to offer users to trigger their own scans and watch the progress and results appear in their browser.
1012

11-
As the "consumer" part of the API/consumer pair at the heart of the [Government as a Platform](https://medium.com/digitalhks/government-as-a-platform-the-hard-problems-part-1-introduction-b57269bcdc6f) model, this is assumed to be the first (but never the only) consumer of the backend API. Shaped by user research its needs then inform the building of the API.
13+
As the "consumer" part of the API/consumer pair at the heart of the [Government as a Platform](https://medium.com/digitalhks/government-as-a-platform-the-hard-problems-part-1-introduction-b57269bcdc6f) model, this is assumed to be the first (but never the only) consumer of the backend API.
14+
Shaped by user research its needs then inform the building of the API.
1215

1316
## Development
1417

15-
In addition to the frontend service, this folder contains files needed to create a good developer workflow. Before diving into the details of the development workflow itself, it's worth talking through the thinking behind what constitutes a "good" workflow.
18+
In addition to the frontend service, this folder contains files needed to create a good developer workflow.
19+
Before diving into the details of the development workflow itself, it's worth talking through the thinking behind what constitutes a "good" workflow.
1620

1721
### The philosophy
1822

19-
Applications without APIs project organizational silos into the digital space. With an API, experiences can be created that are [centered on the user](https://www.publictechnology.net/articles/features/interview-singapore%E2%80%99s-digital-chief-redesigning-government-around-%E2%80%98moments-life%E2%80%99) rather than organizational silos.
23+
Applications without APIs project organizational silos into the digital space.
24+
With an API, experiences can be created that are [centered on the user](https://www.publictechnology.net/articles/features/interview-singapore%E2%80%99s-digital-chief-redesigning-government-around-%E2%80%98moments-life%E2%80%99) rather than organizational silos.
2025

2126
By adopting a microservices approach we can lay the foundation for a user centered service, and our new application can fit with the [TBS Directive on Management of Information Technology](https://www.tbs-sct.gc.ca/pol/doc-eng.aspx?id=15249#claD.2.2.4), but the developer workflow around this isn't clear.
2227

2328
One possible way to do local development is to bring up a local copy of [Kubernetes](https://kubernetes.io/) in something like [Minikube](https://minikube.sigs.k8s.io/) or [Kind](https://kind.sigs.k8s.io/), and then use a tool like [skaffold](https://skaffold.dev/) to run all your services just as you would in production.
2429

25-
This approach can work for small sets of services, but demands extremely powerful dev machines. Since services are developed while running every other service it's easy to build in interdependence into the system.
30+
This approach can work for small sets of services, but demands extremely powerful dev machines.
31+
Since services are developed while running every other service it's easy to build in interdependence into the system.
2632

27-
The big idea here is that realizing the benefits of microservices requires protecting their independence, and that requires developing them independently. This then is the core assumption about what constitutes a "good" workflow: it must be lightweight, and let the developer develop the services independently.
33+
The big idea here is that realizing the benefits of microservices requires protecting their independence, and that requires developing them independently.
34+
This then is the core assumption about what constitutes a "good" workflow: it must be lightweight, and let the developer develop the services independently.
2835

2936
### The workflow
3037

31-
The dev workflow being created here centers on [Docker-compose](https://docs.docker.com/compose/), a tool that helps developers run multiple containers together.
32-
So here we use docker-compose to bring up the frontend service with a mocked API. Running those two services behind [Envoy](https://www.envoyproxy.io/) allows us a way to present the API at `/graphql` just as it would be in production.
38+
The dev workflow being created here centre's on [Docker-compose](https://docs.docker.com/compose/), a tool that helps developers run multiple containers together.
39+
So here we use docker-compose to bring up the frontend service with a mocked API.
40+
Running those two services behind [Envoy](https://www.envoyproxy.io/) allows us a way to present the API at `/graphql` just as it would be in production.
3341

3442
The files to support this are the docker compose configuration (`docker-compose.yaml`), the config file for Envoy telling it to proxy requests to the API and frontend (`envoy-dev.yaml`).
3543

3644
#### Starting it
3745

38-
This frontend uses a simple Webpack setup which either runs a hot reloading dev server. To start it, you need to be inside the frontend folder and run the following command:
46+
This frontend uses a simple Webpack setup which either runs a hot reloading dev server.
47+
To start it, you need to be inside the frontend folder and run the following command:
3948

4049
```sh
4150
docker-compose up -d
4251
```
4352

44-
This will bring up Envoy, the mocked API and the frontend service and [detach](https://docs.docker.com/compose/reference/up/) returning the terminal to the user. As part of this process docker compose will [bind mount](https://docs.docker.com/storage/bind-mounts/) the frontend folder into the container. This allows changes to the code to be reflected immediately in the running container.
53+
This will bring up Envoy, the mocked API and the frontend service and [detach](https://docs.docker.com/compose/reference/up/) returning the terminal to the user.
54+
As part of this process docker compose will [bind mount](https://docs.docker.com/storage/bind-mounts/) the frontend folder into the container.
55+
This allows changes to the code to be reflected immediately in the running container.
4556

46-
You can see the service running on `localhost:3000` and the API running on `localhost:3000/graphql`. If you want to modify the schema you can reach the editor at `localhost:3000/editor`.
57+
You can see the service running on `localhost:3000` and the API running on `localhost:3000/graphql`.
58+
If you want to modify the schema you can reach the editor at `localhost:3000/editor`.
4759

4860
#### Stopping it it
4961

@@ -64,3 +76,39 @@ npm install
6476
```sh
6577
npm test
6678
```
79+
80+
#### Running the linter
81+
82+
The linter performs a code analysis that flags programming errors, bugs, stylistic errors, and suspicious constructs.
83+
Style errors are determined by the prettier configuration in `.prettierrc`, and plugins exist for automatically formatting code on file save.
84+
85+
```sh
86+
npm run lint
87+
```
88+
89+
### The Mocker
90+
91+
The mocker is used to create API data for use on the local instance of Tracker when using docker.
92+
It can be used to create specific behaviours in the app in order to test certain behaviours and features.
93+
94+
### Building the Application
95+
96+
The frontend is built using [React](https://reactjs.org/docs/getting-started.html).
97+
React uses JSX allow for the creation of HTML elements inside Javascript.
98+
These elements support the use of variables and any other Javascript inside them by wrapping the Javascript inside of `{}`.
99+
100+
The frontend user interface is styled using [Chakra](https://chakra-ui.com/).
101+
Chakra contains many React components that are used for designing page layouts.
102+
Chakra also allows for the use of ['style props'](https://chakra-ui.com/docs/features/style-props), which apply css properties to components.
103+
Chakra comes with a default theme, that Tracker extends in [/frontend/src/theme/canada.js](https://github.com/canada-ca/tracker/blob/master/frontend/src/theme/canada.js).
104+
The theme contains colour, size, and spacing definitions, along with default component styles and custom component variants.
105+
106+
The frontend communicates to the database API using [GraphQL](https://graphql.org/).
107+
The primary interactions are queries, used for requesting data from the database, and mutations, used for manipulating data in the database.
108+
The faked_schema.js is used to define the inputs and returns, and their corresponding types when running a local copy of Tracker.
109+
110+
The /src/ folder is organized into folders for each page, along with:
111+
an app folder for the overall structure of the page;
112+
an auth folder for all the login and account creation pages;
113+
a components folder for any shared components;
114+
and a utilities folder for functions.

0 commit comments

Comments
 (0)