Skip to content

NusaHub is a Web3 crowdfunding platform connecting Indonesian game developers with global investors through milestone-based funding and anti-fraud investor voting.

Notifications You must be signed in to change notification settings

NusaHub/backend

Repository files navigation

Web3 Crowdfunding API

REST API service untuk platform crowdfunding Web3 yang dibangun dengan Golang, Fiber, dan PostgreSQL.

πŸš€ Fitur

  • βœ… CRUD operations untuk Projects
  • βœ… Investor Tracking - Track investor wallet addresses dengan PostgreSQL arrays
  • βœ… Manajemen User Profiles (Upsert)
  • βœ… Sistem Comments dengan support untuk nested comments
  • βœ… Manajemen External Links untuk setiap project (social media, website, dll)
  • βœ… Auto-migration database dengan GORM
  • βœ… UUID v7 untuk primary keys (time-ordered, better DB performance)
  • βœ… CORS enabled untuk kemudahan pengembangan
  • βœ… Request logging
  • βœ… Error handling yang konsisten
  • βœ… Validasi input
  • βœ… Interactive Swagger/OpenAPI Documentation

πŸ“‹ Prasyarat

  • Go 1.21 atau lebih tinggi
  • PostgreSQL 12 atau lebih tinggi

πŸ› οΈ Instalasi

  1. Clone repository:
git clone <repository-url>
cd hackathon
  1. Install dependencies:
go mod download
  1. Setup database PostgreSQL dan buat database baru:
CREATE DATABASE web3_crowdfunding;
  1. Copy file .env dan sesuaikan konfigurasi database:
# File .env sudah ada, sesuaikan dengan konfigurasi PostgreSQL Anda
  1. Jalankan aplikasi:
go run cmd/main/main.go

Server akan berjalan di http://localhost:3000

οΏ½ API Documentation

API ini dilengkapi dengan Swagger/OpenAPI documentation yang interaktif!

Akses Swagger UI:

http://localhost:3000/docs/

Fitur Swagger Documentation:

  • βœ… Interactive API testing
  • βœ… Complete request/response examples
  • βœ… Model schemas
  • βœ… Try it out functionality
  • βœ… Easy sharing dengan partner

Generate ulang Swagger docs:

make swagger
# atau
swag init -g cmd/main/main.go --output docs

οΏ½πŸ“š API Endpoints

Projects

GET /api/v1/projects

Mendapatkan semua proyek (termasuk investor_wallet_addresses array).

Response:

[
  {
    "id": "uuid",
    "creator_wallet_address": "0x...",
    "title": "My Game Project",
    "description": "Description here",
    "cover_image_url": "https://...",
    "developer_name": "Developer Name",
    "genre": "RPG",
    "game_type": "web3",
    "created_at": "2025-10-15T10:00:00Z",
    "updated_at": "2025-10-15T10:00:00Z"
  }
]

GET /api/v1/projects/:id

Mendapatkan detail proyek berdasarkan ID.

Response:

  • 200 OK: Detail proyek
  • 404 Not Found: Proyek tidak ditemukan

POST /api/v1/projects

Membuat proyek baru.

Request Body:

{
  "creator_wallet_address": "0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb",
  "title": "My Awesome Game",
  "description": "This is an amazing Web3 game",
  "cover_image_url": "https://example.com/image.jpg",
  "developer_name": "John Doe",
  "genre": "Action",
  "game_type": "web3"
}

Response:

  • 201 Created: Proyek berhasil dibuat (dengan UUID yang dihasilkan)
  • 400 Bad Request: Data tidak valid

PATCH /api/v1/projects/:id

Memperbarui proyek.

Request Body:

{
  "title": "Updated Title",
  "description": "Updated description"
}

Response:

  • 200 OK: Proyek berhasil diperbarui
  • 404 Not Found: Proyek tidak ditemukan

Investors

GET /api/v1/projects/:id/investors

Mendapatkan semua investor wallet addresses untuk sebuah proyek.

Response:

{
  "investors": [
    "0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb",
    "0x1234567890abcdef1234567890abcdef12345678"
  ]
}

POST /api/v1/projects/:id/investors

Menambahkan investor wallet address ke proyek.

Request Body:

{
  "wallet_address": "0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb"
}

Response:

  • 200 OK: Investor berhasil ditambahkan
  • 404 Not Found: Proyek tidak ditemukan
  • 409 Conflict: Investor sudah ada
  • 400 Bad Request: Format wallet address tidak valid

DELETE /api/v1/projects/:id/investors/:walletAddress

Menghapus investor dari proyek.

Response:

  • 200 OK: Investor berhasil dihapus
  • 404 Not Found: Proyek tidak ditemukan

