-
Notifications
You must be signed in to change notification settings - Fork 9
Frontend
The frontend is built with Vite, React, TypeScript, TanStack Query, TanStack Router and Chakra UI.
Before you begin, ensure that you have either the Node Version Manager (nvm) installed on your system.
-
You can install nvm using the official nvm guide.
-
After installing nvm, proceed to the
frontend
directory:
cd frontend
- If the Node.js version specified in the
.nvmrc
file isn't installed on your system, you can install it using the appropriate command:
nvm install
- Once the installation is complete, switch to the installed version:
nvm use
- Within the
frontend
directory, install the necessary NPM packages:
npm install
- And start the live server with the following
npm
script:
npm run dev
- Then open your browser at http://localhost:5173/.
Notice that this live server is not running inside Docker, it's for local development, and that is the recommended workflow. Once you are happy with your frontend, you can build the frontend Docker image and start it, to test it in a production-like environment. But building the image at every change will not be as productive as running the local development server with live reload.
Check the file package.json
to see other available options.
-
Start the Docker Compose stack.
-
Download the OpenAPI JSON file from
http://localhost/api/v1/openapi.json
and copy it to a new fileopenapi.json
at the root of thefrontend
directory. -
To simplify the names in the generated frontend client code, modify the
openapi.json
file by running the following script:
node modify-openapi-operationids.js
- To generate the frontend client, run:
npm run generate-client
- Commit the changes.
Notice that everytime the backend changes (changing the OpenAPI schema), you should follow these steps again to update the frontend client.
If you want to use a remote API, you can set the environment variable VITE_API_URL
to the URL of the remote API. For example, you can set it in the frontend/.env
file:
VITE_API_URL=https://my-remote-api.example.com
Then, when you run the frontend, it will use that URL as the base URL for the API.
The frontend code is structured as follows:
-
frontend/src
- The main frontend code. -
frontend/src/assets
- Static assets. -
frontend/src/client
- The generated OpenAPI client. -
frontend/src/components
- The different components of the frontend. -
frontend/src/hooks
- Custom hooks. -
frontend/src/routes
- The different routes of the frontend which include the pages. -
theme.tsx
- The Chakra UI custom theme.
The frontend includes an end-to-end tests using Playwright. To run the tests, you need to have the Docker Compose stack running. Start the stack with the following command:
docker compose up -d
Then, you can run the tests with the following command:
npx playwright test
You can also run your tests in UI mode to see the browser and interact with it running:
npx playwright test --ui
To stop and remove the Docker Compose stack and clean the data created in tests, use the following command:
docker compose down -v
To update the tests, navigate to the tests directory and modify the existing test files or add new ones as needed.
For more information on writing and running Playwright tests, refer to the official Playwright documentation.