DEV Community

Cover image for One Java Class, a Full Admin Panel, and Zero Generated Code
erupts
erupts

Posted on Fully Autonomous

One Java Class, a Full Admin Panel, and Zero Generated Code

A 2-minute video version of this post is above. The text goes a little deeper.

Writing CRUD is easy. Changing it is the hard part.

Every backend developer has built the same admin page a hundred times: a table, a search bar, a create/edit form, an export button. Building it once is fine. The pain comes later.

Say the business asks for a phone number on the student record. In a typical Spring Boot + frontend setup, that one field touches eight places:

  1. the entity
  2. the mapper / SQL
  3. the DTO
  4. controller validation
  5. the table column
  6. the form input
  7. the search bar
  8. the Excel export

Miss one, and you've shipped a bug. Code generators make the first version faster, but they hand you hundreds of lines that are now yours to maintain — and the next new field means regenerating and merging by hand.

erupt (open source, Apache-2.0, built on Spring Boot) takes a different route: there is exactly one place, your Java class.

The whole admin panel is this class

@Erupt(name = "Students", power = @Power(importable = true, export = true))
@Entity
public class Student extends BaseModel {

    @EruptField(
            views = @View(title = "Name"),
            edit = @Edit(title = "Name", notNull = true, search = @Search)
    )
    private String name;

    @EruptField(
            views = @View(title = "Gender"),
            edit = @Edit(title = "Gender", boolType = @BoolType(trueText = "Male", falseText = "Female"))
    )
    private Boolean sex;

    @EruptField(
            views = @View(title = "Birthday"),
            edit = @Edit(title = "Birthday")
    )
    private LocalDate birthday;

    @EruptField(
            views = @View(title = "Grade"),
            edit = @Edit(title = "Grade", type = EditType.CHOICE, search = @Search,
                    choiceType = @ChoiceType(vl = {
                            @VL(value = "1", label = "Grade 10"),
                            @VL(value = "2", label = "Grade 11"),
                            @VL(value = "3", label = "Grade 12")
                    }))
    )
    private String grade;
}
Enter fullscreen mode Exit fullscreen mode
  • @View → a table column
  • @Edit → a form input (notNull gives you validation, a LocalDate gets a date picker, CHOICE gets a dropdown)
  • search = @Search → the field shows up in the search bar

Start the app, open Menu Management, add a menu entry whose value is Student. (Remember this step — it matters later.)

The generated table with search bar

That's it: a paged table, filtering by grade, a validated form, and one-click Excel export. No controller, no frontend page.

The generated form

So how does it work? It doesn't generate code at all.

This is the part most people get wrong when they first see erupt. There is no generator step and no generated files in your repo.

At startup, erupt reads your annotations into a page description — plain JSON you can look at yourself:

GET /erupt-api/build/Student
Enter fullscreen mode Exit fullscreen mode

The frontend fetches that description and renders it on the fly with generic components. Every table and form above is drawn from it. Because nothing is generated, nothing can drift: the model and the page are always in sync.

One API for every model — so who's allowed to call it?

The backend side is just as small. Every model goes through the same endpoint; only the class name in the path changes:

POST /erupt-api/data/table/Student
POST /erupt-api/data/table/Teacher
...
Enter fullscreen mode Exit fullscreen mode

Which raises the obvious question: if one endpoint serves every class, can anyone query anything?

No. On every request, an interceptor (EruptSecurityInterceptor) checks one thing: is this class in the current user's menu?

I tested it. I added a Teacher class and didn't give it a menu entry. Same admin account:

Request Result
table/Student (has a menu entry) 200
table/Teacher (no menu entry) 403

Even the admin gets a 403.

The "aha": the menu is the permission

So that "add a menu entry" step from earlier isn't busywork. The menu is the permission model. Assign a menu to a role and that role can use the model; don't, and the API is closed. Fine-grained button permissions (Add, Edit, Delete, Export…) are generated from the menu too, so you don't write a separate permission table or @PreAuthorize on every endpoint.

Back to that phone field

Here is the entire change:

@EruptField(
        views = @View(title = "Phone"),
        edit = @Edit(title = "Phone", search = @Search)
)
private String phone;
Enter fullscreen mode Exit fullscreen mode

Five lines, a three-second restart, and the table column, the search bar, the form and the export all have it. (Adding a field needs a restart; if you only tweak annotations on existing fields, erupt.hot-build lets you skip it.)

What about real business logic?

Annotations cover the page; your logic goes in a DataProxy, which hooks in before and after any CRUD operation:

public class StudentProxy implements DataProxy<Student> {
    @Resource
    private EruptDao eruptDao;

    @Override
    public void beforeAdd(Student s) {
        long n = eruptDao.lambdaQuery(Student.class)
                .eq(Student::getPhone, s.getPhone()).count();
        if (n > 0) throw new EruptApiErrorTip("Phone already exists");
    }
}

@Erupt(name = "Students", dataProxy = StudentProxy.class)
Enter fullscreen mode Exit fullscreen mode

To be clear about the boundary: erupt is built for admin panels and internal tools. It's not meant for custom, customer-facing UIs. For the admin-panel job, though, it removes a lot of repetitive work.

Try it in three steps

  1. Add one dependency to a Spring Boot 3 project:
   <dependency>
       <groupId>xyz.erupt</groupId>
       <artifactId>erupt-spring-boot-starter</artifactId>
       <version>2.4.1</version>
   </dependency>
Enter fullscreen mode Exit fullscreen mode
  1. Write one @Erupt class.
  2. Register it in Menu Management.

⭐ GitHub: https://github.com/erupts/erupt

What should the next post cover? Let me know in the comments.

Top comments (0)