API sederhana dengan Golang (Fiber) + PostgreSQL untuk registrasi, login, dan manajemen kontak (CRUD) menggunakan pendekatan DDD (Domain-Driven Design) dan Repository Pattern.
- 🔐 User Register & Login (JWT)
- 👤 CRUD Kontak
- 🧠 Clean Architecture (DDD & Repository)
- 🐘 PostgreSQL Database
- ⚡ Fiber (Express-style Go web framework)
.
├── cmd/ # Entry Point
│ └── main.go
├── internal/
│ ├── domain/ # Entity & interface
│ ├── handler/ # HTTP handlers
│ ├── infrastructure/ # Repository impl
│ ├── middleware/ # JWT middleware
│ └── usecase/ # Business logic
├── migrations/ # SQL table schema
├── go.mod / go.sum
└── .env
flowchart TD
A[Client] -->|POST /register| B[Register Handler]
B --> C[UserUsecase.Register]
C --> D[UserRepository.Create]
D --> E[(PostgreSQL)]
A2[Client] -->|POST /login| F[Login Handler]
F --> G[UserUsecase.Login]
G --> H[UserRepository.FindByEmail]
H --> I[(PostgreSQL)]
G --> J[Generate JWT]
erDiagram
USERS ||--o{ CONTACTS : has
USERS {
int id PK
string name
string email
string password
timestamp created_at
timestamp updated_at
}
CONTACTS {
int id PK
int user_id FK
string name
string phone
string email
string note
timestamp created_at
timestamp updated_at
}
git clone https://github.com/your-username/fiber-contact-api.git
cd fiber-contact-api
go mod tidy
Buat file .env
:
PORT=3000
DB_HOST=localhost
DB_PORT=5432
DB_USER=postgres
DB_PASSWORD=yourpassword
DB_NAME=yourdb
JWT_SECRET=your_jwt_secret
# PostgreSQL
psql -U postgres -d yourdb -f migrations/create_users_table.sql
psql -U postgres -d yourdb -f migrations/create_contacts_table.sql
go run main.go
Method | Endpoint | Description |
---|---|---|
POST | /api/register |
Register user |
POST | /api/login |
Login & get token |
Method | Endpoint | Description |
---|---|---|
POST | /api/contacts |
Create new contact |
GET | /api/contacts |
List all contacts |
GET | /api/contacts/:id |
Get single contact |
PUT | /api/contacts/:id |
Update contact |
DELETE | /api/contacts/:id |
Delete contact |
404 Not Found Indonesia
Contributor:
This project is open-sourced software licensed under the MIT license.