-
Notifications
You must be signed in to change notification settings - Fork 60
docs: add Claude Code project documentation #899
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
bonzofenix
wants to merge
17
commits into
main
Choose a base branch
from
init-claude-code
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
4351e6f
Add initial claude code configs
bonzofenix a45dd79
Add 'simplify' skill for code clarity and maintainability
bonzofenix 809352d
feat: implement smart-pr skill for automated PR generation and updates
bonzofenix 10e6197
feat: add automatic PR label selection to smart-pr skill
bonzofenix 2e03951
docs: simplify and refine skill documentation for clarity
bonzofenix 6e7a705
fix: correct agent type reference in simplify skill
bonzofenix af4aa4d
chore: add gh api permission to Claude settings
bonzofenix 6cc6a07
docs: add PR comment resolution workflow to CLAUDE.md
bonzofenix 7dd0cdc
feat: add unresolved-comments skill
bonzofenix 497f390
chore: add git permissions to Claude settings
bonzofenix c0e4954
chore: ignore Claude Code cache directory
bonzofenix 1d752cb
Remove Claude Code configuration files
bonzofenix 9c6a5fa
Update .gitignore to exclude entire .claude directory
bonzofenix 702b8cf
Improve CLAUDE.md documentation formatting and clarity
bonzofenix 34700b0
Update documentation for consistency and clarity
bonzofenix 4a41a64
Merge branch 'main' into init-claude-code
bonzofenix 28e29d4
Document CF task execution and environment variable syntax
bonzofenix File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,252 @@ | ||
| # CLAUDE.md | ||
|
|
||
| This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. | ||
|
|
||
| ## Project Overview | ||
|
|
||
| **Application Autoscaler for Cloud Foundry** is a production-grade microservices system that automatically scales Cloud Foundry applications based on metrics (CPU, memory, throughput, custom metrics) and schedules. It acts as a Cloud Foundry service broker, allowing apps to bind to the autoscaler service and define scaling policies. | ||
|
|
||
| ## Technology Stack | ||
|
|
||
| - **Go 1.24.3**: Used for 6 of 7 microservices (api, eventgenerator, scalingengine, metricsforwarder, operator, acceptance tests) | ||
| - **Java 17+/Spring Boot 3.5**: Used only for the Scheduler component with Quartz scheduler | ||
| - **PostgreSQL**: Primary database (multiple logical databases per component) | ||
| - **Testing**: Ginkgo/Gomega for Go, JUnit for Java | ||
| - **Mocking**: Counterfeiter for generating test fakes | ||
|
|
||
| ## Build & Test Commands | ||
|
|
||
| ### Building | ||
| ```bash | ||
| make build # Build all Go services | ||
| make scheduler.build # Build Java scheduler component | ||
| make build-test-app # Build test application | ||
| make build_all # Build everything (programs + tests) | ||
| make mta-build # Build MTA archive for Cloud Foundry deployment | ||
| ``` | ||
|
|
||
| ### Testing | ||
| ```bash | ||
| make test # Run all unit tests (auto-starts PostgreSQL via Docker) | ||
| make autoscaler.test # Run Go unit tests only | ||
| make scheduler.test # Run Java scheduler tests | ||
| make integration # Run integration tests | ||
| make acceptance-tests # Run acceptance tests (requires deployed autoscaler) | ||
| make mta-acceptance-tests # Run acceptance tests via CF tasks in parallel | ||
|
|
||
| # Run specific test suite | ||
| make test TEST=./api # Run tests for specific package | ||
|
|
||
| # Test options via GINKGO_OPTS | ||
| GINKGO_OPTS="--focus=scaling" make test | ||
| ``` | ||
|
|
||
| ### Database Management | ||
| ```bash | ||
| make start-db # Start PostgreSQL via Docker | ||
| make stop-db # Stop PostgreSQL | ||
| make init-db # Initialize database schemas | ||
| ``` | ||
|
|
||
| ### Code Quality | ||
| ```bash | ||
| make lint # Run all linters (Go, markdown, GitHub Actions) | ||
| OPTS=--fix make lint # Auto-fix linting issues | ||
| make fmt # Format Go code | ||
| make generate-fakes # Generate test mocks with Counterfeiter | ||
| make generate-openapi-generated-clients-and-servers # Generate OpenAPI clients/servers | ||
| ``` | ||
|
|
||
| ### Deployment | ||
| ```bash | ||
| make mta-deploy # Deploy to Cloud Foundry using MTA | ||
| make mta-undeploy # Undeploy from Cloud Foundry | ||
| make deploy-register-cf # Register service broker with CF | ||
| make deploy-cleanup # Clean up autoscaler deployment | ||
| ``` | ||
|
|
||
| ### Cleanup | ||
| ```bash | ||
| make clean # Clean all build artifacts, fakes, and caches | ||
| make clean-acceptance # Clean acceptance test artifacts | ||
| ``` | ||
|
|
||
| ## High-Level Architecture | ||
|
|
||
| The autoscaler is a **distributed microservices architecture** with 7 components: | ||
|
|
||
| ### Core Components | ||
|
|
||
| 1. **API Server** (`/api`) | ||
| - Public REST API and Cloud Foundry service broker implementation | ||
| - Manages policies, bindings, scaling history queries | ||
| - Uses: PolicyDB, BindingDB | ||
| - Entry point: `api/cmd/api/main.go` | ||
|
|
||
| 2. **Event Generator** (`/eventgenerator`) | ||
| - Polls metrics from CF Log Cache, aggregates them, evaluates scaling rules | ||
| - Triggers scaling events when thresholds breach | ||
| - Components: MetricPoller, Aggregator, Evaluator, AppManager | ||
| - Uses: AppMetricsDB, PolicyDB | ||
| - Entry point: `eventgenerator/cmd/eventgenerator/main.go` | ||
|
|
||
| 3. **Scaling Engine** (`/scalingengine`) | ||
| - Executes scaling decisions by calling CF API | ||
| - Manages cooldown periods to prevent oscillation | ||
|
bonzofenix marked this conversation as resolved.
|
||
| - Records scaling history and synchronizes schedules | ||
| - Uses: PolicyDB, ScalingEngineDB, SchedulerDB | ||
| - Entry point: `scalingengine/cmd/scalingengine/main.go` | ||
|
|
||
| 4. **Scheduler** (`/scheduler`) - **Java/Spring Boot** | ||
| - Manages scheduled scaling (recurring/specific dates) using Quartz | ||
| - **Only component written in Java** | ||
| - Uses: SchedulerDB | ||
| - Build: Maven with `pom.xml` | ||
|
|
||
| 5. **Metrics Forwarder** (`/metricsforwarder`) | ||
| - Receives custom app metrics via HTTP, forwards to Log Cache | ||
| - Rate limits metric submissions | ||
| - Uses: PolicyDB, BindingDB | ||
| - Entry point: `metricsforwarder/cmd/metricsforwarder/main.go` | ||
|
|
||
| 6. **Operator** (`/operator`) | ||
| - Background tasks: database pruning, schedule sync, app state sync | ||
| - Uses distributed locking for single active instance | ||
| - Uses: AppMetricsDB, ScalingEngineDB, PolicyDB, LockDB | ||
| - Entry point: `operator/cmd/operator/main.go` | ||
|
|
||
| 7. **Service Broker** (part of API Server) | ||
| - Cloud Foundry service broker API implementation | ||
| - Handles provisioning, binding, policy management | ||
|
|
||
| ### Data Flow Example | ||
|
|
||
| 1. User creates service binding with policy → API Server → PolicyDB | ||
| 2. Event Generator polls metrics from Log Cache → aggregates → evaluates against policy | ||
| 3. Threshold breached → Event Generator calls Scaling Engine | ||
| 4. Scaling Engine checks cooldown → scales via CF API → records history | ||
|
|
||
| ## Important Development Patterns | ||
|
|
||
| ### Shared Code Structure | ||
|
|
||
| - `/models`: Shared data models (policy, metrics, API types) | ||
| - `/db`: Database interfaces and SQL implementations | ||
| - `/cf`: Cloud Foundry client wrapper | ||
|
|
||
| ### Database Architecture | ||
|
|
||
| Each service uses its own logical PostgreSQL database: | ||
|
|
||
| - `policy_db`: Scaling policies and credentials | ||
| - `binding_db`: Service bindings and instances | ||
| - `appmetrics_db`: Metrics time-series data | ||
| - `scalingengine_db`: Scaling history and cooldown state | ||
| - `scheduler_db`: Schedules and Quartz job data | ||
| - `lock_db`: Distributed locks | ||
|
|
||
| ### Testing Patterns | ||
|
|
||
| - **Unit tests**: Use Ginkgo/Gomega, run with `make test` | ||
| - **Fakes**: Generated via Counterfeiter with `make generate-fakes` | ||
| - **Integration tests**: Require running PostgreSQL (auto-started) | ||
| - **Test certs**: Auto-generated via `make test-certs` | ||
| - Always regenerate fakes after interface changes | ||
|
|
||
| ### Configuration Management | ||
|
|
||
| Services use YAML configuration files. See `scripts/vars.source.sh` for standard environment variables: | ||
|
|
||
| - `DEPLOYMENT_NAME`: Deployment identifier (default: `autoscaler-mta-${PR_NUMBER}`) | ||
| - `SYSTEM_DOMAIN`: CF system domain | ||
| - `DBURL`: Database connection string | ||
| - `BBL_STATE_PATH`: BBL state directory (optional, falls back to error message if missing) | ||
|
|
||
| ### Scripts | ||
|
|
||
| Critical scripts in `/scripts`: | ||
|
|
||
| - `vars.source.sh`: Sets standard environment variables (source in other scripts) | ||
| - `mta-build.sh`: Builds MTA archive | ||
| - `mta-deploy.sh`: Deploys to Cloud Foundry | ||
| - `run-mta-acceptance-tests.sh`: Runs acceptance tests in parallel via CF tasks | ||
|
|
||
| `vars.source.sh` uses ERR trap for error handling. When writing scripts that source it, be aware that commands that fail will trigger error reporting. | ||
|
|
||
| ## API Specifications | ||
|
|
||
| OpenAPI 3.0 specs in `/openapi`: | ||
|
|
||
| - `policy-api.openapi.yaml`: Scaling policy management | ||
| - `scaling-history-api.openapi.yaml`: Query scaling history | ||
| - `custom-metrics-api.openapi.yaml`: Submit custom metrics | ||
|
|
||
| Code generation uses `ogen` tool via `make generate-openapi-generated-clients-and-servers`. | ||
|
|
||
| ## Common Gotchas | ||
|
|
||
| 1. **Counterfeiter**: Uses pinned `golang.org/x/tools v0.39.0` due to compatibility issues. Don't upgrade without checking. | ||
| 2. **Database vendoring**: Run `make init-db` after database schema changes. | ||
| 3. **Java component**: Scheduler is the only Java component, built separately with Maven. | ||
| 4. **Test database**: Tests auto-start PostgreSQL via Docker. Use `db_type=postgres` (default) or `db_type=mysql`. | ||
| 5. **MTA deployment**: Requires Cloud Foundry MTA plugin and proper credentials. | ||
| 6. **Go modules**: `GOWORK=off` is set to disable workspace mode. | ||
| 7. **FIPS builds**: `GOFIPS140=v1.0.0` enables FIPS 140 compliance. | ||
| 8. **BBL_STATE_PATH**: Script continues gracefully if path doesn't exist (shows error message but doesn't fail). | ||
|
|
||
| ## Acceptance Tests | ||
|
|
||
| Located in `/acceptance`: | ||
|
|
||
| - Require deployed autoscaler instance | ||
| - Configuration file: `acceptance/acceptance_config.json` | ||
| - Run in parallel via CF tasks: `make mta-acceptance-tests` | ||
| - See `acceptance/README.md` for details | ||
|
|
||
| ### Running Acceptance Tests with CF Tasks | ||
|
|
||
| To run acceptance tests on a deployed autoscaler via Cloud Foundry tasks: | ||
|
|
||
| ```bash | ||
| # Run all app suite tests | ||
| cf run-task acceptance-tests --command "export SUITES=app NODES=1; bash /home/vcap/app/scripts/run-acceptance-tests-task.sh" --name "run-app-tests" | ||
|
|
||
| # Run with focus filter (memory tests only) | ||
| cf run-task acceptance-tests --command "export SUITES=app NODES=1 GINKGO_OPTS='--focus=memoryused'; bash /home/vcap/app/scripts/run-acceptance-tests-task.sh" --name "memory-tests" | ||
|
|
||
| # Check results | ||
| cf logs acceptance-tests --recent | ||
| ``` | ||
|
|
||
| **Important - Environment Variable Syntax:** | ||
|
|
||
| When passing environment variables to `cf run-task`, use this format: | ||
| ```bash | ||
| export VAR1=value1 VAR2=value2; bash script.sh | ||
| ``` | ||
|
|
||
| **NOT** this format (won't work): | ||
| ```bash | ||
| VAR1=value1 VAR2=value2 bash script.sh | ||
| ``` | ||
|
|
||
| **GINKGO_OPTS patterns** for filtering tests (used with `--focus`): | ||
| - `memoryused`: Tests scaling by memory used metric | ||
| - `memoryutil`: Tests scaling by memory utilization % | ||
| - `cpu`: Tests scaling by CPU metric | ||
| - `throughput`: Tests scaling by request throughput | ||
| - `responsetime`: Tests scaling by response time | ||
| - `disk`: Tests scaling by disk usage | ||
| - Custom patterns: Use Ginkgo v2 regex syntax | ||
|
|
||
| **Task Monitoring:** | ||
| ```bash | ||
| # List all tasks for acceptance-tests app | ||
| cf tasks acceptance-tests | ||
|
|
||
| # View running task logs | ||
| cf logs acceptance-tests --recent | ||
|
|
||
| # Search for specific test results | ||
| cf logs acceptance-tests --recent | grep "SUCCESS\|FAILED" | ||
| ``` | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.