- Under the
srcfolder is the whole project. - There you'll find a
pages,components, andstylesfolders, here you can add or modify the files that you need. - Avoid modifing the root files such as
App.tsx,main.tsxandindex.htmlunless absolutely necessary.
- Have
npminstalled in your system. - Run
npm installin a terminal inside the repository. - Finally, once all the dependencies are installed, run
npm run dev. - The terminal will show a local address where the page is running with live changes.
VITE v6.0.11 ready in 133 ms
➜ Local: http://localhost:5173/
➜ Network: use --host to expose
➜ press h + enter to show help
- Head to the
package.json - If you need the dependency on the dev environment only, add it to the
devDependencies, however if the dependency is needed for the functioning of the app, add it to thedependencies. - Run
npm installin a terminal inside the repository.
- When creating a component that can be reused, save it under the
componentsfolder, under it's own subfolder named like the component with it's own.cssfile (use theHeadercomponent as an example). - When using colors in your styling, avoid hardcoding them, under the
global.cssadd or use a color variable from there.
The project runs C++ version 23, and the minimum CMake version required for the project to run is version 3.30. If you're not sure which CMake version you have installed, use the following command in the terminal to get your current CMake version:
cmake --versionBefore setting up the backend, make sure you have the following installed:
- Install Homebrew if not already installed:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"- To install dependencies and run the project, execute the following commands:
xattr -d com.apple.quarantine ./run.sh
chmod +x ./run.sh
./run.sh- Install Visual Studio with C++ development tools
- Install CMake
- Install MySQL
- Install Boost
- Install CURL
-
Start MySQL Server:
- macOS:
brew services start mysql - Windows: Through Services app or
net start mysqlin admin command prompt
- macOS:
-
Create the database:
mysql -u root -p
CREATE DATABASE pruebaBase;- In the
PokemonBattleArenafolder, create a.envfile with your database credentials:
DB_HOST=tcp://127.0.0.1:3306
DB_USER=your_username
DB_PASSWORD=your_password
DB_NAME=pruebaBase
ALLOWED_ORIGIN=frontend_domain
VITE_SERVER_HOST=backend_domain
./run.shcd backend
mkdir build
cd build
cmake ..
cmake --build .After building, start the server (make sure to be inside the 'build' folder):
- macOS:
./backend - Windows:
.\Debug\backend.exeor.\Release\backend.exe
The server will start running on http://localhost:3000.
POST /signup: Register a new userPOST /login: Authenticate a user
POST /api/pokemon/encounter: Generate a random Pokemon based on zone-
Request body:
{"zone": "forest"} -
Available zones:
forest- grass, bug, poison types (Levels: 5-15)mountain- rock, ground, fighting types (Levels: 15-30)cave- rock, ground, dark types (Levels: 10-25)ocean- water types (Levels: 20-35)beach- water, ground types (Levels: 10-20)volcano- fire, rock types (Levels: 30-45)meadow- grass, fairy, normal types (Levels: 5-15)city- normal, electric, poison types (Levels: 10-25)ruins- ghost, psychic, rock types (Levels: 25-40)jungle- grass, bug, poison, flying types (Levels: 15-30)
-
Response example:
{ "id": 25, "isShiny": false, "level": 8, "name": "pikachu", "sprite": "https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/25.png", "stats": { "attack": 13, "defense": 10, "hp": 23, "special-attack": 13, "special-defense": 12, "speed": 18 }, "types": ["electric"], "zone": "city" }-
-
In
include/database/database_manager.hpp:- Declare your new function in the DatabaseManager class
- Follow the existing function declaration patterns
-
In
src/database/database_manager.cpp:- Implement your declared function
- Use try-catch blocks for error handling
- Use prepared statements for database queries
- In
src/connection.cpp, locate the endpoints section (where other CROW_ROUTE are defined) - Add your new endpoint following this pattern:
CROW_ROUTE(app, "/your-endpoint").methods(crow::HTTPMethod::POST/GET)
([&db](const crow::request& req) {
// Your endpoint logic here
});- Remember to:
- Handle requests and responses in JSON format
- Use the ApiResponse structure for consistent responses
- Include appropriate error handling
- Test your endpoint before committing
All endpoints should return responses in this format:
{
"httpStatusCode": number,
"message": "string"
}You can test the endpoints using curl on your terminal:
curl -X POST http://localhost:3000/api/pokemon/encounter \
-H "Content-Type: application/json" \
-d '{
"zone": "forest"
}'Or you can make use of Postman and follow these steps:
- Open Postman
- Create a new request
- Configure the request as follows:
- Method:
POST/GET/PUT/PATCH/DELETE/HEAD - URL:
http://localhost:3000/your_endpoint_method - Headers:
Content-Type: application/json - Body:
- Select "raw" and "JSON"
- Paste this JSON and modify it to your convenience:
{ "field": "information", }
- Method:
-
MySQL Connection Issues:
- Verify MySQL is running
- Check credentials in .env file
- Ensure database exists
-
Build Errors:
- Verify all dependencies are installed
- Check CMake version compatibility
- Ensure C++ compiler supports C++23
-
ASIO/Crow Errors:
- Verify Boost and ASIO are properly installed
- Check include paths in CMakeLists.txt
-
PokeAPI Connection Issues:
- Check internet connectivity
- Verify CURL is properly installed
- If PokeAPI is down, the generator will use fallback options
-
Missing Crow Submodule: If after pulling changes you notice the 'external/Crow' folder is empty or missing, you'll need to initialize and update the submodule. Run these commands from the backend folder:
git submodule init git submodule update
backend/
├── .env (not in repository - create locally)
├── .env.example (template for .env)
├── CMakeLists.txt (build configuration)
├── external/ (external dependencies)
│ └── Crow/ (Crow framework submodule)
├── include/ (header files)
│ ├── database/
│ ├── models/
│ └── services/
│ └── pokemon_generator.hpp (Pokemon generator service)
└── src/ (source files)
├── connection.cpp (API endpoints)
├── database/
└── services/
└── pokemon_generator.cpp (Pokemon generator implementation)