This is the solution to the XE.gr Web Dev Challenge using React with Vite and ChakraUI
The front end solution consists of a React application served with Vite using ChakraUI as a component library
- ChakraUI, as component library
- react-router, for page routing
- vitest, for running the unit tests with react-testing-library
There are 3 pages accessible, the plain home page, a page to add a new property and a page to list all the properties.
The back end consists of a very simple nodejs web application using expressjs
The server is responsible for interacting with the autocomplete API and persisting the data.
- Get autocomplete suggestions
GET /places?input={query}
- Get all properties from the db
GET /properties
- Create new property entry
POST /property
{
title: string,
area; {
placeId: string,
mainText: string,
secondaryText: string
},
type: string,
price: string,
}
For the data persistance, a very simple solution was selected.
The library chosen is node-persist
, which is a lightweight storage mechanism that stores each entry as a separate file. The folder used in this project is ./server/persist
and it acts as a single table storage mechanism
The reasons it was selected over a DB solution was:
- Simplicity of installation, just a node module, no need for user installation of a specific db (good for demo purposes)
- The data persisted are very simple, a single table, with a very simple, get all values "query", and
node-persist
provides a very fast and easy way to demonstrate a persistance layer without spending much time
For the caching mechanism, node-cache
is used, which is a simple caching mechanism, with a localstorage-like api
*Prerequisites: Docker and Docker Compose need to be installed (installation depends on the platform)
On the root project folder, when the following command is run for the first time, new docker images are going to be build, containing all the required installation packages
docker-compose up
For manual installation, node v14+
is required
cd server/
npm install
cd client/
npm install
Using docker compose, the following command will start both services
docker-compose up
The back end service is running on locahost:4001
The front end service is running on localhost:4000
. Visit localhost:4000 to interact with the application
Assuming node v14+ is installed and the installation steps have already been performed performed
cd client
npm run dev
cd server
node index.js
The back end service is running on locahost:4001
The front end service is running on localhost:4000
. Visit localhost:4000 to interact with the application
In case there are other services running on ports 4000 and 4001 on your local machine, modify the left hand side values of the ports
sections on docker-compose.yml
file. Do not forget to change the enviromental variable for the port (VITE_PROPERTIES_API_PORT
) on the front end service accordingly.
With the current setup, the application is only accessible from the machine it is running on. In case you want to run the application on another device on your local network, like a phone, change the VITE_PROPERTIES_API_URL
env variable in the compose file, to your local ip address
For the manual running of the applications, please change the .env.local
files on each component folder
For the testing, vitest
, react-testing-library
and cypress
were utilised and only for the front end application.
In order to run the front end unit tests, run the following commands
cd client
npm test
For the more complex components, like the form and the list of the persisted properties, cypress was used.
In order to run them, run the following commands
cd client
npm run cupress:run
The component tests are pretty simple and just verify very basic usage