This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
## Core Commands
### Development
```bash
npm run dev # Start Vite dev server at localhost:5173
npm run build # Build production bundle to dist/
npm run preview # Preview production build locally
```
### Testing & Quality
```bash
npm test # Run tests with Vitest
npm run lint # Run ESLint
```
### Docker Operations
```bash
docker compose up -d # Start containerized app on port 3800
docker compose down # Stop containers
docker compose build # Build Docker images
```
## Architecture Overview
### Application Type
React + TypeScript SPA for carbon offsetting calculations for yachts, built with Vite. Features both desktop and mobile-specific routes with Progressive Web App (PWA) support.
### Key Architectural Patterns
**Component Structure**: The app uses a single-page architecture with client-side routing managed through state in `App.tsx`. Navigation changes `currentPage` state rather than using React Router.
**Mobile App Route**: Special `/mobile-app` route renders `MobileCalculator` component exclusively, bypassing the standard layout. This is detected via `window.location.pathname` and managed through `isMobileApp` state.
**Data Flow**:
- Vessel data flows from `App.tsx` → Calculator components → `OffsetOrder`
- Carbon calculations happen in `utils/carbonCalculator.ts`
- API calls go through dedicated clients in `src/api/`
### API Integration
**Wren Climate API** (`src/api/wrenClient.ts`):
- Base URL: `https://www.wren.co/api`
- Requires Bearer token authentication via `VITE_WREN_API_TOKEN`
- Handles portfolio fetching and offset order creation
- Implements retry logic and fallback to default portfolio
**AIS Client** (`src/api/aisClient.ts`):
- Fetches vessel data by IMO number
- Currently uses mock data in development
**Formspree Integration**:
- Contact forms use `VITE_FORMSPREE_CONTACT_ID` and `VITE_FORMSPREE_OFFSET_ID`
- Handled in `Contact.tsx` and offset order components
### State Management
- Local component state via React hooks
- No global state management library
- Form state managed locally within components
- Calculator results passed via props to OffsetOrder components
### Styling Approach
- Tailwind CSS for utility-first styling
- Custom glass morphism effects via `index.css`
- Framer Motion for animations
- Responsive design with mobile-first approach
### Component Responsibilities
**Core Components**:
-`TripCalculator.tsx`: Desktop carbon calculator with trip details form
-`MobileCalculator.tsx`: Mobile-optimized calculator with step-by-step flow
- Pushes to Gitea container registry at `code.puffinoffset.com/matt/puffin-app`
**Image Tagging Strategy**:
-`latest`: Always points to most recent main branch build
-`main-<commit-sha>`: Specific commit version for rollbacks
**Container Registry**:
- Gitea's built-in Docker registry
- Authentication via Gitea credentials
- Registry URL: `code.puffinoffset.com`
**Deployment**:
- Manual deployment via Portainer
- Use `docker-compose.portainer.yml` for production stack configuration
- Environment variables mounted via `.env` file volume
- Detailed deployment instructions in `DEPLOYMENT.md`
**Workflow Optimization**:
- Docker buildx for multi-platform support
- Layer caching to speed up builds
- Separate build cache stored in registry
### Key Implementation Details
**Routing without React Router**: App uses state-based routing via `currentPage` state and `window.history.pushState()`. The `/mobile-app` route is detected by checking `window.location.pathname` and renders only `MobileCalculator` without the standard layout.
**Sample Vessel Data**: A hardcoded `sampleVessel` object is used as default vessel data in `App.tsx` (lines 17-24) since AIS client currently returns mock data.
**Analytics Integration**: `utils/analytics.ts` tracks page views via Google Analytics. Called in `App.tsx` useEffect when route changes.