Skip to Content
QuickstartInstall Boilerplate
View .md

Install Boilerplate

Get started with the Alien Mini App boilerplate. This template includes authentication, payments, database, and the Alien SDK pre-configured.

Prerequisites

Clone the Repository

git clone https://github.com/alien-id/miniapp-boilerplate my-miniapp cd my-miniapp

Install Dependencies

bun install

Project Structure

my-miniapp/ ├── app/ │ ├── api/ │ │ ├── me/route.ts │ │ ├── invoices/route.ts │ │ ├── transactions/route.ts │ │ └── webhooks/payment/route.ts │ ├── store/page.tsx │ ├── profile/page.tsx │ ├── explore/page.tsx │ ├── layout.tsx │ ├── page.tsx │ ├── providers.tsx │ ├── error.tsx │ └── global-error.tsx ├── features/ │ ├── auth/ │ │ ├── components/ │ │ │ └── connection-status.tsx │ │ └── lib.ts │ ├── user/ │ │ ├── components/ │ │ │ └── user-info.tsx │ │ ├── dto.ts │ │ ├── hooks/ │ │ │ └── use-current-user.ts │ │ └── queries.ts │ ├── payments/ │ │ ├── components/ │ │ │ └── diamond-store.tsx │ │ ├── hooks/ │ │ │ └── use-diamond-purchase.ts │ │ ├── constants.ts │ │ ├── dto.ts │ │ └── queries.ts │ └── navigation/ │ └── components/ │ └── tab-bar.tsx ├── lib/ │ ├── db/ │ │ ├── index.ts │ │ └── schema.ts │ └── env.ts ├── drizzle/ ├── scripts/ │ └── migrate.ts ├── docker-compose.yml ├── .env.example └── package.json

Environment Variables

Copy the template and fill in your values:

cp .env.example .env
VariableDescription
DATABASE_URLPostgreSQL connection string
WEBHOOK_PUBLIC_KEYEd25519 public key (hex) for webhooks
NEXT_PUBLIC_RECIPIENT_ADDRESSSolana wallet for USDC payments
NEXT_PUBLIC_ALIEN_RECIPIENT_ADDRESSAlien provider address

Default .env for local development:

DATABASE_URL=postgresql://postgres:postgres@localhost:5432/miniapp WEBHOOK_PUBLIC_KEY=<your-webhook-public-key> NEXT_PUBLIC_RECIPIENT_ADDRESS=<your-solana-wallet> NEXT_PUBLIC_ALIEN_RECIPIENT_ADDRESS=<your-alien-provider-address> NODE_ENV=development

Where to get the values

  • NEXT_PUBLIC_RECIPIENT_ADDRESS — any Solana wallet address you control. This is where USDC payments will be sent.
  • NEXT_PUBLIC_ALIEN_RECIPIENT_ADDRESS — your provider address from the Alien Dev Portal. Found on the Webhooks or Mini Apps pages.
  • WEBHOOK_PUBLIC_KEY — the Ed25519 public key (hex-encoded) provided by the Dev Portal when you register a webhook. Copy it immediately after creation — it is only shown once.

Start the Database

docker compose up -d

Run Migrations

bun run db:migrate

Start Development Server

bun run dev

Open http://localhost:3000 to see the app.

What’s Included

PackagePurpose
@alien_org/reactReact hooks and context provider
@alien_org/auth-clientJWT verification for backend
drizzle-ormType-safe database ORM
nextReact framework (v16)
@tanstack/react-queryData fetching and caching
zodSchema validation for API payloads
tailwindcssUtility-first CSS

Database

PostgreSQL with Drizzle ORM. Local setup uses Docker (docker-compose.yml).

Schema

Users (users):

ColumnTypeDescription
idUUIDAuto-generated primary key
alienIdTEXT (unique)User’s Alien ID from JWT sub
createdAtTIMESTAMPSet on first auth
updatedAtTIMESTAMPUpdated on each auth

Payment Intents (payment_intents):

ColumnTypeDescription
idUUIDAuto-generated primary key
invoiceTEXT (unique)Invoice identifier
senderAlienIdTEXTPayer’s Alien ID
recipientAddressTEXTRecipient wallet address
amountTEXTAmount in smallest units
tokenTEXTToken type (USDC / ALIEN)
networkTEXTNetwork (solana / alien)
productIdTEXTProduct identifier
statusTEXTpending / completed / failed
createdAtTIMESTAMPSet on creation

Transactions (transactions):

ColumnTypeDescription
idUUIDAuto-generated primary key
senderAlienIdTEXTPayer’s Alien ID
recipientAddressTEXTRecipient wallet address
txHashTEXTOn-chain transaction hash
statusTEXTpaid / failed
amountTEXTPayment amount
tokenTEXTToken type
networkTEXTNetwork
invoiceTEXTAssociated invoice
testTEXT"true" if test transaction
payloadJSONBFull webhook payload for audit
createdAtTIMESTAMPSet on creation

Commands

bun run db:generate # Generate migration from schema bun run db:migrate # Apply pending migrations bun run db:push # Push schema directly (dev only) bun run db:studio # Open Drizzle Studio GUI

To run migrations automatically on server start, set RUN_MIGRATIONS=true.

API Endpoints

GET /api/me

Returns the authenticated user. Requires Bearer token.

{ "id": "uuid", "alienId": "user-alien-id", "createdAt": "2024-01-01T00:00:00.000Z", "updatedAt": "2024-01-01T00:00:00.000Z" }

POST /api/invoices

Creates a payment intent. Requires Bearer token.

Request body:

{ "recipientAddress": "wallet-or-provider-address", "amount": "10000", "token": "USDC", "network": "solana", "productId": "usdc-diamonds-10" }

Response:

{ "invoice": "inv-xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", "id": "uuid" }

GET /api/transactions

Returns the authenticated user’s transaction history. Requires Bearer token.

POST /api/webhooks/payment

Receives payment status updates from the Alien platform. Verifies the x-webhook-signature header using Ed25519 against WEBHOOK_PUBLIC_KEY. See Payments — Webhook Setup for details.

Deployment

  1. Set up a PostgreSQL database and configure DATABASE_URL
  2. Register a webhook in the Alien Dev Portal pointing to https://<your-domain>/api/webhooks/payment
  3. Set WEBHOOK_PUBLIC_KEY, NEXT_PUBLIC_RECIPIENT_ADDRESS, and NEXT_PUBLIC_ALIEN_RECIPIENT_ADDRESS
  4. Either run bun run db:migrate manually or set RUN_MIGRATIONS=true for auto-migration on start
  5. Deploy

Next Steps

Last updated on