|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Project Overview |
| 6 | + |
| 7 | +KidsMedia is a Phoenix LiveView application that provides an immersive, kid-friendly interface for exploring educational content about animals. The app fetches images from Unsplash API and is designed for fullscreen, distraction-free experiences. |
| 8 | + |
| 9 | +## Core Architecture |
| 10 | + |
| 11 | +### Key Modules |
| 12 | + |
| 13 | +- **`lib/kids_media/unsplash.ex`**: External API integration for fetching animal images |
| 14 | +- **`lib/kids_media_web/live/home.ex`**: Subject selection page with large, kid-friendly buttons |
| 15 | +- **`lib/kids_media_web/live/subject.ex`**: Fullscreen subject display with image galleries |
| 16 | +- **`lib/kids_media_web/components/layouts/fullscreen.html.heex`**: Custom layout for immersive experiences |
| 17 | + |
| 18 | +### Architectural Patterns |
| 19 | + |
| 20 | +**Fullscreen Layout System**: Both home and subject pages use a custom fullscreen layout (`{KidsMediaWeb.Layouts, :fullscreen}`) set via `assign(:root_layout, ...)` in mount/3. This bypasses the default app header/footer for immersive viewing. |
| 21 | + |
| 22 | +**External API Integration**: The `KidsMedia.Unsplash` module follows this pattern: |
| 23 | + |
| 24 | +```elixir |
| 25 | +def search!(query) do |
| 26 | + # Fetch from API, decode JSON, extract URLs |
| 27 | + # Always returns list of image URLs or raises |
| 28 | +end |
| 29 | +``` |
| 30 | + |
| 31 | +**LiveView Hooks**: Uses `phx-hook="Fullscreen"` with JavaScript hook in `assets/js/app.js` that automatically triggers fullscreen mode after DOM patching. |
| 32 | + |
| 33 | +## Development Commands |
| 34 | + |
| 35 | +### Setup and Development |
| 36 | + |
| 37 | +```bash |
| 38 | +# Initial setup - installs deps, sets up assets |
| 39 | +mix setup |
| 40 | + |
| 41 | +# Start development server (with environment variables) |
| 42 | +source .env && mix phx.server |
| 43 | + |
| 44 | +# Start with IEx console access |
| 45 | +source .env && iex -S mix phx.server |
| 46 | +``` |
| 47 | + |
| 48 | +### Environment Variables |
| 49 | + |
| 50 | +- **Local Development**: If `UNSPLASH_ACCESS_KEY` is not set, prefix commands with `source .env &&` |
| 51 | +- **GitHub Codespaces**: Environment variables are pre-configured, `source .env &&` usually not needed |
| 52 | +- **When in doubt**: Try without prefix first; if you get "environment variable missing" error, then use `source .env &&` |
| 53 | + |
| 54 | +### Testing |
| 55 | + |
| 56 | +```bash |
| 57 | +# Run all tests |
| 58 | +mix test |
| 59 | + |
| 60 | +# Run tests with coverage (minimum 80% required) |
| 61 | +mix test --cover |
| 62 | + |
| 63 | +# Generate detailed coverage report |
| 64 | +mix coveralls.html |
| 65 | + |
| 66 | +# Watch mode for development |
| 67 | +mix test.watch |
| 68 | + |
| 69 | +# Run specific test file |
| 70 | +mix test test/kids_media_web/live/home_live_test.exs |
| 71 | +``` |
| 72 | + |
| 73 | +### Code Quality and CI Validation |
| 74 | + |
| 75 | +**CRITICAL**: Always run these commands before completing changes to ensure PR compliance: |
| 76 | + |
| 77 | +```bash |
| 78 | +# Quick comprehensive validation |
| 79 | +mix ci |
| 80 | + |
| 81 | +# Individual validation steps: |
| 82 | +mix compile --warnings-as-errors |
| 83 | +mix format --check-formatted # or mix format to auto-fix |
| 84 | +mix test --color |
| 85 | +mix credo --strict |
| 86 | +mix sobelow --skip |
| 87 | +mix assets.setup && mix assets.build |
| 88 | +``` |
| 89 | + |
| 90 | +### Asset Management |
| 91 | + |
| 92 | +```bash |
| 93 | +# Setup assets (installs Tailwind/esbuild if missing) |
| 94 | +mix assets.setup |
| 95 | + |
| 96 | +# Build assets for development |
| 97 | +mix assets.build |
| 98 | + |
| 99 | +# Build minified assets for production |
| 100 | +mix assets.deploy |
| 101 | +``` |
| 102 | + |
| 103 | +## Configuration |
| 104 | + |
| 105 | +### Content Security Policy |
| 106 | + |
| 107 | +Custom CSP in `endpoint.ex` allows Unsplash images and YouTube embeds: |
| 108 | + |
| 109 | +```elixir |
| 110 | +"default-src 'self'; img-src 'self' https://images.unsplash.com; frame-src https://www.youtube-nocookie.com; script-src 'self' 'unsafe-inline'" |
| 111 | +``` |
| 112 | + |
| 113 | +### Environment Variables for configuration |
| 114 | + |
| 115 | +- `UNSPLASH_ACCESS_KEY`: Required for image fetching. See `.env.example` for setup. |
| 116 | + |
| 117 | +## LiveView Conventions |
| 118 | + |
| 119 | +- Use `assign(:root_layout, {KidsMediaWeb.Layouts, :fullscreen})` for immersive pages |
| 120 | +- Subject LiveViews should set `page_title` assign for proper browser titles |
| 121 | +- Images are lazy-loaded with `loading="lazy"` |
| 122 | +- Navigation uses `push_navigate(socket, to: ~p"/subject/#{topic}")` pattern |
| 123 | + |
| 124 | +## Test Structure |
| 125 | + |
| 126 | +### Test Types |
| 127 | + |
| 128 | +1. **Unit Tests** (`test/kids_media/`) - Individual modules in isolation |
| 129 | +2. **LiveView Tests** (`test/kids_media_web/live/`) - Phoenix LiveView components |
| 130 | +3. **Integration Tests** (`test/kids_media_web/integration_test.exs`) - End-to-end functionality |
| 131 | +4. **Smoke Tests** (`test/kids_media_web/smoke_test.exs`) - Basic health checks |
| 132 | + |
| 133 | +### Mocking Strategy |
| 134 | + |
| 135 | +External API calls (Unsplash) are mocked using configurable modules to avoid network dependencies and ensure fast, reliable tests. |
| 136 | + |
| 137 | +## Styling Approach |
| 138 | + |
| 139 | +Tailwind CSS with kid-friendly aesthetics: |
| 140 | + |
| 141 | +- Large buttons with emoji (`text-5xl font-bold bg-yellow-400 px-20 py-12`) |
| 142 | +- Black backgrounds for fullscreen content (`bg-black text-white`) |
| 143 | +- Responsive image grids (`flex flex-wrap justify-center gap-4`) |
| 144 | + |
| 145 | +## PRP Workflow (Product Requirements Document) |
| 146 | + |
| 147 | +**CRITICAL**: Always follow the structured PRP approach: **Plan → Create PRP → Execute PRP** |
| 148 | + |
| 149 | +This project uses a rigorous PRP workflow to ensure high-quality, well-documented feature development with one-pass implementation success. |
| 150 | + |
| 151 | +### Creating PRPs |
| 152 | + |
| 153 | +Use the comprehensive research and documentation process to create detailed PRPs: |
| 154 | + |
| 155 | +#### Research Process |
| 156 | + |
| 157 | +1. **Codebase Analysis** |
| 158 | + - Search for similar features/patterns in the codebase |
| 159 | + - Identify files to reference in PRP (`lib/kids_media/`, `lib/kids_media_web/`) |
| 160 | + - Note existing conventions to follow (LiveView patterns, API integration, testing approaches) |
| 161 | + - Check test patterns in `test/` directory for validation approach |
| 162 | + |
| 163 | +2. **External Research** |
| 164 | + - Search for similar features/patterns online |
| 165 | + - Library documentation (include specific URLs for Phoenix LiveView, HTTPoison, etc.) |
| 166 | + - Implementation examples (GitHub/StackOverflow/blogs) |
| 167 | + - Best practices and common pitfalls |
| 168 | + |
| 169 | +3. **Context Gathering** (CRITICAL for AI success) |
| 170 | + - Include ALL necessary documentation, code examples, and gotchas |
| 171 | + - Reference existing patterns from `lib/kids_media/unsplash.ex`, LiveView components |
| 172 | + - Document library quirks (HTTPoison supervision, rate limiting, timeouts) |
| 173 | + - Include validation commands and expected outcomes |
| 174 | + |
| 175 | +#### PRP Template Usage |
| 176 | + |
| 177 | +- Use `PRPs/templates/prp_base.md` as foundation for all PRPs |
| 178 | +- Include executable validation gates (`mix ci`, `mix test`, specific test commands) |
| 179 | +- Reference existing codebase patterns and conventions |
| 180 | +- Provide pseudocode with critical implementation details |
| 181 | +- Document error handling strategies and integration points |
| 182 | + |
| 183 | +#### PRP Storage and Quality |
| 184 | + |
| 185 | +- Save PRPs as `PRPs/{feature-name}.md` |
| 186 | +- Score PRPs 1-10 for implementation confidence |
| 187 | +- Ensure all necessary context is included for one-pass success |
| 188 | +- Include specific file modifications and creation tasks |
| 189 | +- Provide clear implementation path with validation loops |
| 190 | + |
| 191 | +### Executing PRPs |
| 192 | + |
| 193 | +Follow the structured execution process for reliable implementation: |
| 194 | + |
| 195 | +#### 1. Load PRP |
| 196 | + |
| 197 | +- Read the specified PRP file completely |
| 198 | +- Understand all context and requirements |
| 199 | +- Follow all instructions in the PRP |
| 200 | +- Extend research if needed using web searches and codebase exploration |
| 201 | +- Ensure all needed context is available |
| 202 | + |
| 203 | +#### 2. Plan (ULTRATHINK) |
| 204 | + |
| 205 | +- Think comprehensively before executing |
| 206 | +- Use TodoWrite tool to create and track implementation plan |
| 207 | +- Break down complex tasks into smaller, manageable steps |
| 208 | +- Identify implementation patterns from existing code to follow |
| 209 | +- Plan validation approach using existing CI commands |
| 210 | + |
| 211 | +#### 3. Execute |
| 212 | + |
| 213 | +- Implement all code following PRP specifications |
| 214 | +- Follow existing patterns (LiveView conventions, API integration, testing structure) |
| 215 | +- Use established patterns from `lib/kids_media/unsplash.ex` for external API calls |
| 216 | +- Maintain kid-friendly design principles and accessibility considerations |
| 217 | + |
| 218 | +#### 4. Validate |
| 219 | + |
| 220 | +- Run each validation command specified in PRP |
| 221 | +- Use existing CI pipeline: `mix ci` for comprehensive checks |
| 222 | +- Fix any failures iteratively |
| 223 | +- Re-run until all validation gates pass |
| 224 | +- Ensure minimum 80% test coverage maintained |
| 225 | + |
| 226 | +#### 5. Complete |
| 227 | + |
| 228 | +- Ensure all checklist items are completed |
| 229 | +- Run final validation suite |
| 230 | +- Reference the PRP again to ensure everything is implemented |
| 231 | +- Report completion status with validation results |
| 232 | + |
| 233 | +### PRP Best Practices |
| 234 | + |
| 235 | +#### Quality Standards |
| 236 | + |
| 237 | +- Include executable validation commands (`mix ci`, `mix test --cover`) |
| 238 | +- Reference existing codebase patterns consistently |
| 239 | +- Document error handling strategies and gotchas |
| 240 | +- Provide clear implementation path with pseudocode |
| 241 | +- Score implementation confidence 1-10 |
| 242 | + |
| 243 | +#### Integration with Existing Workflow |
| 244 | + |
| 245 | +- Connect PRP validation gates to existing CI commands section |
| 246 | +- Use established test patterns and coverage requirements |
| 247 | +- Follow LiveView conventions and architectural patterns |
| 248 | +- Maintain consistency with styling approach and accessibility requirements |
| 249 | + |
| 250 | +## Important Notes |
| 251 | + |
| 252 | +- YouTube integration is planned but not yet implemented (see commented code in subject.ex) |
| 253 | +- Assets are processed via esbuild/tailwind, not Node.js package manager |
| 254 | +- Application is designed for touch interfaces and accessibility |
| 255 | +- All compilation must complete without warnings for PR approval |
| 256 | +- Code must be properly formatted using `mix format` |
| 257 | +- Minimum 80% test coverage required |
0 commit comments