Development Server
Start the Next.js development server onlocalhost:3000:
- Hot-reload on file changes
- Display compilation errors in the browser
- Show API route logs in the terminal
- Load environment variables from
.env.local
The dev server runs on port 3000 by default. To use a different port:
npm run dev -- -p 3001Available Scripts
Web Development
Mobile Development
eStory includes an Expo-based mobile app in the
mobile/ directory.Testing Commands
Unit Tests (Vitest)
eStory uses Vitest for fast unit testing with React Testing Library.Test files are located in
__tests__/. The test setup is in __tests__/setup.ts.E2E Tests (Playwright)
Playwright runs end-to-end tests across Chrome, Firefox, and Safari.E2E tests are in the
e2e/ directory. Configure browsers and settings in playwright.config.ts.Smart Contract Commands
Compilation
contracts/ directory. Generates:
- TypeScript types
- ABI JSON files in
lib/abis/
Deployment
Deploy to Base Sepolia
eStoryToken.sol- ERC20 $STORY tokenStoryProtocol.sol- Tips & paywall paymentsStoryNFT.sol- ERC721 story book NFTs
Separate Contract Deployments
You can also deploy contracts individually:Utility Scripts
Development Workflow
Typical Development Session
Start Dev Server
Make Changes
- Edit files in
app/,components/, orlib/ - Changes hot-reload automatically
- Check terminal for build errors
Adding a New Feature
1. Add API Route
1. Add API Route
Create a new API route in
app/api/[route-name]/:app/api/example/route.ts
All API routes MUST use
validateAuthOrReject for security.2. Create Page Component
2. Create Page Component
Pages follow a two-file pattern:Server Component (Client Component (
app/[page]/page.tsx):app/[page]/ExamplePageClient.tsx):3. Add Navigation Link
3. Add Navigation Link
4. Write Tests
4. Write Tests
Create test file in
__tests__/:__tests__/ExamplePage.test.tsx
Architecture Patterns
Authentication Flow
All protected API routes use the same pattern:Supabase Client Usage
eStory uses three Supabase client variants:- Browser/Client
- Server/API Routes
- Admin
Web3 Hooks
eStory provides custom hooks for contract interactions:Debugging
Browser DevTools
Server Logs
API route logs appear in the terminal runningnpm run dev:
Database Debugging
Query Supabase directly through the dashboard:- Go to Table Editor to view data
- Use SQL Editor for custom queries
- Check Database > Roles for RLS policies
Performance Optimization
Bundle Analysis
Check bundle sizes after build:Bundle Budget
Current first load targets:- Shared (all pages): 104 kB (wagmi + viem + RainbowKit)
- Landing: 426 kB
- Record: 467 kB
- Library: 462 kB
- Profile: 498 kB
- Social: 462 kB
Optimization Techniques
Dynamic Imports
Optimize Packages
Configured in
next.config.mjs:- lucide-react
- framer-motion
- @radix-ui/*
Image Optimization
Use Next.js
<Image> component:Code Splitting
App Router automatically splits by route
Common Issues
Build fails with 'Module not found'
Build fails with 'Module not found'
- Check import paths use
@/alias correctly - Verify the file exists at the specified path
- Run
npm installto ensure dependencies are installed
Supabase returns empty results
Supabase returns empty results
- Check Row Level Security (RLS) policies
- Verify you’re using the correct Supabase client variant
- Ensure user is authenticated if required
Wallet connection fails
Wallet connection fails
- Verify
NEXT_PUBLIC_PROJECT_IDis set - Check MetaMask is installed and unlocked
- Ensure you’re on the correct network (Base Sepolia)
API route returns 401 Unauthorized
API route returns 401 Unauthorized
Tests fail with 'window is not defined'
Tests fail with 'window is not defined'
- Wrap client-only code with
typeof window !== 'undefined' - Mock browser APIs in test setup (
__tests__/setup.ts) - Use dynamic imports with
ssr: falsefor client-only components
Pre-Push Checklist
Before pushing code, always run:Next Steps
API Reference
Explore all available API endpoints
Database Schema
Learn about data models and relationships
Smart Contracts
Understand the blockchain layer
Testing Guide
Write and run tests effectively