|
| 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 | +Toolchain Labs built commercial solutions around the Pants OSS build system, including remote execution, caching, and build optimization. This repo is a snapshot of Toolchain's proprietary codebase (May 2023), now Apache 2.0 licensed. It is a polyglot codebase (Python, Rust, Go, TypeScript, Shell). |
| 8 | + |
| 9 | +## Build System |
| 10 | + |
| 11 | +This repo uses [Pants](https://www.pantsbuild.org/) v2.16.0 as its build tool. The `./pants` wrapper script invokes Pants. |
| 12 | + |
| 13 | +### Common Commands |
| 14 | + |
| 15 | +```shell |
| 16 | +# Run all Python tests |
| 17 | +./pants test src/python:: |
| 18 | + |
| 19 | +# Run tests for a specific directory |
| 20 | +./pants test src/python/toolchain/buildsense/:: |
| 21 | + |
| 22 | +# Run a single test file |
| 23 | +./pants test src/python/toolchain/util/some_test.py |
| 24 | + |
| 25 | +# Lint (all Python linters: black, isort, flake8, pylint, mypy, bandit, autoflake, pyupgrade, docformatter, ruff) |
| 26 | +./pants lint src/python:: |
| 27 | + |
| 28 | +# Format code (black + isort for Python, shfmt for shell) |
| 29 | +./pants fmt src/python:: |
| 30 | + |
| 31 | +# Type check |
| 32 | +./pants check src/python:: |
| 33 | + |
| 34 | +# List targets |
| 35 | +./pants list src/python/toolchain/service:: |
| 36 | +``` |
| 37 | + |
| 38 | +### Rust (not managed by Pants) |
| 39 | + |
| 40 | +Rust code lives in `src/rust/` as a Cargo workspace. CI uses standard cargo commands: |
| 41 | +```shell |
| 42 | +cd src/rust |
| 43 | +cargo fmt --all -- --check |
| 44 | +cargo build |
| 45 | +cargo test |
| 46 | +cargo clippy --all-targets -- -D warnings |
| 47 | +``` |
| 48 | +Rust toolchain version: 1.68.0 (see `rust-toolchain.toml`). |
| 49 | + |
| 50 | +### Node.js (not managed by Pants) |
| 51 | + |
| 52 | +Frontend apps are in `src/node/`. Uses Yarn for package management, Jest for tests, Cypress for E2E. |
| 53 | + |
| 54 | +## Code Style |
| 55 | + |
| 56 | +- **Python**: Black formatter, line length 120, target Python 3.9 (`CPython>=3.9,<3.10`) |
| 57 | +- **isort**: multi_line_output=3, trailing commas, known_first_party=`toolchain` |
| 58 | +- **Shell**: shfmt with `-i 2 -ci -sr` (2-space indent, case indent, redirect spacing) |
| 59 | +- Lint configs live in `build-support/python/` (flake8, pylintrc, mypy.ini, bandit.yaml) |
| 60 | +- Python project-level config in `pyproject.toml` (Black, isort, ruff settings) |
| 61 | +- Copyright headers enforced via `build-support/preambles/config.yaml` |
| 62 | + |
| 63 | +## Architecture |
| 64 | + |
| 65 | +### Python Services (`src/python/toolchain/service/`) |
| 66 | + |
| 67 | +Django-based microservices. Each service is a Django "project" composed of reusable Django "apps" that live elsewhere under `src/python/toolchain/`. Service project-level files (settings.py, urls.py, gunicorn_conf.py) live in the service directory; reusable app code lives in its own package. |
| 68 | + |
| 69 | +Run a local dev service: |
| 70 | +```shell |
| 71 | +./src/python/toolchain/service/<service_name>/manage.py runserver |
| 72 | +``` |
| 73 | + |
| 74 | +Key services: `buildsense/api` (build analytics), `users`, `webhooks`, `servicerouter`, `infosite`, `toolshed`, `payments`, `notifications`. |
| 75 | + |
| 76 | +Service definitions are in `src/python/toolchain/config/services.json`. |
| 77 | + |
| 78 | +### Remote Execution Platform (`src/rust/`) |
| 79 | + |
| 80 | +REAPI-compliant remote execution system. Request flow: **Client → AWS ALB → proxy-server → execution-server → Buildbox worker**. |
| 81 | + |
| 82 | +Rust workspace crates: |
| 83 | +- **proxy** / **proxy_server**: Authenticates gRPC requests (JWT), dispatches to backends. Uses `ginepro` for in-process load balancing across backend pods. |
| 84 | +- **execution** / **execution_server**: Queues execution requests; workers pull work via Bots protocol (leases). |
| 85 | +- **storage** / **storage_server**: Content Addressable Storage (CAS) and Action Cache. |
| 86 | +- **worker**: Worker process management. |
| 87 | +- **protos**: Protocol buffer definitions (REAPI, Bots protocol, CAS). |
| 88 | +- **digest**, **grpc_util**, **execution_util**: Shared utilities. |
| 89 | + |
| 90 | +Detailed architecture: `docs/remoting/life-of-a-request.md`. |
| 91 | + |
| 92 | +### Deployment (`prod/`) |
| 93 | + |
| 94 | +- **Docker images**: `prod/docker/` — Dockerfiles for Django services (gunicorn+nginx) and Rust services. |
| 95 | +- **Helm charts**: `prod/helm/` — Kubernetes deployment. Per-service charts under `prod/helm/services/`. |
| 96 | +- **Terraform**: `prod/terraform/` — AWS infrastructure (ECR, IAM, DynamoDB, S3, ALB). |
| 97 | +- **Kubernetes**: AWS EKS clusters (dev, prod, remoting). Namespace isolation per developer in dev. |
| 98 | + |
| 99 | +### Key Source Directories |
| 100 | + |
| 101 | +- `src/python/toolchain/pants/` — Custom Pants build system plugins |
| 102 | +- `src/python/toolchain/django/` — Shared Django utilities and common code |
| 103 | +- `src/python/toolchain/base/` — Core utilities and templates |
| 104 | +- `src/python/toolchain/remoting/` — Python-side remoting infrastructure |
| 105 | +- `3rdparty/` — Dependency lockfiles (two Python resolves: `default-toolchain` and `pants-plugin`) |
| 106 | + |
| 107 | +## Pants Dependency Management |
| 108 | + |
| 109 | +Two Python resolves exist: |
| 110 | +- `default-toolchain`: Main application code (`3rdparty/python/default_toolchain.lock`) |
| 111 | +- `pants-plugin`: Pants plugin code (`3rdparty/python/pants_plugin.lock`) |
| 112 | + |
| 113 | +Unowned dependency behavior is set to `error` — all imports must be traceable to BUILD targets. |
| 114 | + |
| 115 | +## Testing |
| 116 | + |
| 117 | +- Tests live alongside source code (pattern: `*_test.py`, `test_*.py`) |
| 118 | +- Default test timeout: 60 seconds |
| 119 | +- pytest v7.3.1 with pytest-icdiff for diff output |
| 120 | +- CI config: `pants.ci.toml` (enables coverage, verbose mode, 4 parallel processes) |
0 commit comments