private FallbackParsingStrategy createFallbackStrategy()

in doc-architect/doc-architect-core/src/main/java/com/docarchitect/core/scanner/impl/java/MongoDbScanner.java [283:353]


    private FallbackParsingStrategy<EntityResult> createFallbackStrategy() {
        return (file, content) -> {
            List<EntityResult> results = new ArrayList<>();

            // Check if file contains MongoDB document annotations
            if (!content.contains("@Document")) {
                return results;
            }

            // Extract class name and package using shared utility
            String className = RegexPatterns.extractClassName(content, file);
            String packageName = RegexPatterns.extractPackageName(content);
            String fullyQualifiedName = RegexPatterns.buildFullyQualifiedName(packageName, className);

            // Extract collection name using pattern
            String collectionName = className; // Default
            Matcher collectionMatcher = DOCUMENT_PATTERN.matcher(content);
            if (collectionMatcher.find()) {
                collectionName = collectionMatcher.group(1);
            } else {
                collectionName = toSnakeCase(className);
            }

            // Extract basic fields using shared field pattern
            List<DataEntity.Field> fields = new ArrayList<>();
            Matcher fieldMatcher = RegexPatterns.FIELD_PATTERN.matcher(content);
            while (fieldMatcher.find()) {
                String fieldType = fieldMatcher.group(1);
                String fieldName = fieldMatcher.group(2);

                // Skip fields that look like relationships
                if (!fieldType.startsWith("List<") && !fieldType.startsWith("Set<") &&
                    !fieldType.startsWith("Collection<")) {
                    fields.add(new DataEntity.Field(fieldName, fieldType, true, null));
                }
            }

            // Extract @DBRef relationships (simplified)
            List<Relationship> relationships = new ArrayList<>();
            Matcher dbrefMatcher = DBREF_PATTERN.matcher(content);
            while (dbrefMatcher.find()) {
                String targetType = dbrefMatcher.group(1);
                // Extract target entity type (handle collections)
                String targetEntity = targetType
                    .replaceAll(LIST_TYPE_PATTERN, "$1")
                    .replaceAll(SET_TYPE_PATTERN, "$1")
                    .replaceAll(COLLECTION_TYPE_PATTERN, "$1");

                relationships.add(new Relationship(
                    fullyQualifiedName,
                    targetEntity,
                    RelationshipType.DEPENDS_ON,
                    DBREF_RELATIONSHIP_DESCRIPTION,
                    RELATIONSHIP_TECHNOLOGY
                ));
            }

            DataEntity entity = new DataEntity(
                fullyQualifiedName,
                collectionName,
                DATA_ENTITY_TYPE_COLLECTION,
                fields,
                null, // primary key unknown in fallback
                DOCUMENT_DESCRIPTION_PREFIX + className
            );

            results.add(new EntityResult(entity, relationships));
            log.debug("Fallback parsing found entity: {} -> {}", fullyQualifiedName, collectionName);
            return results;
        };
    }