Skip to content

Latest commit

 

History

History
188 lines (125 loc) · 5.37 KB

README.md

File metadata and controls

188 lines (125 loc) · 5.37 KB

A Full-Stack Rust application where users can vote for their favorite images. Inspired from the Elo rating system used in chess, each image is assigned a rating. A Multi-Layer Feed-Forward Network is then used to analyze voting patterns and image characteristics to predict accurate base rankings for new images.

Warning

At the moment, the API is deployed on render (https://api.b1o.co) which can lead to significant loading times when opening the web-app.

OVERVIEW

CONFIG

Start backend

cargo build

cargo install cargo-make

cargo run --bin backend

OR

cargo make start_back_prod

Start frontend

(npm install)

(npm install -g pnpm)

(npm install -g wasm-pack)

pnpm install --dir ./frontend

pnpm run --dir ./frontend build

pnpm run --dir ./frontend dev

OR

cargo make start_front_prod

OR

simple-http-server ./frontend/dist -i -p 8000 --nocache --try-file ./frontend/dist/index.html

[!NOTE] You might have to Set-ExecutionPolicy RemoteSigned to run pnpm commands on Windows.

RUNNING ON DOCKER

First install Docker and docker-compose. You can find instructions here and here.

In theory it would be sufficient to run docker-compose up and, once everything is up and running, visit http://localhost:3000 to view the app.

Note

docker-compose will start the app in production mode.

To push to your remote docker-repository run:

docker-compose up
docker tag b1o-backend:latest <docker-username>/<docker-repository>:backend
docker tag b1o-frontend:latest <docker-username>/<docker-repository>:frontend
docker push <docker-username>/<docker-repository>:backend
docker push <docker-username>/<docker-repository>:frontend

RUNNING OUTSIDE DOCKER

Database Setup

Make sure to have a Postgres database with all read and write priviledges running.

Example:

sudo -u postgres psql
create database b1o;
create user coreuser with encrypted password 'password';
grant all privileges on database b1o to coreuser;
exit

Note

If you get an error message saying "connection refused", your postgres server may have installed on port 5433 rather than the default 5432. To resolve this, try using the -p flag as follows:

sudo -u postgres psql -p 5433

ENV file

You'll need a .env file to hold necessary environment variables. If you're running docker, it should be named docker.env and contain the following:

FRONTEND_HOST=localhost
FRONTEND_PORT=3000
FRONTEND_PROTOCOL=http

DATABASE_PROTOCOL=postgres
DATABASE_PORT=5432
DATABASE_URL=<SECRET>
POSTGRES_USER=<SECRET>
POSTGRES_PASSWORD=<SECRET>
POSTGRES_DB=<SECRET>
POSTGRES_HOST=<SECRET>

BACKEND_HOST=localhost
BACKEND_HOST_INTERNAL=0.0.0.0
BACKEND_PORT=8080
BACKEND_PROTOCOL=http

MONGO_URL=<SECRET>
MONGO_COLLECTION=<SECRET>

Running the App

Cargo Make as a task running to simplify starting and stopping the application. To use cargo make, run cargo install cargo-make.

To start the application in development mode, run cargo make start_all.

To start the application in production mode, run cargo make start_all_prod.

Note

On Windows, you might see the following error:

<e> [webpack-dev-middleware] Error: spawn npm ENOENT
<e>     at ChildProcess._handle.onexit (node:internal/child_process:285:19)
<e>     at onErrorNT (node:internal/child_process:483:16)
<e>     at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
<e>   errno: -4058,
<e>   code: 'ENOENT',
<e>   syscall: 'spawn npm',
<e>   path: 'npm',
<e>   spawnargs: [ 'install', '-g', 'wasm-pack' ]
<e> }

If you get this error, run the following command and then try again:

npm install -g wasm-pack

To view all the available tasks, open Makefile.toml.

CONTRIBUTING

If you find any bugs or have suggestions for improvement, please open a new issue or submit a pull request.

LICENSE

This project is licensed under the GPL-3.0 license. See the LICENSE file for details.

Note

The general concept has been inspired by this and this article.


© Carlo Bortolan

Carlo Bortolan  ·  GitHub carlobortolan  ·  contact via [email protected]