Prerequisites
Before you begin, ensure you have the following installed:- Node.js 20.x or higher
- npm 9.x or higher
- Git for version control
- OpenRouter API key from openrouter.ai/keys
Initial Setup
1. Clone the Repository
2. Install Dependencies
package.json, including:
- Next.js, React, and TypeScript
- Tailwind CSS and shadcn/ui components
- Vitest for testing
- Development tools (ESLint, etc.)
3. Configure Environment Variables
Create a.env.local file in the project root:
If a
.env.example file exists, you can copy it: cp .env.example .env.localOPENROUTER_MODELdefaults toopenai/gpt-4o-mini, falls back togoogle/gemini-2.0-flashif unsetOPENROUTER_PDF_ENGINEdefaults topdf-text
Running the Development Server
Start the Next.js development server:- Hot module replacement (HMR)
- Fast refresh for React components
- Automatic TypeScript compilation
- Real-time error overlay
- API route hot reload
Alternative Package Managers
Development Workflow
Hot Reload
The development server automatically reloads when you make changes: Client-side changes:- Component files (
*.tsx,*.ts) - Styles (
globals.css, Tailwind classes) - Fast refresh preserves component state
- API routes (
app/api/*/route.ts) - Server components
- Configuration files (requires manual restart)
Project Structure Navigation
Key directories to work in:Common Development Tasks
Running Tests
Watch mode (recommended for TDD):- Terminal (text)
coverage/index.html(browse in browser)coverage/coverage-final.json(for CI)
Linting
Run ESLint to check code quality:Fix all lint errors before committing. ESLint uses
next/core-web-vitals rules.Building for Production
Create an optimized production build:- Type-check TypeScript
- Lint the codebase
- Bundle and optimize assets
- Generate static pages
- Create
.next/output directory
Type Checking
TypeScript is checked automatically during build, but you can run it manually:Development Tips
Code Organization
Import alias: Use@/ for all internal imports:
Styling Best Practices
Use Tailwind utilities:cn():
API Route Development
API routes inapp/api/*/route.ts:
Debugging
Console logging:- Client components: Browser console
- Server components: Terminal where
npm run devis running - API routes: Terminal output
- React Developer Tools extension
- Network tab for API calls
- Console for client-side errors
.vscode/launch.json:
Testing the Application
Manual Testing Flow
-
Start development server:
-
Visit
http://localhost:3000 -
Test OCR upload:
- Drag and drop an invoice image
- Or click to select a file
- Verify extraction results
-
Test JSON review tool:
- Visit
http://localhost:3000/review - Paste LangFuse trace JSON
- Verify reconciliation math
- Visit
Unit Testing
Add tests inlib/__tests__/:
Troubleshooting
Common Issues
Port 3000 already in use:- Ensure
.env.localexists in project root - Restart the dev server after changing
.env.local - Check for typos in variable names
- Verify
OPENROUTER_API_KEYis set correctly - Check API key at https://openrouter.ai/keys
- Review API limits and quotas
Getting Help
Project documentation:README.md- User-facing setup guideCLAUDE.MD- Comprehensive project documentationAGENTS.md- Repository guidelines and conventions
- Next.js docs: https://nextjs.org/docs
- OpenRouter docs: https://openrouter.ai/docs
- Tailwind CSS: https://tailwindcss.com/docs
Git Workflow
Commit Guidelines
Follow Conventional Commits format:Pre-commit Checklist
- Code compiles without TypeScript errors
- All tests pass (
npm test) - Lint checks pass (
npm run lint) - No console.log statements left in code
- No secrets in committed files
- Changes are tested locally
Next Steps
Project Structure
Understand the codebase organization
Tech Stack
Learn about the technologies used
API Reference
Explore the API endpoints
Architecture
Learn about the system design
