
BHS-task
A test assignment for a backend developer at BHS
Task
- Go language, JWT Auth
- Create a basic web application in the Go language (the framework is not important) with a JWT-based authentication system. The user must be able to register, log in and log out of the system.
- Working with PostgreSQL
- Use PostgreSQL to store information about users and their "assets". Create the users and assets tables linked by a one-to-many relationship. Fields for assets: id, name, description, price. Fields for users: id, username, password_hash. Optionally, you can add additional fields.
- Implement the functionality of adding and removing assets for registered users.
- Implement a mechanism for processing asset purchases. It is important to get rid of possible data races.
- Connect the database to the app on Go. Use the migration mechanism (migrate library). To work with the database, you can use both ORM (for example, GORM) and pure SQL and add-ons on it (for example, SQLX, using squirrel will also be a plus).
- API and documentation
- Create a RESTful API for working with assets and users. Try to adhere to the rules of clean architecture (using a template will be a plus https://github.com/evrone/go-clean-template ).
- Create API documentation using Swagger or other similar tools.
- Tests
- *Makefile
- Create and write a Makefile with the ability to run the entire application with the infrastructure via docker-compose (make up) and only the infrastructure (in our case, only the database) via docker-compose or a separate container (make dev-up). Additional commands are not required, but they will be a plus (make test, make dev-down, make down, etc.).
Tech Stack
Server: Go, JWT, PostgreSQL, Chi
Installation
Install make, go, docker and docker-compose (if it not installed):
For Debian/Ubuntu based systems:
# Update package index
sudo apt update
# Install make, Go, Docker, Docker Compose, and golangci-lint
sudo apt install -y wget make golang docker.io docker-compose curl
# Install Allure
wget https://github.com/allure-framework/allure2/releases/download/2.32.0/allure_2.32.0-1_all.deb
sudo dpkg -i allure_2.32.0-1_all.deb
rm allure_2.32.0-1_all.deb
# Install golangci-lint
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s latest
# Start and enable Docker service
sudo systemctl start docker
sudo systemctl enable docker
# Verify installation
make --version
go version
docker --version
docker-compose --version
golangci-lint --version
allure --version
For macOS using Homebrew:
# Install dependencies using Homebrew
brew install make go docker docker-compose golangci-lint allure
# Verify installation
make --version
go version
docker --version
docker-compose --version
golangci-lint --version
allure --version
Run Locally
Clone the project
git clone https://github.com/Klef99/bhs-task.git
Go to the project directory
cd bhs-task
Rename .env.example to .env and edit the variables in it
Start the server
make up
Avaliable commands
Usage:
make <target>
help Display this help screen
up Run docker-compose
down Down docker-compose
dev-up Up infrastructure
dev-down Down infrastructure
mock-generate generate mocks
rm-volume remove docker volume
linter-golangci check by golangci linter
test run test
cover create cover file report
migrate-create create new migration
migrate-up migration up
migrate-down migration down
integration-test run integration-test
allure run allure on 9999 port
Running Tests
To run tests, run the following command
make test
API Documentation

The API description is available at http://<ip or domain>:<port>/swagger/index.html.
If the project is running locally with the standard settings: http://localhost:8080/swagger/index.html
Acknowledgements