Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

8 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

FaniLab Frontend πŸš€

Production-ready Next.js frontend for blockchain-powered logistics platform on Stellar

TypeScript Next.js Stellar License

πŸ“‹ Overview

FaniLab is a decentralized logistics platform that connects senders with delivery drivers using blockchain technology for trustless escrow and transparent delivery tracking.

Key Features

  • πŸ” Secure Escrow: Smart contract-based payment protection
  • πŸ“¦ Real-time Tracking: Monitor delivery status on blockchain
  • πŸ’° Instant Settlement: Automatic payment release upon completion
  • 🌐 Decentralized: No central authority or intermediaries
  • πŸ” Transparent: All transactions verifiable on Stellar blockchain

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Next.js App   β”‚
β”‚   (Frontend)    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚
         β”œβ”€β”€β”€ Freighter Wallet (User Auth)
         β”‚
         β”œβ”€β”€β”€ Soroban RPC (Blockchain)
         β”‚    └── Smart Contracts
         β”‚        β”œβ”€β”€ Escrow
         β”‚        β”œβ”€β”€ Delivery
         β”‚        └── Dispute
         β”‚
         └─── API Server (Indexer)
              └── Database

πŸš€ Quick Start

Prerequisites

Installation

# Clone the repository
git clone https://github.com/your-org/fanilab-frontend.git
cd fanilab-frontend

# Install dependencies
npm install

# Copy environment variables
cp .env.example .env.local

# Configure your contract addresses in .env.local
# NEXT_PUBLIC_ESCROW_CONTRACT_ID=C...
# NEXT_PUBLIC_DELIVERY_CONTRACT_ID=C...
# NEXT_PUBLIC_DISPUTE_CONTRACT_ID=C...

# Start development server
npm run dev

Open http://localhost:3000 in your browser.

πŸ“ Project Structure

fanilab-frontend/
β”œβ”€β”€ app/                        # Next.js App Router
β”‚   β”œβ”€β”€ create-delivery/       # Create delivery page
β”‚   β”œβ”€β”€ deliveries/            # Browse deliveries
β”‚   β”œβ”€β”€ dashboard/             # User dashboard
β”‚   β”œβ”€β”€ layout.tsx             # Root layout
β”‚   └── page.tsx               # Home page
β”œβ”€β”€ components/                 # React components
β”‚   β”œβ”€β”€ Header.tsx
β”‚   β”œβ”€β”€ Footer.tsx
β”‚   └── Toaster.tsx
β”œβ”€β”€ lib/                       # Business logic
β”‚   β”œβ”€β”€ soroban/              # Stellar/Soroban SDK
β”‚   β”‚   β”œβ”€β”€ index.ts          # Core utilities
β”‚   β”‚   └── contracts/        # Contract integrations
β”‚   β”‚       β”œβ”€β”€ escrow.ts
β”‚   β”‚       └── delivery.ts
β”‚   β”œβ”€β”€ store/                # State management (Zustand)
β”‚   β”‚   β”œβ”€β”€ wallet-store.ts
β”‚   β”‚   └── delivery-store.ts
β”‚   β”œβ”€β”€ hooks/                # Custom React hooks
β”‚   β”‚   β”œβ”€β”€ useWallet.ts
β”‚   β”‚   └── useDeliveries.ts
β”‚   β”œβ”€β”€ validations/          # Zod schemas
β”‚   β”œβ”€β”€ errors/               # Error handling
β”‚   β”œβ”€β”€ stellar.ts            # Wallet integration
β”‚   β”œβ”€β”€ contracts.ts          # High-level API
β”‚   └── utils.ts
β”œβ”€β”€ types/                     # TypeScript definitions
β”œβ”€β”€ __tests__/                 # Unit tests (Vitest)
β”œβ”€β”€ e2e/                       # E2E tests (Playwright)
β”œβ”€β”€ public/                    # Static assets
└── [config files]

πŸ”§ Configuration

Environment Variables

Variable Description Example
NEXT_PUBLIC_STELLAR_NETWORK Network to use testnet or mainnet
NEXT_PUBLIC_SOROBAN_RPC_URL Soroban RPC endpoint https://soroban-testnet.stellar.org
NEXT_PUBLIC_NETWORK_PASSPHRASE Network passphrase Test SDF Network ; September 2015
NEXT_PUBLIC_ESCROW_CONTRACT_ID Escrow contract address C...
NEXT_PUBLIC_DELIVERY_CONTRACT_ID Delivery contract address C...
NEXT_PUBLIC_DISPUTE_CONTRACT_ID Dispute contract address C...
NEXT_PUBLIC_API_URL Backend API URL http://localhost:3001

Network Configuration

Testnet (Development)

NEXT_PUBLIC_STELLAR_NETWORK=testnet
NEXT_PUBLIC_SOROBAN_RPC_URL=https://soroban-testnet.stellar.org
NEXT_PUBLIC_NETWORK_PASSPHRASE=Test SDF Network ; September 2015

