- PostgreSQL
- Golang 1.21
- SQLC (jump)
- VueJS
- Vite (bundler)
After cloning the repo, you need to install Go dependencies. Run the following command:
go mod tidy
Then, install NodeJS dependencies. Run the following command:
yarn install
For database initialization section you can found it here: Click the link
By using sqlc, this app does not require you to write the models mapping of your table into Golang native structs yourself.
Moreover, you can write a raw SQL query in a .sql
file and convert it into a Golang native func
by placing the .sql
file under the scripts/queries
directory.
โโโ cmd
โ โโโ migrate
โ โ โโโ main.go
โ โ โโโ migrations
โ โ โโโ 00_initial.up.sql
โโโ scripts
โ โโโ queries
โ โโโ order_items.sql (EXAMPLE)
โ โโโ orders.sql (EXAMPLE)
Since you already have your migration and query files, the next step is to generate the struct
and func
for it by running this command:
go run cmd/sqlc/main.go
This will generate .go
files with an expected output like this:
โโโ internal
โ โโโ repo
โ โโโ psql
โ โโโ db.go
โ โโโ models.go
โ โโโ order_items.sql.go
โ โโโ orders.sql.go
โ โโโ querier.go
You can read the file as well by:
cat internal/repo/psql/models.go
NOTE: If you've done Database Initialization
steps from here, make sure to clean up the temporary files that generated in that step.
To run the app locally, you need to run migration first (can skip if you are from Database Initialization
steps)
DATABASE_URL=postgres://user:password@ip:5432/dbname go run cmd/migrate/main.go
Then you can start the backend:
DATABASE_URL=postgres://user:password@ip:5432/dbname go run cmd/server/*.go
# http start at :3980
Then, frontend:
VITE_SERVER_URL=http://localhost:3980 yarn start
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
# โ โ
# โ Serving! โ
# โ โ
# โ - Local: http://localhost:8080 โ
# โ - Network: http://10.XX.XXX.XX:8080 โ
# โ โ
# โ Copied local address to clipboard! โ
# โ โ
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Or:
VITE_SERVER_URL=http://localhost:3980 yarn start:dev
# Open: http://localhost:5173/
NOTE: this steps below is assume that you are already have a running PostgreSQL instance.
Run the migration (skip if already done):
DATABASE_URL=postgres://user:password@ip:5432/dbname go run cmd/migrate/main.go
Build docker image for backend:
docker build \
-t silver-bassoon/backend \
-f Dockerfile.backend \
--no-cache .
Run backend container from created image:
docker run -d \
--name packform-be \
-e DATABASE_URL='postgres://user:password@ip:5432/silver_bassoon?sslmode=disable' \
-p 3980:3980 \
silver-bassoon/backend
Build docker image for frontend:
docker build \
-t silver-bassoon/frontend \
-f Dockerfile.frontend \
--build-arg server_url=http://localhost:3980 \
--build-arg use_browser_tz=false \
--no-cache .
Run frontend container from created image:
docker run -d \
--name packform-fe \
-p 8080:80 \
silver-bassoon/frontend
By using docker compose
, you are not required to have PostgreSQL running, and you are not required to run the migration as well. Everything will be done automatically, encapsulated.
docker compose up -d
go test -v ./...
yarn test