DebtLog is a REST API built with Go.
It’s my personal learning project for backend development, while also serving as a tool to track money debts between me and my friends.
Right now it focuses only on money debt, but I plan to expand it later for other types of debts (items, favors, etc).
This project is a hands-on way for me to explore:
- Building a REST API with Go and Gin
- Working with relational databases using GORM and PostgreSQL
- Authentication & Authorization with JWT
- Configuration management with
.env - Database migrations and ORM models
- Testing in Go
- User registration and authentication (JWT-based)
- Create new debts (who owes who, amount, notes)
- Fetch debts (all debts, or specific debt by ID)
- Update or settle a debt
- Delete a debt
- Language: Go (v1.25.1)
- Framework: Gin (
github.com/gin-gonic/gin) - ORM: GORM (
gorm.io/gorm,gorm.io/driver/postgres) - Database: PostgreSQL
- Auth: JWT (
github.com/golang-jwt/jwt/v5) - Config: godotenv (
github.com/joho/godotenv)
debtlog-api/
├── config/ # Configuration (database, env setup, etc.)
│ └── db.go
│
├── controllers/ # Controllers (handle HTTP requests)
│ ├── auth_controller.go
│ ├── debter_controller.go
│ ├── debtlog_controller.go
│ ├── receipt_controller.go
│ └── share_controller.go
│
├── middleware/ # Custom middlewares
│ └── auth_middlewa re.go
│
├── models/ # Database models (GORM)
│ ├── debt_link.go
│ ├── debt_log.go
│ ├── debt_log_debter.go
│ ├── debter.go
│ ├── receipt.go
│ └── user.go
│
├── routes/ # Route definitions
│ └── routes.go
│
├── tests/ # Unit & integration tests
│ └── auth_test.go
│
├── utils/ # Utility functions
│ └── jwt.go
│
├── .env # Environment variables
├── go.mod
├── go.sum
├── main.go # App entry point
└── main.go.save # Backup file
Before you begin, make sure you have:
- Go 1.25.1+ installed → Download Go
- PostgreSQL installed and running locally (or on Docker)
You can either fork the project to your own GitHub account, or clone it directly:
# Clone directly
git clone https://github.com/faizzmarzuki/debtlog-api.git
# or fork first, then clone your fork:
git clone https://github.com/<your-username>/debtlog-api.git
cd debtlog-apiGo modules will pull everything you need:
go mod tidyCopy the example environment file:
cp .env.example .envThen edit .env with your PostgreSQL details:
DB_HOST=localhost
DB_USER=postgres
DB_PASSWORD=yourpassword
DB_NAME=debtlog
DB_PORT=5432
JWT_SECRET=your_jwt_secretLog into PostgreSQL and create the database:
psql -U postgres
CREATE DATABASE debtlog;
\qIf migrations are set up with GORM auto-migrate (inside main.go), the tables will be created automatically when you first run the app.
If you use a migration tool like golang-migrate, run something like:
migrate -path migrations -database "postgres://postgres:yourpassword@localhost:5432/debtlog?sslmode=disable" up(Optional: depends on how you've set it up — by default, this repo auto-migrates via Go code.)
go run main.goServer should now be running at http://localhost:8080.
go test ./tests -v| Method | Endpoint | Description |
|---|---|---|
| POST | /register |
Register a new user |
| POST | /login |
Login with username/password |
| GET | /health |
Health check |
| GET | /share/:token |
Access a shareable debt link |
| Method | Endpoint | Description |
|---|---|---|
| POST | /debters |
Create a new debter |
| GET | /debters |
List all debters |
| PUT | /debters/:id |
Update debter by ID |
| DELETE | /debters/:id |
Delete debter by ID |
| Method | Endpoint | Description |
|---|---|---|
| POST | /debtlogs |
Create a debt log |
| GET | /debtlogs/:id |
Get debt log details |
| Method | Endpoint | Description |
|---|---|---|
| POST | /debtlogs/:id/receipts |
Upload a receipt for debt |
- Debt categories (money, items, favors)
- Notifications / reminders
- User-to-user friend system
- Swagger documentation
- Frontend (React/Vue)
- Mobile app version
I wanted a simple but real-world project to practice backend development with Go. DebtLog is both:
- A personal tool to track debts with friends
- A learning project to explore Go, Gin, JWT, GORM, and PostgreSQL