findAllByUserStar(int userId, int isCancel, int isDel, int offShelf);
+
+
+ @Transactional
+ @Modifying(clearAutomatically = true)
+ @Query(value = "UPDATE version set star = version.star - ? where `id` = ? AND is_del=0 AND off_shelf=0",nativeQuery=true)
+ int cancelStarVersion(int num, int versionId);
+
+ @Transactional
+ @Query(value = "select version.* from version join template on version.id = template.latest where template.id = ?", nativeQuery = true)
+ VersionDO queryLatestByTemplate(int templateId);
+}
diff --git a/template-marketplace/hertzbeat-template-hub/src/main/java/org/apache/hertzbeat/templatehub/model/dto/LoginDto.java b/template-marketplace/hertzbeat-template-hub/src/main/java/org/apache/hertzbeat/templatehub/model/dto/LoginDto.java
new file mode 100644
index 00000000000..6909ab16f09
--- /dev/null
+++ b/template-marketplace/hertzbeat-template-hub/src/main/java/org/apache/hertzbeat/templatehub/model/dto/LoginDto.java
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hertzbeat.templatehub.model.DTO;
+
+import io.swagger.v3.oas.annotations.media.Schema;
+import jakarta.validation.constraints.Max;
+import jakarta.validation.constraints.NotBlank;
+import jakarta.validation.constraints.Size;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import static io.swagger.v3.oas.annotations.media.Schema.AccessMode.READ_ONLY;
+
+/**
+ * Login registered account information transfer body email
+ */
+@Data
+@Builder
+@AllArgsConstructor
+@NoArgsConstructor
+@Schema(description = "Account information transfer body")
+public class LoginDto {
+
+ /**
+ * type
+ * 1. Account (email) username password login 2. github login
+ */
+ @Schema(description = "type", example = "1", accessMode = READ_ONLY)
+ @Max(value = 4, message = "1. Account (email) password login 2. github login 3. WeChat login")
+ private Byte type;
+
+ /**
+ * User ID
+ */
+ @Schema(description = "user identification", example = "1", accessMode = READ_ONLY)
+ @NotBlank(message = "Identifier can not null")
+ private String identifier;
+
+ /**
+ * key
+ */
+ @Schema(description = "Secret key", example = "1", accessMode = READ_ONLY)
+ @NotBlank(message = "Credential can not null")
+ @Size(max = 512, message = "credential max length 512")
+ private String credential;
+
+}
diff --git a/template-marketplace/hertzbeat-template-hub/src/main/java/org/apache/hertzbeat/templatehub/model/dto/Message.java b/template-marketplace/hertzbeat-template-hub/src/main/java/org/apache/hertzbeat/templatehub/model/dto/Message.java
new file mode 100644
index 00000000000..6586eac7c6d
--- /dev/null
+++ b/template-marketplace/hertzbeat-template-hub/src/main/java/org/apache/hertzbeat/templatehub/model/dto/Message.java
@@ -0,0 +1,97 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hertzbeat.templatehub.model.DTO;
+
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.ToString;
+import org.apache.hertzbeat.templatehub.constants.CommonConstants;
+
+/**
+ * Unified message structure definition for front and back ends
+ *
+ * {
+ * data:{....},
+ * msg: message,
+ * code: 3432
+ * }
+ */
+
+@Data
+@ToString
+@Builder
+@AllArgsConstructor
+public class Message {
+
+ /**
+ * response code, not http code
+ */
+ @Schema(title = "Response Code")
+ private byte code = CommonConstants.SUCCESS_CODE;
+
+ /**
+ * exception message when error happen or success message
+ */
+ @Schema(title = "Other Message")
+ private String msg;
+
+ /**
+ * message body data
+ */
+ @Schema(description = "Response Data")
+ private T data;
+
+ public static Message success() {
+ return new Message<>();
+ }
+
+ public static Message success(String msg) {
+ return new Message<>(msg);
+ }
+
+ public static Message fail(byte code, String msg) {
+ return new Message<>(code, msg);
+ }
+
+ public static Message success(T data) {
+ return new Message<>(data);
+ }
+
+ public static Message successWithData(T data) {
+ return new Message<>(data);
+ }
+
+ private Message() {
+ }
+
+ private Message(String msg) {
+ this.msg = msg;
+ }
+
+ private Message(byte code, String msg) {
+ this.code = code;
+ this.msg = msg;
+ }
+
+ private Message(T data) {
+ this.data = data;
+ }
+
+}
diff --git a/template-marketplace/hertzbeat-template-hub/src/main/java/org/apache/hertzbeat/templatehub/model/dto/RefreshTokenResponse.java b/template-marketplace/hertzbeat-template-hub/src/main/java/org/apache/hertzbeat/templatehub/model/dto/RefreshTokenResponse.java
new file mode 100644
index 00000000000..fcbeb882ff5
--- /dev/null
+++ b/template-marketplace/hertzbeat-template-hub/src/main/java/org/apache/hertzbeat/templatehub/model/dto/RefreshTokenResponse.java
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hertzbeat.templatehub.model.DTO;
+
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+/**
+ * Refresh Token Response
+ */
+@Data
+@Builder
+@NoArgsConstructor
+@AllArgsConstructor
+@Schema(description = "flash token response")
+public class RefreshTokenResponse {
+ @Schema(title = "Access Token")
+ private String token;
+
+ @Schema(title = "Refresh Token")
+ private String refreshToken;
+}
diff --git a/template-marketplace/hertzbeat-template-hub/src/main/java/org/apache/hertzbeat/templatehub/model/dto/SignUpDto.java b/template-marketplace/hertzbeat-template-hub/src/main/java/org/apache/hertzbeat/templatehub/model/dto/SignUpDto.java
new file mode 100644
index 00000000000..780d9602bf3
--- /dev/null
+++ b/template-marketplace/hertzbeat-template-hub/src/main/java/org/apache/hertzbeat/templatehub/model/dto/SignUpDto.java
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hertzbeat.templatehub.model.DTO;
+
+import io.swagger.v3.oas.annotations.media.Schema;
+import jakarta.validation.constraints.Max;
+import jakarta.validation.constraints.NotBlank;
+import jakarta.validation.constraints.Size;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import static io.swagger.v3.oas.annotations.media.Schema.AccessMode.READ_ONLY;
+
+/**
+ * Login registered account information transfer body email
+ */
+@Data
+@Builder
+@AllArgsConstructor
+@NoArgsConstructor
+@Schema(description = "sign up body")
+public class SignUpDto {
+
+ @Schema(description = "name", example = "user", accessMode = READ_ONLY)
+ @NotBlank(message = "Name can not null")
+ @Size(max = 10, message = "name max length 10")
+ private String name;
+
+ @Schema(description = "user email", example = "xxx@xxx.com", accessMode = READ_ONLY)
+ @NotBlank(message = "email can not null")
+ private String email;
+
+ @Schema(description = "password", example = "123456", accessMode = READ_ONLY)
+ @NotBlank(message = "password can not null")
+ @Size(min = 6,max = 16, message = "password max length 16,min 6")
+ private String password;
+
+}
diff --git a/template-marketplace/hertzbeat-template-hub/src/main/java/org/apache/hertzbeat/templatehub/model/dto/TemplateDto.java b/template-marketplace/hertzbeat-template-hub/src/main/java/org/apache/hertzbeat/templatehub/model/dto/TemplateDto.java
new file mode 100644
index 00000000000..d63128dda45
--- /dev/null
+++ b/template-marketplace/hertzbeat-template-hub/src/main/java/org/apache/hertzbeat/templatehub/model/dto/TemplateDto.java
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hertzbeat.templatehub.model.DTO;
+
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import lombok.ToString;
+
+@Data
+@ToString
+@AllArgsConstructor
+@NoArgsConstructor
+public class TemplateDto {
+
+ private int id=0;
+ private String name="";
+ private String description="";
+ private String descriptionVersion="";
+ private int latest=0;
+ private String currentVersion="";
+ private String user="";
+ private int userId=0;
+ private String category="";
+ private int categoryId=0;
+ private int download=0;
+ private int star=0;
+ private String create_time="";
+ private String update_time="";
+ private int off_shelf=0;
+ private int is_del=0;
+}
diff --git a/template-marketplace/hertzbeat-template-hub/src/main/java/org/apache/hertzbeat/templatehub/model/dto/TokenDto.java b/template-marketplace/hertzbeat-template-hub/src/main/java/org/apache/hertzbeat/templatehub/model/dto/TokenDto.java
new file mode 100644
index 00000000000..47686db0318
--- /dev/null
+++ b/template-marketplace/hertzbeat-template-hub/src/main/java/org/apache/hertzbeat/templatehub/model/dto/TokenDto.java
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hertzbeat.templatehub.model.DTO;
+
+import io.swagger.v3.oas.annotations.media.Schema;
+import jakarta.validation.constraints.NotBlank;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+/**
+ * Refresh token dto
+ */
+@Data
+@Builder
+@AllArgsConstructor
+@NoArgsConstructor
+@Schema(description = "Request refresh token transfer body")
+public class TokenDto {
+
+ @Schema(description = "token")
+ @NotBlank(message = "token can not null")
+ private String token;
+
+}
diff --git a/template-marketplace/hertzbeat-template-hub/src/main/java/org/apache/hertzbeat/templatehub/model/entity/Category.java b/template-marketplace/hertzbeat-template-hub/src/main/java/org/apache/hertzbeat/templatehub/model/entity/Category.java
new file mode 100644
index 00000000000..9da3ab446f0
--- /dev/null
+++ b/template-marketplace/hertzbeat-template-hub/src/main/java/org/apache/hertzbeat/templatehub/model/entity/Category.java
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hertzbeat.templatehub.model.entity;
+
+import io.swagger.v3.oas.annotations.media.Schema;
+import jakarta.persistence.*;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import lombok.ToString;
+
+import java.io.Serializable;
+
+@Data
+@AllArgsConstructor
+@NoArgsConstructor
+@ToString
+@Entity
+@Table(name = "category")
+public class Category implements Serializable {
+
+ @Id
+ @GeneratedValue(strategy = GenerationType.IDENTITY)
+ private Integer id;
+
+ @Column(nullable = false)
+ @Schema(description = "Category Name")
+ private String name;
+
+ @Column(nullable = false)
+ private String description;
+
+ @Column(nullable = false,name = "create_time")
+ private String createTime;
+
+ @Column(nullable = false, name = "update_time")
+ private String updateTime;
+
+ @Column(nullable = false,name = "is_del")
+ @Schema(description = "Delete Mark")
+ private Integer isDel;
+}
diff --git a/template-marketplace/hertzbeat-template-hub/src/main/java/org/apache/hertzbeat/templatehub/model/entity/Star.java b/template-marketplace/hertzbeat-template-hub/src/main/java/org/apache/hertzbeat/templatehub/model/entity/Star.java
new file mode 100644
index 00000000000..b4fd1f99cae
--- /dev/null
+++ b/template-marketplace/hertzbeat-template-hub/src/main/java/org/apache/hertzbeat/templatehub/model/entity/Star.java
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hertzbeat.templatehub.model.entity;
+
+import java.io.Serializable;
+
+import io.swagger.v3.oas.annotations.media.Schema;
+import jakarta.persistence.*;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import lombok.ToString;
+
+@Data
+@AllArgsConstructor
+@NoArgsConstructor
+@ToString
+@Table(name = "star")
+@Entity
+public class Star implements Serializable {
+
+ @Id
+ @GeneratedValue(strategy = GenerationType.IDENTITY)
+ private Integer id;
+
+ @Column(name = "user_id",nullable = false)
+ private Integer userId;
+
+ @Column(name = "template_id",nullable = false)
+ private Integer templateId;
+
+ @Column(name = "version_id",nullable = false)
+ private Integer versionId;
+
+ @Column(name = "create_time",nullable = false)
+ private String createTime;
+
+ @Column(name = "is_del",nullable = false)
+ @Schema(description = "Cancel flag, 0 means normal, 1 means cancel")
+ private Integer isDel;
+}
diff --git a/template-marketplace/hertzbeat-template-hub/src/main/java/org/apache/hertzbeat/templatehub/model/entity/Tag.java b/template-marketplace/hertzbeat-template-hub/src/main/java/org/apache/hertzbeat/templatehub/model/entity/Tag.java
new file mode 100644
index 00000000000..60a41f96657
--- /dev/null
+++ b/template-marketplace/hertzbeat-template-hub/src/main/java/org/apache/hertzbeat/templatehub/model/entity/Tag.java
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hertzbeat.templatehub.model.entity;
+
+import java.io.Serializable;
+
+import io.swagger.v3.oas.annotations.media.Schema;
+import jakarta.persistence.*;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import lombok.ToString;
+
+
+@Data
+@AllArgsConstructor
+@NoArgsConstructor
+@ToString
+@Entity
+@Table(name = "tag")
+public class Tag implements Serializable {
+
+ @Id
+ @GeneratedValue(strategy = GenerationType.IDENTITY)
+ private Integer id;
+
+ @Schema(description = "Tag name, no duplication allowed, modification allowed")
+ @Column(nullable = false)
+ private String name;
+
+ @Column(nullable = false)
+ private String description;
+
+ @Column(name = "create_time",nullable = false)
+ private String createTime;
+
+ @Column(name = "is_del",nullable = false)
+ private Integer isDel;
+
+
+}
diff --git a/template-marketplace/hertzbeat-template-hub/src/main/java/org/apache/hertzbeat/templatehub/model/entity/Template.java b/template-marketplace/hertzbeat-template-hub/src/main/java/org/apache/hertzbeat/templatehub/model/entity/Template.java
new file mode 100644
index 00000000000..a572f1dfb5e
--- /dev/null
+++ b/template-marketplace/hertzbeat-template-hub/src/main/java/org/apache/hertzbeat/templatehub/model/entity/Template.java
@@ -0,0 +1,84 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hertzbeat.templatehub.model.entity;
+
+import io.swagger.v3.oas.annotations.media.Schema;
+import jakarta.persistence.*;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import lombok.ToString;
+
+import java.io.Serializable;
+
+@Data
+@AllArgsConstructor
+@NoArgsConstructor
+@ToString
+@Entity
+@Table(name="template")
+public class Template implements Serializable {
+
+ @Id
+ @GeneratedValue(strategy = GenerationType.IDENTITY)
+ private Integer id=1;
+
+ @Column(nullable = false)
+ @Schema(description = "Template name, cannot be modified, but can be repeated")
+ private String name;
+
+ @Column(nullable = false)
+ private String description;
+
+ @Column(nullable = false)
+ @Schema(description = "Latest version id")
+ private Integer latest;
+
+ @Column(nullable = false)
+ @Schema(description = "user id")
+ private Integer user;
+
+ @Column(nullable = false)
+ @Schema(description = "Template category id")
+ private Integer category;
+
+ @Column(nullable = false)
+ @Schema(description = "Template-tag table id")
+ private Integer tag;
+
+ @Column(nullable = false)
+ @Schema(description = "Downloads")
+ private Integer download;
+
+ @Column(nullable = false)
+ private Integer star;
+
+ @Column(nullable = false,name = "create_time")
+ private String createTime;
+
+ @Column(nullable = false, name = "update_time")
+ private String updateTime;
+
+ @Column(nullable = false,name="off_shelf")
+ @Schema(description = "Delisting mark, 0 means normal, 1 means delisting")
+ private Integer offShelf;
+
+ @Column(nullable = false,name = "is_del")
+ @Schema(description = "Delete mark, 0 means normal, 1 means delete")
+ private Integer isDel;
+}
diff --git a/template-marketplace/hertzbeat-template-hub/src/main/java/org/apache/hertzbeat/templatehub/model/entity/TemplateTag.java b/template-marketplace/hertzbeat-template-hub/src/main/java/org/apache/hertzbeat/templatehub/model/entity/TemplateTag.java
new file mode 100644
index 00000000000..24477198e7f
--- /dev/null
+++ b/template-marketplace/hertzbeat-template-hub/src/main/java/org/apache/hertzbeat/templatehub/model/entity/TemplateTag.java
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hertzbeat.templatehub.model.entity;
+
+import java.io.Serializable;
+
+import io.swagger.v3.oas.annotations.media.Schema;
+import jakarta.persistence.*;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import lombok.ToString;
+
+@Data
+@AllArgsConstructor
+@NoArgsConstructor
+@ToString
+@Entity
+@Table(name = "template_tag")
+public class TemplateTag implements Serializable {
+
+ @Id
+ @GeneratedValue(strategy = GenerationType.IDENTITY)
+ private Integer id;
+
+ @Column(nullable = false)
+ @Schema(description = "template id")
+ private Integer template;
+
+ @Column(nullable = false)
+ @Schema(description = "tag id")
+ private Integer tag;
+
+
+}
diff --git a/template-marketplace/hertzbeat-template-hub/src/main/java/org/apache/hertzbeat/templatehub/model/entity/User.java b/template-marketplace/hertzbeat-template-hub/src/main/java/org/apache/hertzbeat/templatehub/model/entity/User.java
new file mode 100644
index 00000000000..b517b4d0a14
--- /dev/null
+++ b/template-marketplace/hertzbeat-template-hub/src/main/java/org/apache/hertzbeat/templatehub/model/entity/User.java
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hertzbeat.templatehub.model.entity;
+
+import java.io.Serializable;
+
+import io.swagger.v3.oas.annotations.media.Schema;
+import jakarta.persistence.*;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import lombok.ToString;
+
+@Data
+@AllArgsConstructor
+@NoArgsConstructor
+@ToString
+@Entity
+@Table(name = "user")
+public class User implements Serializable {
+
+ @Id
+ @GeneratedValue(strategy = GenerationType.IDENTITY)
+ private Integer id;
+
+ @Column(nullable = false)
+ @Schema(description = "Username, can be repeated, can be modified")
+ private String name;
+
+ @Column(nullable = false)
+ @Schema(description = "Email, can be modified, used for user login")
+ private String email;
+
+ @Column(nullable = false,name = "create_time")
+ private String createTime;
+
+ @Column(nullable = false,name = "log_off_time")
+ @Schema(description = "Logout time, if not logged out it is 0, if logged out it is time")
+ private String logOffTime;
+
+
+}
diff --git a/template-marketplace/hertzbeat-template-hub/src/main/java/org/apache/hertzbeat/templatehub/model/entity/Version.java b/template-marketplace/hertzbeat-template-hub/src/main/java/org/apache/hertzbeat/templatehub/model/entity/Version.java
new file mode 100644
index 00000000000..3f983a764d2
--- /dev/null
+++ b/template-marketplace/hertzbeat-template-hub/src/main/java/org/apache/hertzbeat/templatehub/model/entity/Version.java
@@ -0,0 +1,69 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hertzbeat.templatehub.model.entity;
+
+import java.io.Serializable;
+
+import io.swagger.v3.oas.annotations.media.Schema;
+import jakarta.persistence.*;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import lombok.ToString;
+
+@Data
+@AllArgsConstructor
+@NoArgsConstructor
+@ToString
+@Entity
+@Table(name = "version")
+public class Version implements Serializable {
+
+ @Id
+ @GeneratedValue(strategy = GenerationType.IDENTITY)
+ private Integer id;
+
+ @Column(nullable = false)
+ @Schema(description = "template id")
+ private Integer template;
+
+ @Column(nullable = false)
+ @Schema(description = "Version name, modification is not allowed")
+ private String version;
+
+ @Column(nullable = false)
+ @Schema(description = "Version description")
+ private String description;
+
+ @Column(nullable = false)
+ private Integer download;
+
+ @Column(nullable = false)
+ private Integer star;
+
+ @Column(nullable = false,name = "create_time")
+ private String createTime;
+
+ @Column(nullable = false,name = "off_shelf")
+ private Integer offShelf;
+
+ @Column(nullable = false,name = "is_del")
+ private Integer isDel;
+
+
+}
diff --git a/template-marketplace/hertzbeat-template-hub/src/main/java/org/apache/hertzbeat/templatehub/service/AccountService.java b/template-marketplace/hertzbeat-template-hub/src/main/java/org/apache/hertzbeat/templatehub/service/AccountService.java
new file mode 100644
index 00000000000..e189064f41d
--- /dev/null
+++ b/template-marketplace/hertzbeat-template-hub/src/main/java/org/apache/hertzbeat/templatehub/service/AccountService.java
@@ -0,0 +1,99 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hertzbeat.templatehub.service;
+
+import com.usthe.sureness.provider.SurenessAccount;
+import org.apache.hertzbeat.templatehub.model.DTO.LoginDto;
+import org.apache.hertzbeat.templatehub.model.DTO.RefreshTokenResponse;
+import org.apache.hertzbeat.templatehub.model.DTO.SignUpDto;
+
+import javax.naming.AuthenticationException;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Account service
+ */
+public interface AccountService {
+ /**
+ * Verify account validity, username and password
+ * @param account account info
+ * @return success-true failed-false
+ */
+ boolean authenticateAccount(LoginDto account);
+
+ /**
+ * Get all roles owned by this username account, combine them into string list
+ * @param username account username
+ * @return role-string eg role1,role3,role2
+ */
+ List loadAccountRoles(String username);
+
+ /**
+ * register account
+ * @param account account info
+ * @return success-true failed-false
+ */
+ boolean registerAccount(SignUpDto account);
+
+ /**
+ * Determine whether the account already exists
+ * @param account account info
+ * @return exist-true no-false
+ */
+ boolean isAccountExist(LoginDto account);
+
+ /**
+ * Account password login to obtain associated user information
+ * @param loginDto loginDto
+ * @return token info
+ * @throws AuthenticationException when authentication is failed
+ */
+ Map authGetToken(LoginDto loginDto) throws AuthenticationException;
+
+ /**
+ * Load the account information by username
+ * @param username account username
+ * @return account
+ */
+ SurenessAccount loadAccount(String username);
+
+ /**
+ * authority User Role by username and roleId
+ * @param appId account username
+ * @param roleId roleId
+ * @return success-true failed-false
+ */
+ boolean authorityUserRole(String appId, Long roleId);
+
+ /**
+ * delete authority User Role by username and roleId
+ * @param appId account username
+ * @param roleId roleId
+ * @return success-true failed-false
+ */
+ boolean deleteAuthorityUserRole(String appId, Long roleId);
+
+ /**
+ * Use refresh TOKEN to re-acquire TOKEN
+ * @param refreshToken refreshToken
+ * @return token and refresh token
+ * @throws Exception failed to refresh
+ */
+ RefreshTokenResponse refreshToken(String refreshToken) throws Exception;
+}
diff --git a/template-marketplace/hertzbeat-template-hub/src/main/java/org/apache/hertzbeat/templatehub/service/CategoryService.java b/template-marketplace/hertzbeat-template-hub/src/main/java/org/apache/hertzbeat/templatehub/service/CategoryService.java
new file mode 100644
index 00000000000..fa3c8426c89
--- /dev/null
+++ b/template-marketplace/hertzbeat-template-hub/src/main/java/org/apache/hertzbeat/templatehub/service/CategoryService.java
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hertzbeat.templatehub.service;
+
+import org.apache.hertzbeat.templatehub.model.DO.CategoryDO;
+import org.springframework.data.domain.Page;
+
+import java.util.List;
+
+public interface CategoryService {
+
+ boolean addCategory(String categoryName,String categoryDescription,String nowTime);
+
+ boolean modifyCategory(int id, String categoryName,String categoryDescription,String nowTime);
+
+ boolean deleteCategory(int id);
+
+ List getAllCategoryByIsDel(int isDel);
+
+ Page getPageByIsDel(int isDel, int page, int size);
+}
diff --git a/template-marketplace/hertzbeat-template-hub/src/main/java/org/apache/hertzbeat/templatehub/service/FileStorageService.java b/template-marketplace/hertzbeat-template-hub/src/main/java/org/apache/hertzbeat/templatehub/service/FileStorageService.java
new file mode 100644
index 00000000000..5df5a0cd491
--- /dev/null
+++ b/template-marketplace/hertzbeat-template-hub/src/main/java/org/apache/hertzbeat/templatehub/service/FileStorageService.java
@@ -0,0 +1,30 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hertzbeat.templatehub.service;
+
+import org.springframework.core.io.Resource;
+import org.springframework.web.multipart.MultipartFile;
+
+public interface FileStorageService {
+
+ void uploadFile(MultipartFile file, String path, String fileName);
+
+ void deleteFile(String path, String fileName);
+
+ Resource downloadFile(String path, String fileName);
+}
diff --git a/template-marketplace/hertzbeat-template-hub/src/main/java/org/apache/hertzbeat/templatehub/service/ResourceService.java b/template-marketplace/hertzbeat-template-hub/src/main/java/org/apache/hertzbeat/templatehub/service/ResourceService.java
new file mode 100644
index 00000000000..7587d639a17
--- /dev/null
+++ b/template-marketplace/hertzbeat-template-hub/src/main/java/org/apache/hertzbeat/templatehub/service/ResourceService.java
@@ -0,0 +1,86 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hertzbeat.templatehub.service;
+
+import org.apache.hertzbeat.templatehub.model.DO.AuthResourceDO;
+import org.springframework.data.domain.Page;
+
+import java.util.List;
+import java.util.Optional;
+import java.util.Set;
+
+/**
+ * @author tomsun28
+ * @date 00:13 2019-08-01
+ */
+public interface ResourceService {
+
+ /**
+ * add uri resource
+ * @param authResource resource
+ * @return success-true failed-false
+ */
+ boolean addResource(AuthResourceDO authResource);
+
+ /**
+ * Determine whether the resource already exists
+ * @param authResource resource
+ * @return existed-true no-false
+ */
+ boolean isResourceExist(AuthResourceDO authResource);
+
+ /**
+ * update uri resource
+ * @param authResource resource
+ * @return success-true failed-false
+ */
+ boolean updateResource(AuthResourceDO authResource);
+
+ /**
+ * delete uri resource
+ * @param resourceId resource ID
+ * @return success-true no existed-false
+ */
+ boolean deleteResource(Long resourceId);
+
+ /**
+ * get all resources
+ * @return resource list
+ */
+ Optional> getAllResource();
+
+ /**
+ * get resource by page
+ * @param currentPage current page
+ * @param pageSize page size
+ * @return Page of resource
+ */
+ Page getPageResource(Integer currentPage, Integer pageSize);
+
+ /**
+ * get enabled resource-path-role eg: /api/v2/host===post===[role2,role3,role4]
+ * @return resource-path-role
+ */
+ Set getAllEnableResourcePath();
+
+ /**
+ * get disable resource-path-role eg: /api/v2/host===post===[role2,role3,role4]
+ * @return resource-path-role
+ */
+ Set getAllDisableResourcePath();
+}
diff --git a/template-marketplace/hertzbeat-template-hub/src/main/java/org/apache/hertzbeat/templatehub/service/RoleService.java b/template-marketplace/hertzbeat-template-hub/src/main/java/org/apache/hertzbeat/templatehub/service/RoleService.java
new file mode 100644
index 00000000000..ba56707ff12
--- /dev/null
+++ b/template-marketplace/hertzbeat-template-hub/src/main/java/org/apache/hertzbeat/templatehub/service/RoleService.java
@@ -0,0 +1,105 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hertzbeat.templatehub.service;
+
+import org.apache.hertzbeat.templatehub.model.DO.AuthResourceDO;
+import org.apache.hertzbeat.templatehub.model.DO.AuthRoleDO;
+import org.springframework.data.domain.Page;
+
+import java.util.List;
+import java.util.Optional;
+
+public interface RoleService {
+
+ Long getRoleIdByCode(String code);
+
+ /**
+ * Determine whether the role already exists
+ * @param authRole role
+ * @return existed-true no-false
+ */
+ boolean isRoleExist(AuthRoleDO authRole);
+
+ /**
+ * add role
+ * @param authRole role
+ * @return add success-true failed-false
+ */
+ boolean addRole(AuthRoleDO authRole);
+
+ /**
+ * update role
+ * @param authRole role
+ * @return success-true failed-false
+ */
+ boolean updateRole(AuthRoleDO authRole);
+
+ /**
+ * delete role
+ * @param roleId role ID
+ * @return success-true failed-false
+ */
+ boolean deleteRole(Long roleId);
+
+ /**
+ * get all role list
+ * @return role list
+ */
+ Optional> getAllRole();
+
+ /**
+ * get roles page
+ * @param currentPage current page
+ * @param pageSize page size
+ * @return Page of roles
+ */
+ Page getPageRole(Integer currentPage, Integer pageSize);
+
+ /**
+ * get pageable resources which this role owned
+ * @param roleId role ID
+ * @param currentPage current page
+ * @param pageSize page size
+ * @return Page of resources
+ */
+ Page