A Spring Boot RESTful API for a personal note-taking application with JWT authentication, built with Kotlin, Spring Data JPA, PostgreSQL, Flyway, Spring Security, and JJWT.
-
Authentication & Authorization
- JWT-based authentication with secure token generation
- User registration and login
- Token-based API access control
-
Notes Management
- Create, read, update, and delete personal notes
- Pin important notes
- Filter notes by category
- Full audit trail (createdAt, updatedAt)
-
Categories
- Organize notes with custom categories
- Color-coded categories for visual organization
- CRUD operations for category management
-
Security
- Spring Security with JWT tokens
- Password encryption with BCrypt
- User-scoped data isolation (users can only access their own data)
my-note/
├── src/main/kotlin/com/yoesuv/mynote/
│ ├── config/ # Configuration classes (Security, JPA, JWT)
│ ├── controller/ # REST API controllers
│ ├── domain/ # JPA entities
│ ├── dto/ # Data Transfer Objects
│ │ ├── auth/ # Auth request/response DTOs
│ │ ├── category/ # Category request/response DTOs
│ │ └── note/ # Note request/response DTOs
│ ├── exception/ # Exception handling
│ ├── repository/ # Spring Data repositories
│ ├── security/ # JWT service and filters
│ └── service/ # Business logic layer
├── src/main/resources/
│ └── db/migration/ # Flyway database migrations
└── docs/ # API documentation
- Java 17 or higher
- PostgreSQL 12+
- Gradle (or use the included wrapper)
-
Clone the repository
git clone <repository-url> cd my-note
-
Create database
Create a PostgreSQL database (tables will be auto-created on first run):
CREATE DATABASE mynotes;
Or using psql:
psql -U postgres -c "CREATE DATABASE mynotes;" -
Configure database connection
Update
src/main/resources/application.properties:spring.datasource.url=jdbc:postgresql://localhost:5432/mynotes spring.datasource.username=your_username spring.datasource.password=your_password
-
Configure JWT (optional)
Update JWT settings in
application.properties:jwt.secret=your-256-bit-secret-key-here-minimum-32-characters jwt.expiration=86400000
-
Run the application
./gradlew bootRun
Or build and run the JAR:
./gradlew build java -jar build/libs/my-note-0.0.1-SNAPSHOT.jar
The API will be available at http://localhost:8080
| Method | Endpoint | Description |
|---|---|---|
| POST | /api/auth/register |
Register a new user |
| POST | /api/auth/login |
Login and get JWT token |
| POST | /api/auth/logout |
Logout (client-side token removal) |
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/notes |
Get all notes (optionally filter by ?categoryId={id}) |
| GET | /api/notes/{id} |
Get a specific note |
| POST | /api/notes |
Create a new note |
| PUT | /api/notes/{id} |
Update an existing note |
| DELETE | /api/notes/{id} |
Delete a note |
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/categories |
Get all categories |
| GET | /api/categories/{id} |
Get a specific category |
| POST | /api/categories |
Create a new category |
| PUT | /api/categories/{id} |
Update a category |
| DELETE | /api/categories/{id} |
Delete a category |
All endpoints except /api/auth/** require a valid JWT token:
Authorization: Bearer <your-jwt-token>
Register:
curl -X POST http://localhost:8080/api/auth/register \
-H "Content-Type: application/json" \
-d '{
"username": "johndoe",
"email": "john@example.com",
"password": "password123"
}'Login:
curl -X POST http://localhost:8080/api/auth/login \
-H "Content-Type: application/json" \
-d '{
"username": "johndoe",
"password": "password123"
}'Create a Note:
curl -X POST http://localhost:8080/api/notes \
-H "Authorization: Bearer <token>" \
-H "Content-Type: application/json" \
-d '{
"title": "My First Note",
"content": "This is the content of my note",
"isPinned": true
}'For complete API documentation, see the /docs directory:
The application uses Flyway for database migrations. Tables are automatically created:
users- User accountscategories- Note categoriesnotes- User notes
./gradlew test./gradlew bootJarThe production JAR will be in build/libs/.
This project is open source and available under the MIT License.
Note: This is a backend API. For a complete application, pair it with a frontend client (web, mobile, or desktop).