--- created_date: 2025-09-25 last_modified_date: 2025-09-25 last_modified_summary: Created comprehensive codebase organization guide reflecting the cleaned up project structure --- # ๐Ÿ“ Codebase Organization ## Overview This document describes the organization and structure of the OrangeCat codebase after a comprehensive cleanup and reorganization. The structure follows industry best practices for maintainability, scalability, and developer experience. --- ## ๐Ÿ—๏ธ Project Root Structure ``` orangecat/ โ”œโ”€โ”€ ๐Ÿ“ src/ # Main source code โ”œโ”€โ”€ ๐Ÿ“ scripts/ # Organized utility scripts โ”‚ โ”œโ”€โ”€ ๐Ÿ“ db/ # Database operations โ”‚ โ”œโ”€โ”€ ๐Ÿ“ deployment/ # Deployment utilities โ”‚ โ”œโ”€โ”€ ๐Ÿ“ dev/ # Development tools โ”‚ โ”œโ”€โ”€ ๐Ÿ“ test/ # Testing utilities โ”‚ โ””โ”€โ”€ ๐Ÿ“ maintenance/ # Cleanup and optimization โ”œโ”€โ”€ ๐Ÿ“ tests/ # All test files (unified structure) โ”œโ”€โ”€ ๐Ÿ“ docs/ # Comprehensive documentation โ”œโ”€โ”€ ๐Ÿ“ public/ # Static assets โ”œโ”€โ”€ ๐Ÿ“ supabase/ # Supabase configuration โ”œโ”€โ”€ ๐Ÿ“ __mocks__/ # Test mocks (Vitest) โ”œโ”€โ”€ ๐Ÿ“ coverage/ # Test coverage reports โ””โ”€โ”€ ๐Ÿ“„ Standard config files # package.json, tsconfig.json, etc. ``` --- ## ๐Ÿ“ Source Code Structure (src/) ### Core Architecture ``` src/ โ”œโ”€โ”€ ๐Ÿ“ app/ # Next.js 13+ App Router โ”‚ โ”œโ”€โ”€ ๐Ÿ“ api/ # API routes (Next.js) โ”‚ โ”œโ”€โ”€ ๐Ÿ“ (authenticated)/ # Protected routes โ”‚ โ””โ”€โ”€ ๐Ÿ“ auth/ # Authentication pages โ”œโ”€โ”€ ๐Ÿ“ components/ # React components โ”‚ โ”œโ”€โ”€ ๐Ÿ“ auth/ # Authentication components โ”‚ โ”œโ”€โ”€ ๐Ÿ“ bitcoin/ # Bitcoin-related components โ”‚ โ”œโ”€โ”€ ๐Ÿ“ dashboard/ # Dashboard components โ”‚ โ”œโ”€โ”€ ๐Ÿ“ funding/ # Funding components โ”‚ โ”œโ”€โ”€ ๐Ÿ“ layout/ # Layout components โ”‚ โ”œโ”€โ”€ ๐Ÿ“ ui/ # Reusable UI components โ”‚ โ””โ”€โ”€ ๐Ÿ“ __tests__/ # Component tests โ”œโ”€โ”€ ๐Ÿ“ services/ # Business logic services โ”‚ โ”œโ”€โ”€ ๐Ÿ“ profile/ # Profile management โ”‚ โ”œโ”€โ”€ ๐Ÿ“ supabase/ # Supabase services โ”‚ โ”œโ”€โ”€ ๐Ÿ“ bitcoin/ # Bitcoin services โ”‚ โ”œโ”€โ”€ ๐Ÿ“ projects/ # Campaign services โ”‚ โ””โ”€โ”€ ๐Ÿ“ __tests__/ # Service tests โ”œโ”€โ”€ ๐Ÿ“ hooks/ # Custom React hooks โ”‚ โ””โ”€โ”€ ๐Ÿ“ __tests__/ # Hook tests โ”œโ”€โ”€ ๐Ÿ“ lib/ # Utility libraries โ”œโ”€โ”€ ๐Ÿ“ stores/ # State management (Zustand) โ”‚ โ””โ”€โ”€ ๐Ÿ“ __tests__/ # Store tests โ”œโ”€โ”€ ๐Ÿ“ utils/ # Utility functions โ”‚ โ””โ”€โ”€ ๐Ÿ“ __tests__/ # Utility tests โ”œโ”€โ”€ ๐Ÿ“ types/ # TypeScript type definitions โ”œโ”€โ”€ ๐Ÿ“ config/ # Configuration files โ”œโ”€โ”€ ๐Ÿ“ middleware/ # Next.js middleware โ””โ”€โ”€ ๐Ÿ“„ profileService.ts # Re-export for clean imports ``` ### Architecture Principles 1. **Feature-Based Organization**: Components and services are organized by business domain 2. **Separation of Concerns**: Clear separation between UI, business logic, and utilities 3. **Testing Colocation**: Tests are located alongside the code they test 4. **Clean Imports**: Use of path aliases (@/) for clean, consistent imports --- ## ๐Ÿ“ Scripts Organization The scripts directory is organized by purpose for easy maintenance: ### Database Scripts (scripts/db/) - Schema management and migrations - Profile creation and management - Data validation and cleanup - Supabase configuration ### Deployment Scripts (scripts/deployment/) - Production deployment utilities - Environment setup - Deployment verification - Monitoring and validation ### Development Scripts (scripts/dev/) - Development server management - API key management - Environment synchronization - Development utilities ### Testing Scripts (scripts/test/) - Test execution utilities - Test data generation - Test environment setup ### Maintenance Scripts (scripts/maintenance/) - Bundle analysis and optimization - Console log cleanup - Performance monitoring - Code quality checks --- ## ๐Ÿ“ Testing Structure All tests are unified under the `tests/` directory: ``` tests/ โ”œโ”€โ”€ ๐Ÿ“ auth/ # Authentication tests โ”œโ”€โ”€ ๐Ÿ“ security/ # Security tests โ”œโ”€โ”€ ๐Ÿ“ e2e/ # End-to-end tests โ”œโ”€โ”€ ๐Ÿ“ setup/ # Test setup utilities โ”œโ”€โ”€ ๐Ÿ“„ setup.ts # Global test setup โ”œโ”€โ”€ ๐Ÿ“„ teardown.ts # Global test teardown โ””โ”€โ”€ ๐Ÿ“„ utils.ts # Test utilities ``` ### Test Categories - **Unit Tests**: Located in `__tests__/` subdirectories within each feature - **Integration Tests**: Located alongside the code they test - **E2E Tests**: In `tests/e2e/` directory - **Security Tests**: In `tests/security/` directory --- ## ๐Ÿ“ Documentation Structure Comprehensive documentation organized by purpose: ``` docs/ โ”œโ”€โ”€ ๐Ÿ“„ README.md # Main documentation entry point โ”œโ”€โ”€ ๐Ÿ“ architecture/ # System architecture โ”œโ”€โ”€ ๐Ÿ“ development/ # Development guides โ”œโ”€โ”€ ๐Ÿ“ operations/ # Deployment and operations โ”œโ”€โ”€ ๐Ÿ“ security/ # Security documentation โ”œโ”€โ”€ ๐Ÿ“ design-system/ # UI/UX design system โ”œโ”€โ”€ ๐Ÿ“ components/ # Component documentation โ”œโ”€โ”€ ๐Ÿ“ features/ # Feature documentation โ”œโ”€โ”€ ๐Ÿ“ api/ # API documentation โ””โ”€โ”€ ๐Ÿ“ templates/ # Documentation templates ``` --- ## ๐Ÿ“ Configuration Files ### Consolidated Configuration - **vitest.config.ts**: Vitest configuration - **vitest.setup.ts**: Comprehensive test environment setup - **tsconfig.json**: TypeScript configuration with path mapping - **next.config.js**: Next.js configuration - **tailwind.config.ts**: Tailwind CSS configuration ### Configuration Principles 1. **Single Source of Truth**: No duplicate configuration files 2. **Environment-Specific**: Proper separation of dev/prod configs 3. **Type Safety**: Full TypeScript support for configuration 4. **Performance**: Optimized for development and production --- ## ๐Ÿงน Code Quality Standards ### Import Strategy - Use path aliases (`@/`) for all internal imports - Avoid relative imports (`../../../`) when possible - Group imports by type (external, internal, relative) - Use index files for clean public APIs ### File Organization - One component per file (except for tightly coupled components) - Single responsibility principle for all modules - Consistent naming conventions (kebab-case for files, PascalCase for components) - Proper TypeScript typing throughout ### Code Style - ESLint + Prettier for consistent formatting - TypeScript strict mode enabled - No `any` types (except in rare, well-documented cases) - Comprehensive error handling --- ## ๐Ÿš€ Development Workflow ### Getting Started 1. **Setup**: Follow the [Development Setup](../../SETUP.md) guide 2. **Environment**: Copy `config/production.env.template` to `.env.local` 3. **Dependencies**: Run `pnpm install` 4. **Development**: Use `pnpm run dev` for development server ### Code Organization Guidelines 1. **New Features**: Create feature branch with descriptive name 2. **File Placement**: Follow the established directory structure 3. **Tests**: Write tests alongside new code 4. **Documentation**: Update relevant documentation 5. **Reviews**: Follow the contributing guidelines ### Best Practices - Keep files under 400 lines when possible - Use feature flags for experimental features - Implement proper error boundaries - Follow accessibility guidelines - Maintain performance budgets --- ## ๐Ÿ” Finding Files ### Quick Navigation - **Components**: `src/components/[feature]/` - **Services**: `src/services/[domain]/` - **Types**: `src/types/[domain].ts` - **Tests**: `src/[module]/__tests__/` or `tests/[category]/` - **Documentation**: `docs/[category]/[topic].md` ### Search Strategy 1. Use IDE search for exact file names 2. Check feature directories for related functionality 3. Look in `docs/` for documentation 4. Search by component/service name in the appropriate directory --- ## ๐Ÿ“ Maintenance Guidelines ### Keeping Organized 1. **Regular Cleanup**: Remove unused files and dependencies 2. **Update Documentation**: Keep docs in sync with code changes 3. **Review Structure**: Periodically review and optimize organization 4. **Archive Old Files**: Move deprecated code to appropriate locations ### Adding New Code 1. Follow the established directory structure 2. Add tests for new functionality 3. Update relevant documentation 4. Use consistent naming conventions 5. Follow the project's coding standards --- ## ๐ŸŽฏ Benefits of This Structure ### For Developers - **Easy Navigation**: Clear, logical file organization - **Fast Onboarding**: Well-documented structure and guidelines - **Consistent Patterns**: Standardized approach across the codebase - **Quality Assurance**: Comprehensive testing and documentation ### For Maintenance - **Scalability**: Structure supports growth and new features - **Debugging**: Easy to locate and fix issues - **Refactoring**: Clear boundaries for code changes - **Team Collaboration**: Consistent structure across team members ### For Production - **Reliability**: Comprehensive testing and validation - **Performance**: Optimized build and runtime configuration - **Security**: Security-first approach with proper isolation - **Deployability**: Clean deployment pipeline with proper environments --- **๐Ÿ“š Next Steps**: Review the [Contributing Guide](../../../CONTRIBUTING.md) for detailed development workflows and the [Architecture Overview](architecture/ARCHITECTURE.md) for system design details.