The majority of Hack4Impact projects are web based, and from those, are built using the MERN stack. MERN is one of the most widely used stacks for modern web development. Composed of MongoDB, Express, React, and Node, MERN represents the full stack from the frontend to the backend.
- Sexy README
- Frontend and backend skeletons
- Frontend testing with Cypress
- Backend testing with Jest
- Frontend and backend linting with ESLint
- Continuous integration tests with GitHub Actions
The frontend code is contained in client/
and the backend code is contained in api/
. Each corresponding directory contains the respective configurations for testing and linting, as well as a package.json
file with the necessary production and development packages.
A sexy readme is provided. A couple things to change include
- Nonprofit logo (replaces Hack4Impact logo)
- Team member images & links
Navigate to client/
To begin to set up the client, navigate to the /public
directory. This will contain project metadata, such as the favicon and Apple touch icon. In addition, you can change the title of your project in index.html
.
In package.json
, change the fields as needed (including project name, GitHub repository, and license).
To run, yarn
to install dependencies, and then yarn start
to start the development server. It will be located on http://localhost:3000
.
In /src
, the React components will be developed. Given is a single Home
component located in /src/pages
which connects to the backend. It simply just renders an h1
header and two p
tags. If the API is not connected, the second tag will render the default state that indicates that the API is not connected. If it is connected, the state gets updated upon API fetch.
The linting, formatting, and testing frameworks have been provided.
Linting uses ESLint linter, with the Airbnb style guide. Customization for specific rules can be entered in .eslintrc.json
. To run linting, yarn lint
within the client
directory.
Formatting uses prettier
and can be customized in .prettierrc
. Run formatting with yarn format
in the client
directory.
Type checking uses Flow, which can be run with yarn flow
. For a file to be detected by flow, add // @flow
at the top. By default, type checking is not enabled in continuous integration as it hinders fast project development.
Frontend testing uses Cypress. There is a default configuration for Cypress set up. For your project, please navigate to the Hack4Impact UIUC Cypress dashboard (which can be reached by signing in with GitHub to Cypress), and enable your project. You will recieve a project id, which you should enter in cypress.json
. Tests can be found in client/cypress/integration
To run Cypress tests, yarn test
in the client
directory.
Navigate to api/
In package.json
, change the fields as needed (including project name, GitHub repository, and license).
Here in /src
, there are many folders. /src/api
contains the code for fetching from MongoDB (currently commented out), /src/middleware
contains the code for error handling, /src/models
contains the MongoDB models, and /src/routes
contains the routes for the endpoints of the API.
There is also configuration for three seperate envirments: production (production
), development (dev
), and testing (test
). Each of these have their own database, which can be configured within the /config
directory. Inside, create three .env
files: production.env
, dev.env
, and test.env
. Each should contain the following field, with unique values (a seperate database for each environment).
MONGO_URL=mongodb://<username>:<password>@<id>.mlab.com:<id/project>
production
is set on deployment, dev
is set whenever running locally, and test
is set when tests are running. These environments are automatically set based on the task within app.js
.
To run, yarn
to install dependencies, and then yarn start
to start the development server. It will be located on http://localhost:9000
.
Currently there is a single endpoint at /api/home
which returns the text for home.
The linting, formatting, and testing frameworks have been provided.
Linting uses ESLint linter, with the Airbnb style guide. Customization for specific rules can be entered in .eslintrc.json
. To run linting, yarn lint
within the api
directory.
Formatting uses prettier
and can be customized in .prettierrc
. Run formatting with yarn format
in the api
directory.
Backend testing uses Jest. There is a default configuration for Jest set up. Tests can be found in api/test
. Simply run yarn test
to run the tests.
Continuous integration is just the practice of automatically running tests for every single code push, which can be automated by services such as GitHub Actions. To edit these, modify the yaml
configuration files in .github/workflows
.
Currently, provided jobs include:
client
lint
: Ensuringyarn lint
within theclient/
directoryclient
test
: Ensuringyarn test
within theclient/
directoryclient
format
: Ensuringyarn format:check
within theclient/
directoryclient
build
: Ensuringyarn build
within theclient/
directoryapi
lint
: Ensuringyarn lint
within theapi/
directoryapi
test
: Ensuringyarn test
within theapi/
directoryapi
format
: Ensuringyarn format:check
within theapi/
directory
If you have set up Cypress in the dashboard and gotten your project id, add it to the CircleCI environment variables and add the record: true
flag.
By default for client
test
, parallelism is turned off. To enable parallelism, add the flag
parallel
:true