From f83035052d1402c5d2cf3bb65ae3e32156eadacd Mon Sep 17 00:00:00 2001 From: "andreas.dinauer" Date: Thu, 6 Aug 2026 17:04:59 +0000 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Add=20CLAUDE.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CLAUDE.md | 125 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 125 insertions(+) create mode 100644 CLAUDE.md diff --git a/CLAUDE.md b/CLAUDE.md new file mode 100644 index 0000000..8c3e68e --- /dev/null +++ b/CLAUDE.md @@ -0,0 +1,125 @@ +# Architecture +- We always feature first package structure +``` +src/ +└── main/ + └── java/ + └── com/example/app/ + └── order/ + ├── OrderEntity.java # JPA-Entity (Datenbank-Mapping) + ├── Order.java # Domain-/DTO-Model + ├── OrderRepo.java # Datenbankzugriff (Hibernate Panache) + ├── OrderService.java # Business-Logik + ├── OrderMapper.java # Mapping Entity > DTO + └── OrderResource.java # REST-Endpoints + Mapping +``` +- We always use `Resource` > `Service` > `Repository` +- We use DTOs +- We use Java classes as mappers that always offer a method map for single entity and lists like: +```java +@ApplicationScoped +public class OrderMapper +{ + public Order map(OrderEntity input) + { + return new Order(input.getId(), input.getTimestamp()); + } + + public List map(List input) + { + return input.stream().map(this::map).toList(); + } +} +``` +- Mapping happens before we return the data in our resources like: +```java +@GET +@Path("/orders") +public List get() +{ + return orderMapper.map(orderRepo.list()); +} +``` +- We use Builder Pattern for POJOs that are not records +- Our Entities have suffix `Entity` and have an ID of type String like this: +```java +@Entity +@Table(name = "order") +public class OrderEntity +{ + @Id + @GeneratedValue(strategy = GenerationType.UUID) + private String id; + + public ProductEntity setId(String id) + { + this.id = id; + return this; + } + + public String getId() + { + return id; + } +} +``` +- We use the Repository pattern. Every Entity that needs to be queried gets a repostiory like: +```java +@ApplicationScoped +public class OrderRepo implements PanacheRepositoryBase +{ +} +``` + +# Naming Conventions +- We keep naming short and accurate like OrderCreationService.create() and NOT OrderCreationService.createOrder() + +# Code Style +- Opening braces `{` always go on their own line (Allman style), never at the end of the previous line. +- `catch` and `else` keywords also go on their own line +- We do not use constructor injection. We do field injection: + +```java +import jakarta.inject.Inject; +import org.eclipse.microprofile.config.inject.ConfigProperty; + +@Inject +OrderService orderService; + +@ConfigProperty(name = "dev.dinauer.r9t.workdir", defaultValue = "/var/lib/r9t") +String path; +``` +- When we use if statements we most of the time go the happy path within the if statement like: +```java +public int getPrice() +{ + if (orderItem.price != null) + { + return orderItem.price; + } + return 0; +} +``` +- Using breaks or continue like this when we could just invert the if is a code smell: +```java +public int sumPrice(Order order) +{ + int total = 0; + for (Item item : order.items) + { + if (item.price == null) + { + continue; + } + else + { + total += item.price; + } + } + return total; +} +``` +- We never use ternary operators +- Don't Repeat Yourself: Duplizierten Code in wiederverwendbare Funktionen/Module auslagern statt copy-pasten. +- No comments at all +- Ursachen von Fehlern finden. Nicht Symptome beheben. Fehler nicht stillschweigend verschlucken. \ No newline at end of file