Skip to content

Spring Boot REST API for folder-based notes with reusable tags, clean service-layer logic, and centralized exception handling using Spring Data JPA and H2.

Notifications You must be signed in to change notification settings

CharanMunur/SpringBoot-Notes-Api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SpringBoot-Notes-Api — Backend

A RESTful backend for managing folder-based notes with reusable tags, built with Spring Boot and Spring Data JPA.

Overview

This backend provides a cleanly designed REST API for folder-based notes with reusable tags, featuring:

  • Full CRUD (Create, Read, Update, Delete)
  • Partial updates (PATCH) and full replacement (PUT)
  • Clear, conventional HTTP status codes
  • Centralized error handling
  • Auto-managed createdAt timestamps
  • In-memory H2 database for easy development

Tech Stack

  • Java 17+
  • Spring Boot
  • Spring Web
  • Spring Data JPA (declarative transactions with @Transactional)
  • H2 Database (dev)
  • Jackson (JSON)

Design choices:

  • REST semantics (PUT vs PATCH)
  • Service-layer invariants (validation + business rules)

Project Structure

src/main/java/com/practice/notes/
NotesApplication.java
├── controller/
│   └── NoteController.java
│   └── FolderController.java
├── exceptions/
│   ├── BadRequestException.java
│   ├── NotFoundException.java
│   └── GlobalExceptionHandler.java
├── model/
│   └── Note.java
│   └── Folder.java
│   └── Tag.java
├── repository/
│   └── NoteRepository.java
│   └── FolderRepository.java
│   └── TagRepository.java
└── service/
    └── NoteService.java
    └── FolderService.java
src/main/resources/
application.properties

Data Model

Note

Field Description
id Auto-generated primary key
title Required
content Required
folder Each note belongs to a folder
tags Many-to-many tags (stored separately)
createdAt Automatically set on creation
pinned Pin state

Folder

Field Description
id Auto-generated primary key
name Required

Tag

Field Description
id Auto-generated primary key
name Unique tag name

Tag behavior

  • Tags are created implicitly when notes are created or updated.
  • Tags do not have an independent lifecycle or controller.
  • Tag resolution is centralized in NoteService.

API Endpoints

NoteController

Method Endpoint Description
POST /folders/{folderId}/notes Create a note in a folder
GET /notes/{id} Get note by ID
GET /folders/{folderId}/notes Get notes by folder
PATCH /notes/{id} Partial update
PUT /notes/{id} Full replace
PATCH /notes/{id}/pin Pin a note
DELETE /notes/{id} Delete a note

Notes:

  • Folder ID comes from the URL path, not the request body.
  • Controllers stay thin; service layer enforces invariants.

FolderController

Method Endpoint Description
POST /folders Create a folder
GET /folders Get all folders
DELETE /folders/{id} Delete a folder

Error Handling

The API returns errors in a consistent format using custom exceptions and a global handler. Errors are thrown from the service layer so controllers remain lightweight.

Example: 404 — Not Found

{
  "error": "NOT_FOUND",
  "message": "Note not found"
}

Example: 400 — Bad Request

{
  "error": "BAD_REQUEST",
  "message": "Title is required"
}

Database

  • Uses H2 in-memory database for development
  • Schema auto-generated via JPA
  • Data resets on app restart

Running the Application

  1. Clone the repository
    git clone https://github.com/YOUR_USERNAME/SpringBoot-Notes-Api.git

  2. Run the application

    mvn spring-boot:run
    
  3. Access the API:
    http://localhost:8080


Why This Project Matters

  • Models real relationships (folders, notes, tags) instead of flat CRUD.
  • Enforces rules in services, not controllers.
  • Avoids unnecessary controllers (tags are managed implicitly).
  • Keeps API intent clear with REST semantics.

About

Spring Boot REST API for folder-based notes with reusable tags, clean service-layer logic, and centralized exception handling using Spring Data JPA and H2.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages