AI Development Guidelines
This document provides guidelines for AI assistants working on this codebase. All AI assistants MUST follow these guidelines.
⚠️ CRITICAL: Always Test Builds Before Pushing
MANDATORY RULE: Before committing and pushing any changes, you MUST:
-
Test the frontend build:
cd apps/frontend npm run build- The build MUST complete successfully with exit code 0
- Fix any TypeScript errors, ESLint errors, or build failures
- Warnings are acceptable, but errors will block deployment
-
Test the backend build:
cd apps/backend npm run build- The build MUST complete successfully
- Fix any TypeScript errors or compilation issues
-
Only push if both builds succeed
Why This Matters
- Vercel and Railway will fail deployments if builds fail
- Catching errors locally saves time and prevents broken deployments
- Build errors are easier to fix locally than debugging in CI/CD
Build Checklist
Before every commit/push:
- Frontend builds successfully (
cd apps/frontend && npm run build) - Backend builds successfully (
cd apps/backend && npm run build) - No TypeScript errors
- No ESLint errors (warnings OK)
- All pages can be pre-rendered (no Suspense boundary errors)
Code Quality Standards
TypeScript
- All code must be properly typed
- No
anytypes unless absolutely necessary (with justification) - Fix all TypeScript errors before committing
ESLint
- Fix all ESLint errors (they block builds)
- ESLint warnings are acceptable but should be addressed when possible
- Common issues:
- Unescaped entities in JSX (use
',", etc.) - Missing dependencies in useEffect hooks
- Using
<img>instead of Next.js<Image />
- Unescaped entities in JSX (use
React/Next.js Best Practices
- Wrap
useSearchParams()usage in Suspense boundaries - Mark dynamic pages with
export const dynamic = 'force-dynamic'when needed - Use proper TypeScript types for all props and state
File Organization
- Frontend code:
apps/frontend/src/ - Backend code:
apps/backend/src/ - Documentation: Root level
.mdfiles ordocs/directory - Migrations:
supabase/migrations/
Testing Workflow
- Make changes
- Test locally:
# Frontend cd apps/frontend && npm run build # Backend cd apps/backend && npm run build - Fix any errors
- Re-test builds
- Only then commit and push
Common Build Errors and Fixes
TypeScript Errors
- HeadersInit type issues: Cast to
Record<string, string> - querySelector type issues: Cast to specific element type (e.g.,
HTMLInputElement) - Missing types: Add proper type annotations
Next.js Errors
- useSearchParams() without Suspense: Wrap component in Suspense boundary
- Pre-rendering errors: Add
export const dynamic = 'force-dynamic'to page - Missing dependencies: Add to useEffect dependency array or use useCallback
ESLint Errors
- Unescaped entities: Replace
'with',"with" - Missing img alt: Add alt text or use Next.js Image component
Commit Messages
Use clear, descriptive commit messages:
- Start with a verb (Fix, Add, Update, Remove)
- Describe what was changed and why
- Reference related issues if applicable
Example:
Fix build errors: TypeScript types and Suspense boundaries
- Fix TypeScript error in api.ts (HeadersInit type)
- Add Suspense boundaries for useSearchParams()
- Resolves Vercel build failures
Environment Variables
- Never commit
.envfiles - Document required environment variables in relevant docs
- Use
.env.examplefiles as templates
Documentation
- Update relevant documentation when making significant changes
- Add comments for complex logic
- Update
TESTING_BUILDS.mdif build process changes
Git and GitHub
- DO NOT auto-push to GitHub unless explicitly asked by the user
- Only commit changes locally unless the user requests a push
- When the user asks to "commit and push" or similar, then push
- Always test builds before pushing (see Build Checklist above)
Deployment
- Frontend auto-deploys to Vercel on push to
main - Backend auto-deploys to Railway on push to
main - Both platforms will fail if builds fail
- Always test builds locally first to prevent deployment failures
Questions?
If you encounter build errors you can't resolve:
- Check
TESTING_BUILDS.mdfor common solutions - Review recent commits for similar fixes
- Check Next.js/TypeScript documentation
- Ask for help rather than pushing broken builds
Remember: A successful local build = a successful deployment. Always test before pushing!