This project is my first attempt at using Golang and Next. It uses web-socket communication between clients and the server to instantly send messages. Has simple token based authentication and users can sign up using an email and password.
- Golang
- Docker or PostgreSQL
- Make
- Migrate
- If you do not have make installed, please install it. For debian based systems, you can simply run the commands below.
sudo apt update
sudo apt install make
For windows, refer to this discussion.
If you still do not wish to install it, refer to server/Makefile
and simply run the respective commands listed there.
-
If you do not have go-migrate installed, install it from here.
-
Clone the repository and go inside the server directory.
cd server
- You will need to setup a PostgreSQL database. We recommend using docker as the Makefile uses docker commands below.
make postgresinit
make createdb
You can also use a standalone PostgreSQL database, however you will need to change the database connection url in the link and run the commands on your own. The Makefile's command postgresinit
and createdb
shows how to configure a PostgreSQL database on docker.
- After setting up the PostgreSQL database, you wll need to setup the database schema. For this you can use the Makefile's command.
make migrateup
- The application's backend server should be ready now. To run it simply use
make dev
- Install Node.js. Download it from here. We recommend version 22.
- Install a package manager. Pnpm can be downloaded by running
npm install -g @pnpm/exe
- Install the dependencies using
pnpm install
- The app should be ready. Run the following command
pnpm dev
- Next.js
- shadcn/ui
- Tailwindcss
- React useWebSocket for managing websocket communication.
- Zod for validating data received from the server.
- Go
- Gin web framework.
- Gorilla WebSocket to write and read messages from the websocket connection.
- sqlc to generate type safe interfaces for
SQL
queries.
The database handles user information and text messages. The diagram below illustrates the design.