User Profiles

GET /api/v1/profiles/:walletAddress

Mendapatkan profil berdasarkan wallet address.

Response:

  • 200 OK: Detail profil
  • 404 Not Found: Profil tidak ditemukan

PUT /api/v1/profiles/:walletAddress

Membuat atau memperbarui profil (Upsert).

Request Body:

{
  "username": "johndoe",
  "email": "john@example.com",
  "profile_image_url": "https://example.com/avatar.jpg",
  "kyc_status": "verified"
}

Response:

  • 200 OK: Profil berhasil dibuat/diperbarui
  • 400 Bad Request: Data tidak valid
  • 409 Conflict: Username atau email sudah digunakan

Comments

GET /api/v1/projects/:id/comments

Mendapatkan semua komentar untuk sebuah proyek.

Response:

[
  {
    "id": "uuid",
    "project_id": "uuid",
    "author_wallet_address": "0x...",
    "parent_comment_id": null,
    "content": "Great project!",
    "created_at": "2025-10-15T10:00:00Z",
    "updated_at": "2025-10-15T10:00:00Z"
  }
]

POST /api/v1/projects/:id/comments

Menambahkan komentar baru.

Request Body:

{
  "author_wallet_address": "0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb",
  "content": "This looks amazing!",
  "parent_comment_id": "uuid-optional"
}

External Links

GET /api/v1/projects/:id/links

Mendapatkan semua external links untuk sebuah proyek (social media, website, dll).

Response:

[
  {
    "id": "uuid",
    "project_id": "uuid",
    "name": "Instagram",
    "url": "https://instagram.com/mygame",
    "created_at": "2025-10-15T10:00:00Z",
    "updated_at": "2025-10-15T10:00:00Z"
  },
  {
    "id": "uuid",
    "project_id": "uuid",
    "name": "Twitter",
    "url": "https://twitter.com/mygame",
    "created_at": "2025-10-15T10:00:00Z",
    "updated_at": "2025-10-15T10:00:00Z"
  }
]

POST /api/v1/projects/:id/links

Menambahkan external link baru ke proyek.

Request Body:

{
  "name": "Instagram",
  "url": "https://instagram.com/mygame"
}

Response:

  • 201 Created: Link berhasil ditambahkan
  • 404 Not Found: Proyek tidak ditemukan
  • 400 Bad Request: Data tidak valid

PUT /api/v1/projects/:id/links/:linkId

Memperbarui external link.

Request Body:

{
  "name": "Instagram Official",
  "url": "https://instagram.com/mygame_official"
}

Response:

  • 200 OK: Link berhasil diperbarui
  • 404 Not Found: Link tidak ditemukan
  • 400 Bad Request: Data tidak valid

DELETE /api/v1/projects/:id/links/:linkId

Menghapus external link.

Response:

  • 200 OK: Link berhasil dihapus
  • 404 Not Found: Link tidak ditemukan

Health Check

GET /api/v1/health

Mengecek status API.

Response:

{
  "status": "ok",
  "message": "Web3 Crowdfunding API is running"
}

πŸ—‚οΈ Struktur Proyek

/hackathon
β”œβ”€β”€ cmd/
β”‚   └── main/
β”‚       └── main.go              # Entry point aplikasi
β”œβ”€β”€ internal/
β”‚   β”œβ”€β”€ config/
β”‚   β”‚   └── config.go            # Konfigurasi aplikasi
β”‚   β”œβ”€β”€ database/
β”‚   β”‚   └── database.go          # Inisialisasi database
β”‚   β”œβ”€β”€ handler/
β”‚   β”‚   β”œβ”€β”€ project_handler.go   # Project handlers
β”‚   β”‚   β”œβ”€β”€ user_profile_handler.go  # Profile handlers
β”‚   β”‚   β”œβ”€β”€ comment_handler.go   # Comment handlers
β”‚   β”‚   └── external_link_handler.go  # External link handlers
β”‚   β”œβ”€β”€ model/
β”‚   β”‚   └── model.go             # GORM models (4 tables)
β”‚   β”œβ”€β”€ repository/
β”‚   β”‚   β”œβ”€β”€ project_repository.go     # Project repository
β”‚   β”‚   β”œβ”€β”€ user_profile_repository.go  # Profile repository
β”‚   β”‚   β”œβ”€β”€ comment_repository.go     # Comment repository
β”‚   β”‚   └── external_link_repository.go  # External link repository
β”‚   └── router/
β”‚       └── router.go            # Route definitions
β”œβ”€β”€ docs/
β”‚   β”œβ”€β”€ docs.go                  # Generated Swagger docs
β”‚   β”œβ”€β”€ swagger.json             # OpenAPI JSON spec
β”‚   └── swagger.yaml             # OpenAPI YAML spec
β”œβ”€β”€ .env                         # Environment variables
β”œβ”€β”€ .gitignore
β”œβ”€β”€ go.mod
β”œβ”€β”€ go.sum
└── README.md

