mirror of
https://github.com/bitbaum/orangecat.git
synced 2026-12-03 22:37:18 +01:00
Forty-five 2025 plans, assessments, design scenarios, status reports and superseded business docs move to docs/archive/ (same relative path). Each described a plan or a snapshot as if it were the running system: strict:false, a five-table schema, an "organization" entity, price_sats, a Gemini /api/chat widget, a /auth/forgot-password page, Google Places, building group labels and contract voting flows that never landed. Fixed in place: NAVIGATION_UX_DESIGN.md (referenced by .claude/rules) gains a status note naming what shipped and where; GENERIC_API_HANDLERS.md lists the handler options the code actually takes; datetime_standards.md points at scripts/dev/; CONTRIBUTING.md describes the auto-merge shipping flow. Inbound links repointed (SECURITY.md at the root, SUPABASE_SCHEMA_GUIDE.md for schema). Claude-Session: https://claude.ai/code/session_01PJkbo18cRNXtgPWZN2S9cD Co-authored-by: Claude <noreply@anthropic.com>
16 KiB
16 KiB
OrangeCat Developer Guide
Welcome to the OrangeCat codebase! This guide will help you understand the project structure, find what you need, and contribute effectively.
🚀 Quick Start
For New Developers
- Read this guide - Understand the project structure
- Set up your environment - See Environment Setup
- Run the project - Use
pnpm run dev - Explore the codebase - Start with the sections below
For Contributors
- Understand the architecture - See Architecture
- Follow the patterns - Check Development Patterns
- Write tests - See Testing
- Submit changes - Follow Contributing
📁 Project Structure
/home/g/dev/orangecat/
├── 📁 src/ # Main application code
│ ├── 📁 app/ # Next.js app router pages
│ │ ├── 📁 (authenticated)/ # Protected routes
│ │ │ ├── 📁 dashboard/ # Main dashboard
│ │ │ ├── 📁 profile/ # User profile pages
│ │ │ └── 📁 organizations/ # Organization pages
│ │ ├── 📁 auth/ # Authentication pages
│ │ ├── 📁 api/ # API routes
│ │ └── 📁 blog/ # Blog pages
│ ├── 📁 components/ # React components
│ │ ├── 📁 ui/ # Base UI components
│ │ ├── 📁 layout/ # Layout components
│ │ ├── 📁 profile/ # Profile-related components
│ │ ├── 📁 wallet/ # Wallet-related components
│ │ └── 📁 funding/ # Funding-related components
│ ├── 📁 services/ # Business logic services
│ │ ├── 📁 supabase/ # Supabase integration
│ │ ├── 📁 bitcoin/ # Bitcoin utilities
│ │ └── 📁 search/ # Search functionality
│ ├── 📁 types/ # TypeScript type definitions
│ ├── 📁 utils/ # Utility functions
│ ├── 📁 hooks/ # Custom React hooks
│ ├── 📁 stores/ # State management
│ └── 📁 lib/ # Library functions
├── 📁 content/ # Static content
│ └── 📁 blog/ # Blog posts (MDX)
├── 📁 docs/ # Documentation
│ ├── 📁 architecture/ # System architecture docs
│ ├── 📁 development/ # Development guides
│ ├── 📁 security/ # Security documentation
│ └── 📁 deployment/ # Deployment guides
├── 📁 scripts/ # Utility scripts
│ ├── 📁 db/ # Database scripts
│ ├── 📁 deployment/ # Deployment scripts
│ └── 📁 dev/ # Development scripts
└── 📁 tests/ # Test files
├── 📁 e2e/ # End-to-end tests
└── 📁 unit/ # Unit tests
🔧 Environment Setup
Prerequisites
- Node.js 18+ (LTS recommended)
- npm or yarn
- Git
- Supabase CLI (optional, for local development)
Installation
# Clone the repository
git clone <repository-url>
cd orangecat
# Install dependencies
pnpm install
# Set up environment variables
cp config/production.env.template .env.local
# Edit .env.local with your Supabase credentials
# Start development server
pnpm run dev
Environment Variables
Required:
NEXT_PUBLIC_SUPABASE_URL- Your Supabase project URLNEXT_PUBLIC_SUPABASE_ANON_KEY- Your Supabase anon key
Optional:
SUPABASE_SERVICE_ROLE_KEY- For admin operationsSUPABASE_ACCESS_TOKEN- For MCP tools
🏗️ Architecture Overview
Core Technologies
- Frontend: Next.js 16, React 19, TypeScript
- Backend: Supabase (PostgreSQL + Auth + Storage)
- Styling: Tailwind CSS
- State Management: Zustand
- Testing: Vitest, Playwright
- Deployment: Self-hosted on Hetzner (bitbaum, behind Caddy)
Key Features
- Bitcoin Funding Platform - Crowdfunding with Bitcoin/Lightning
- Profile Management - User profiles with verification
- Organization Support - Multi-user organizations
- Wallet Integration - Bitcoin wallet discovery and management
- Social Features - Following, associations, networking
Architecture Principles
- Modular Design - Small, focused components and services
- Type Safety - Comprehensive TypeScript coverage
- Security First - Multi-layer security validation
- Performance Optimized - Lazy loading and code splitting
📖 Where to Find What
🧩 Components
- UI Components:
src/components/ui/- Buttons, forms, cards, etc. - Layout Components:
src/components/layout/- Header, footer, navigation - Feature Components:
src/components/<feature>/- Profile, wallet, funding, etc.
🔧 Business Logic
- Services:
src/services/- Supabase integration, Bitcoin utilities, search - Utilities:
src/utils/- Validation, formatting, helpers - Types:
src/types/- TypeScript definitions
📄 Pages & Routes
- App Pages:
src/app/- Next.js pages organized by feature - API Routes:
src/app/api/- Server-side API endpoints
🗄️ Data & Configuration
- Blog Posts:
content/blog/- MDX blog posts - Entity Registry:
src/config/entity-registry.ts- SSOT for every entity type - Demo Data:
src/data/- Mock data for development
🧪 Testing
- Unit Tests:
__tests__/(repo root, Vitest) - E2E Tests:
tests/e2e/- Playwright tests - Smoke Tests:
__tests__/smoke/
🚀 Development Workflow
Creating New Features
-
Plan the Feature
# Check existing patterns in similar features find src/components -name "*[feature]*" -type d -
Create Component Structure
mkdir -p src/components/new-feature # Create index.tsx, types.ts, utils.ts as needed -
Add to Navigation
// Update navigation config // Add to appropriate dashboard config -
Write Tests
pnpm test new-feature
Database Changes
-
Create Migration
# Use Supabase migrations supabase migration new feature_name -
Update Types
// Update src/types/database.ts // Update validation schemas -
Test Locally
pnpm run dev # Test the changes
Blog Posts
-
Create MDX File
# Use the template cp scripts/blog/blog-template.mdx content/blog/new-post.mdx -
Write Content
- Use the available MDX components
- Add frontmatter with metadata
- Use
<Alert>,<YouTube>,<CTA>components
-
Publish
// Set published: true in frontmatter // Deploy to see live
🔒 Security & Validation
Bitcoin Address Validation
import { isValidBitcoinAddress } from '@/utils/validation';
// Validates format, length, and security
const result = isValidBitcoinAddress('bc1qxy2kgdygjrsqtzq2n0yrf2493p83kkfjhx0wlh');
Profile Security
import { isValidUsername, isValidBio } from '@/utils/validation';
// Prevents impersonation and injection
const usernameResult = isValidUsername('elonmusk'); // Blocked
const bioResult = isValidBio('<script>alert("xss")</script>'); // Blocked
Authentication
- Uses Supabase Auth with RLS policies
- JWT tokens for API access
- Protected routes for sensitive features
🧪 Testing Strategy
Test Organization
tests/
├── e2e/ # Playwright end-to-end tests
│ ├── auth/ # Authentication flows
│ ├── profile/ # Profile management
│ └── funding/ # Campaign creation
└── unit/ # Vitest unit tests
├── components/ # Component tests
├── utils/ # Utility tests
└── services/ # Service tests
Running Tests
# Run all tests
pnpm test
# Run specific test suites
pnpm run test:unit # Full fast Vitest suite (unit + smoke + env — what CI gates)
pnpm run test:auth # Auth tests
pnpm run test:security # Security tests
# Run with coverage
pnpm run test:ci # CI mode with coverage
Writing Tests
// Component test example
import { render, screen } from '@testing-library/react'
import MyComponent from './MyComponent'
test('renders correctly', () => {
render(<MyComponent />)
expect(screen.getByText('Expected text')).toBeInTheDocument()
})
🚀 Deployment
Production Deployment
# Build for production
pnpm run build:production
# Deploy: self-hosted on Hetzner (bitbaum, behind Caddy).
# See docs/operations/deployment/DEPLOYMENT_PROCESS.md for the on-box flow.
Environment Variables
- Development:
.env.local(gitignored) - Production:
/opt/orangecat/app/.envon the Hetzner box
Database Migrations
# Migrations apply automatically on deploy (scripts/apply-migrations.sh)
# Generate new migration
pnpm exec supabase migration new feature_name
📚 Documentation Structure
📁 docs/ Directory Organization
Architecture (docs/architecture/)
ARCHITECTURE.md- High-level system overviewSUPABASE_SCHEMA_GUIDE.md- Database tables and conventionsservices-architecture.md- Service layer design
Development (docs/development/)
BEST_PRACTICES.md- Code standards and patternshooks-guide.md- Custom hook patternstypes-guide.md- TypeScript usage guideutils-guide.md- Utility function patterns
Security (docs/security/)
auth_system.md- Authentication system detailscelebrity-impersonation-prevention.md- Anti-impersonation measures
Deployment (docs/operations/deployment/)
DEPLOYMENT_PROCESS.md- How a merge reaches production- Infrastructure and DevOps guides
Features (docs/features/)
- Feature-specific documentation and guides
Standards (docs/development/standards/)
documentation_standards.md- Documentation guidelinesdatetime_standards.md- Date/time handling standards
📋 Key Documentation Files
| Topic | File | Purpose |
|---|---|---|
| Project Overview | README.md |
High-level project description |
| Setup Guide | docs/development/README.md |
Getting started instructions |
| Architecture | docs/architecture/ARCHITECTURE.md |
System design overview |
| Security | SECURITY.md |
Reporting vulnerabilities |
| Standards | docs/development/standards/documentation_standards.md |
Documentation guidelines |
| Contributing | docs/development/contributing/CONTRIBUTING.md |
Contribution guidelines |
🛠️ Common Development Tasks
Adding a New Component
-
Create the component file
# In src/components/feature/ touch NewComponent.tsx -
Add proper TypeScript types
interface NewComponentProps { // Define props } -
Follow naming conventions
- Use PascalCase for components
- Use camelCase for props and functions
- Export as default
-
Add to index file if needed
// src/components/feature/index.ts export { default as NewComponent } from './NewComponent';
Creating API Routes
-
Create route file
# In src/app/api/feature/ touch route.ts -
Implement proper error handling
import { handleApiError } from '@/lib/errors'; -
Add authentication if needed
import { withAuth } from '@/lib/api/withAuth';
Database Changes
-
Create migration
supabase migration new add_new_table -
Update TypeScript types
// src/types/database.ts export interface NewTable { // Define new table structure } -
Update validation schemas
// src/lib/validation.ts export const newTableSchema = z.object({...})
🔍 Finding Information
Quick Reference
| I Need To... | Look In... | File/Path |
|---|---|---|
| Create a component | Component templates | docs/development/templates/component.md |
| Add validation | Validation utilities | src/lib/validation/ |
| Update database | Migrations guide | docs/operations/supabase/migrations-guide.md |
| Add API route | API templates | docs/development/templates/api-endpoint.md |
| Write tests | Testing guide | docs/testing/test-guide.md |
| Deploy | Deployment docs | docs/operations/deployment/ |
| Security check | Security docs | docs/security/ |
Search Tips
- Use
grepfor finding specific code patterns - Check
docs/for comprehensive guides - Look in
src/types/for TypeScript definitions - Check
src/services/for business logic
🎯 Best Practices
Code Organization
- Single Responsibility - One file, one purpose
- Consistent Naming - Follow established patterns
- Type Safety - Use TypeScript everywhere
- Error Handling - Proper error boundaries and logging
Performance
- Lazy Loading - Use
React.lazy()for large components - Code Splitting - Dynamic imports for routes
- Memoization - Use
useMemoanduseCallbackappropriately - Bundle Analysis - Run
pnpm run analyzeregularly
Security
- Input Validation - Always validate user input
- Authentication - Use Supabase Auth properly
- Authorization - Check permissions for all actions
- Data Sanitization - Clean user data before processing
Testing
- Unit Tests - Test individual functions and components
- Integration Tests - Test service interactions
- E2E Tests - Test complete user flows
- Security Tests - Test authentication and authorization
📞 Getting Help
Common Issues
- Build Errors: Check TypeScript compilation with
pnpm run type-check - Runtime Errors: Check browser console and server logs
- Database Issues: Verify Supabase connection and migrations
- Authentication: Check auth configuration and RLS policies
Resources
- Project README:
README.md- High-level overview - Architecture Docs:
docs/architecture/- System design - Development Guide:
docs/development/- Day-to-day development - Security Guide:
docs/security/- Security policies - Standards:
docs/development/standards/- Coding standards
Community
- GitHub Issues - For bugs and feature requests
- Pull Requests - For code contributions
- Documentation - Help improve these guides
🔄 Keeping This Guide Updated
This guide should evolve with the codebase. When you:
- Add new features → Update the architecture section
- Change file structure → Update the project structure section
- Add new patterns → Update the development workflow section
- Find missing information → Add it to the appropriate section
Remember: A good developer guide is a living document that grows with the project!
Last Updated: $(date) Version: 1.0.0