|
1 | | -Rosetta-Java Cardano Application — Development Guide (Context Window For AI Agents) |
2 | | - |
3 | | -✅ Overview |
4 | | - |
5 | | -This project is a Java implementation of the Rosetta specification, adapted from Coinbase’s original mesh. It targets the Cardano blockchain and is optimized for performance, scalability, and testability. |
6 | | - |
7 | | -⸻ |
8 | | - |
9 | | -🛠️ Technologies & Standards |
10 | | -• Java 24 – Latest LTS features leveraged. |
11 | | -• Lombok – For reducing boilerplate (e.g., getters, constructors). |
12 | | -• Hibernate + JOOQ – A hybrid approach planned: |
13 | | -• Hibernate for standard ORM tasks. |
14 | | -• JOOQ for complex SQL operations. |
15 | | -• Hibernate for standard ORM needs. |
16 | | -• JOOQ for high-performance, complex SQL queries. |
17 | | -• Flywheel – Used for event-sourced state and domain logic. |
18 | | -• OpenAPI (api.yaml) – Contract-first approach: |
19 | | -• Edit src/main/resources/rosetta-specifications-1.4.15/api.yaml for API changes. |
20 | | -• Code generation tools automatically create request/response classes. |
21 | | -• No Spring RestControllers – All endpoints are generated from OpenAPI spec; avoid manually annotating endpoints. |
22 | | -• JUnit 5 with @Nested tests – Organize tests into logical groups. |
23 | | -• AssertJ – Preferred assertion framework for fluent and expressive assertions. |
24 | | - |
25 | | -⸻ |
26 | | - |
27 | | -📋 Step-by-Step Context Window / Discovery |
28 | | - |
29 | | -1. Rosetta API Specification |
30 | | - • Maintained in: |
31 | | - src/main/resources/rosetta-specifications-1.4.15/api.yaml |
32 | | - • ❗ All endpoints and models are generated, do not manually modify controller classes. |
33 | | - |
34 | | -2. Code Generation |
35 | | - • Triggered via build tools (Gradle/Maven). |
36 | | - • Output includes: |
37 | | - • DTOs |
38 | | - • Server interfaces |
39 | | - • Clients |
40 | | - • Ensures OpenAPI remains the single source of truth. |
41 | | - |
42 | | -3. Persistence Layer |
43 | | - • Hibernate handles standard CRUD and entity management. |
44 | | - • JOOQ will be used for: |
45 | | - • Bulk operations |
46 | | - • Deep filtering |
47 | | - • Custom joins / window functions |
48 | | - • Both work seamlessly alongside Flywheel event sourcing. |
49 | | - |
50 | | -4. Domain Logic with Flywheel |
51 | | - • Domain state transitions are event-driven. |
52 | | - • Promotes traceability and immutability. |
53 | | - |
54 | | -5. Testing Strategy |
55 | | - • JUnit 5 with @Nested classes to: |
56 | | - • Separate concerns within test files. |
57 | | - • Improve readability and scope clarity. |
58 | | - • AssertJ provides fluent API for: |
59 | | - • Clean, expressive assertions. |
60 | | - • Better failure messages than vanilla JUnit or Hamcrest. |
61 | | - |
62 | | -⸻ |
63 | | - |
64 | | -📎 Notes |
65 | | -• Avoid using @RestController or manual API layer. |
66 | | -• All changes to API contract must be made in api.yaml. |
67 | | -• Lombok annotations (@Value, @Builder, @Getter, etc.) are preferred to minimize boilerplate. |
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +This project is a Java implementation of the Rosetta specification for the Cardano blockchain, consisting of multiple Maven modules for API services, blockchain indexing, and testing utilities. |
| 8 | + |
| 9 | +## Build and Development Commands |
| 10 | + |
| 11 | +### Maven Commands |
| 12 | +```bash |
| 13 | +# Build entire project (from root) |
| 14 | +mvn clean install |
| 15 | + |
| 16 | +# Build specific module |
| 17 | +mvn clean install -pl api |
| 18 | +mvn clean install -pl yaci-indexer |
| 19 | +mvn clean install -pl test-data-generator |
| 20 | + |
| 21 | +# Run tests |
| 22 | +mvn test # All tests |
| 23 | +mvn test -pl api # API module tests only |
| 24 | +mvn test -Dtest=ClassName # Single test class |
| 25 | + |
| 26 | +# Code generation (happens automatically during build) |
| 27 | +mvn generate-sources # Generates OpenAPI code from api.yaml |
| 28 | + |
| 29 | +# Run application (API module) |
| 30 | +cd api && mvn spring-boot:run |
| 31 | + |
| 32 | +# Package for deployment |
| 33 | +mvn clean package |
| 34 | +``` |
| 35 | + |
| 36 | +### Docker Commands |
| 37 | +```bash |
| 38 | +# Build from source |
| 39 | +docker build -t rosetta-java -f ./docker/Dockerfile . |
| 40 | + |
| 41 | +# Run with docker-compose (full stack) |
| 42 | +docker-compose up -d |
| 43 | + |
| 44 | +# Run specific services |
| 45 | +docker-compose up -d api indexer postgres |
| 46 | + |
| 47 | +# View logs |
| 48 | +docker logs rosetta -f |
| 49 | +docker exec rosetta tail -f /logs/node.log |
| 50 | +docker exec rosetta tail -f /logs/indexer.log |
| 51 | +``` |
| 52 | + |
| 53 | +## Architecture Overview |
| 54 | + |
| 55 | +### Multi-Module Structure |
| 56 | +- **`api/`** - Main Rosetta API implementation (Spring Boot) |
| 57 | +- **`yaci-indexer/`** - Blockchain data indexer using Yaci Store libraries |
| 58 | +- **`test-data-generator/`** - Testing utility for transaction test data |
| 59 | + |
| 60 | +### Key Technologies |
| 61 | +- **Java 24** with preview features |
| 62 | +- **Spring Boot 3.5.0** with Spring Security and Web |
| 63 | +- **Maven** multi-module build |
| 64 | +- **OpenAPI 3.0** code generation from `/api/src/main/resources/rosetta-specifications-1.4.15/api.yaml` |
| 65 | +- **MapStruct** for object mapping |
| 66 | +- **Lombok** for boilerplate reduction |
| 67 | +- **JUnit 5** with `@Nested` test organization |
| 68 | +- **AssertJ** for test assertions |
| 69 | +- **PostgreSQL** (production) / **H2** (development/testing) |
| 70 | + |
| 71 | +### Code Generation Pattern |
| 72 | +- All API endpoints and DTOs are generated from `api.yaml` |
| 73 | +- Generated code located in `/target/generated-sources/openapi/` |
| 74 | +- **NEVER** manually modify controller classes - edit `api.yaml` instead |
| 75 | +- Controller implementations in `api/{domain}/controller/` implement generated interfaces |
| 76 | + |
| 77 | +### Database Architecture |
| 78 | +- **Hibernate JPA** for standard ORM operations |
| 79 | +- **Custom entities** with JSON storage for UTXO data using Hypersistence Utils |
| 80 | +- **Yaci-Store** handles blockchain data synchronization in separate indexer module |
| 81 | +- Database migration handled through Yaci Store's built-in Flyway integration |
| 82 | + |
| 83 | +### API Layer Organization |
| 84 | +Each Rosetta endpoint has its own package under `api/src/main/java/org/cardanofoundation/rosetta/api/`: |
| 85 | +- `account/` - Account balances and UTXO operations |
| 86 | +- `block/` - Block and transaction retrieval |
| 87 | +- `construction/` - Transaction building and signing |
| 88 | +- `mempool/` - Mempool operations |
| 89 | +- `network/` - Network status and configuration |
| 90 | +- `search/` - Transaction search functionality |
| 91 | + |
| 92 | +Each package contains: |
| 93 | +- `controller/` - REST endpoints implementing generated OpenAPI interfaces |
| 94 | +- `service/` - Business logic layer |
| 95 | +- `mapper/` - MapStruct mappers for entity/DTO conversion |
| 96 | +- `model/` - Domain objects and entities |
| 97 | + |
| 98 | +### Testing Patterns |
| 99 | +- Use `@Nested` classes to group related tests |
| 100 | +- Extend `BaseSpringMvcSetup` for integration tests |
| 101 | +- Extend `BaseMapperSetup` for mapper tests |
| 102 | +- Test data stored in `/src/test/resources/testdata/` |
| 103 | +- Use AssertJ for fluent assertions: `assertThat(result).isNotNull().satisfies(...)` |
| 104 | + |
| 105 | +### Configuration Management |
| 106 | +- Main config: `application.yaml` |
| 107 | +- Environment profiles: `application-{profile}.yaml` (h2, offline, online, staging, test) |
| 108 | +- Spring profiles control database backend and operational mode |
| 109 | +- Environment variables documented in README.md and Docker configs |
| 110 | + |
| 111 | +### Development Workflow |
| 112 | +1. **API Changes**: Edit `api.yaml` → run build → implement in controller classes |
| 113 | +2. **Database Changes**: Modify entities → Yaci Store handles migrations automatically |
| 114 | +3. **New Features**: Follow domain package structure → add controller, service, mapper |
| 115 | +4. **Testing**: Write nested test classes → use appropriate base setup class |
| 116 | + |
| 117 | +### Common Gotchas |
| 118 | +- OpenAPI code generation requires clean build when `api.yaml` changes |
| 119 | +- Yaci-indexer must be running for API integration tests |
| 120 | +- Use correct Spring profile for your database backend (h2/postgres) |
| 121 | +- Generated OpenAPI models use different package (`org.openapitools.client.model`) |
| 122 | +- MapStruct mappers require annotation processor to be enabled |
| 123 | + |
| 124 | +### Module Dependencies |
| 125 | +- **API module** communicates with yaci-indexer via HTTP (`YaciHttpGateway`) |
| 126 | +- **Yaci-indexer** provides REST endpoints for blockchain data queries |
| 127 | +- **Test-data-generator** creates realistic transaction scenarios for testing |
| 128 | +- All modules share common configuration from parent POM |
0 commit comments