@yosr-ai/template-spring 0.0.0-stage → 0.2.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +20 -0
- package/LICENSE +21 -0
- package/README.md +14 -2
- package/features/auth-api-key/files/src/main/java/com/yosr/app/core/ApiKeyFilter.java +52 -0
- package/features/auth-api-key/files/src/test/java/com/yosr/app/ApiKeyTest.java +45 -0
- package/features/auth-api-key/snippets/application-api-key.yaml +1 -0
- package/features/data-jpa/files/dependencies-lock.json +811 -0
- package/features/data-jpa/files/pom.xml +91 -0
- package/features/data-jpa/files/src/main/java/com/yosr/app/core/AppConfig.java +34 -0
- package/features/data-jpa/files/src/main/java/com/yosr/app/core/AppSettings.java +40 -0
- package/features/data-jpa/files/src/main/java/com/yosr/app/core/DataSourceUrl.java +33 -0
- package/features/data-jpa/files/src/main/java/com/yosr/app/features/notes/JpaNoteStore.java +59 -0
- package/features/data-jpa/files/src/main/java/com/yosr/app/features/notes/NoteEntity.java +68 -0
- package/features/data-jpa/files/src/main/java/com/yosr/app/features/notes/NoteRepository.java +5 -0
- package/features/data-jpa/files/src/main/resources/application.yml +14 -0
- package/features/data-jpa/files/src/test/java/com/yosr/app/JpaTestConfig.java +7 -0
- package/features/data-jpa/files/src/test/java/com/yosr/app/NotesApiTest.java +119 -0
- package/features/data-jpa/snippets/readme-db.md +3 -0
- package/features/deploy-docker/files/.dockerignore +5 -0
- package/features/deploy-docker/files/Dockerfile +20 -0
- package/features/deploy-docker/files/compose.yaml +12 -0
- package/features/deploy-docker/snippets/readme-docker.md +3 -0
- package/features/deploy-docker-postgres/snippets/app-config.yaml +3 -0
- package/features/deploy-docker-postgres/snippets/app-env.yaml +1 -0
- package/features/deploy-docker-postgres/snippets/compose-header.yaml +1 -0
- package/features/deploy-docker-postgres/snippets/compose-volumes.yaml +3 -0
- package/features/deploy-docker-postgres/snippets/postgres-service.yaml +13 -0
- package/features/deploy-docker-postgres/snippets/readme-docker.md +3 -0
- package/features/errors-result/files/src/main/java/com/yosr/app/features/notes/NotesController.java +64 -0
- package/features/errors-result/files/src/main/java/com/yosr/app/features/notes/NotesService.java +55 -0
- package/features/errors-result/files/src/main/java/com/yosr/app/shared/Result.java +8 -0
- package/features/errors-result/files/src/test/java/com/yosr/app/NotesServiceTest.java +46 -0
- package/files/.env.example +7 -0
- package/files/.java-version +1 -0
- package/files/README.md +22 -0
- package/files/dependencies-lock.json +547 -0
- package/files/gitignore +9 -0
- package/files/pom.xml +77 -0
- package/files/src/main/java/com/yosr/app/AppApplication.java +12 -0
- package/files/src/main/java/com/yosr/app/core/AppConfig.java +21 -0
- package/files/src/main/java/com/yosr/app/core/AppSettings.java +32 -0
- package/files/src/main/java/com/yosr/app/core/HealthController.java +14 -0
- package/files/src/main/java/com/yosr/app/core/RestExceptionHandler.java +22 -0
- package/files/src/main/java/com/yosr/app/core/WebConfig.java +27 -0
- package/files/src/main/java/com/yosr/app/features/notes/MemoryNoteStore.java +71 -0
- package/files/src/main/java/com/yosr/app/features/notes/Note.java +53 -0
- package/files/src/main/java/com/yosr/app/features/notes/NoteDtos.java +21 -0
- package/files/src/main/java/com/yosr/app/features/notes/NoteStore.java +15 -0
- package/files/src/main/java/com/yosr/app/features/notes/NotesController.java +47 -0
- package/files/src/main/java/com/yosr/app/features/notes/NotesService.java +43 -0
- package/files/src/main/java/com/yosr/app/shared/NotFoundException.java +8 -0
- package/files/src/main/resources/application.yml +7 -0
- package/files/src/test/java/com/yosr/app/NotesApiTest.java +102 -0
- package/files/src/test/java/com/yosr/app/NotesServiceTest.java +42 -0
- package/package.json +26 -4
- package/rules/architecture.md +5 -0
- package/rules/auth-api-key.md +3 -0
- package/rules/commands.md +7 -0
- package/rules/data-jpa.md +3 -0
- package/rules/data-none.md +3 -0
- package/rules/errors-result.md +3 -0
- package/rules/errors-throw.md +3 -0
- package/rules/layout-feature.md +5 -0
- package/rules/layout-flat.md +3 -0
- package/rules/layout-layer.md +3 -0
- package/rules/project-overview.md +5 -0
- package/seed.template.json +711 -0
- package/style/.gitkeep +0 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# @yosr-ai/template-spring
|
|
2
|
+
|
|
3
|
+
## 0.2.6
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 2373b62: Fix Spring create success next-steps (`mvn spring-boot:run` instead of `pnpm dev`) and add download links when the JDK or Maven is missing (same clarity as .NET’s https://dot.net/download).
|
|
8
|
+
|
|
9
|
+
## 0.2.5
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 63badc9: Add the ASP.NET Core API template (`--template dotnet`, ADR 0026): .NET 10 LTS, minimal API, xUnit + WebApplicationFactory, locked NuGet restore with committed `packages.lock.json` and `global.json`, notes API, database none/Postgres (EF Core + Npgsql), API-key auth, multi-stage non-root Docker. Engine gains `engines.dotnet` / package manager `dotnet` (and the same shape for later `engines.java` / `maven`). Joins the Yosr Seed fixed group.
|
|
14
|
+
- 11f252b: Add Spring Boot template-spring (ADR 0027): Java 25, Maven locked resolve, optional JPA Postgres.
|
|
15
|
+
|
|
16
|
+
## 0.2.4
|
|
17
|
+
|
|
18
|
+
### Minor Changes
|
|
19
|
+
|
|
20
|
+
- First npm package of the Spring Boot API template (`--template spring`, ADR 0027): Java 25, Spring Boot 4.1.2, Maven + Spotless, JUnit 5 + MockMvc, locked Maven resolve, notes API, database none/Postgres (Spring Data JPA), API-key auth, Docker (multi-stage non-root). Awaits CLI wire-up and Changesets fixed group.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Wael Zohny / Yosr AI
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @yosr-ai/template-spring
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Yosr Seed template for an API-only Spring Boot service on Java 25 (ADR 0027). Create with:
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
npx create-yosr-seed@latest my-api --template spring
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
Published MIT. Exact-pinned by the `yosr-seed` CLI.
|
|
10
|
+
|
|
11
|
+
## Bugs and feedback
|
|
12
|
+
|
|
13
|
+
Email **wzohny@gmail.com**. The source repository is private, so there is no public issue tracker.
|
|
14
|
+
|
|
15
|
+
Site: [seed.yosr.ai](https://seed.yosr.ai)
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
package com.yosr.app.core;
|
|
2
|
+
|
|
3
|
+
import jakarta.servlet.FilterChain;
|
|
4
|
+
import jakarta.servlet.ServletException;
|
|
5
|
+
import jakarta.servlet.http.HttpServletRequest;
|
|
6
|
+
import jakarta.servlet.http.HttpServletResponse;
|
|
7
|
+
import java.io.IOException;
|
|
8
|
+
import java.util.Map;
|
|
9
|
+
import org.springframework.beans.factory.annotation.Value;
|
|
10
|
+
import org.springframework.http.MediaType;
|
|
11
|
+
import org.springframework.stereotype.Component;
|
|
12
|
+
import org.springframework.web.filter.OncePerRequestFilter;
|
|
13
|
+
import tools.jackson.databind.ObjectMapper;
|
|
14
|
+
|
|
15
|
+
@Component
|
|
16
|
+
public class ApiKeyFilter extends OncePerRequestFilter {
|
|
17
|
+
|
|
18
|
+
public static final String HEADER_NAME = "X-API-Key";
|
|
19
|
+
|
|
20
|
+
private final String apiKey;
|
|
21
|
+
private final ObjectMapper json;
|
|
22
|
+
|
|
23
|
+
public ApiKeyFilter(@Value("${app.api-key:}") String apiKey, ObjectMapper json) {
|
|
24
|
+
this.apiKey = apiKey;
|
|
25
|
+
this.json = json;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
@Override
|
|
29
|
+
protected boolean shouldNotFilter(HttpServletRequest request) {
|
|
30
|
+
return "/health".equals(request.getRequestURI());
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
@Override
|
|
34
|
+
protected void doFilterInternal(
|
|
35
|
+
HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
|
|
36
|
+
throws ServletException, IOException {
|
|
37
|
+
if (apiKey == null || apiKey.isBlank()) {
|
|
38
|
+
response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
|
|
39
|
+
response.setContentType(MediaType.APPLICATION_JSON_VALUE);
|
|
40
|
+
json.writeValue(response.getOutputStream(), Map.of("detail", "API_KEY is not configured."));
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
String provided = request.getHeader(HEADER_NAME);
|
|
44
|
+
if (provided == null || !apiKey.equals(provided)) {
|
|
45
|
+
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
|
|
46
|
+
response.setContentType(MediaType.APPLICATION_JSON_VALUE);
|
|
47
|
+
json.writeValue(response.getOutputStream(), Map.of("detail", "Invalid or missing API key."));
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
filterChain.doFilter(request, response);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
package com.yosr.app;
|
|
2
|
+
|
|
3
|
+
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
|
4
|
+
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
|
5
|
+
|
|
6
|
+
import com.yosr.app.core.ApiKeyFilter;
|
|
7
|
+
import org.junit.jupiter.api.BeforeEach;
|
|
8
|
+
import org.junit.jupiter.api.Test;
|
|
9
|
+
import org.springframework.beans.factory.annotation.Autowired;
|
|
10
|
+
import org.springframework.boot.test.context.SpringBootTest;
|
|
11
|
+
import org.springframework.test.context.TestPropertySource;
|
|
12
|
+
import org.springframework.test.web.servlet.MockMvc;
|
|
13
|
+
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
|
14
|
+
import org.springframework.web.context.WebApplicationContext;
|
|
15
|
+
|
|
16
|
+
@SpringBootTest
|
|
17
|
+
@TestPropertySource(properties = "app.api-key=test-api-key")
|
|
18
|
+
class ApiKeyTest {
|
|
19
|
+
|
|
20
|
+
@Autowired private WebApplicationContext context;
|
|
21
|
+
|
|
22
|
+
private MockMvc mockMvc;
|
|
23
|
+
|
|
24
|
+
@BeforeEach
|
|
25
|
+
void setup() {
|
|
26
|
+
mockMvc = MockMvcBuilders.webAppContextSetup(context).build();
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
@Test
|
|
30
|
+
void missingApiKeyIsUnauthorized() throws Exception {
|
|
31
|
+
mockMvc.perform(get("/notes")).andExpect(status().isUnauthorized());
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
@Test
|
|
35
|
+
void healthStaysOpen() throws Exception {
|
|
36
|
+
mockMvc.perform(get("/health")).andExpect(status().isOk());
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
@Test
|
|
40
|
+
void validApiKeyWorks() throws Exception {
|
|
41
|
+
mockMvc
|
|
42
|
+
.perform(get("/notes").header(ApiKeyFilter.HEADER_NAME, "test-api-key"))
|
|
43
|
+
.andExpect(status().isOk());
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
api-key: ${API_KEY:}
|