Skip to content

Arquisoft/yovi_es1c

Repository files navigation

Yovi_es1c - Game Y at UniOvi

Release — Test, Build, Publish, Deploy Quality Gate Status Coverage CodeScene Average Code Health

This project is a template with some basic functionality for the ASW labs.

El proyecto está desplegado en: aqui

Contributors

  • UO302313 - David Fernando Bolaños Lopez
  • UO294946 - Raúl Velasco Vizán
  • UO301919 - Ángela Nistal Guerrero
  • UO300731 - Olai Navarro Baizán
  • UO301831 - Alejandro Requena Roncero

Project Structure

The project is divided into three main components, each in its own directory:

  • webapp/: A frontend application built with React, Vite, and TypeScript.
  • users/: A backend service for managing users and profile/statistics data, built with Node.js and Express.
  • auth/: A backend authentication service (Node.js + Express + TypeScript) for register/login/refresh and internal JWT verification.
  • gamey/: A Rust game engine and bot service.
  • docs/: Architecture documentation sources following Arc42 template

Each component has its own package.json file with the necessary scripts to run and test the application.

Basic Features

  • User Registration: The web application provides a simple form to register new users.
  • User Service: The user service receives the registration request, simulates some processing, and returns a welcome message.
  • GameY: A basic Game engine which only chooses a random piece.

Components

Webapp

The webapp is a single-page application (SPA) created with Vite and React.

  • src/App.tsx: The main component of the application.
  • src/RegisterForm.tsx: The component that renders the user registration form.
  • package.json: Contains scripts to run, build, and test the webapp.
  • vite.config.ts: Configuration file for Vite.
  • Dockerfile: Defines the Docker image for the webapp.

Users Service

The users service is a simple REST API built with Node.js and Express.

  • users-service.js: The main file for the user service. It defines an endpoint /createuser to handle user creation.
  • package.json: Contains scripts to start the service.
  • Dockerfile: Defines the Docker image for the user service.

Auth Service

The auth service is the authentication backend built with Node.js, Express and TypeScript.

  • src/index.ts: Entry point and route mounting under /api/auth.
  • src/routes/auth.routes.ts: Auth endpoints (register, login, refresh, verify).
  • openapi.yaml: OpenAPI 3.x contract for Auth endpoints.
  • package.json: Contains scripts for run/test/coverage.

Auth endpoints:

  • POST /api/auth/register
  • POST /api/auth/login
  • POST /api/auth/refresh
  • POST /api/auth/verify (internal only; blocked externally in Nginx)

Important env vars:

  • JWT_SECRET (required)
  • AUTH_DB_PATH (defaults to /app/auth/data/auth.db in compose)

Internal verification URL for service-to-service calls:

  • AUTH_INTERNAL_VERIFY_URL=http://auth:3001/api/auth/verify (recommended timeout: 500ms–1s)

Gamey

The gamey component is a Rust-based game engine with bot support, built with Rust and Cargo.

  • src/main.rs: Entry point for the application.
  • src/lib.rs: Library exports for the gamey engine.
  • src/bot/: Bot implementation and registry.
  • src/core/: Core game logic including actions, coordinates, game state, and player management.
  • src/notation/: Game notation support (YEN, YGN).
  • src/web/: Web interface components.
  • Cargo.toml: Project manifest with dependencies and metadata.
  • Dockerfile: Defines the Docker image for the gamey service.

Running the Project

You can run this project using Docker (recommended) or locally without Docker.

With Docker

This is the easiest way to get the project running. You need to have Docker and Docker Compose installed.

  1. Build and run the containers: From the root directory of the project, run:
docker-compose up --build

This command will build the Docker images for both the webapp and users services and start them.

2.Access the application:

Without Docker

To run the project locally without Docker, you will need to run each component in a separate terminal.

Prerequisites

1. Running the User Service

Navigate to the users directory:

cd users

Install dependencies:

npm install

Run the service:

npm start

The user service will be available at http://localhost:3000.

2. Running the Web Application

Navigate to the webapp directory:

cd webapp

Install dependencies:

npm install

Run the application:

npm run dev

The web application will be available at http://localhost:5173.

3. Running the Auth Service

Navigate to the auth directory:

cd auth

Install dependencies:

npm install

Run the service:

npm run start

Run tests and coverage:

npm test
npm run test:coverage

Verify auth.db exists (from monorepo root, when running with compose volume ./data:/app/data):

test -f ./data/auth.db && echo "auth.db exists"

4. Running the GameY application

At this moment the GameY application is not needed but once it is needed you should also start it from the command line.

Available Scripts

Each component has its own set of scripts defined in its package.json. Here are some of the most important ones:

Webapp (webapp/package.json)

  • npm run dev: Starts the development server for the webapp.
  • npm test: Runs the unit tests.
  • npm run test:e2e: Runs the end-to-end tests.
  • npm run start:all: A convenience script to start both the webapp and the users service concurrently.

Users (users/package.json)

  • npm start: Starts the user service.
  • npm test: Runs the tests for the service.

Auth (auth/package.json)

  • npm run start: Starts the auth service.
  • npm test: Runs auth service tests.
  • npm run test:coverage: Runs auth tests with coverage.
  • npm run db:init: Initializes the auth database schema.

Gamey (gamey/Cargo.toml)

  • cargo build: Builds the gamey application.
  • cargo test: Runs the unit tests.
  • cargo run: Runs the gamey application.
  • cargo doc: Generates documentation for the GameY engine application

Environment Configuration

Before running the project (especially with Docker), you must create a .env file in the root directory. This file is not committed to the repository for security reasons.

Create a file named .env and add the following variables:

# Secret key used to sign JWT tokens for authentication
JWT_SECRET=yovi_es1c_2526

# Internal path where the services will look for the database files inside the containers
DB_PATH=/app/data/