XenElectronic
This is an MVP web application built on top of React which satisfies the following requirements:
- Customers should be able to view the list of the products based on the product categories
- Customers should be able to add the products to the shopping cart
- Customers should be able to view the products listed on the shopping cart
- Customers should be able to remove the products listed on the shopping cart
- Customers should be able to checkout shopping cart and continue their transaction to payment
Getting Started
Prerequisites
Setup Environment
Execute the following command to setup development environment and installing project dependencies:
$ make setup
It will create symlink from etc/git-pre-push
file to .git/hooks/pre-push
to execute make test
every time you push to upstream.
Setup Database
To setup database, first you have to create a new database in your PostgreSQL server.
For example, a database named xen_electronic
is created
Then, using golang-migrate, execute the following command:
$ migrate -database 'postgres://user:pass@localhost:5432/xen_electronic?sslmode=disable' -path db/migrations up
Installing
To install, you need to compile the source first.
$ make build
The compiled binary will be at out/xenelectronic-server
path.
Running the server
First, set database connection string through environment variable.
$ export DSN='postgres://user:pass@localhost:5432/xen_electronic'
You can also set both host
and port
where the program will bind to through environment variable or command flag
$ HOST=0.0.0.0 PORT=9000 ./out/xenelectronic-server
or
$ ./out/xenelectronic-server --port=9000
To know more about what parameters are available within the program, use command below.
$ ./out/xenelectronic-server --help
Running the frontend
This project uses React for the frontend which is placed under web/
directory.
To run the frontend server, install the dependencies first.
$ cd web
$ npm install
After that, to configure the frontend to connect to local server, you need to set
REACT_APP_API_BASE_URL
environment variable.
$ REACT_APP_API_BASE_URL=http://localhost:9000 npm start
You can also set it through .env
file. For example:
REACT_APP_API_BASE_URL=http://localhost:9000
BROWSER=none
then execute npm start
.
Shortcuts
A single command to test, build, and run server:
$ make
To serve the frontend:
$ make run-frontend
Running the tests
Execute the following command:
$ make test
Deployment
A sample server is deployed at Heroku, while the frontend is hosted at Netlify.
Notes
To deploy to Heroku, please set the host
to 0.0.0.0
to enable Heroku
routing the traffic to the server. You can use it by passing environment
variable HOST=0.0.0.0
or command line flag --host=0.0.0.0
.
API Documentation
The API documentation is written using swagger at swagger.yml
file.
You can view it using swagger tool by executing the following command:
$ swagger serve --flavor=redoc -p 10000 ./swagger.yml
Or, you can also access the embedded documentation here:
https://xenelectronic.herokuapp.com/docs
API Generation
The server is generated using go-swagger from swagger.yml
. To do that, execute the following command:
$ swagger generate server -A xenelectronic -f ./swagger.yml
License
This project is licensed under the MIT License - see the LICENSE file for details