# CLAUDE.md

This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.

## Commands

```bash
# Build WAR artifact (output: target/coatchtime.war)
./mvnw clean package

# Run locally (defaults to test profile, port 8000)
./mvnw spring-boot:run

# Run with a specific profile
SPRING_PROFILES_ACTIVE=production ./mvnw spring-boot:run

# Compile only (no tests)
./mvnw compile

# Run tests
./mvnw test

# Run a single test class
./mvnw test -Dtest=SomeTestClassName
```

## Architecture

This is a **Spring Boot 4.0.3 / Java 17** backend for a coaching platform. It is packaged as a WAR, deployed via Jenkins CI to a Linux systemd service (`coachtime`), and runs on port 8000 with HTTPS (self-signed JKS keystore).

### Profiles

| Profile | Activated by | Notes |
|---|---|---|
| `test` | default (`SPRING_PROFILES_ACTIVE` unset) | Local dev, PostgreSQL on `127.0.0.1:5432/coache` |
| `production` | `SPRING_PROFILES_ACTIVE=production` | Same DB config, different log paths |

Both profiles point to the same local PostgreSQL instance (`coache` database, user/pass `camelsoft/camelsoft`). Redis is always required on `127.0.0.1:6379` with password `redisSecret`.

### Package layout (`com.camelsoft.coachtime`)

```
controller/
  Auth/        — login, signup, user profile
  Coach/       — coach config (payment, SMTP, OpenAI, tracking, Zoom)
  Courses/     — course CRUD and v2 endpoints
  meeting/     — Zoom meeting lifecycle
  notification/— push and in-app notifications
  Public/      — unauthenticated public API
  Tools/       — wallet / payment endpoints
  web/         — website builder (articles, consultations, programs, colors, etc.)
services/      — business logic, mirrors controller subpackages
repository/    — Spring Data JPA repositories
models/        — JPA entities
request/       — incoming DTO classes
response/Dto/  — outgoing DTO classes
Redis/         — Redis service wrappers (articles, notifications, view counts, wishlist)
Sheduler/      — scheduled jobs (PendingPaymentScheduler, runs every 15 min)
tools/
  configuration/ — Spring beans, security, WebSocket, Tomcat, Jackson, Swagger
  exception/     — custom exception types + GlobalExceptionHandler
  util/          — JWT utilities, startup initializer, logout cache
filter/        — AuthFilter (JWT extraction)
Enum/          — domain enums
```

### Security & Auth flow

All requests go through `AuthFilter` (`filter/AuthFilter.java`). It extracts a JWT from:
1. `Authorization: Bearer <token>` header (normal API calls)
2. `?token=<token>` query parameter (Moyasar payment callback redirects)

Public endpoints are whitelisted in `SecurityConfig.PUBLIC_ENDPOINTS`. Method-level security is enabled (`@EnableMethodSecurity`). Sessions are stateless.

`FirstTimeInitializer` seeds admin/coach/user accounts at startup if they don't exist.

### Key integrations

- **Zoom** — meeting creation, registrant management, recording/transcript retrieval (`ZoomService`, `ZoomConfig`)
- **OpenAI** — async meeting summary generation triggered when a meeting ends (`AIService`, `OpenAIConfigService`)
- **Stripe + Moyasar** — dual payment providers; active provider is stored per-coach in `CoachPaymentConfig`. `PendingPaymentScheduler` polls both every 15 minutes to reconcile `PENDING` wallet entries and enroll users in courses/consultations
- **Firebase FCM** — push notifications via `FireBaseFCMService`; config loaded from `firebase-service-account.json` at classpath
- **LiveKit** — video room tokens (`livekit-server` SDK)
- **Cloudflare** — DNS record management (credentials in `application.yml`)
- **Redis** — caching for articles, notifications, view counts, wishlists via dedicated service classes in `Redis/`
- **WebSocket** — raw text signaling via `SocketHandler` (broadcast to all peers except sender); endpoint `/ws` and `/signaling`

### Database

PostgreSQL with Hibernate DDL auto-update (`hbm2ddl.auto: update`) and Flyway migrations in the `migrations` schema (migration files under `resources/migration/`). `hypersistence-utils-hibernate-70` provides JSON column type support for Hibernate 7.

### Naming conventions (existing inconsistency)

The codebase mixes naming styles: some entity and service classes use lowercase (`users`, `courses`, `consultaionrequeststate`, `articleService`) while others use PascalCase. Follow the existing style of the file you are editing rather than renaming.
