A demo Spring Boot project that demonstrates how to build a secure, production-ready REST API.
- Framework: Spring Boot 4.x
- Language: Java 25
- Security: Spring Security & JWT (JSON Web Tokens)
- Database: PostgreSQL
- Migration: Flyway
- Containerization: Docker & Docker Compose
- Build Tool: Maven
- Full CRUD Operations: Create, Read, Update, and Delete notes.
- Secure Authentication: Email/Password login with stateless JWT token issuance.
- Database Versioning: Flyway ensures schema consistency across environments.
- Validation: Input validation using Jakarta Bean Validation (e.g., description length, non-empty fields).
- Containerized: One-command setup for both the app and the database.
- Docker and Docker Compose installed.
- Java 25 (if running locally without Docker).
- Clone the repository.
- Build the jar file:
./mvnw clean package -DskipTests
- Spin up the containers:
docker-compose up --build
The application will be available at http://localhost:8080.
- Register/Login: Send a POST request to
/api/auth/loginwith your credentials. - Receive Token: The server returns a JWT string.
- Authorize: Include the token in the
Authorizationheader for all protected endpoints:Authorization: Bearer <your_token_here>
| Method | Endpoint | Description |
|---|---|---|
POST |
/api/auth/login |
Authenticate user and return JWT |
| Method | Endpoint | Description |
|---|---|---|
GET |
/api/notes |
Get all notes for the authenticated user |
GET |
/api/notes/{id} |
Get a specific note by ID |
POST |
/api/notes |
Create a new note |
PUT |
/api/notes/{id} |
Update an existing note |
DELETE |
/api/notes/{id} |
Delete a note |
Migrations are located in src/main/resources/db/migration.
- V1__init.sql: Creates the
notesanduserstables. - V2__...: Subsequent schema changes. Flyway handles the execution of these scripts automatically on startup.
The following variables can be configured in the docker-compose.yml or application.properties:
SPRING_DATASOURCE_URL: JDBC connection string.JWT_SECRET: Secret key for signing tokens.POSTGRES_USER/POSTGRES_PASSWORD: Database credentials.