Skip to content

Commit d7c2ef9

Browse files
committed
add readme
1 parent 379f0f8 commit d7c2ef9

File tree

1 file changed

+39
-164
lines changed

1 file changed

+39
-164
lines changed

README.md

Lines changed: 39 additions & 164 deletions
Original file line numberDiff line numberDiff line change
@@ -1,164 +1,39 @@
1-
# template-microservice
2-
This serves as a template for the microservices
3-
4-
## Package structure
5-
6-
This package structure is based on multiple sources of best practices in Spring Boot, using roughly the "Package by layer" approach.
7-
- *root*
8-
- *config*
9-
- *controller*
10-
- *dapr*
11-
- *dto*
12-
- *exception*
13-
- *persistence*
14-
- *entity*
15-
- *repository*
16-
- *mapper*
17-
- *service*
18-
- *util* (optional, if needed)
19-
- *validation*
20-
21-
Detailed description of the packages:
22-
23-
### Root package
24-
25-
This should be named after the microservice itself. This is the root package for the microservice. It contains the `Application.java` file (or of similar name), which is the entry point for the microservice. Usually, this is the only class in this package.
26-
27-
### Config package
28-
This package should contain any classes that are used to configure the application. This includes [Sprint Boot configuration classes](https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/context/annotation/Configuration.html) but might also contain anything else related to configuration the microservice.
29-
The classes that are in this package should not be deleted in the actual microservice as they provide useful functionality.
30-
31-
### Controller package
32-
33-
**Location:src/main/java/de/unistuttgart/iste/meitrex/{service_name}/controller**
34-
35-
This package contains the GraphQL controllers (and other types of controllers if needed). The GraphQL controllers are annotated with the `@Controller` annotation. Controllers contain no business logic, but only delegate the requests to the service layer. They handle the "technical stuff" of the request.
36-
37-
In some services, there is also a class called SubscriptionController which handles all dapr event subscriptions.
38-
39-
More information can be found in
40-
the [Controller package](src/main/java/de/unistuttgart/iste/meitrex/template/controller/package-info.java).
41-
42-
### Dapr package
43-
44-
**Location**:src/main/java/de/unistuttgart/iste/meitrex/{service_name}/dapr
45-
46-
This package should contain all classes that are used to communicate with Dapr, e.g. using pub sub.
47-
48-
### DTO package
49-
50-
**This package will not be located in the src/main/java folder, but in the build/generated folder.**
51-
52-
This package contains the generated DTOs (data transfer objects) from the GraphQL schema. The DTOs are generated when building the project with gradle.
53-
54-
If not necessary, no other files should be added manually to this package.
55-
56-
#### Why both DTOs and Entities?
57-
58-
The DTOs are used to transfer data between the GraphQL controller and the service layer. The entities are used to persist data in the database. This is done to separate the data transfer from the data persistence. This is a common approach in Spring Boot applications as it can happen that we want to store more data in the database than we want to transfer to the client or vice versa.
59-
60-
### Exception package
61-
62-
**Location**:src/main/java/de/unistuttgart/iste/meitrex/{service_name}/exception
63-
64-
This package is used for exception handling. Note that with GraphQL, the exceptions are not thrown directly, but are wrapped in a `GraphQLException`, which is different that from the usual Spring Boot approach.
65-
66-
More information can be found in
67-
the [Exception package](src/main/java/de/unistuttgart/iste/meitrex/template/exception/package-info.java).
68-
69-
### Persistence package
70-
71-
**Location**:src/main/java/de/unistuttgart/iste/meitrex/{service_name}/persistence
72-
73-
This package contains all classes that are used to persist data in the database. This includes the entities, the mapping
74-
logic between entities and DTOs, as well as the repositories.
75-
76-
This package handles the calls to the database and defines the database entities. It is structured into three sub-packages:
77-
78-
#### 1. entity
79-
This package contains the database entities.
80-
81-
#### 2. repository
82-
This package contains the interfaces to the database, also known as Data Access Objects (DAOs), used to perform various database operations. Note that these interfaces may sometimes be empty, especially when the default methods provided by the Spring Framework are sufficient for the required operations.
83-
84-
#### 3. mapper
85-
The 'mapper' package is responsible for the mapping logic between the database entities and the data types defined in the GraphQL schema. Specifically, it maps the database entity classes to the corresponding classes generated from the GraphQL schema.
86-
87-
This structure helps organize the database-related components of the project, making it easier to manage and maintain.
88-
89-
More information can be found in
90-
the [Entity package](src/main/java/de/unistuttgart/iste/meitrex/template/persistence/entity/package-info.java) and
91-
the [Repository package](src/main/java/de/unistuttgart/iste/meitrex/template/persistence/repository/package-info.java).
92-
93-
### Service package
94-
95-
**Location**:src/main/java/de/unistuttgart/iste/meitrex/{service_name}/service
96-
97-
This package contains all classes that are used to handle the business logic of the microservice. Services are annotated with the `@Service` annotation. Services contain only business logic and delegate the data access to the persistence layer (repositories).
98-
99-
More information can be found in
100-
the [Service package](src/main/java/de/unistuttgart/iste/meitrex/template/service/package-info.java).
101-
102-
### Validation package
103-
104-
**Location**:src/main/java/de/unistuttgart/iste/meitrex/{service_name}/validation
105-
106-
This package should contain the *class-level* validation logic, i.e. the validation logic that is not directly related to a specific field, e.g. validation if an end date is after a start date.
107-
108-
Field-level validation logic should not be placed in this package, but in the graphql schema, via directives.
109-
If these directives are not sufficient, the validation logic can also be placed in this package.
110-
111-
## Getting Started
112-
113-
### Todos
114-
115-
Follow the guide in the wiki: https://github.com/MEITREX/wiki/blob/main/dev-manuals/backend/new-service.md
116-
117-
Addtionally, after cloning the repository, you need to do the following steps:
118-
- [ ] Setup the gradle files correctly. This means
119-
- [ ] Change the project name in the `settings.gradle` file
120-
- [ ] Change the sonar project key in the `build.gradle` file (should be MEITREX_repository_name)
121-
- [ ] Add/Remove dependencies in the `build.gradle` file
122-
- [ ] Rename the package in the `src/main/java` folder to a more suitable name (should be the service name)
123-
- [ ] Remove the package-info.java files in the `src/main/java` folder, if the file is present (or update with the microservice specific information)
124-
- [ ] Update the application.properties file in the `src/main/resources` folder (check the TODOS in the file)
125-
- [ ] Change the ports and name of the database in the docker-compose.yml (see wiki on how to)
126-
- [ ] Define the GraphQL schema in the `src/main/resources/schema.graphqls` file
127-
<!-- TODO there probably more TODOs -->
128-
129-
130-
After creating a new service you need to do the following:
131-
- [ ] Add the repository to sonarcloud, follow the instructions for extra configuration, unselect automatic analysis and choose github actions, only the first step needs to be completed
132-
- [ ] Add SONAR_TOKEN to the service repository secrets on Github (this requires you to have admin permissions on sonarcloud)
133-
134-
### Pull new changes from this template
135-
136-
If this template changes and you want to pull the changes to the actual microservice, you can run the following commands:
137-
```bash
138-
git remote add template https://github.com/MEITREX/template_microservice # only necessary once
139-
git fetch --all
140-
git checkout [branch] # replace [branch] with the branch name you want the changes to be merged into (preferably not main)
141-
git merge template/main --allow-unrelated-histories
142-
# you will probably need to commit afterwars
143-
```
144-
145-
### Guides
146-
The following guides illustrate how to use some features concretely:
147-
148-
* [Building a GraphQL service](https://spring.io/guides/gs/graphql-server/)
149-
* [Accessing Data with JPA](https://spring.io/guides/gs/accessing-data-jpa/)
150-
* [Validation with GraphQL directives](https://github.com/graphql-java/graphql-java-extended-validation/blob/master/README.md)
151-
* [Error handling](https://www.baeldung.com/spring-graphql-error-handling)
152-
153-
### Reference Documentation
154-
For further reference, please consider the following sections:
155-
156-
* [Official Gradle documentation](https://docs.gradle.org)
157-
* [Spring Boot Gradle Plugin Reference Guide](https://docs.spring.io/spring-boot/docs/3.0.6/gradle-plugin/reference/html/)
158-
* [Spring Configuration Processor](https://docs.spring.io/spring-boot/docs/3.0.6/reference/htmlsingle/#appendix.configuration-metadata.annotation-processor)
159-
* [Spring Boot DevTools](https://docs.spring.io/spring-boot/docs/3.0.6/reference/htmlsingle/#using.devtools)
160-
* [Spring for GraphQL](https://docs.spring.io/spring-boot/docs/3.0.6/reference/html/web.html#web.graphql)
161-
* [Spring Data JPA](https://docs.spring.io/spring-boot/docs/3.0.6/reference/htmlsingle/#data.sql.jpa-and-spring-data)
162-
* [Validation](https://docs.spring.io/spring-boot/docs/3.0.6/reference/htmlsingle/#io.validation)
163-
* [Generating Sonarqube Token](https://docs.sonarqube.org/latest/user-guide/user-account/generating-and-using-tokens/)
164-
* [Adding secrets on Github](https://docs.github.com/en/actions/security-guides/encrypted-secrets)
1+
# Gamification Service
2+
3+
## Description
4+
5+
The Gamification Service primarily focuses on the following core responsibilities:
6+
- Calculating the Player Hexad Score if the results of the questionaire
7+
8+
## Environment variables
9+
### Relevant for deployment
10+
| Name | Description | Value in Dev Environment | Value in Prod Environment |
11+
|----------------------------|------------------------------------|--------------------------------------------------------|-----------------------------------------------------|
12+
| spring.datasource.url | PostgreSQL database URL | jdbc:postgresql://localhost:5432/gamification_service | jdbc:postgresql://localhost:1032/${database_name} |
13+
| spring.datasource.username | Database username | root | gits |
14+
| spring.datasource.password | Database password | root | *secret* |
15+
| DAPR_HTTP_PORT | Dapr HTTP Port | 1200 | 3500 |
16+
| server.port | Port on which the application runs | 1201 | 2001 |
17+
18+
### Other properties
19+
| Name | Description | Value in Dev Environment | Value in Prod Environment |
20+
|-----------------------------------------|-------------------------------------------|-----------------------------------------|-----------------------------------------|
21+
| spring.graphql.graphiql.enabled | Enable GraphiQL web interface for GraphQL | true | true |
22+
| spring.graphql.graphiql.path | Path for GraphiQL when enabled | /graphiql | /graphiql |
23+
| spring.profiles.active | Active Spring profile | dev | prod |
24+
| spring.jpa.properties.hibernate.dialect | Hibernate dialect for PostgreSQL | org.hibernate.dialect.PostgreSQLDialect | org.hibernate.dialect.PostgreSQLDialect |
25+
| spring.sql.init.mode | SQL initialization mode | always | always |
26+
| spring.jpa.show-sql | Show SQL queries in logs | true | false |
27+
| spring.sql.init.continue-on-error | Continue on SQL init error | true | true |
28+
| spring.jpa.hibernate.ddl-auto | Hibernate DDL auto strategy | create | update |
29+
| DAPR_GRPC_PORT | Dapr gRPC Port | - | 50001 |
30+
31+
## GraphQL API
32+
33+
The API documentation can be found in the wiki in the [API docs](api.md).
34+
35+
The API is available at `/graphql` and the GraphiQL interface is available at `/graphiql`.
36+
37+
## Get started
38+
A guide how to start development can be
39+
found in the [wiki](https://meitrex.readthedocs.io/en/latest/dev-manuals/backend/get-started.html).

0 commit comments

Comments
 (0)