This guide provides comprehensive instructions for developers contributing to the Morpheus APP project, including environment setup, local development, and the contribution workflow.
- Prerequisites
- Initial Setup
- Environment Configuration
- Local Development
- Building from Source
- Development Guidelines
- Branch Strategy & Workflow
- Troubleshooting
Before you begin, ensure you have the following installed:
-
Node.js: Version 22.x or higher (see
.nvmrcfor exact version)node --version # Should show v22.x or higher -
pnpm: Version 9.15.0 or higher (project uses pnpm as package manager)
# Install pnpm if not already installed npm install -g pnpm pnpm --version # Should show 9.15.0 or higher
-
Git: For version control
git --version
- GitHub account with access to the
morpheusais/morpheus-marketplace-apprepository - Understanding of Next.js, React, and TypeScript
# Clone the repository
git clone https://github.com/morpheusais/morpheus-marketplace-app.git
# Navigate to the project directory
cd morpheus-marketplace-app# Install all project dependencies using pnpm
pnpm installThis will install all required packages listed in package.json, including:
- Next.js 15.5.9
- React 18.2.0
- AWS Cognito integration libraries
- Tailwind CSS and shadcn/ui components
- TypeScript and type definitions
- Web3 libraries (wagmi, viem, Reown AppKit)
- Payment integrations (Stripe, Coinbase Commerce)
- React Query for data fetching
- Recharts for analytics visualizations
# Check that dependencies installed correctly
pnpm list --depth=0# Copy the example environment file
cp env.example .env.localEdit .env.local with your local development configuration. The env.example file is pre-configured with dev environment values, so you can use it directly for local development:
# =============================================================================
# API Configuration
# =============================================================================
# Dev endpoint (default for local development)
NEXT_PUBLIC_API_BASE_URL=https://api.dev.mor.org
# =============================================================================
# Authentication - AWS Cognito Configuration
# =============================================================================
NEXT_PUBLIC_COGNITO_REGION=us-east-2
NEXT_PUBLIC_COGNITO_USER_POOL_CLIENT_ID=gllbg66ej476tsaf2ibfjc7g8
NEXT_PUBLIC_COGNITO_DOMAIN=auth.mor.org
# =============================================================================
# Analytics - Google Analytics & Google Tag Manager
# =============================================================================
# Leave empty to disable tracking in development
NEXT_PUBLIC_GA_ID=
NEXT_PUBLIC_GTM_ID=
# =============================================================================
# Model Filtering Configuration
# =============================================================================
NEXT_PUBLIC_ALLOWED_MODEL_TYPES=LLM, EMBEDDING
NEXT_PUBLIC_DEFAULT_MODEL=hermes-4-14b
# =============================================================================
# Automation Settings Defaults
# =============================================================================
NEXT_PUBLIC_DEFAULT_AUTOMATION_ENABLED=true
################################################################################
# 5 SECRETS BELOW - DO NOT SHARE WITH ANYONE
################################################################################
# Admin API Authentication
ADMIN_API_SECRET=
# Payment Integration - Coinbase Commerce
COINBASE_COMMERCE_API_KEY=
COINBASE_COMMERCE_API_SECRET=
COINBASE_COMMERCE_WEBHOOK_SECRET=
# Reown AppKit Configuration (Web3 Wallet Connection)
NEXT_PUBLIC_PROJECT_ID=| Variable | Purpose | Dev Value |
|---|---|---|
NEXT_PUBLIC_API_BASE_URL |
Backend API endpoint | https://api.dev.mor.org |
NEXT_PUBLIC_COGNITO_REGION |
AWS region | us-east-2 |
NEXT_PUBLIC_COGNITO_USER_POOL_CLIENT_ID |
Cognito client | gllbg66ej476tsaf2ibfjc7g8 |
NEXT_PUBLIC_COGNITO_DOMAIN |
Auth domain | auth.mor.org |
NEXT_PUBLIC_GA_ID |
Google Analytics | Leave empty for dev |
NEXT_PUBLIC_GTM_ID |
Google Tag Manager | Leave empty for dev |
NEXT_PUBLIC_ALLOWED_MODEL_TYPES |
Model types to display | LLM, EMBEDDING |
NEXT_PUBLIC_DEFAULT_MODEL |
Default model selection | hermes-4-14b |
NEXT_PUBLIC_DEFAULT_AUTOMATION_ENABLED |
Default automation state | true |
| Variable | Purpose | Notes |
|---|---|---|
ADMIN_API_SECRET |
Admin API authentication | Must match backend's ADMIN_API_SECRET |
COINBASE_COMMERCE_API_KEY |
Coinbase Commerce API key | Required for payment testing |
COINBASE_COMMERCE_API_SECRET |
Coinbase Commerce API secret | Required for payment testing |
COINBASE_COMMERCE_WEBHOOK_SECRET |
Webhook verification secret | Required for webhook testing |
NEXT_PUBLIC_PROJECT_ID |
Reown AppKit project ID | Get from Reown Dashboard |
⚠️ Important: The.env.localfile is gitignored and should NEVER be committed to the repository. Never share secrets!
💡 Tip: The env.example is pre-configured for local development with the dev API. For basic development (chat, auth, API keys), you don't need any secrets. Secrets are only needed for payment flows and Web3 wallet connection.
# Start the Next.js development server with Turbopack
pnpm devThe application will be available at:
- URL: http://localhost:3000
- Hot Reload: Enabled (changes auto-refresh)
- Turbopack: Fast refresh and optimized builds
- Navigate to http://localhost:3000
- Click "Sign In" or navigate to
/signin - Sign up for a new account (
/signup) or sign in with existing credentials - Confirm registration via email if signing up (
/confirm-registration) - Create an API key in the API Keys page
- Test the Chat interface
- URL: http://localhost:3000
- Features: Landing page with navigation
- Sign In: http://localhost:3000/signin
- Sign Up: http://localhost:3000/signup
- Forgot Password: http://localhost:3000/forgot-password
- Confirm Registration: http://localhost:3000/confirm-registration
- Auth Required: No
- URL: http://localhost:3000/chat
- Features: Interactive chat, model selection, chat history, streaming responses
- Auth Required: Yes (with verified API key)
- URL: http://localhost:3000/api-keys
- Features: Create/delete API keys, view key usage
- Auth Required: Yes
- URL: http://localhost:3000/billing
- Features: View balance, fund account (Stripe/Coinbase/Crypto), transaction history, usage overview
- Auth Required: Yes
- URL: http://localhost:3000/usage-analytics
- Features: Detailed usage charts, spending breakdown by model, data export
- Auth Required: Yes
- URL: http://localhost:3000/account
- Features: Change email, change password, delete account
- Auth Required: Yes
# Run linter to check code quality
pnpm lint# Check types without building
pnpm exec tsc --noEmit# Create an optimized production build
pnpm buildThis will:
- Compile TypeScript to JavaScript
- Optimize React components
- Generate static pages where possible
- Bundle and minify assets
- Create a
.nextdirectory with build artifacts
# First, build the application
pnpm build
# Then start the production server
pnpm startAccess the production build at: http://localhost:3000
💡 Tip: Always test your changes with a production build before creating a PR to ensure there are no build-time issues.
Before submitting a PR:
- Build completes without errors
- No TypeScript errors
- ESLint passes without errors
- All pages load correctly
- Authentication flows work (sign in, sign up, password reset)
- API key management functions properly
- Chat interface operates as expected
- Billing page loads (if you have payment credentials configured)
- TypeScript: All new code must use TypeScript
- React: Use functional components with hooks
- Formatting: Follow the project's ESLint configuration
- Comments: Add comments for complex logic
- Naming: Use descriptive variable and function names
src/
├── app/ # Next.js App Router (routes)
│ ├── api/ # API routes (webhooks, payments)
│ │ ├── coinbase/ # Coinbase payment endpoints
│ │ ├── stripe/ # Stripe payment endpoints
│ │ └── webhooks/ # Payment webhook handlers
│ ├── account/ # Account settings page
│ ├── api-keys/ # API key management page
│ ├── auth/callback/ # OAuth callback handler
│ ├── billing/ # Billing dashboard
│ ├── chat/ # Chat interface
│ │ └── [chatId]/ # Dynamic chat routes
│ ├── confirm-registration/ # Email confirmation page
│ ├── forgot-password/ # Password reset page
│ ├── register/ # Registration page
│ ├── signin/ # Sign in page
│ ├── signup/ # Sign up page
│ └── usage-analytics/ # Usage analytics pages
│ └── export-data/ # Data export page
├── components/ # Reusable components
│ ├── ai-elements/ # Chat/AI components (conversation, messages)
│ ├── auth/ # Auth-specific components
│ ├── billing/ # Billing components (charts, tables, widgets)
│ ├── providers/ # Context providers (GTM, Query)
│ └── ui/ # shadcn/ui components
├── config/ # Configuration files
│ └── appkit.tsx # Reown AppKit config (Web3)
├── context/ # React context providers
│ └── AppKitProvider.tsx # Web3 wallet provider
├── hooks/ # Custom React hooks
├── lib/ # Utility libraries
│ ├── api/ # API client & services
│ ├── auth/ # Authentication logic (Cognito)
│ ├── hooks/ # Library-specific hooks
│ ├── types/ # TypeScript type definitions
│ └── utils/ # Helper functions
└── types/ # Global TypeScript types
-
Component Design
- Keep components small and focused
- Use TypeScript interfaces for props
- Implement proper error handling
- Add loading states for async operations
- Use shadcn/ui components from
src/components/ui/
-
State Management
- Use React Context for global state (see
src/context/andsrc/lib/) - Use React Query (TanStack Query) for server state and API data
- Keep local state minimal
- Use custom hooks from
src/lib/hooks/(e.g.,use-billing.ts)
- Use React Context for global state (see
-
API Calls
- Use the
apiService.tshelper functions insrc/lib/api/ - Use the
billing.tsservice for billing-related calls - Handle errors gracefully with try/catch
- Show user-friendly error messages via toast notifications
- Implement proper loading indicators
- Use the
-
Authentication
- Never store sensitive tokens in localStorage
- Use the CognitoAuth context for auth state (
src/lib/auth/CognitoAuthContext.tsx) - Check authentication status before protected operations
- Handle token expiration gracefully
- Use
authenticated-layout.tsxwrapper for protected pages
-
Web3 Integration
- Use the AppKit provider for wallet connections (
src/context/AppKitProvider.tsx) - Configure supported chains in
src/config/appkit.tsx - Handle wallet connection states appropriately
- Use the AppKit provider for wallet connections (
-
Security
- Never commit credentials or API keys
- Server-side secrets (e.g.,
COINBASE_COMMERCE_API_SECRET) should never haveNEXT_PUBLIC_prefix - Validate user input
- Sanitize data before rendering
- Use environment variables for configuration
Use the following prefixes for branch names:
feature/- New featuresfix/- Bug fixeshotfix/- Urgent fixesrefactor/- Code refactoringdocs/- Documentation updatestest/- Test additions or modifications
Examples:
feature/add-model-filtering
fix/chat-history-loading
hotfix/cognito-callback-error
refactor/api-service-layer
docs/update-developer-guide
# Ensure you're on dev branch and up to date
git checkout dev
git pull origin dev
# Create a new feature branch
git checkout -b feature/your-feature-name- Write your code following the development guidelines
- Test thoroughly in your local environment (http://localhost:3000)
- Run the linter and fix any issues
- Build and test the production build locally
# Run linter
pnpm lint
# Test production build
pnpm build
pnpm start# Stage your changes
git add .
# Commit with a descriptive message
git commit -m "Add feature: descriptive message about what you did"Commit Message Guidelines:
- Use present tense ("Add feature" not "Added feature")
- Be descriptive but concise
- Reference issue numbers if applicable
# Push your branch to GitHub
git push origin feature/your-feature-name- Go to the GitHub repository
- Click "New Pull Request"
- Select your feature branch →
devbranch - Fill in the PR template:
- Title: Clear, descriptive title
- Description: What changes were made and why
- Testing: How you tested the changes
- Screenshots: If applicable (for UI changes)
- ✅ 1 peer review required before merge
- ✅ All CI checks must pass
- ✅ No merge conflicts with dev
- ✅ Code follows project guidelines
- ✅ Local testing completed successfully
- ✅ Build succeeds without errors
Once merged to dev, AWS Amplify will automatically deploy your changes to:
- Dev Environment: https://app.dev.mor.org
This is where you and the team can test and review your changes in a live environment before they're promoted to production.
When code in the dev environment is stable and ready:
- ✅ 2 peer reviews required before merge
- ✅ All CI checks must pass
- ✅ Thorough testing completed on https://app.dev.mor.org
- ✅ No critical bugs identified
- ✅ Stakeholder approval (if required)
Once merged to main, AWS Amplify will automatically deploy to production:
- Production Environment: https://app.mor.org
⚠️ Note: Only stable, well-tested code should be merged tomain. All development and testing should happen through thedevbranch first.
As a Reviewer:
- Check code quality and style
- Verify the PR description is clear
- Review for potential bugs or edge cases
- Check that tests pass
- Provide constructive feedback
- Approve only when satisfied
As an Author:
- Respond to all review comments
- Make requested changes promptly
- Re-request review after changes
- Thank reviewers for their time
┌─────────────────┐
│ Local Dev │
│ localhost:3000 │
└────────┬────────┘
│
▼
┌─────────────────┐
│ Feature Branch │
│ (your-feature) │
└────────┬────────┘
│
▼ PR (1 review)
┌─────────────────┐
│ dev branch │
└────────┬────────┘
│
▼ Auto-deploy
┌─────────────────┐
│ Dev Environment │
│ app.dev.mor.org │
└────────┬────────┘
│
▼ PR (2 reviews)
┌─────────────────┐
│ main branch │
└────────┬────────┘
│
▼ Auto-deploy
┌─────────────────┐
│ Production │
│ app.mor.org │
└─────────────────┘
Solution:
# Clear pnpm cache
pnpm store prune
# Delete node_modules and lockfile
rm -rf node_modules pnpm-lock.yaml
# Reinstall
pnpm installSolution:
# Check required version in .nvmrc
cat .nvmrc # Shows 22
# If using nvm, switch to correct version
nvm install 22
nvm use 22
# Verify
node --version # Should show v22.xSolution: This is usually a TypeScript language server issue:
- Ensure
node_modulesexists:pnpm install - Restart your IDE
- In VS Code/Cursor: Reload window (Cmd+Shift+P → "Reload Window")
Solution:
- Check your
.env.localfile has correct Cognito values - Verify client ID is set to:
gllbg66ej476tsaf2ibfjc7g8 - Clear browser cookies and try again
- Check browser console for specific error messages
- Ensure
NEXT_PUBLIC_API_BASE_URLpoints tohttps://api.dev.mor.org
Solution:
- Verify
NEXT_PUBLIC_API_BASE_URL=https://api.dev.mor.org - Check if the API is operational at https://api.dev.mor.org/docs
- Ensure your API key is valid (create one in the API Keys page)
- Check browser network tab for error details
- For payment-related calls, ensure the relevant
COINBASE_COMMERCE_*orADMIN_API_SECRETvars are set
Solution:
# Check for TypeScript errors
pnpm exec tsc --noEmit
# Fix type errors in reported files
# Then try building again
pnpm buildSolution:
# Restart dev server
# Press Ctrl+C to stop, then:
pnpm devSolution:
- Verify your PR was merged to
devbranch - Check AWS Amplify build status in the AWS console
- Wait a few minutes for the build and deployment to complete
- Clear browser cache and refresh
- Check if there were any build errors in Amplify
Solution:
- Ensure
NEXT_PUBLIC_PROJECT_IDis set with a valid Reown project ID - Get a project ID from https://dashboard.reown.com
- Clear browser cache and reconnect wallet
Solution:
- For Coinbase payments, ensure all
COINBASE_COMMERCE_*variables are set - For webhook testing, use a tool like ngrok to expose localhost
- Ensure
ADMIN_API_SECRETmatches the backend configuration
If you encounter issues not covered here:
- Check Existing Issues: Search GitHub Issues for similar problems
- Search the Codebase: Look for similar patterns in the code
- Ask the Team: Post in the team Discord channel
- Create a GitHub Issue: If the problem persists, create a detailed issue with:
- Problem description
- Steps to reproduce
- Expected vs actual behavior
- Screenshots/logs if applicable
- Your environment (OS, Node version, npm version)
- Next.js Documentation: https://nextjs.org/docs
- React Documentation: https://react.dev
- TypeScript Handbook: https://www.typescriptlang.org/docs/
- Tailwind CSS Docs: https://tailwindcss.com/docs
- shadcn/ui Components: https://ui.shadcn.com/docs
- TanStack Query (React Query): https://tanstack.com/query/latest/docs
- Dev API Docs: https://api.dev.mor.org/docs
- Dev App: https://app.dev.mor.org
- Production App: https://app.mor.org
- Morpheus Website: https://mor.org
- AWS Cognito Docs: https://docs.aws.amazon.com/cognito/
- AWS Amplify Docs: https://docs.amplify.aws/
- Reown AppKit (Web3): https://docs.reown.com/appkit/overview
- Coinbase Commerce: https://docs.cdp.coinbase.com/commerce-onchain/docs/welcome
- pnpm Documentation: https://pnpm.io/
# Initial setup
git clone https://github.com/morpheusais/morpheus-marketplace-app.git
cd morpheus-marketplace-app
nvm use # Switch to correct Node version (22.x)
pnpm install # Install dependencies
cp env.example .env.local # Pre-configured for dev environment
# Development
pnpm dev # Start dev server
pnpm lint # Run linter
pnpm build # Build for production
pnpm start # Start production server
pnpm exec tsc --noEmit # Type check without building
# Git workflow
git checkout dev
git pull origin dev
git checkout -b feature/your-feature
# ... make changes ...
git add .
git commit -m "Add feature: description"
git push origin feature/your-feature
# ... create PR to dev ...For questions or clarifications about this guide:
- Open an issue on GitHub
- Ask in the team Discord
- Contact the development team leads
Happy coding! 🚀