πŸ”§ Konfigurasi

Edit file .env untuk mengubah konfigurasi:

# Database Configuration
DB_HOST=localhost
DB_PORT=5432
DB_USER=postgres
DB_PASSWORD=postgres
DB_NAME=web3_crowdfunding
DB_SSLMODE=disable

# Server Configuration
SERVER_PORT=3000

πŸ—„οΈ Database Schema

Table: projects

  • id (UUID, Primary Key)
  • creator_wallet_address (VARCHAR(42))
  • title (VARCHAR(255))
  • description (TEXT)
  • cover_image_url (VARCHAR(255))
  • developer_name (VARCHAR(100))
  • genre (VARCHAR(50))
  • game_type (VARCHAR(10))
  • investor_wallet_addresses (TEXT[], Array of wallet addresses)
  • created_at (TIMESTAMPTZ)
  • updated_at (TIMESTAMPTZ)

Table: user_profiles

  • wallet_address (VARCHAR(42), Primary Key)
  • username (VARCHAR(50), Unique)
  • email (VARCHAR(255), Unique)
  • profile_image_url (VARCHAR(255))
  • kyc_status (VARCHAR(20), Default: 'unverified')
  • created_at (TIMESTAMPTZ)
  • updated_at (TIMESTAMPTZ)

Table: comments

  • id (UUID, Primary Key)
  • project_id (UUID, Foreign Key)
  • author_wallet_address (VARCHAR(42))
  • parent_comment_id (UUID, Foreign Key, Nullable)
  • content (TEXT)
  • created_at (TIMESTAMPTZ)
  • updated_at (TIMESTAMPTZ)

Table: external_links

  • id (UUID, Primary Key)
  • project_id (UUID, Foreign Key)
  • name (VARCHAR(50)) - e.g., "Instagram", "Twitter", "Website"
  • url (VARCHAR(500)) - The actual link
  • created_at (TIMESTAMPTZ)
  • updated_at (TIMESTAMPTZ)

πŸ§ͺ Testing dengan cURL

Membuat Project Baru

curl -X POST http://localhost:3000/api/v1/projects \
  -H "Content-Type: application/json" \
  -d '{
    "creator_wallet_address": "0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb",
    "title": "Epic Web3 Game",
    "description": "An amazing blockchain game",
    "developer_name": "GameDev Studio",
    "genre": "RPG",
    "game_type": "web3"
  }'

Mendapatkan Semua Projects

curl http://localhost:3000/api/v1/projects

Membuat User Profile

curl -X PUT http://localhost:3000/api/v1/profiles/0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb \
  -H "Content-Type: application/json" \
  -d '{
    "username": "gamer123",
    "email": "gamer@example.com",
    "kyc_status": "verified"
  }'

Menambahkan Comment

curl -X POST http://localhost:3000/api/v1/projects/{project-id}/comments \
  -H "Content-Type: application/json" \
  -d '{
    "author_wallet_address": "0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb",
    "content": "This project looks promising!"
  }'

Menambahkan External Link

curl -X POST http://localhost:3000/api/v1/projects/{project-id}/links \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Instagram",
    "url": "https://instagram.com/mygame"
  }'

Mendapatkan External Links untuk Project

curl http://localhost:3000/api/v1/projects/{project-id}/links

πŸ“ Catatan Pengembangan

  • API ini tidak memerlukan autentikasi karena state krusial ditangani oleh smart contract
  • UUID digunakan untuk memastikan konsistensi antara database off-chain dan smart contract on-chain
  • Middleware CORS dikonfigurasi untuk menerima request dari semua origin (untuk development)
  • Semua timestamp menggunakan TIMESTAMPTZ untuk timezone awareness
  • Auto-migration akan otomatis membuat tabel saat aplikasi pertama kali dijalankan

πŸš€ Deployment

Untuk production:

  1. Update CORS configuration untuk membatasi origins
  2. Set DB_SSLMODE=require untuk koneksi database yang aman
  3. Gunakan environment variables untuk konfigurasi sensitif
  4. Implementasikan rate limiting
  5. Setup monitoring dan logging yang proper

πŸ“„ License

MIT License

πŸ‘¨β€πŸ’» Author

Backend Engineering Team

About

NusaHub is a Web3 crowdfunding platform connecting Indonesian game developers with global investors through milestone-based funding and anti-fraud investor voting.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published