Model-config web apps: describe the app in configuration instead of writing code. Built on Polars and DuckDB.
SPRING_BOOT_IN_CONFIG.yaml · 9.0 KB · 385 lines
| 1 | # Spring Boot in Config |
| 2 | # Everything Spring Boot does in ~200 lines of YAML |
| 3 | # 100,000+ lines of Java → 200 lines |
| 4 | |
| 5 | name: "Spring Boot Application" |
| 6 | framework_replaced: "Spring Boot + JPA + Security + WebFlux + Kafka" |
| 7 | |
| 8 | # ========================================== |
| 9 | # JPA ENTITIES → CONFIG |
| 10 | # ========================================== |
| 11 | entities: |
| 12 | # @Entity classes |
| 13 | User: |
| 14 | table: "users" |
| 15 | fields: |
| 16 | id: |
| 17 | type: "Long" |
| 18 | annotations: ["@Id", "@GeneratedValue"] |
| 19 | email: |
| 20 | type: "String" |
| 21 | annotations: ["@Column(unique=true)", "@Email"] |
| 22 | password: |
| 23 | type: "String" |
| 24 | annotations: ["@JsonIgnore"] |
| 25 | roles: |
| 26 | type: "Set<Role>" |
| 27 | annotations: ["@ManyToMany(fetch=EAGER)"] |
| 28 | |
| 29 | repository: |
| 30 | extends: "JpaRepository<User, Long>" |
| 31 | custom_queries: |
| 32 | findByEmail: "Optional<User>" |
| 33 | existsByEmail: "boolean" |
| 34 | |
| 35 | Order: |
| 36 | fields: |
| 37 | id: "UUID" |
| 38 | customer: "@ManyToOne User" |
| 39 | items: "@OneToMany List<OrderItem>" |
| 40 | total: "BigDecimal" |
| 41 | status: "OrderStatus enum" |
| 42 | |
| 43 | auditing: true # @CreatedDate, @LastModifiedDate |
| 44 | |
| 45 | # ========================================== |
| 46 | # REST CONTROLLERS → CONFIG |
| 47 | # ========================================== |
| 48 | controllers: |
| 49 | # @RestController classes |
| 50 | UserController: |
| 51 | base_path: "/api/users" |
| 52 | |
| 53 | endpoints: |
| 54 | GET: |
| 55 | "/": |
| 56 | method: "findAll" |
| 57 | response: "Page<User>" |
| 58 | pageable: true |
| 59 | |
| 60 | "/{id}": |
| 61 | method: "findById" |
| 62 | response: "User" |
| 63 | cache: "users" |
| 64 | |
| 65 | POST: |
| 66 | "/": |
| 67 | method: "create" |
| 68 | body: "@Valid UserDTO" |
| 69 | response: "User" |
| 70 | status: "CREATED" |
| 71 | |
| 72 | PUT: |
| 73 | "/{id}": |
| 74 | method: "update" |
| 75 | body: "@Valid UserDTO" |
| 76 | response: "User" |
| 77 | |
| 78 | DELETE: |
| 79 | "/{id}": |
| 80 | method: "delete" |
| 81 | response: "void" |
| 82 | security: "hasRole('ADMIN')" |
| 83 | |
| 84 | # ========================================== |
| 85 | # SPRING SECURITY → CONFIG |
| 86 | # ========================================== |
| 87 | security: |
| 88 | # SecurityConfig.java |
| 89 | authentication: |
| 90 | type: "JWT" |
| 91 | header: "Authorization" |
| 92 | prefix: "Bearer" |
| 93 | secret: "${JWT_SECRET}" |
| 94 | expiration: 3600 |
| 95 | |
| 96 | authorization: |
| 97 | matchers: |
| 98 | "/api/public/**": "permitAll()" |
| 99 | "/api/admin/**": "hasRole('ADMIN')" |
| 100 | "/api/**": "authenticated()" |
| 101 | |
| 102 | cors: |
| 103 | allowed_origins: ["http://localhost:3000"] |
| 104 | allowed_methods: ["GET", "POST", "PUT", "DELETE"] |
| 105 | allowed_headers: ["*"] |
| 106 | |
| 107 | csrf: |
| 108 | enabled: false # Using JWT |
| 109 | |
| 110 | # ========================================== |
| 111 | # SERVICES → CONFIG |
| 112 | # ========================================== |
| 113 | services: |
| 114 | # @Service classes |
| 115 | UserService: |
| 116 | dependencies: |
| 117 | - UserRepository |
| 118 | - PasswordEncoder |
| 119 | - EmailService |
| 120 | |
| 121 | methods: |
| 122 | registerUser: |
| 123 | transaction: true |
| 124 | params: ["email", "password"] |
| 125 | logic: | |
| 126 | Check if user exists |
| 127 | Encode password |
| 128 | Save user |
| 129 | Send welcome email |
| 130 | |
| 131 | authenticateUser: |
| 132 | params: ["email", "password"] |
| 133 | returns: "JWT token" |
| 134 | |
| 135 | # ========================================== |
| 136 | # SPRING DATA JPA → CONFIG |
| 137 | # ========================================== |
| 138 | jpa: |
| 139 | # application.yml |
| 140 | datasource: |
| 141 | url: "jdbc:postgresql://localhost:5432/myapp" |
| 142 | username: "${DB_USER}" |
| 143 | password: "${DB_PASSWORD}" |
| 144 | |
| 145 | hibernate: |
| 146 | ddl-auto: "validate" # or update, create |
| 147 | dialect: "PostgreSQLDialect" |
| 148 | show_sql: false |
| 149 | |
| 150 | properties: |
| 151 | batch_size: 20 |
| 152 | cache: |
| 153 | use_second_level_cache: true |
| 154 | region_factory: "ehcache" |
| 155 | |
| 156 | # ========================================== |
| 157 | # VALIDATION → CONFIG |
| 158 | # ========================================== |
| 159 | validation: |
| 160 | # DTO validation |
| 161 | UserDTO: |
| 162 | fields: |
| 163 | email: |
| 164 | - "@NotBlank" |
| 165 | - "@Email" |
| 166 | password: |
| 167 | - "@NotNull" |
| 168 | - "@Size(min=8, max=100)" |
| 169 | age: |
| 170 | - "@Min(18)" |
| 171 | - "@Max(120)" |
| 172 | |
| 173 | custom_validators: |
| 174 | UniqueEmail: |
| 175 | message: "Email already exists" |
| 176 | logic: "!userRepository.existsByEmail(value)" |
| 177 | |
| 178 | # ========================================== |
| 179 | # EXCEPTION HANDLING → CONFIG |
| 180 | # ========================================== |
| 181 | exceptions: |
| 182 | # @ControllerAdvice |
| 183 | handlers: |
| 184 | EntityNotFoundException: |
| 185 | status: "NOT_FOUND" |
| 186 | message: "Resource not found" |
| 187 | |
| 188 | ValidationException: |
| 189 | status: "BAD_REQUEST" |
| 190 | message: "Validation failed" |
| 191 | include_errors: true |
| 192 | |
| 193 | AccessDeniedException: |
| 194 | status: "FORBIDDEN" |
| 195 | message: "Access denied" |
| 196 | |
| 197 | global_handler: |
| 198 | status: "INTERNAL_SERVER_ERROR" |
| 199 | message: "An error occurred" |
| 200 | log: true |
| 201 | |
| 202 | # ========================================== |
| 203 | # MESSAGING (KAFKA/RABBITMQ) → CONFIG |
| 204 | # ========================================== |
| 205 | messaging: |
| 206 | # @KafkaListener, @RabbitListener |
| 207 | kafka: |
| 208 | bootstrap_servers: "localhost:9092" |
| 209 | |
| 210 | producers: |
| 211 | order-events: |
| 212 | topic: "orders" |
| 213 | key_serializer: "StringSerializer" |
| 214 | value_serializer: "JsonSerializer" |
| 215 | |
| 216 | consumers: |
| 217 | order-processor: |
| 218 | topics: ["orders"] |
| 219 | group_id: "order-processing-group" |
| 220 | handler: "processOrder" |
| 221 | |
| 222 | # ========================================== |
| 223 | # SCHEDULED TASKS → CONFIG |
| 224 | # ========================================== |
| 225 | scheduling: |
| 226 | # @Scheduled |
| 227 | tasks: |
| 228 | cleanup_old_sessions: |
| 229 | cron: "0 0 * * * *" # Every hour |
| 230 | method: "sessionRepository.deleteExpired()" |
| 231 | |
| 232 | generate_reports: |
| 233 | fixed_delay: 3600000 # Every hour in ms |
| 234 | method: "reportService.generateHourly()" |
| 235 | |
| 236 | send_reminders: |
| 237 | fixed_rate: 86400000 # Daily |
| 238 | initial_delay: 60000 # 1 minute |
| 239 | |
| 240 | # ========================================== |
| 241 | # CACHING → CONFIG |
| 242 | # ========================================== |
| 243 | cache: |
| 244 | # @Cacheable, @CacheEvict |
| 245 | provider: "redis" |
| 246 | |
| 247 | caches: |
| 248 | users: |
| 249 | ttl: 600 # 10 minutes |
| 250 | max_size: 1000 |
| 251 | |
| 252 | products: |
| 253 | ttl: 3600 |
| 254 | max_size: 10000 |
| 255 | |
| 256 | methods: |
| 257 | getUserById: |
| 258 | cache: "users" |
| 259 | key: "#id" |
| 260 | |
| 261 | evictUser: |
| 262 | evict: "users" |
| 263 | key: "#user.id" |
| 264 | |
| 265 | # ========================================== |
| 266 | # WEBFLUX REACTIVE → CONFIG |
| 267 | # ========================================== |
| 268 | reactive: |
| 269 | # Reactive endpoints |
| 270 | endpoints: |
| 271 | "/api/stream/orders": |
| 272 | produces: "text/event-stream" |
| 273 | method: | |
| 274 | return orderRepository |
| 275 | .findAll() |
| 276 | .delayElements(Duration.ofSeconds(1)) |
| 277 | |
| 278 | "/api/reactive/users": |
| 279 | returns: "Flux<User>" |
| 280 | method: "userRepository.findAll()" |
| 281 | |
| 282 | # ========================================== |
| 283 | # ACTUATOR & MONITORING → CONFIG |
| 284 | # ========================================== |
| 285 | actuator: |
| 286 | endpoints: |
| 287 | enabled: ["health", "metrics", "info"] |
| 288 | |
| 289 | health: |
| 290 | show_details: "when-authorized" |
| 291 | indicators: |
| 292 | - database |
| 293 | - redis |
| 294 | - kafka |
| 295 | |
| 296 | metrics: |
| 297 | export: |
| 298 | prometheus: |
| 299 | enabled: true |
| 300 | |
| 301 | # ========================================== |
| 302 | # TESTING → CONFIG |
| 303 | # ========================================== |
| 304 | testing: |
| 305 | # @SpringBootTest, @MockBean |
| 306 | integration_tests: |
| 307 | UserControllerTest: |
| 308 | mock_beans: [UserService] |
| 309 | tests: |
| 310 | - "GET /api/users returns 200" |
| 311 | - "POST /api/users creates user" |
| 312 | |
| 313 | unit_tests: |
| 314 | UserServiceTest: |
| 315 | mocks: [UserRepository, EmailService] |
| 316 | tests: |
| 317 | - "registerUser creates new user" |
| 318 | - "authenticateUser returns JWT" |
| 319 | |
| 320 | # ========================================== |
| 321 | # BUILD & DEPLOYMENT → CONFIG |
| 322 | # ========================================== |
| 323 | build: |
| 324 | # pom.xml / build.gradle |
| 325 | packaging: "jar" |
| 326 | java_version: 17 |
| 327 | |
| 328 | dependencies: |
| 329 | - spring-boot-starter-web |
| 330 | - spring-boot-starter-data-jpa |
| 331 | - spring-boot-starter-security |
| 332 | - postgresql |
| 333 | |
| 334 | plugins: |
| 335 | - spring-boot-maven-plugin |
| 336 | - dockerfile-maven-plugin |
| 337 | |
| 338 | deployment: |
| 339 | docker: |
| 340 | base_image: "openjdk:17-alpine" |
| 341 | port: 8080 |
| 342 | health_check: "/actuator/health" |
| 343 | |
| 344 | kubernetes: |
| 345 | replicas: 3 |
| 346 | cpu_limit: "1000m" |
| 347 | memory_limit: "1Gi" |
| 348 | |
| 349 | # ========================================== |
| 350 | # THE COMPARISON |
| 351 | # ========================================== |
| 352 | # Spring Boot Project Structure: |
| 353 | # my-spring-app/ |
| 354 | # pom.xml (100+ dependencies) |
| 355 | # src/ |
| 356 | # main/ |
| 357 | # java/ |
| 358 | # com/example/myapp/ |
| 359 | # MyApplication.java |
| 360 | # config/ |
| 361 | # SecurityConfig.java (200+ lines) |
| 362 | # WebConfig.java (100+ lines) |
| 363 | # CacheConfig.java (100+ lines) |
| 364 | # controller/ (20+ files, 2000+ lines) |
| 365 | # service/ (15+ files, 1500+ lines) |
| 366 | # repository/ (10+ files, 500+ lines) |
| 367 | # entity/ (15+ files, 1000+ lines) |
| 368 | # dto/ (20+ files, 1000+ lines) |
| 369 | # exception/ (10+ files, 500+ lines) |
| 370 | # util/ (10+ files, 1000+ lines) |
| 371 | # resources/ |
| 372 | # application.yml (200+ lines) |
| 373 | # application-prod.yml |
| 374 | # db/migration/ (20+ SQL files) |
| 375 | # test/ |
| 376 | # java/ (50+ test files, 5000+ lines) |
| 377 | # |
| 378 | # Total: 200+ files, 100,000+ lines of Java |
| 379 | # |
| 380 | # DBBasic: This 1 file, ~200 lines |
| 381 | # ========================================== |
| 382 | |
| 383 | # THE REAL DIFFERENCE: |
| 384 | # Spring Boot: 6 months to learn, AbstractSingletonProxyFactoryBean |
| 385 | # DBBasic: 5 minutes to learn, just YAML |