An open API service indexing awesome lists of open source software.

https://github.com/mzivkovicdev/spring-crud-generator

Generate production-ready Spring Boot backend boilerplate from a single YAML or JSON spec.
https://github.com/mzivkovicdev/spring-crud-generator

api apis crud crud-generator docker generator graphql graphql-codegen graphql-java java maven-plugin nosql rest rest-api spring spring-boot springboot springboot3 springboot4 sql

Last synced: 6 days ago
JSON representation

Generate production-ready Spring Boot backend boilerplate from a single YAML or JSON spec.

Awesome Lists containing this project

README

          

# Spring CRUD Generator

[![CI](https://github.com/mzivkovicdev/spring-crud-generator/actions/workflows/ci.yml/badge.svg)](https://github.com/mzivkovicdev/spring-crud-generator/actions/workflows/ci.yml)
[![License](https://img.shields.io/badge/License-Apache_2.0-blue.svg?style=flat)](https://opensource.org/licenses/Apache-2.0)
![Open Source](https://img.shields.io/badge/Open%20Source-Yes-success?style=flat)
[![Maven Central](https://img.shields.io/maven-central/v/dev.markozivkovic/spring-crud-generator.svg)](https://central.sonatype.com/artifact/dev.markozivkovic/spring-crud-generator)
[![Docs](https://img.shields.io/badge/Docs-Available-blue?style=flat)](./docs/README.md)

![Java](https://img.shields.io/badge/Java-17--25-blue?style=flat&logo=openjdk&logoColor=white)
![Spring Boot 3](https://img.shields.io/badge/Spring%20Boot-3.x-6DB33F?style=flat&logo=springboot&logoColor=white)
![Spring Boot 4](https://img.shields.io/badge/Spring%20Boot-4.x-6DB33F?style=flat&logo=springboot&logoColor=white)

![PostgreSQL](https://img.shields.io/badge/PostgreSQL-4169E1?style=flat&logo=postgresql&logoColor=white)
![MySQL](https://img.shields.io/badge/MySQL-4479A1?style=flat&logo=mysql&logoColor=white)
![MariaDB](https://img.shields.io/badge/MariaDB-003545?style=flat&logo=mariadb&logoColor=white)
![Microsoft SQL Server](https://img.shields.io/badge/Microsoft%20SQL%20Server-CC2927?style=flat&logo=microsoftsqlserver&logoColor=white)
![MongoDB](https://img.shields.io/badge/MongoDB-47A248?style=flat&logo=mongodb&logoColor=white)
![Redis](https://img.shields.io/badge/Redis-DD0031?style=flat&logo=redis&logoColor=white)
![Hazelcast](https://img.shields.io/badge/Hazelcast-Real--time%20Data%20Platform-0A0A0A?style=flat&logo=hazelcast&logoColor=white)

Generate production-ready Spring Boot backend boilerplate from a single YAML or JSON spec.

A Maven plugin for bootstrapping consistent, inspectable Spring Boot backends with generated CRUD layers, migrations, API docs, tests, and more.

## Demo video

Watch the demo on YouTube: [Spring CRUD Generator Demo](https://www.youtube.com/watch?v=jwVINP_YxSk)

## Best for
- Starting new Spring Boot backends faster
- Teams that want a consistent backend baseline
- Developers who want inspectable generated code, not a black box

## Try a full generated example
See the demo project generated from a real spec: [Spring Crud Demo](https://github.com/mzivkovicdev/spring-crud-generator-demo)

## Documentation

Full documentation is available in [`/docs`](./docs/README.md).

- [Getting started](./docs/getting-started.md)
- [Configuration reference](./docs/configuration.md)
- [Packages configuration](./docs/packages.md)
- [Entities and fields](./docs/entities.md)
- [Migrations](./docs/migrations.md)
- [Incremental generation](./docs/incremental-generation.md)
- [Spring CRUD Generator vs Bootify](./docs/comparison-with-bootify.md)
- [Full SQL spec example](./docs/examples/crud-spec-full.yaml)
- [Full MongoDB spec example](./docs/examples/mongo-crud-spec-full.yaml)
- [JSON Schema](./docs/schema/crud-spec.schema.json)

> Maven Central: `dev.markozivkovic:spring-crud-generator:1.8.0`
> Artifact page: https://central.sonatype.com/artifact/dev.markozivkovic/spring-crud-generator

---

## What you get

### Core backend
- Entities / Documents
- Repositories
- Services
- DTOs and mappers
- REST controllers

### Optional platform features
- Database migrations (Flyway for SQL, Mongock for MongoDB)
- OpenAPI resources
- GraphQL
- Docker resources
- Caching
- Optimistic locking

### Developer experience
- Unit tests
- JSON Schema validation
- Incremental generation

> ⚠️ Table/collection deletion is **not** supported by the generator and must be handled manually.

---

## Documentation guide

Choose what you need:

- New user? → [Getting started](./docs/getting-started.md)
- Need all available options? → [Configuration reference](./docs/configuration.md)
- Working with entities and fields? → [Entities and fields](./docs/entities.md)
- Need package customization? → [Packages configuration](./docs/packages.md)
- Need a complete SQL example? → [Full SQL spec example](./docs/examples/crud-spec-full.yaml)
- Need a complete MongoDB example? → [Full MongoDB spec example](./docs/examples/mongo-crud-spec-full.yaml)
- Want autocomplete/validation? → [JSON Schema](./docs/schema/crud-spec.schema.json)

---

## Quick start

Generate a fully functional Spring Boot CRUD application in minutes using a single YAML or JSON configuration file.

### Step 1: Add Maven Profile

Add the following `profile` section to your `pom.xml`:

```xml


generate-resources



dev.markozivkovic
spring-crud-generator
1.8.0


generate-spring-crud

generate



${project.basedir}/src/main/resources/crud-spec.yaml


${project.basedir}/src/main/java/com/sql/demo/springboot_postgres_json_demo

true






```

### Step 2: Create configuration file

Create the configuration file at the location defined by `inputSpecFile`.
The file name is arbitrary. Only the extension matters: `.yaml`, `.yml`, or `.json`.

```text
src/main/resources/crud-spec.yaml
```

**SQL example (PostgreSQL, MySQL, MariaDB, MSSQL)**

```yaml
configuration:
database: postgresql
openApi:
apiSpec: true
generateResources: true
errorResponse: simple
tests:
unit: true
dataGenerator: instancio
entities:
- name: ProductModel
storageName: product_table
description: "Represents a product"
fields:
- name: id
type: Long
description: "The unique identifier for the product"
id:
strategy: IDENTITY
- name: name
description: "The name of the product"
type: String
column:
nullable: false
unique: true
length: 255
```

**MongoDB example**

```yaml
configuration:
database: mongodb
openApi:
apiSpec: true
generateResources: true
errorResponse: simple
tests:
unit: true
dataGenerator: instancio
entities:
- name: ProductModel
storageName: products
description: "Represents a product"
fields:
- name: id
type: String
id: true
description: "MongoDB document id"
- name: name
description: "The name of the product"
type: String
validation:
required: true
notBlank: true
maxLength: 255
```

This spec file can define:

- global generator configuration (database, OpenAPI, Docker, tests, caching, migration scripts, etc.)
- entities/documents, fields, constraints, and relationships
- additional features like base path, soft delete, audit, and more

Note: the examples above show only a minimal subset. See the full examples for all available options.

Both YAML (`.yaml/.yml`) and JSON (`.json`) formats are supported.

### Copilot + autocomplete for spec files

For better completion in VS Code/Copilot, bind your spec to the schema.

YAML (`*.yaml` / `*.yml`):

```yaml
# yaml-language-server: $schema=https://raw.githubusercontent.com/mzivkovicdev/spring-crud-generator/main/docs/schema/crud-spec.schema.json
configuration:
database: postgresql
```

JSON (`*.json`):

```json
{
"$schema": "https://raw.githubusercontent.com/mzivkovicdev/spring-crud-generator/main/docs/schema/crud-spec.schema.json",
"configuration": {
"database": "postgresql"
}
}
```

### Step 3: Validate spec (dry-run, optional)

Use the `validate` goal to check whether the spec file is valid before generating code:

```bash
mvn spring-crud-generator:validate -DinputSpecFile=src/main/resources/crud-spec.yaml
```

### Step 4: Run the generator

Run the generator using the Maven profile:

```bash
mvn clean install -Pgenerate-resources
```

After execution:

- source code is generated into the directory defined by `outputDir`
- Flyway migration scripts are generated (if enabled, SQL databases)
- Mongock `@ChangeUnit` classes are generated (if enabled, MongoDB)
- Swagger/OpenAPI resources are generated (if enabled)
- Docker and Docker Compose files are generated (if enabled)

### Step 5: Configuration parameters

| Parameter | Description |
| --- | --- |
| `inputSpecFile` | Path to the YAML/JSON configuration file |
| `outputDir` | Directory where generated source code is written |
| `forceRegeneration` | Forces regeneration of all non-ignored entities, ignoring state files |

For the `validate` goal, only `inputSpecFile` is required.

### Important notes

Incremental generation is enabled by default:

- Generator state is stored in: `generator-state.json` and `migration-state.json`
- Setting `forceRegeneration=true` ignores these files
- Database tables are never dropped automatically

---

## Supported Java versions

- Java **17** – **25**

---

## License

This project is licensed under the Apache License 2.0 - see the [LICENSE](./LICENSE.txt) file for details.

---

## Contact

For questions, feedback, collaboration, or support, feel free to reach out::

- Email: **mzivkovic.dev@gmail.com**
- LinkedIn: [Marko Zivkovic](https://www.linkedin.com/in/marko-zivkovic-84547017a/)