Provides architectural overview, development commands, and key patterns for future Claude instances working with this codebase. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
3.3 KiB
3.3 KiB
CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Development Commands
npm run dev- Start development server (Next.js)npm run build- Build production versionnpm start- Start production servernpm run prettier- Format code with Prettiernpm run prettier:check- Check code formattingnpm run seed- Seed database with initial data
Deployment Commands
./build.sh- Build Docker image for deployment./deploy.sh- Deploy Docker service to production./debug-deploy.sh- Deploy with debug configuration
Architecture Overview
This is a Next.js 14 utility bills tracking application ("Evidencija Režija") with the following key components:
Tech Stack
- Framework: Next.js 14 with App Router and standalone output for Docker
- Authentication: NextAuth v5 with Google OAuth
- Database: MongoDB with connection pooling
- Internationalization: next-intl (Croatian/English)
- Styling: Tailwind CSS with DaisyUI components
- Deployment: Docker with MongoDB 4.4.27 (AVX compatibility)
Core Architecture Patterns
Multi-user Data Isolation: All database operations use the withUser higher-order function from app/lib/auth.ts:102 to automatically inject authenticated user ID into queries, ensuring data isolation between users.
Server Actions Pattern: Form handling uses Next.js Server Actions with Zod validation. Actions are defined in app/lib/actions/ and follow the pattern:
export const actionName = withUser(async (user: AuthenticatedUser, ...args) => {
// Server action implementation with automatic user context
});
Internationalization: Uses next-intl with locale-based routing. Messages are in messages/ directory. The middleware handles both auth and i18n routing.
Key Files & Responsibilities
middleware.ts- Handles authentication and i18n routing, defines public pagesapp/lib/auth.ts- NextAuth configuration,withUserHOF for user contextapp/lib/dbClient.ts- MongoDB connection with development/production handlingapp/lib/actions/- Server actions for data mutations (locations, bills, months)app/i18n.ts- Internationalization configuration (Croatian default)next.config.js- Standalone build config withserverActions.allowedOriginsfor Docker deployment
Database Schema
- Collections: Locations, Bills, Months (year-month periods)
- User Association: All documents include
userIdfield for multi-tenant isolation - Database Name: "utility-bills"
Docker Deployment Notes
- Uses standalone Next.js build for Docker optimization
- MongoDB 4.4.27 required for older CPU compatibility (no AVX instructions)
HOSTNAME=0.0.0.0withserverActions.allowedOriginsconfig to handle reverse proxy headers- Environment variables:
MONGODB_URI,GOOGLE_ID,GOOGLE_SECRET,AUTH_SECRET
Barcode/QR Code Feature
- Uses
@zxing/libraryand@zxing/browserfor PDF document scanning - Heavy barcode decoding operations should be moved to background threads if performance issues arise
- PDF processing with
pdfjs-distfor utility bill scanning
Testing & Code Quality
- ESLint with Next.js and Prettier configurations
- No specific test framework configured - check with user before assuming testing approach