|
| 1 | +# MetaObjects Project - Claude AI Assistant Guide |
| 2 | + |
| 3 | +## ⚠️ CRITICAL ARCHITECTURAL PRINCIPLE ⚠️ |
| 4 | + |
| 5 | +**MetaObjects follows a LOAD-ONCE IMMUTABLE design pattern analogous to Java's Class/Field reflection system:** |
| 6 | + |
| 7 | +- **MetaData objects are loaded once during application startup and remain immutable thereafter** |
| 8 | +- **They are permanent in memory for the application lifetime (like Java Class objects)** |
| 9 | +- **Thread-safe for concurrent READ operations after loading phase** |
| 10 | +- **DO NOT treat MetaData as mutable domain objects - they are immutable metadata definitions** |
| 11 | + |
| 12 | +### Framework Analogy |
| 13 | +| Java Reflection | MetaObjects Framework | |
| 14 | +|----------------|----------------------| |
| 15 | +| `Class.forName()` | `MetaDataLoader.load()` | |
| 16 | +| `Class.getFields()` | `MetaObject.getMetaFields()` | |
| 17 | +| `Field.get(object)` | `MetaField.getValue(object)` | |
| 18 | +| Permanent in memory | Permanent MetaData objects | |
| 19 | +| Thread-safe reads | Thread-safe metadata access | |
| 20 | +| ClassLoader registry | MetaDataTypeRegistry | |
| 21 | + |
| 22 | +## Project Overview |
| 23 | + |
| 24 | +MetaObjects is a Java-based suite of tools for metadata-driven development, providing sophisticated control over applications beyond traditional model-driven development techniques. |
| 25 | + |
| 26 | +- **Current Version**: 5.2.0 (development) |
| 27 | +- **Java Version**: Java 21 |
| 28 | +- **Build Tool**: Maven |
| 29 | +- **License**: Apache License 2.0 |
| 30 | + |
| 31 | +## Current Architecture (v6.0.0+) |
| 32 | + |
| 33 | +### Service-Based Type Registry |
| 34 | +- **MetaDataTypeRegistry**: Service-based type registry (replaces TypesConfig) |
| 35 | +- **MetaDataEnhancementService**: Context-aware metadata enhancement |
| 36 | +- **ServiceLoader Discovery**: OSGI-compatible service discovery |
| 37 | +- **Cross-Language Ready**: String-based types work across Java/C#/TypeScript |
| 38 | + |
| 39 | +### Project Structure |
| 40 | +``` |
| 41 | +├── metadata/ # Base metadata models and types |
| 42 | +├── codegen/ # Code generation libraries (v6.0.0+) |
| 43 | +├── maven-plugin/ # Maven plugin for code generation |
| 44 | +├── core/ # Core MetaObjects functionality |
| 45 | +├── om/ # Object Manager module |
| 46 | +├── omdb/ # Database Object Manager |
| 47 | +├── omnosql/ # NoSQL Object Manager |
| 48 | +├── web/ # React MetaView components |
| 49 | +├── demo/ # Demo applications with React integration |
| 50 | +└── docs/ # Documentation |
| 51 | +``` |
| 52 | + |
| 53 | +### Build Dependencies (CRITICAL ORDER) |
| 54 | +``` |
| 55 | +metadata → codegen → maven-plugin → core → om → omdb/omnosql → web → demo |
| 56 | +``` |
| 57 | + |
| 58 | +**Build the project**: `mvn clean compile` |
| 59 | + |
| 60 | +## Core Concepts |
| 61 | + |
| 62 | +### MetaObjects Types |
| 63 | +- **ValueMetaObject**: Dynamic objects with public getter/setter access |
| 64 | +- **DataMetaObject**: Wrapped objects with protected access + Builder patterns |
| 65 | +- **ProxyMetaObject**: Proxy implementations without concrete classes |
| 66 | +- **MappedMetaObject**: Works with Map interface objects |
| 67 | + |
| 68 | +### Key Features |
| 69 | +- **Metadata-driven development** with sophisticated control mechanisms |
| 70 | +- **Cross-language code generation** (Java, C#, TypeScript) |
| 71 | +- **JSON/XML serialization** with custom type adapters |
| 72 | +- **Validation framework** with field-level and object-level validators |
| 73 | +- **React MetaView System** with TypeScript components |
| 74 | +- **Enhanced error reporting** with hierarchical paths and context |
| 75 | + |
| 76 | +## Current Service Architecture Patterns |
| 77 | + |
| 78 | +### MetaDataTypeRegistry Usage |
| 79 | +```java |
| 80 | +// v6.0.0+ pattern - service-based type registry |
| 81 | +MetaDataTypeRegistry registry = ServiceRegistry.getInstance() |
| 82 | + .getService(MetaDataTypeRegistry.class); |
| 83 | + |
| 84 | +// Register custom types |
| 85 | +registry.registerType("customField", CustomField.class); |
| 86 | +``` |
| 87 | + |
| 88 | +### MetaDataEnhancement Usage |
| 89 | +```java |
| 90 | +// Attribute enhancement for cross-cutting concerns |
| 91 | +MetaDataEnhancementService enhancer = new MetaDataEnhancementService(); |
| 92 | +for (MetaObject metaObject : loader.getChildren(MetaObject.class)) { |
| 93 | + enhancer.enhanceForService(metaObject, "objectManagerDB", |
| 94 | + Map.of("dialect", "postgresql", "schema", "public")); |
| 95 | +} |
| 96 | +// Objects now have dbTable, dbCol, dbNullable attributes |
| 97 | +``` |
| 98 | + |
| 99 | +### Modern API Patterns |
| 100 | +```java |
| 101 | +// Optional-based APIs (v5.1.0+) |
| 102 | +Optional<String> name = metaObject.findString("name"); |
| 103 | +String email = metaObject.requireString("email"); // throws if missing |
| 104 | + |
| 105 | +// Builder patterns |
| 106 | +ValueObject obj = ValueObject.builder() |
| 107 | + .field("name", "John") |
| 108 | + .field("age", 30) |
| 109 | + .build(); |
| 110 | + |
| 111 | +// Stream APIs |
| 112 | +metaObject.getFieldsStream() |
| 113 | + .filter(field -> field.getType() == DataTypes.STRING) |
| 114 | + .forEach(field -> processField(field)); |
| 115 | +``` |
| 116 | + |
| 117 | +## React MetaView Integration |
| 118 | + |
| 119 | +### Backend API Pattern |
| 120 | +```java |
| 121 | +// Spring REST controllers serve metadata as JSON |
| 122 | +@RestController |
| 123 | +public class MetaDataApiController { |
| 124 | + |
| 125 | + @GetMapping("/api/metadata/{objectName}") |
| 126 | + public ResponseEntity<String> getMetaObjectJson(@PathVariable String objectName) { |
| 127 | + MetaObject metaObject = loader.getMetaObject(objectName); |
| 128 | + return ResponseEntity.ok(JsonObjectWriter.write(metaObject)); |
| 129 | + } |
| 130 | +} |
| 131 | +``` |
| 132 | + |
| 133 | +### Frontend Component Pattern |
| 134 | +```typescript |
| 135 | +// TypeScript MetaView components |
| 136 | +import { MetaViewRenderer } from './components/metaviews/MetaViewRenderer'; |
| 137 | +import { MetaObjectForm } from './components/forms/MetaObjectForm'; |
| 138 | + |
| 139 | +// Automatic form generation from metadata |
| 140 | +<MetaObjectForm |
| 141 | + metaObjectName="User" |
| 142 | + onSubmit={handleSubmit} |
| 143 | + validation={true} |
| 144 | +/> |
| 145 | +``` |
| 146 | + |
| 147 | +### JSON Metadata Location |
| 148 | +- Place JSON metadata in `/src/main/resources/metadata/` for proper classpath loading |
| 149 | +- Use FileMetaDataLoader with JsonMetaDataParser for existing infrastructure |
| 150 | + |
| 151 | +## Development Guidelines |
| 152 | + |
| 153 | +### Code Style & Patterns |
| 154 | +- Use **SLF4J** for all logging (migrated from Commons Logging) |
| 155 | +- Follow **Builder patterns** for complex object creation |
| 156 | +- Use **Optional-based APIs** for safe null handling |
| 157 | +- Maintain **backward compatibility** in all changes |
| 158 | +- Add **comprehensive JavaDoc** for public APIs |
| 159 | + |
| 160 | +### Testing |
| 161 | +- Use **JUnit 4.13.2** for testing |
| 162 | +- All modules must compile successfully with Java 21 |
| 163 | +- Test files should follow existing patterns in `*/src/test/java/` |
| 164 | + |
| 165 | +### Module Integration |
| 166 | +- **codegen module**: Contains all code generation functionality |
| 167 | +- **web module**: React TypeScript components and generic Spring controllers |
| 168 | +- **demo module**: Fishstore demo, data controllers, and JSON metadata |
| 169 | +- **Controllers**: Demo-specific controllers → demo module, generic → web module |
| 170 | + |
| 171 | +### React & Frontend Development |
| 172 | +- **Use Existing Infrastructure**: Leverage FileMetaDataLoader, JsonObjectWriter from IO package |
| 173 | +- **Spring Integration**: Proper controller module placement based on functionality |
| 174 | +- **TypeScript Components**: Follow React MetaView patterns for metadata-driven UI |
| 175 | +- **State Management**: Redux Toolkit with React Query for form state and data fetching |
| 176 | + |
| 177 | +## Enhanced Error Reporting (v5.2.0+) |
| 178 | + |
| 179 | +### Rich Exception Context |
| 180 | +```java |
| 181 | +try { |
| 182 | + // MetaObjects operation |
| 183 | +} catch (MetaDataException e) { |
| 184 | + Optional<MetaDataPath> path = e.getMetaDataPath(); |
| 185 | + Optional<String> operation = e.getOperation(); |
| 186 | + Map<String, Object> context = e.getContext(); |
| 187 | + |
| 188 | + // Enhanced error messages include context and alternatives |
| 189 | + // "Field 'invalidField' not found in User: Available: age, email, name" |
| 190 | +} |
| 191 | +``` |
| 192 | + |
| 193 | +### Factory Method Patterns |
| 194 | +```java |
| 195 | +// Context-rich exception creation |
| 196 | +ObjectNotFoundException.forId(userId, metaObject, "userLookup"); |
| 197 | +PersistenceException.forSave(entity, metaObject, sqlException); |
| 198 | +GeneratorException.forTemplate("user.java.vm", metaObject, templateException); |
| 199 | +``` |
| 200 | + |
| 201 | +## Key Build Commands |
| 202 | + |
| 203 | +```bash |
| 204 | +# Build entire project |
| 205 | +mvn clean compile |
| 206 | + |
| 207 | +# Run tests |
| 208 | +mvn test |
| 209 | + |
| 210 | +# Package project |
| 211 | +mvn package |
| 212 | + |
| 213 | +# Generate code using MetaObjects plugin |
| 214 | +mvn metaobjects:generate |
| 215 | + |
| 216 | +# Build specific module (respects dependency order) |
| 217 | +cd metadata && mvn compile |
| 218 | +cd core && mvn compile |
| 219 | +``` |
| 220 | + |
| 221 | +## Maven Configuration |
| 222 | +- Parent POM manages dependency versions |
| 223 | +- OSGi bundle support enabled via Apache Felix Maven Bundle Plugin |
| 224 | +- Java 21 compatibility with --release flag |
| 225 | +- Two distribution profiles: default (Draagon) and nexus (Maven Central) |
| 226 | + |
| 227 | +## Critical Files for Development |
| 228 | + |
| 229 | +### Source Code |
| 230 | +- Core source: `core/src/main/java/com/draagon/meta/` |
| 231 | +- Metadata models: `metadata/src/main/java/com/draagon/meta/` |
| 232 | +- Tests: `*/src/test/java/` |
| 233 | + |
| 234 | +### React MetaView System |
| 235 | +- React components: `web/src/typescript/components/metaviews/` |
| 236 | +- React forms: `web/src/typescript/components/forms/` |
| 237 | +- TypeScript types: `web/src/typescript/types/metadata.ts` |
| 238 | +- Spring controllers: `web/src/main/java/com/draagon/meta/web/react/api/` |
| 239 | +- Demo controllers: `demo/src/main/java/com/draagon/meta/demo/fishstore/api/` |
| 240 | +- JSON metadata: `demo/src/main/resources/metadata/fishstore-metadata.json` |
| 241 | + |
| 242 | +### Configuration |
| 243 | +- `pom.xml` - Main project configuration |
| 244 | +- `package.json` & `tsconfig.json` - React/TypeScript configuration (web module) |
| 245 | +- `README.md` - Basic project information |
| 246 | +- `RELEASE_NOTES.md` - Version history |
| 247 | + |
| 248 | +## Key Technologies & Dependencies |
| 249 | + |
| 250 | +- **Java 21** with Maven compiler plugin 3.13.0 |
| 251 | +- **SLF4J + Logback** for logging |
| 252 | +- **JUnit 4.13.2** for testing |
| 253 | +- **OSGi Bundle Support** via Apache Felix Maven Bundle Plugin |
| 254 | +- **Gson 2.13.1** for JSON handling |
| 255 | +- **Commons Validator 1.9.0** for validation |
| 256 | +- **React + TypeScript** for frontend components |
| 257 | +- **Redux Toolkit** for state management |
| 258 | + |
| 259 | +## VERSION MANAGEMENT FOR CLAUDE AI |
| 260 | + |
| 261 | +**CRITICAL**: When user requests "increment version", "update version", or "release new version": |
| 262 | + |
| 263 | +1. **AUTOMATICALLY UPDATE ALL VERSION REFERENCES**: |
| 264 | + - All pom.xml files (root + 8 modules) |
| 265 | + - README.md "Current Release:" line |
| 266 | + - RELEASE_NOTES.md (add new version section) |
| 267 | + - This CLAUDE.md version references |
| 268 | + |
| 269 | +2. **FOLLOW VERSION STRATEGY**: |
| 270 | + - Release: Remove -SNAPSHOT from current version |
| 271 | + - Next Dev: Increment version + add -SNAPSHOT |
| 272 | + - Ensure ALL modules have identical versions |
| 273 | + |
| 274 | +3. **VERIFY BUILD**: Run `mvn clean compile` after changes |
| 275 | + |
| 276 | +This ensures complete version synchronization across the entire project when versions are updated. |
0 commit comments