Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ dist-ssr
# Test coverage
coverage

# Raw Perenual API responses cached by backend/seedDataFetch.js
backend/data/

# Environment variables (.env.example and frontend/.env.production are committed on purpose)
.env
*.local
Expand Down
68 changes: 40 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,33 @@ I <3 Plants is a web app for finding plants that suit you and reading about them
## Concept

- **The problem:** A long plant catalogue is hard to get started with if you do not know what you are looking for.
- **The idea:** Instead of scrolling through a long list, you first choose your preferences for water, sun and care. The app then shows you one plant at a time, starting with the plants that match your preferences best. You like or skip each plant, and the ones you like are saved in My Matches so you can come back to them later.
- **Low threshold:** There is no login. A user is created the first time the app is opened, so anyone can start finding plants right away, without creating an account.
- **For those who know what they want:** Users who already know what they are looking for can search and filter the whole collection instead.
- **The idea:** Instead of scrolling through a long list, you can easily match with plants by either swiping right or left on them. You can also set your preferences for water, sun and care if you know them, or take the plant owner test and get suggestions for preferences. Your preferences will be highlighted on the plants, and the plants that match your preferences best will be shown first. The ones you like are saved in My Matches so you can come back to them later. Alternatively, if you know what plant you want to read about, you can search for it directly on the Explore Plants page.
- **Low threshold:** There is no login. A user is created the first time the app is opened and is connected to your browser, so anyone can start finding plants right away, without creating an account.

## Link to VM

http://it2810-03.idi.ntnu.no/project2/

## Documentation

| Document | Contents |
| --------------------------------------- | ------------------------------------------------------------------------------------------------- |
| [architecture.md](docs/architecture.md) | How the frontend, backend and database fit together, the plant data, data flow and code structure |
| [tests.md](docs/tests.md) | Test strategy, how to run the tests, coverage and what the tests found |
| [quality.md](docs/quality.md) | Work practices, accessibility, sustainable web development and design choices |
| [ai-usage.md](docs/ai-usage.md) | How AI tools were used during development |
| Document | Contents |
| --------------------------------------- | --------------------------------------------------------------------------------------------------------------------------- |
| [architecture.md](docs/architecture.md) | How the frontend, backend and database fit together, the plant data, data flow, code structure and the architecture choices |
| [tests.md](docs/tests.md) | Test strategy, how to run the tests, coverage and what the tests found |
| [quality.md](docs/quality.md) | Work practices, accessibility, sustainable web development and design choices |
| [ai-usage.md](docs/ai-usage.md) | How AI tools were used during development |

## Core features

- **Plant Match:** The user swipes the card right to match with a plant and left to skip it, or uses the ♥ and ✖ buttons. Plants matching the most preferences come first, otherwise the order is random. The deck is kept while the user visits other pages, so they can continue where they left off.
- **My Matches:** Collects liked plants from both Plant Match and Explore Plants, with the same search, filters and match counts as Explore Plants. Both pages can also sort the plants by how well they match the user's preferences. The user only stores plant ids, and the list is fetched one page at a time, so responses do not grow with the number of matches.
- **Explore Plants:** Search, filtering, sorting and pagination run in the backend, so the frontend only receives one page at a time, whatever the size of the collection. The state is kept in the URL, so a view survives a refresh and can be shared as a link. Each filter value shows how many plants it would give, and values that would give none can't be chosen, so filtering never ends in an empty list.
- **Plant Owner Test:** Four questions give one of six plant owner types, whose picture can be used as profile picture. The result also suggests one preference each for watering, light and care level, based on the answers and the description of the type. The user chooses which of them to add, and they are added to the preferences they already have, so PlantMatch puts plants that suit them first right away.
- **Walkthrough:** A short guide opens on the first visit and explains what the user can do on each page. It can be reopened at any time with the ? button, starts at the current page (or at the welcome step on the home page), links to each page and lets the user change language without closing it.
- **Plant Match:** The user swipes the card right to match with a plant and left to skip it, or uses the ♥ and ✖ buttons. Plants matching the most preferences come first, otherwise the order is random. This is to make it easier for the user to find plants they are compatible with. When plants are matched on Plant Match or Explore Plants, a badge on My Matches in the sidebar shows how many plants have been matched since the page was last opened, to make it easier to understand where the matches end up.

- **My Matches:** Collects the plants the user has liked (♥) on Plant Match and Explore Plants, and lets them search, filter and sort among them, with a count of how many matches they have.

- **Explore Plants:** The page where the user can find specific plants they are searching for without having matched with them. Search, filtering and sorting are possible. The state is kept in the URL, so a view survives a refresh and the user can share the page as a link.

- **Plant Owner Test:** A short test (four questions) to give the user insight into what kind of plant owner they are. It is meant to help them set one preference each for watering, light and care level, based on the answers and the description of the type. It also gives an avatar that can be used as a profile picture that can only be achieved through the test to communicate the type of plant owner the user is.