Mainnet (Production)

NEXT_PUBLIC_STELLAR_NETWORK=mainnet
NEXT_PUBLIC_SOROBAN_RPC_URL=https://soroban.stellar.org
NEXT_PUBLIC_NETWORK_PASSPHRASE=Public Global Stellar Network ; September 2015

πŸ§ͺ Testing

Unit Tests (Vitest)

# Run all tests
npm run test

# Run with UI
npm run test:ui

# Generate coverage report
npm run test:coverage

E2E Tests (Playwright)

# Run E2E tests
npm run test:e2e

# Run in headed mode
npx playwright test --headed

# Run specific test
npx playwright test e2e/home.spec.ts

Type Checking

npm run type-check

🎨 Code Quality

Linting

# Check for issues
npm run lint

# Auto-fix issues
npm run lint:fix

Formatting

# Format all files
npm run format

# Check formatting
npm run format:check

Pre-commit Hooks

Git hooks automatically run linting and formatting on commit using Husky and lint-staged.

πŸ“¦ Building for Production

# Create production build
npm run build

# Test production build locally
npm start

# Analyze bundle size
npm run build -- --analyze

πŸš€ Deployment

Vercel (Recommended)

Deploy with Vercel

# Install Vercel CLI
npm i -g vercel

# Deploy
vercel --prod

Docker

# Build image
docker build -t fanilab-frontend .

# Run container
docker run -p 3000:3000 --env-file .env.production fanilab-frontend

Other Platforms

See PRODUCTION_SETUP.md for detailed deployment instructions.

πŸ”— Integration with Smart Contracts

Contract Deployment

  1. Deploy smart contracts from FaniLab-SmartContract repository
  2. Note contract IDs
  3. Update .env.local with contract addresses
  4. Verify contracts on Stellar Expert

Transaction Flow

// 1. Create delivery with escrow
const { deliveryId, escrowId } = await createDelivery({
  sender: address,
  amount: 10.5,
  pickupLocation: "123 Main St",
  deliveryLocation: "456 Oak Ave"
});

// 2. Driver accepts delivery
await acceptDelivery({
  deliveryId,
  driverAddress: driverAddress
});

// 3. Recipient confirms delivery (releases payment)
await confirmDelivery({
  deliveryId,
  recipientAddress: address,
  escrowId
});

πŸ“š API Reference

Wallet Operations

import { useWallet } from '@/lib/hooks/useWallet';

const { 
  address,          // User's Stellar address
  balance,          // XLM balance
  isConnected,      // Connection status
  connect,          // Connect wallet
  disconnect,       // Disconnect wallet
  refreshBalance    // Refresh balance
} = useWallet();

Delivery Operations

import { createDelivery, acceptDelivery } from '@/lib/contracts';

// Create delivery
const result = await createDelivery({
  sender: 'G...',
  amount: 10.5,
  pickupLocation: 'Location A',
  deliveryLocation: 'Location B',
  description: 'Package details'
});

// Accept delivery
await acceptDelivery({
  deliveryId: 'delivery-id',
  driverAddress: 'G...'
});

See API.md for complete API documentation.

πŸ› οΈ Development Tools

  • Framework: Next.js 14 (App Router)
  • Language: TypeScript 5
  • Styling: TailwindCSS 3
  • State: Zustand + SWR
  • Validation: Zod
  • Forms: React Hook Form
  • Testing: Vitest + Playwright
  • Blockchain: Stellar SDK 11
  • Wallet: Freighter API

πŸ“– Documentation

πŸ› Troubleshooting

Common Issues

Wallet not connecting?

  • Ensure Freighter extension is installed
  • Check you're on the correct network (testnet/mainnet)
  • Refresh the page

Transaction failing?

  • Verify contract addresses are correct
  • Ensure sufficient XLM balance (including fees)
  • Check network connectivity

Build errors?

  • Clear .next folder: rm -rf .next
  • Delete node_modules and reinstall: rm -rf node_modules && npm install
  • Check Node.js version: node --version (requires 18+)

See TROUBLESHOOTING.md for more help.

🀝 Contributing

We welcome contributions! Please see CONTRIBUTING.md for details.

Contributors

Thanks to all contributors! πŸŽ‰

πŸ“„ License

This project is licensed under the MIT License - see LICENSE file for details.

πŸ”— Related Repositories

πŸ“ž Support

🌟 Stellar Resources

πŸ™ Acknowledgments

  • Stellar Development Foundation
  • Freighter Wallet Team
  • Next.js Team
  • Open source community

Built with ❀️ for the Stellar ecosystem

About

Production-ready Next.js frontend for blockchain-powered logistics platform on Stellar. Decentralized escrow, real-time delivery tracking, and instant settlements.

Resources

Contributing

Security policy

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages