This project is a template with some basic functionality for the ASW labs.
| UO | Nombre |
|---|---|
| 301609 | Hugo Suárez Palicio |
| 301901 | Dario Formoso Vijande |
| 301693 | Pablo Polledo Blanco |
| 276366 | Daniel Valle Álvarez |
WebApp: Yovi_es5a WebApp
Documentation: Yovi_es5a_Documentation
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, built with Node.js and Express.database/: Database schema and initialization files.scripts/: Scripts for database setup and maintenance.
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.
- User Registration: The web application provides a simple form to register new users.
- User Service: The user service receives the registration request, processes it, and stores users in a MySQL database.
- GameY: A basic Game engine which only chooses a random piece.
The project now includes a MySQL service that is automatically created when you run docker-compose up --build for the first time. The database and users table are initialized automatically through the users/database/init.sql script.
When you run:
docker-compose up --buildThe following happens automatically:
- MySQL service starts and creates the database
yovi_dband theuserstable (first run only) - The database persists in
mysql_datavolume (survives container restarts) - Users service connects to MySQL using
DB_HOST=mysql(the service name in docker-compose.yml)
Subsequent runs of docker-compose up will use the existing database (no re-initialization).
Copy .env.example to .env for custom configuration:
cp users/.env.example users/.envDefault values in docker-compose.yml:
DB_HOST:mysql(Docker service name)DB_USER:rootDB_PASSWORD:rootpasswordDB_NAME:yovi_db
For production on Azure VM, update .env with:
DB_HOST: Your Azure VM IP addressDB_PASSWORD: Your actual MySQL password
The database is created automatically with:
CREATE DATABASE yovi_db;
USE yovi_db;
CREATE TABLE users (
id INT AUTO_INCREMENT PRIMARY KEY,
username VARCHAR(255) NOT NULL UNIQUE,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);If deploying to Azure VM without Docker:
- Install MySQL on the VM
- Copy
users/scripts/init-db.shandusers/database/init.sqlto the VM - Set environment variables and execute:
export DB_HOST=localhost
export DB_USER=root
export DB_PASSWORD=your_password
chmod +x users/scripts/init-db.sh
./users/scripts/init-db.shThen update .env with your VM credentials before starting the service.
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.
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/createuserto handle user creation and stores users in a MySQL database.package.json: Contains scripts to start the service.Dockerfile: Defines the Docker image for the user service.database/init.sql: SQL script to initialize the database and create the users table.scripts/init-db.sh: Bash script to run on Azure VM to set up the database..env.example: Template for environment variables (credentials and database host).
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.
You can run this project using Docker (recommended) or locally without Docker.
This is the easiest way to get the project running. You need to have Docker and Docker Compose installed.
- Build and run the containers: From the root directory of the project, run:
docker-compose up --buildThis command will:
- Create and start a MySQL database (first run only)
- Build and start the
usersservice (connected to MySQL) - Build and start the
webappservice - Build and start the
gameyand monitoring services
The database initializes automatically on the first run using users/database/init.sql.
2.Access the application:
- Web application: http://localhost
- User service API: http://localhost:3000
- Gamey API: http://localhost:4000
To run the project locally without Docker, you will need to run each component in a separate terminal.
- Node.js and npm installed.
- MySQL server installed and running locally.
First, set up the database. You can do this by:
- Open MySQL client:
mysql -u root -p - Copy and paste the contents of
users/database/init.sql - Or, run:
mysql -u root -p < users/database/init.sql
Then, navigate to the users directory:
cd usersInstall dependencies:
npm installCreate a .env file from .env.example and update with your MySQL credentials:
cp .env.example .env
# Edit .env with your local MySQL connection detailsRun the service:
npm startThe user service will be available at http://localhost:3000.
Navigate to the webapp directory:
cd webappInstall dependencies:
npm installRun the application:
npm run devThe web application will be available at http://localhost:5173.
At this moment the GameY application is not needed but once it is needed you should also start it from the command line.
Each component has its own set of scripts defined in its package.json. Here are some of the most important ones:
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 thewebappand theusersservice concurrently.
npm start: Starts the user service.npm test: Runs the tests for the service.
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