codeforboston / police-data-trust

A national archive of police data collected by journalists, lawyers, and activists around the country.
https://www.nationalpolicedata.org
MIT License
40 stars 71 forks source link
accountability open-government police-misconduct transparency

police-data-trust

To get started:

  1. Fork a copy of the main repo to your GitHub account.

  2. Clone your fork: git clone git@github.com:YOUR_GITHUB_NAME/police-data-trust.git

  3. Add the main repo to your remotes

cd police-data-trust
git remote add upstream https://github.com/codeforboston/police-data-trust.git
git fetch upstream

Now, whenever new code is merged you can pull in changes to your local repository:

git checkout main
git pull upstream main

Installation (Full Application)

This method uses Docker to run the complete application stack.

  1. Make sure that Docker is installed on your machine.

  2. Create a .env file by running cp .env.template .env in the root of your local project folder, and add your preferred PostgreSQL username and password:

Note When running locally, you may need to update one of the ports in the .env file if it conflicts with another application on your machine.

  1. Build and run the project with docker-compose build && docker-compose up -d && docker-compose logs -f

Installation (Frontend Only)

This method runs the frontend natively on your computer and does not require a running backend, which can be convenient.

  1. Make sure that you have node 16+ and either npm 7+ or yarn installed.
  2. Follow the install instructions in the frontend directory.

Testing with Docker

All code must pass the unit tests and style checks before it can be merged into the main branch. You can run the tests locally by opening up a comand line interface to a docker container while it's running the application:

docker exec -it "police-data-trust-api-1" /bin/bash

You'll need to replace police-data-trust-api-1 with the name of the container you'd like tro connect to. You can see the names of all currently running containers by running docker container ls

docker container ls
CONTAINER ID   IMAGE                   COMMAND                  CREATED              STATUS              PORTS                    NAMES
c0cf********   police-data-trust-api   "/bin/sh -c '/wait &…"   About a minute ago   Up About a minute   0.0.0.0:5001->5001/tcp   police-data-trust-api-1
5e6f********   postgres:16.1           "docker-entrypoint.s…"   3 days ago           Up About a minute   0.0.0.0:5432->5432/tcp   police-data-trust-db-1
dacd********   police-data-trust-web   "docker-entrypoint.s…"   3 days ago           Up About a minute   0.0.0.0:3000->3000/tcp   police-data-trust-web-1

Backend Tests

The current backend tests can be found in the GitHub Actions workflow file python-tests.yml

To run the tests locally, first start the application with docker-compose. Then open up a command line interface to the running container:

docker exec -it "police-data-trust-api-1" /bin/bash

Then run the tests:

flake8 backend/
python -m pytest

Front End Tests

The current frontend tests can be found in the GitHub Actions workflow file frontend-checks.yml

To run the tests locally, first start the application with docker-compose. Then open up a command line interface to the running container:

docker exec -it "police-data-trust-web-1" /bin/bash

Then run the tests:

npm run lint
npm run check-formatting
npm run test
npm run check-types

Documentation

Docs

Code Standards

Typescript Style Guide

This style guide is intended to act as a quick reference for the most common scenarios

Custom Types

For this codebase, we are using interfaces instead of type aliases.

Utilizing Types

Functions

React

Props

Hooks

Forms & Events

Organization of props and attributes

Ordering of components —

HTML Props/attributes order:

Directory structure: