Skip to content
Merged
16 changes: 16 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Dependencies
node_modules/

# Build output
dist/

# Environment variables and secrets
.env
.env.*
!.env.example

# Logs
*.log

# macOS
.DS_Store
127 changes: 124 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Before a pull request can be merged:
request, and approvals from staff do not count — you review each other's
code.
2. **Every review comment must be marked resolved.** Reply to each one, fix it
or explain why not, then click *Resolve conversation*.
or explain why not, then click _Resolve conversation_.
3. **Pushing new commits dismisses the approval**, so if you change something
after being approved, ask for another review. This is deliberate: what was
approved is what gets merged.
Expand All @@ -29,8 +29,7 @@ Before a pull request can be merged:

The project plan is to build an application that displays information about a Pokèmon draft. This will involve being able to search through Pokèmon to set up teams, save than, and display information on them. This information will include move access, common vulnerabilities and stats. Adding to this, one should be able to select format, meaning that if you select RBY (Generation 1), only Pokèmon from gen 1 with the moves and stats they had back then should apper. While one would think just 1000+ Pokèmon is not a particularly large dataset, with the relations between moves, formats and Pokèmon, needing to relate them in an orderly manner, and having to conjoin data for the Natdex-formats who keeps cut content, the need for scalable solution are certainly present.

![Example from prep spreadsheet]()
---
## ![Example from prep spreadsheet]()

# Dataset

Expand Down Expand Up @@ -65,3 +64,125 @@ The overall system architecture is shown below.

For a more detailed explanation of the architecture, see
[Architecture documentation](docs/architecture.md).

# Backend Setup

The backend uses Node.js, TypeScript, Apollo Server, GraphQL, and MariaDB. It exposes a GraphQL API that the React frontend uses to retrieve Pokémon data.

## Requirements

- Node.js and npm (Node.js 24 or newer)
- Access to the environment where the backend and database will run
- MariaDB with the Pokémon dataset imported

## Installation

From the repository root, run:

```bash
cd backend
npm install
```

## Database Configuration

Create a `.env` file in the `backend` directory with the following variables:

```dotenv
DB_HOST=127.0.0.1
DB_PORT=3306
DB_USER=your_database_username
DB_PASSWORD=your_database_password
DB_NAME=pokemon
```

Replace the username and password placeholders with valid database credentials. Set the host and port to match your database configuration.

When running the backend locally on your Mac and connecting to MariaDB on the NTNU VM through an SSH tunnel, use the local tunnel endpoint instead:

```dotenv
DB_HOST=127.0.0.1
DB_PORT=3307
```

Keep your actual database credentials in `.env`. Do not commit `.env` files or database credentials to the repository.

## Build and Start the Backend

From the `backend` directory, compile the TypeScript code:

```bash
npm run build
```

Start the compiled server:

```bash
npm start
```

For development with automatic restarts, use:

```bash
npm run dev
```

The GraphQL API listens on port `3001` and is available at [http://localhost:3001/](http://localhost:3001/) from the machine running the backend.

## Example GraphQL Queries

Retrieve Pokémon:

```graphql
query {
pokemons {
id
name
type
}
}
```

Retrieve one Pokémon by ID:

```graphql
query {
pokemon(id: "pikachu") {
id
name
type
}
}
```

The `type` field contains the Pokémon's type or types as a string. The `pokemon` query returns `null` when no Pokémon matches the supplied ID.

## Frontend Integration

The React frontend uses Apollo Client to communicate with the GraphQL API. Configure the frontend's GraphQL endpoint to match the backend's accessible URL.

When the backend runs locally on your Mac and the database is on the NTNU VM, keep the database SSH tunnel open while using the application:

```bash
ssh -N -L 3307:127.0.0.1:3306 <username>@it2810-24.idi.ntnu.no
```

Replace `<username>` with your VM username. This tunnel forwards local port `3307` to MariaDB on the VM's port `3306`.

If the backend itself runs on the VM and you want to access the GraphQL API locally, use a separate tunnel:

```bash
ssh -N -L 3001:127.0.0.1:3001 <username>@it2810-24.idi.ntnu.no
```

Keep the relevant SSH session open while using the tunnel.

## Importing the Dataset

The backend includes an import script for importing the Pokémon Showdown dataset. To run it, configure the database connection in `.env`, then execute:

```bash
npm run import
```

Run the import when needed; it may modify the database contents.
Loading