- **Walkthrough:** A short guide opens on the first visit and explains what the user can do on each page. It can be reopened at any time with the ? button. It is meant to help with any confusion connected to how the application works, and help the user to get started.

## Tech stack

Expand All @@ -40,10 +43,6 @@ http://it2810-03.idi.ntnu.no/project2/
| Testing | Vitest, React Testing Library, jsdom, mongodb-memory-server, Playwright, axe-core |
| Tooling | ESLint, Prettier, GitHub Actions |

## Architecture

See [architecture.md](docs/architecture.md) for how the frontend, backend and database fit together, and how the code is organised. It also describes the plant data and the Perenual API, why we chose GraphQL and MongoDB, and how the data flows from the API to the frontend.

## Run the project locally

### Requirements
Expand All @@ -53,8 +52,6 @@ See [architecture.md](docs/architecture.md) for how the frontend, backend and da
- Access to the NTNU network (use the NTNU VPN if you are not on campus)
- An NTNU user with access to the VM `it2810-03.idi.ntnu.no`

The local backend uses the database on the VM, which is why you need the NTNU network and a user on the VM.

### 1. Install dependencies

```bash
Expand All @@ -71,7 +68,7 @@ This installs the dependencies for the repo root, `backend` and `frontend`, whic
cp backend/.env.example backend/.env
```

The backend reads the database address, the database name and its port from this file. The default values work as they are. `.env` is ignored by git and must never be committed.
The backend reads the database address, the database name and its port from this file. The default values work as they are. `PERENUAL_API_KEY` can be left empty, since it is only used by the seed script (`npm run seed`), which the running app does not need. `.env` is ignored by git and must never be committed.

### 3. Open an SSH tunnel to the database (in a separate PC-terminal)

Expand Down Expand Up @@ -117,10 +114,31 @@ Apache serves the built frontend on the VM. The build was copied to the folder A

MongoDB is installed directly on the VM and only listens on `127.0.0.1`, so it cannot be reached from outside the VM. The plant data was loaded once with `npm run seed` in the backend, so the running app never calls the Perenual API and is not limited by its daily request quota (see [architecture.md](docs/architecture.md#data-source-the-perenual-api)).

### How to start the backend if it stops

On the VM, the backend runs in pm2 under the name `plants-backend`, as the user `alexajah`, from `/home/alexajah/T03-Project-2/backend`. pm2 restarts it if it crashes or the VM reboots.

Log in with:

```bash
ssh <ntnu-username>@it2810-03.idi.ntnu.no
```

If you are not `alexajah`, put `sudo -u alexajah` in front of the pm2 commands, since pm2 only shows the processes of the user who started them.

```bash
pm2 list # is plants-backend online?
pm2 restart plants-backend # start it again if it is not
```

If the logs show that the backend cannot connect to MongoDB, the database has stopped and must be started before the backend is restarted.

## Testing

The application is tested on three levels: component tests for the frontend (Vitest and React Testing Library), backend tests against an in-memory MongoDB (Vitest and mongodb-memory-server), and end-to-end and API tests with Playwright, which also check all pages against WCAG 2.1 AA with axe. Each level has its own purpose: the component and backend tests are fast and test one part at a time, also cases that are hard to reach through the UI, while the end-to-end tests check that the parts work together the way a user experiences them. None of the tests use the database on the VM. The backend and e2e tests use an in-memory MongoDB filled with known test data, so every run starts from the same data, the tests never change real user data, and they need neither the VPN nor the SSH tunnel. The tests run in GitHub Actions on every pull request, so a change that breaks a test is caught before it is merged.

The first time you run the e2e tests, install the browser with `npx playwright install chromium`. If the tests do not start, see [If the tests do not start](docs/tests.md#if-the-tests-do-not-start).

Run the tests from the repo root:

```bash
Expand All @@ -131,21 +149,15 @@ npm run test:e2e

`npm run test:all` runs all three after each other, and `npm run ci:all` first does a clean install (`npm ci`) in the root, backend and frontend, and then runs all the tests. Only run one e2e test run at a time, since all the e2e tests share the same test database and servers.

The first time you run the e2e tests, install the browser with `npx playwright install chromium`.

### Test coverage

| Part | Statements | Branches | Functions | Lines |
| -------- | ---------- | -------- | --------- | ------- |
| Frontend | 97.38 % | 93.86 % | 96.76 % | 98.39 % |
| Frontend | 97.44 % | 93.78 % | 96.83 % | 98.43 % |
| Backend | 100 % | 100 % | 100 % | 100 % |

See [tests.md](docs/tests.md) for the test strategy, more ways to run the tests, how to run the tests with coverage and screenshots of the coverage reports, what the test files cover and what the tests found.

## Quality and design

See [quality.md](docs/quality.md) for work practices, accessibility, sustainable web development and design choices.

## Known issues

- The plant images are stored as base64 in the database, which takes about 33 % more space than image files. See [Limitations of the architecture](docs/architecture.md#limitations-of-the-architecture) for why we chose it and how it could be improved.
Expand Down
Loading
Loading