|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## What is Sidecar? |
| 6 | + |
| 7 | +Sidecar is a Laravel package that lets you deploy and run AWS Lambda functions directly from your Laravel app. Write a function in Node, Python, Ruby, Java, or any Lambda-supported runtime, and call it from PHP as easily as `MyFunction::execute(['key' => 'value'])`. |
| 8 | + |
| 9 | +The package handles all the AWS complexity: packaging your code, uploading to S3, creating/updating Lambda functions, managing versions, and invoking them. |
| 10 | + |
| 11 | +## Testing |
| 12 | + |
| 13 | +```bash |
| 14 | +# Run all tests |
| 15 | +./vendor/bin/phpunit |
| 16 | + |
| 17 | +# Run a single test file |
| 18 | +./vendor/bin/phpunit tests/Unit/FunctionTest.php |
| 19 | + |
| 20 | +# Run a specific test method |
| 21 | +./vendor/bin/phpunit --filter test_runtime_value_resolves_enum_to_string |
| 22 | +``` |
| 23 | + |
| 24 | +Tests use Orchestra Testbench. The test suite has unit tests in `tests/Unit/` and integration tests in `tests/Integration/`. Most development work uses unit tests with mocked AWS clients. |
| 25 | + |
| 26 | +## How the Code is Organized |
| 27 | + |
| 28 | +### The Main Players |
| 29 | + |
| 30 | +**`LambdaFunction`** is the abstract base class that users extend. Every function needs two methods: |
| 31 | +- `handler()` - tells Lambda which file/function to run (e.g., `'image.handler'`) |
| 32 | +- `package()` - lists files to include in the deployment ZIP |
| 33 | + |
| 34 | +Users call static methods like `MyFunction::execute($payload)` to run their functions. |
| 35 | + |
| 36 | +**`Manager`** (accessed via the `Sidecar` facade) does the actual work of invoking Lambda functions. It prepares payloads, calls the AWS SDK, and wraps responses in result objects. |
| 37 | + |
| 38 | +**`Deployment`** handles the deploy workflow: package the code, create or update the Lambda function, then optionally activate it by pointing an alias to the new version. |
| 39 | + |
| 40 | +**`Package`** builds the ZIP file for deployment. It collects files based on include/exclude patterns, computes a hash for change detection, and streams the ZIP directly to S3. |
| 41 | + |
| 42 | +### AWS Clients |
| 43 | + |
| 44 | +The `src/Clients/` directory has thin wrappers around AWS SDK clients: |
| 45 | +- `LambdaClient` extends the SDK client and adds retry logic for Lambda's "Pending" state |
| 46 | +- `S3Client` and `CloudWatchLogsClient` are simpler wrappers |
| 47 | + |
| 48 | +### Results |
| 49 | + |
| 50 | +When you execute a function: |
| 51 | +- Sync calls return a `SettledResult` with the response body, logs, and error info |
| 52 | +- Async calls return a `PendingResult` that resolves to `SettledResult` when you call `->settled()` |
| 53 | + |
| 54 | +### Runtime and Architecture |
| 55 | + |
| 56 | +`Runtime` and `Architecture` are PHP 8.1 backed enums. There are also deprecated `RuntimeConstants` and `ArchitectureConstants` classes for backwards compatibility. |
| 57 | + |
| 58 | +When working with these, use `runtimeValue()` and `architectureValue()` methods to get the string values - they handle both enum and string inputs. |
| 59 | + |
| 60 | +## Configuration |
| 61 | + |
| 62 | +Everything lives in `config/sidecar.php`: |
| 63 | +- `functions` - array of `LambdaFunction` classes to deploy |
| 64 | +- `env` - environment name, used to namespace function names (defaults to `APP_ENV`) |
| 65 | +- `timeout`, `memory`, `storage` - default Lambda settings |
| 66 | +- AWS credentials (`aws_key`, `aws_secret`, `aws_region`, `aws_bucket`, `execution_role`) |
| 67 | + |
| 68 | +Function names are automatically prefixed with app name and environment to avoid collisions. |
| 69 | + |
| 70 | +## Artisan Commands |
| 71 | + |
| 72 | +These are what users run (not needed for package development, but good to know): |
| 73 | +- `sidecar:deploy` - packages and deploys functions to Lambda |
| 74 | +- `sidecar:activate` - points the "active" alias to latest version |
| 75 | +- `sidecar:deploy --activate` - both in one step |
| 76 | +- `sidecar:warm` - pre-warms function instances to reduce cold starts |
| 77 | +- `sidecar:configure` - interactive wizard to set up AWS resources |
| 78 | + |
| 79 | +## Events |
| 80 | + |
| 81 | +The package fires Laravel events you can hook into: |
| 82 | +- `BeforeFunctionsDeployed` / `AfterFunctionsDeployed` |
| 83 | +- `BeforeFunctionsActivated` / `AfterFunctionsActivated` |
| 84 | +- `BeforeFunctionExecuted` / `AfterFunctionExecuted` |
| 85 | + |
| 86 | +## Things to Know |
| 87 | + |
| 88 | +- This package supports Laravel 8 through 12 and PHP 8.1+ |
| 89 | +- All source files use `declare(strict_types=1)` |
| 90 | +- The codebase uses constructor property promotion and typed properties throughout |
| 91 | +- Tests use Mockery for mocking AWS clients - check existing tests for patterns |
0 commit comments