|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Essential Commands |
| 6 | + |
| 7 | +### Build & Development |
| 8 | +```bash |
| 9 | +# Build everything |
| 10 | +yarn build |
| 11 | + |
| 12 | +# Build JavaScript assets |
| 13 | +yarn build:js |
| 14 | + |
| 15 | +# Build flow editor |
| 16 | +yarn build:editor |
| 17 | + |
| 18 | +# Watch flow editor during development |
| 19 | +yarn watch:editor |
| 20 | + |
| 21 | +# Build CSS |
| 22 | +yarn build:css |
| 23 | + |
| 24 | +# Rails commands |
| 25 | +bundle install |
| 26 | +rails db:migrate |
| 27 | +rails db:seed |
| 28 | +rails server |
| 29 | +``` |
| 30 | + |
| 31 | +### Testing |
| 32 | +```bash |
| 33 | +# Run Rails tests |
| 34 | +rails test |
| 35 | + |
| 36 | +# Run flow editor tests |
| 37 | +cd flow_editor && yarn test |
| 38 | + |
| 39 | +# Run flow editor tests with coverage |
| 40 | +cd flow_editor && yarn test:coverage |
| 41 | + |
| 42 | +# Run flow editor tests in watch mode |
| 43 | +cd flow_editor && yarn test:watch |
| 44 | + |
| 45 | +# Lint flow editor code |
| 46 | +cd flow_editor && yarn lint |
| 47 | +``` |
| 48 | + |
| 49 | +### Code Quality |
| 50 | +```bash |
| 51 | +# Run Ruby linter (Standard) |
| 52 | +bundle exec standardrb |
| 53 | + |
| 54 | +# Run security analysis |
| 55 | +bundle exec brakeman |
| 56 | +``` |
| 57 | + |
| 58 | +### Docker & Microservices |
| 59 | +```bash |
| 60 | +# Start all services (Rails app + Docling service) |
| 61 | +docker-compose up |
| 62 | + |
| 63 | +# Start in background |
| 64 | +docker-compose up -d |
| 65 | + |
| 66 | +# View logs |
| 67 | +docker-compose logs -f |
| 68 | + |
| 69 | +# Stop all services |
| 70 | +docker-compose down |
| 71 | + |
| 72 | +# Rebuild services |
| 73 | +docker-compose build |
| 74 | + |
| 75 | +# Start just the docling service |
| 76 | +docker-compose up docling-service |
| 77 | +``` |
| 78 | + |
| 79 | +## Architecture Overview |
| 80 | + |
| 81 | +This is a Rails 8.0.2 application. |
| 82 | + |
| 83 | +### Core Components |
| 84 | +- **Rails Backend**: Main application with multi-tenant architecture using Plutonium framework |
| 85 | + |
| 86 | +### Multi-Database Setup |
| 87 | +The application uses SQLite with multiple database connections: |
| 88 | +- Main database: Core application data |
| 89 | +- Queue database: Background job processing (Solid Queue) |
| 90 | +- Cache database: Application caching (Solid Cache) |
| 91 | +- Errors database: Error tracking (Solid Errors) |
| 92 | + |
| 93 | +## Development Patterns |
| 94 | + |
| 95 | +### Plutonium Framework |
| 96 | +The application heavily uses Plutonium for rapid admin interface development: |
| 97 | +- Models include `Plutonium::Resource::Record` |
| 98 | +- Definitions control UI and behavior declaratively |
| 99 | +- Policies handle authorization and access control |
| 100 | +- Auto-detection of fields from model attributes |
| 101 | + |
| 102 | +### Node Development |
| 103 | +When adding or modifying nodes, ensure you update: |
| 104 | +- `flow_editor/schemas/validators/javascript/schema-validator.js` |
| 105 | +- `flow_editor/schemas/validators/ruby/schema_validator.rb` |
| 106 | +- `flow_editor/schemas/flow_schema.json` |
| 107 | +- `app/views/home/features.html.erb` |
| 108 | + |
| 109 | +### Testing Strategy |
| 110 | +- Rails tests use fixtures and parallel execution |
| 111 | +- React tests use Testing Library with comprehensive coverage |
| 112 | +- Both unit and integration tests are maintained |
| 113 | +- Flow execution tests ensure conversation logic works correctly |
| 114 | + |
| 115 | +## Key Configuration Files |
| 116 | + |
| 117 | +### Frontend Build |
| 118 | +- `flow_editor/vite.config.js`: Flow editor build configuration |
| 119 | +- `flow_editor/vite.webchat.config.js`: WebChat widget build configuration |
| 120 | +- `postcss.config.js`: CSS processing configuration |
| 121 | +- `tailwind.config.js`: Tailwind CSS configuration |
| 122 | + |
| 123 | +### Rails Configuration |
| 124 | +- `config/packages.rb`: Package registration |
| 125 | +- `config/initializers/plutonium.rb`: Plutonium framework configuration |
| 126 | +- `config/initializers/flowchat.rb`: FlowChat engine configuration |
| 127 | +- `config/initializers/ruby_llm.rb`: AI/LLM integration |
| 128 | + |
| 129 | +## Development Guidelines |
| 130 | + |
| 131 | +### File Organization |
| 132 | +When creating new files in the flow editor, follow these conventions: |
| 133 | +- **Validation utilities**: Place in `flow_editor/src/utils/validation/` |
| 134 | +- **Shared constants and utilities**: Place in `flow_editor/src/shared/` |
| 135 | +- **Component-specific utilities**: Keep with the component or in `flow_editor/src/utils/` |
| 136 | +- **Export from index files**: Update the relevant `index.js` files when adding new exports |
| 137 | + |
| 138 | +### Node Schema Updates |
| 139 | +When modifying node data structures or validation logic, always maintain consistency between JavaScript and Ruby implementations. |
| 140 | + |
| 141 | +### Regression Testing |
| 142 | +When fixing bugs, add regression tests to prevent similar issues in the future. |
| 143 | + |
| 144 | +### Code Reusability |
| 145 | +Extract common logic into reusable functions rather than duplicating code across components. |
| 146 | + |
| 147 | +### CSS Framework |
| 148 | +The project uses Tailwind CSS v4 for all styling. Use Tailwind utilities instead of custom CSS whenever possible. |
| 149 | + |
| 150 | +## Authentication & Authorization |
| 151 | + |
| 152 | +### Multi-tier Authentication |
| 153 | +- **User Authentication**: Rodauth-based with email/password |
| 154 | +- **Admin Authentication**: Separate admin system with enhanced security |
| 155 | +- **Entity-based Authorization**: Multi-tenant access control through entity memberships |
| 156 | + |
| 157 | +### Security Features |
| 158 | +- CSRF protection enabled |
| 159 | +- Content Security Policy configured |
| 160 | +- Brakeman static security analysis |
| 161 | +- Secure session management |
| 162 | + |
| 163 | +## Entity Scoping & Multi-Tenancy |
| 164 | + |
| 165 | +### How Entity Scoping Works |
| 166 | +The application uses Plutonium's built-in entity scoping to ensure data isolation between tenants: |
| 167 | + |
| 168 | +1. **Automatic Scoping**: The customer portal has `scope_to_entity Entity, strategy: :current_entity` configured in `packages/customer_portal/lib/engine.rb` |
| 169 | +2. **Current Entity**: Available via `current_entity` method in controllers, which returns `Entity.for_user(current_user)` |
| 170 | +3. **Query Filtering**: All queries through `authorized_resource_scope()` are automatically filtered by `entity_id` |
| 171 | + |
| 172 | +### Using Authorized Scopes |
| 173 | +Always use Plutonium's authorization helpers to ensure proper scoping: |
| 174 | + |
| 175 | +```ruby |
| 176 | +# ✅ CORRECT - Automatically scoped to current_entity |
| 177 | +@hackers = authorized_resource_scope(Hacker) |
| 178 | +@teams = authorized_resource_scope(Hackathon::Team) |
| 179 | + |
| 180 | +# ❌ WRONG - Bypasses entity scoping |
| 181 | +@hackers = Hacker.all |
| 182 | +``` |
| 183 | + |
| 184 | + |
| 185 | +### Policy Implementation |
| 186 | +Create policies for proper authorization: |
| 187 | + |
| 188 | +```ruby |
| 189 | +module HackerDashboardPortal |
| 190 | + module Hackathon |
| 191 | + class DefinitionPolicy < ResourcePolicy |
| 192 | + def show? |
| 193 | + record.entity_id == context[:current_entity].id |
| 194 | + end |
| 195 | + end |
| 196 | + end |
| 197 | +end |
| 198 | +``` |
| 199 | + |
| 200 | +### Security Checklist |
| 201 | +- ✅ Always use `authorized_resource_scope()` for queries |
| 202 | +- ✅ Never use `.all` or `.find()` directly on entity-scoped models |
| 203 | +- ✅ Implement policies for all resources |
| 204 | +- ✅ Test cross-entity access attempts |
| 205 | +- ✅ For analytics, ensure all aggregations respect entity boundaries |
| 206 | + |
| 207 | +## Deployment & Production |
| 208 | + |
| 209 | +### Background Jobs |
| 210 | +- Solid Queue for job processing |
| 211 | +- Mission Control for job monitoring |
| 212 | +- Recurring job support for scheduled tasks |
| 213 | + |
| 214 | +### Error Monitoring |
| 215 | +- Solid Errors for comprehensive error tracking |
| 216 | +- Built-in error pages and handling |
| 217 | + |
| 218 | +### Asset Pipeline |
| 219 | +- Propshaft for asset serving |
| 220 | +- ESBuild for JavaScript bundling |
| 221 | +- Tailwind CSS for styling |
| 222 | +- Source maps enabled for debugging |
0 commit comments