Doctracer is a Spring Boot application written in Kotlin that provides a RESTful API for managing and analyzing document measurements, materials, and spectral data. This application was made in the scope of an engineering thesis. Frontend part available at doc-tracer-frontend.
Project includes:
- User authentication with JWT tokens (including roles and permissions).
- Database entities for devices, covered materials, covering materials, measurements, and samples.
- A seeder to populate mock data (only on the
devprofile) for quick testing. - REST endpoints for creating, reading, updating, and deleting various domain objects.
- Key Features
- Technology Stack
- Project Structure
- Installation and Running
- Database Seeding
- Authentication and Security
- Endpoints Overview
- User Authentication & Authorization:
- JWT-based login and role-based method security.
- Roles:
ADMIN,EDITOR,VIEWER.
- Measurement & Spectral Data Management:
- Entities for different types of materials (
CoveredMaterial,CoveringMaterial),Measurement,Sample, etc. - Automatic JSONB storage for spectral data in PostgreSQL.
- Entities for different types of materials (
- RESTful Endpoints:
- Comprehensive set of controllers to manage users, roles, devices, measurements, and samples.
- Kotlin (JDK 17+ recommended).
- Spring Boot (REST API, Security).
- Spring Data JPA (Persistence with repositories).
- Hibernate (ORM).
- JWT (JSON Web Token) for authentication/authorization.
- PostgreSQL (Recommended database, due to JSONB usage).
Note: If you use a different database, ensure you adjust any Postgres-specific features (like JSONB columns).
- Java 17+ (Spring Boot requires Java 17 or later in newer versions).
- Maven or Gradle (depending on your project setup – typically you will have either
pom.xmlfor Maven orbuild.gradle.ktsfor Gradle). - A PostgreSQL database instance (or any database supported by Spring Data JPA).
- If using PostgreSQL, ensure the
jsonbcolumn types are supported and configured.
- If using PostgreSQL, ensure the
-
Configure the application:
- Set up your application properties (in
application.properties) for your database connection and JWT secret.
- Set up your application properties (in
-
Run the application:
- Using Maven:
mvn spring-boot:run
- Using Gradle:
./gradlew bootRun
- Using Maven:
-
Check the logs to confirm the application started successfully on the default port
8080. -
Test the API by accessing, for instance,
http://localhost:8080/auth/login.
dev: Enables theDatabaseSeederto insert test data (admin user, sample measurements, etc.).prod: Production-like environment (no automatic seeding).
To activate a profile, use the --spring.profiles.active=dev (or =prod) flag:
java -jar build/libs/doctracer.jar --spring.profiles.active=devWhen you run the application with the dev profile, the DatabaseSeeder class inserts:
- Default Roles:
ADMIN,EDITOR,VIEWER - Default Users:
- Username:
admin/ Password:password1 - Username:
user1/ Password:password1 - Username:
user2/ Password:password2
- Username:
- Sample devices, covered/covering materials, measurements, and sample spectral data.
This data is intended to help you quickly test and explore the system.
- The application uses JWT-based security.
- Endpoints require appropriate roles. For example:
@PreAuthorize("hasRole('ADMIN')")on Admin endpoints.@PreAuthorize("hasRole('EDITOR')")on create/update endpoints.@PreAuthorize("hasRole('VIEWER')")to read endpoints.
- Obtain a JWT by calling the
/auth/loginendpoint with valid credentials. Then includeAuthorization: Bearer <token>in subsequent requests.
Note: All secured endpoints require an HTTP header
Authorization: Bearer <jwt>after logging in.
| Method | Endpoint | Description | Public/Secured |
|---|---|---|---|
| POST | /auth/register |
Register a new user | Public |
| POST | /auth/login |
Login with username and password | Public |
| PUT | /auth/change-password |
Change the password for the currently logged-in user | Secured (any role) |
| Method | Endpoint | Description | Required Role |
|---|---|---|---|
| GET | /admin/users |
Get all users | ADMIN |
| GET | /admin/users/{id} |
Get user by ID | ADMIN |
| PUT | /admin/users/{id}/activate |
Activate a user | ADMIN |
| PUT | /admin/users/{id}/deactivate |
Deactivate a user | ADMIN |
| PUT | /admin/users/{userId}/roles/{roleName} |
Assign a role to a user | ADMIN |
| DELETE | /admin/users/{userId}/roles/{roleName} |
Remove a role from a user | ADMIN |
| PUT | /admin/users/bulk-update |
Bulk update users | ADMIN |
Covered Materials (/covered-materials):
| Method | Endpoint | Description | Required Role |
|---|---|---|---|
| GET | /covered-materials |
List all covered materials | VIEWER |
| GET | /covered-materials/{id} |
Get covered material by ID | VIEWER |
| POST | /covered-materials |
Create covered material | EDITOR |
| PUT | /covered-materials/{id} |
Update covered material | EDITOR |
| DELETE | /covered-materials/{id} |
Delete covered material | EDITOR |
Covering Materials (/covering-materials):
| Method | Endpoint | Description | Required Role |
|---|---|---|---|
| GET | /covering-materials |
List all covering materials | VIEWER |
| GET | /covering-materials/{id} |
Get covering material by ID | VIEWER |
| POST | /covering-materials |
Create covering material | EDITOR |
| PUT | /covering-materials/{id} |
Update covering material | EDITOR |
| DELETE | /covering-materials/{id} |
Delete covering material | EDITOR |
| Method | Endpoint | Description | Required Role |
|---|---|---|---|
| GET | /devices |
List all devices | VIEWER |
| GET | /devices/{id} |
Get device details by ID | VIEWER |
| Method | Endpoint | Description | Required Role |
|---|---|---|---|
| GET | /measurements |
List all measurements | VIEWER |
| GET | /measurements/{id} |
Get measurement by ID | VIEWER |
| GET | /measurements/{id}/samples |
List all samples for a specific measurement | VIEWER |
| POST | /measurements |
Create a new measurement | EDITOR |
| PUT | /measurements/{id} |
Update an existing measurement | EDITOR |
| DELETE | /measurements/{id} |
Delete a measurement (and associated conditions) | EDITOR |
| Method | Endpoint | Description | Required Role |
|---|---|---|---|
| GET | /samples |
List all samples (with limited data) | VIEWER |
| GET | /samples/{id} |
Get a sample by ID (detailed) | VIEWER |
| POST | /samples |
Create a new sample | EDITOR |
| PUT | /samples/{id} |
Update a sample | EDITOR |
| DELETE | /samples/{id} |
Delete a sample | EDITOR |