This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
This is the Mesh API repository containing protobuf definitions and multi-language SDK generation for Mesh's trading platform APIs. The repository follows a schema-first approach where protobuf definitions are the source of truth, with generated client libraries in Go, Python, and TypeScript.
Workspace Structure: This is a yarn workspace with the following members:
ts/- TypeScript SDK package (@meshtrade/api)docs/- Docusaurus documentation site (mesh-api-docs)tool/protoc-gen-meshts/cmd/- TypeScript protobuf generator tool
Workspace Commands: All commands should be run from the repository root:
yarn install- Install all workspace dependenciesyarn build- Build TypeScript SDKyarn build:docs- Build documentation siteyarn start:docs- Start documentation dev server at http://localhost:3000/api/yarn serve:docs- Serve built documentationyarn test- Run TypeScript testsyarn lint- Lint TypeScript codeyarn generate- Run code generation script
yarn start:docs- Start Docusaurus development server (http://localhost:3000/api/)yarn build:docs- Build static Docusaurus siteyarn serve:docs- Serve built documentation site- Site URL: https://meshtrade.github.io/api
./dev/tool.sh all- Main development tool that cleans, generates, and builds all client libraries./dev/tool.sh generate- Generate code from protobuf definitions./dev/tool.sh build- Build SDK packages./dev/tool.sh test- Run comprehensive test suites for all languages./dev/tool.sh doctor- Check development environment health./dev/tool.sh clean- Clean generated filesbuf generate- Direct buf generation (used internally by dev scripts)
Playwright screenshots for testing purposes should be stored in the docs/testing_screenshots directory.
CRITICAL: Playwright should always be run in headless mode.
./dev/test/go.sh- Run comprehensive Go tests with coverage and lintinggo test ./...- Run basic Go testsgo mod tidy- Clean up Go module dependencies
./dev/test/python.sh- Run comprehensive Python tests with coverage and lintingpip install -e ".[dev]"- Install Python package in development modepytest- Run Python testsruff check python/ --fix- Lint Python code (CRITICAL: Always run after Python changes)ruff format python/- Format Python codetox- Run full test suite with tox
./dev/test/typescript.sh- Run comprehensive TypeScript tests with Jest and lintingyarn test- Run TypeScript testsyarn build- Build TypeScript libraryyarn lint- Lint TypeScript code
./dev/test/java.sh- Run comprehensive Java tests with Maven and coverage analysis
CRITICAL: Python code must run in a virtual environment:
# Setup virtual environment
python -m venv .venv
source .venv/bin/activate
# Install dependencies in development mode
pip install -e ".[dev]"
# Run tests
pytest
# Run linting (CRITICAL: Always run after Python changes)
ruff check . --fix
ruff format .Configuration: Uses ruff with 150-character line limit (see pyproject.toml)
Key Linting Rules:
- E501: Line length (150 chars max)
- E711: Use
is/is notfor None comparisons (never== None) - F401: Remove unused imports OR add proper
__all__lists to modules - SIM112: Environment variables must use UPPER_CASE naming
Critical Python Module Organization Rule:
- NEVER put code other than imports in
__init__.pyfiles - use dedicated modules instead. This ensures clean module structure and prevents import issues.
Best Practices for Line Length:
- Use parentheses for implicit line continuation on function calls
- Break long docstrings across multiple lines
- Use
# noqa: E501ONLY for extreme cases (300+ chars) like malformed test data - Break long f-strings using multiple f-string concatenation
Example Good Line Breaking:
# Good - function call with parentheses
result = (
some_long_function_name_that_exceeds_limit(
parameter_one=value,
parameter_two=other_value,
)
)
# Good - docstring breaking
def function():
"""
This is a long docstring that needs to be broken across multiple lines
to respect the line length limit while maintaining readability.
"""
# Good - f-string breaking
message = (
f"This is a long message with {variable_one} and "
f"another {variable_two} that spans multiple lines"
)Configuration: Uses comprehensive linting stack with multiple tools (see java/pom.xml)
Linting Tools:
- Checkstyle: Code style enforcement (Google Java Style Guide)
- PMD: Code quality analysis and complexity checking
- Error Prone: Compile-time bug detection (Google)
Key Style Rules:
- Line Length: 120 characters max (adjusted for Java verbosity)
- JavaDoc: Required for all public classes, methods, and constructors
- Indentation: 4 spaces (no tabs)
- Naming: camelCase for variables/methods, PascalCase for classes, UPPER_SNAKE_CASE for constants
- Imports: No star imports, organized by groups (java., javax., , co.meshtrade.)
Running Linters:
cd java
# Run all linters (part of test suite)
mvn verify
# Run individual linters
mvn checkstyle:check # Code style
mvn pmd:check # Code quality
# View HTML reports
open target/site/checkstyle.html
open target/site/pmd.htmlConfiguration Files:
java/checkstyle.xml- Checkstyle rules (Google Style)java/pmd-ruleset.xml- PMD custom rulesjava/.editorconfig- Editor consistency settings
Best Practices:
- Run
mvn verifybefore committing to catch all violations - Fix violations immediately - don't accumulate technical debt
- Use
@SuppressWarningssparingly and only with justification comments - Generated protobuf code is automatically excluded from all checks
/proto/- Protobuf API definitions (source of truth)/meshtrade/- All API services organized by domain- Each service follows pattern:
domain/resource/v1/
/go/- Generated Go client libraries and utilities/python/- Generated Python packages with additional utilities/ts/- Generated TypeScript modules/docs/- Docusaurus-based documentation site- 📖 IMPORTANT FOR AGENTS: Always read
/docs/CLAUDE.mdfor detailed documentation site guidance docs/- Main documentation content (MDX files)blog/- News/blog postssrc/- React components and pagesstatic/- Static assets (images, logos, etc.)docusaurus.config.ts- Docusaurus configurationsidebars.ts- Navigation sidebar configurationpackage.json- Documentation site dependencies
- 📖 IMPORTANT FOR AGENTS: Always read
/dev/- Development tools (generation, build, clean, test, deploy)tool.sh- Main orchestration script with comprehensive helpgenerate/- Code generation scripts for each languagebuild/- Build scripts for SDK packagesclean/- Cleanup scripts for generated filestest/- Test execution scripts for all languagesenv/- Environment validation scripts and doctor tool
/tool/protoc-gen-meshgo/- Custom protobuf generator for Go
Services are organized by business domain:
compliance/client/v1- Client compliance and KYCiam/role/v1&iam/group/v1- Identity and access managementissuance_hub/instrument/v1- Financial instrument managementtrading/direct_order/v1,trading/limit_order/v1,trading/spot/v1- Trading serviceswallet/account/v1- Account and wallet managementtype/v1- Shared types used across services (Amount, Decimal, Token, etc.)
- Protobuf definitions in
/proto/define the API contracts ./dev/tool.sh allor./dev/tool.sh generateruns comprehensive code generation:- Validates environment prerequisites for each language
- Cleans generated files using language-specific cleanup scripts
- Runs
buf generatewith individual language configurations - Applies post-processing (formatting, index generation)
- Multiple protobuf plugins generate language-specific code:
- Go: Standard protobuf + gRPC + custom meshgo generator
- Python: Standard protobuf generators + custom meshpy utilities
- TypeScript: protobuf-js + grpc-web + custom meshts enhancements
- Java: Standard protobuf + gRPC + custom meshjava utilities
- Docs: Custom meshdoc generator for MDX documentation
- Language-specific build processes create final packages
The /proto/meshtrade/type/v1/ directory contains foundational types used across multiple services:
Decimal- High-precision decimal arithmeticAmount- Monetary amounts with currencyToken- Blockchain token representationsLedger- Ledger-related types- Custom Go and TypeScript utilities extend these with helper functions
- Making API Changes: Always modify protobuf files in
/proto/first - Code Generation: Run
./dev/tool.sh allto clean, generate, and build all client libraries- For selective generation:
./dev/tool.sh generate --targets=go,python - For individual languages:
./dev/tool.sh generate --targets=typescript
- For selective generation:
- Testing: Use the comprehensive testing infrastructure after generation
- Run all tests:
./dev/tool.sh test - Run specific language tests:
./dev/tool.sh test --targets=python,java - Environment validation:
./dev/tool.sh doctor
- Run all tests:
- Version Management: API versions are managed through protobuf package paths (v1, v2, etc.)
- Environment Requirements: The dev tool validates all prerequisites automatically:
- Go 1.21+, Python 3.12+ with active venv, Node.js 18+, Java 21, Maven, Yarn, buf
The testing system provides robust validation across all SDK languages:
# Test all languages with environment validation
./dev/tool.sh test
# Test specific languages
./dev/tool.sh test --targets=python,java,typescript
# Verbose output for debugging
./dev/tool.sh test --targets=go --verbose
# Individual language tests
./dev/test/python.sh # Python with pytest, coverage, ruff linting
./dev/test/java.sh # Java with Maven, JaCoCo coverage
./dev/test/go.sh # Go with race detection, coverage, golangci-lint
./dev/test/typescript.sh # TypeScript with Jest, type checking, ESLintBefore testing, validate your development environment:
# Comprehensive environment check
./dev/tool.sh doctor
# Individual environment validation
./dev/env/python.sh # Python venv, dependencies
./dev/env/java.sh # Java 21, Maven setup
./dev/env/go.sh # Go version, modules
./dev/env/typescript.sh # Node.js, Yarn, dependencies
./dev/env/general.sh # buf, git, general toolsPython Tests: pytest with coverage, ruff linting, virtual environment validation Java Tests: Maven surefire/failsafe, JaCoCo coverage Go Tests: Standard testing, race detection, coverage analysis, security linting TypeScript Tests: Jest framework, type checking, ESLint validation, build verification
# Fail-fast for CI pipelines
./dev/test/all.sh --fail-fast
# Environment + testing workflow
./dev/tool.sh doctor && ./dev/tool.sh testCRITICAL: When working with documentation, ALWAYS read /docs/CLAUDE.md first for comprehensive documentation site guidance, including:
- Playwright MCP setup and testing workflows
- Background server management
- Documentation site architecture
- Testing and screenshot procedures
- Root README.md: Simplified overview with link to full documentation site
- docs/docs/: Main documentation content in MDX format
introduction.mdx- Getting started guideapi-reference/- Generated API documentation from protobufarchitecture/- Architecture and design documentation
- docs/blog/: News and updates
- docs/src/: Custom React components and pages
- Uses
@docusaurus/preset-classicwith custom theme - Mermaid diagrams supported via
@docusaurus/theme-mermaid - Configured for multi-language code examples (Go, Python, TypeScript, Protobuf)
- Custom CSS styling in
src/css/custom.css
- Create MDX files in
docs/docs/with front matter:--- sidebar_position: 1 title: Page Title ---
- Update
sidebars.tsto include new pages in navigation - Use MDX features like React components and code blocks
- docs/docs/api-reference/: Auto-generated from protobuf using
protoc-gen-meshdoc - Manual pages: Architecture, introduction, and other hand-written content
- Navigation: Managed through
sidebars.tsconfiguration
- All generated files (*.pb.go, *_pb2.py, *pb.js, etc.) should not be manually edited
- The repository uses buf for protobuf management and linting
- Each language SDK is independently packaged and versioned
- Breaking changes require new API versions (e.g., v1 -> v2)
- Custom protobuf generator
protoc-gen-meshgocreates additional Go utilities
- Docusaurus site is self-contained in
/docs/directory as a yarn workspace member - Use
yarn start:docsfrom repository root to start development server - API documentation auto-generated from protobuf using
protoc-gen-meshdoctool - Site builds successfully and serves on http://localhost:3000/api/
- Generated documentation includes interactive code examples and type definitions
- Resource Service Naming: All resource services follow consistent pattern:
- Method names include resource name (e.g.,
GetAccount,CreateClient,MintInstrument) - Request/Response messages include resource name (e.g.,
GetAccountRequest,ListClientsResponse) - Get/Create methods return the resource directly, not a response wrapper
- Method names include resource name (e.g.,
- Authorization Model: Uses Role enum from
meshtrade/option/v1/role.proto:- File-level
standard_rolesoption declares all roles used by service - Method-level
rolesoption specifies which roles can access each method - Extension tags:
standard_roles= 50003,roles= 50005,method_type= 50004 - Role definitions follow pattern:
ROLE_{DOMAIN}_{ADMIN|VIEWER}(e.g.,ROLE_COMPLIANCE_ADMIN,ROLE_IAM_VIEWER) - Each service domain has both admin and viewer roles with appropriate permissions
- File-level
- Method Type Classification: Uses MethodType enum from
meshtrade/option/v1/method_type.proto:- All RPC methods must specify
method_typeoption as eitherMETHOD_TYPE_READorMETHOD_TYPE_WRITE - Read operations (Get, List, Search) use
METHOD_TYPE_READ - Write operations (Create, Update, Delete, Mint, Burn) use
METHOD_TYPE_WRITE
- All RPC methods must specify
- Extension Tag Management: Be careful with protobuf extension tag conflicts across option files
- Response Message Cleanup: Remove unused response messages when methods return resources directly
- Always run
./dev/tool.sh allafter protobuf changes to regenerate all language bindings - Use
buf lintto validate protobuf syntax and style before generation - Role definitions must be added to
meshtrade/option/v1/role.protofollowing theROLE_{DOMAIN}_{ADMIN|VIEWER}pattern - Method type annotations are mandatory for all RPC methods using
METHOD_TYPE_READorMETHOD_TYPE_WRITE - File-level role declarations ensure service authorization model is self-documenting
- Method-level role assignments control granular access permissions per operation
- Modify protobuf files in
/proto/directory - Run
buf lintto validate changes - Run
./dev/tool.sh allto regenerate all client libraries - Run language-specific tests and linting to verify correctness
When adding options to protobuf files, keep the following in mind:
- Option Syntax: Custom options for services or methods should be declared directly. The correct syntax is
option (custom.option) = VALUE;and notoption (custom.option) = { key: VALUE };. - Enum Scopes: When referencing enums from an imported
.protofile (likemethod_type.protoorrole.proto), you should use the enum value directly (e.g.,METHOD_TYPE_READ) without the fully qualified package path, as long as the necessary import statement is present. - Option Scopes (
FileOptionsvs.ServiceOptions): It's critical to apply options at the correct level. For example,standard_rolesis aFileOptionand must be declared at the top level of the file, not within aservicedefinition, which usesServiceOptions.