A Spring Boot REST API for managing daily notes with MongoDB storage. The project is fully Dockerized, includes Swagger (OpenAPI) documentation and Spring Boot Actuator for monitoring.
- Features
- Tech Stack
- Project Structure
- Quick Start with Docker Compose
- Running Without Docker
- API Documentation (Swagger)
- API Testing
- REST API Endpoints
- Tag Filtering
- MongoDB Verification
- Stopping the Application
- Troubleshooting
- Testing
- Support
- Production-Ready Highlights
- CRUD operations for notes
- Tag-based filtering (BUSINESS, PERSONAL, IMPORTANT)
- Word statistics for each note
- Pagination and sorting (newest first)
- Input validation
- Health checks with Actuator
- Interactive API documentation with Swagger
- Java 17 (for local development)
- Spring Boot
- Spring Data MongoDB
- Spring Boot Actuator
- Swagger / OpenAPI
- MongoDB
- Maven (for local development only)
- Docker and Docker Compose
- Docker Desktop installed and running
notesapp/
βββ src/main/java
β βββ com.example.notes
β βββ controller
β βββ service
β βββ repository
β βββ model
βββ src/main/resources
β βββ application.properties
βββ Dockerfile
βββ docker-compose.yml
βββ pom.xml
βββ README.md- Docker
- Docker Compose
- Docker Desktop Running
- Build and run the application:
docker-compose up --build
- Wait for services to start (takes 1-2 minutes)
- MongoDB will start on port 27017
- Spring Boot app will start on port 8080
-
Verify services are running:
docker ps
You should see both notesapp and mongodb containers.
-
Test the application:
curl http://localhost:8080/actuator/health
Expected response:
{ "status": "UP" }
-
Build the application JAR:
mvn clean package
-
Build Docker image:
docker build -t notes-app . -
Start MongoDB:
docker run -d --name mongodb -p 27017:27017 -e MONGO_INITDB_DATABASE=notesdb mongo:latest
-
Start the application:
docker run -d --name notes-app -p 8080:8080 --link mongodb -e SPRING_DATA_MONGODB_URI=mongodb://mongodb:27017/notesdb notes-app
- Java 17
- Maven
- MongoDB installed locally
-
Start MongoDB locally:
mongod
-
Run the application:
mvn spring-boot:run
-
Application will be available at: http://localhost:8080
Swagger UI is available at:
π http://localhost:8080/swagger-ui/index.html
Use Swagger to:
- Explore all endpoints
- Test requests
- Validate request/response models
Once running, test the API endpoints:
-
Create a Note
curl -X POST http://localhost:8080/api/notes \ -H "Content-Type: application/json" \ -d '{ "title": "Meeting Notes", "text": "Discussed project requirements and timelines", "tags": ["BUSINESS", "IMPORTANT"] }'
-
Get All Notes (Paginated)
curl "http://localhost:8080/api/notes?page=0&size=10" -
Get Notes Filtered by Tags
curl "http://localhost:8080/api/notes?tags=BUSINESS,PERSONAL&page=0&size=10" -
Get Specific Note
curl http://localhost:8080/api/notes/{note-id} -
Get Word Statistics
curl http://localhost:8080/api/notes/{note-id}/statistics -
Update Note
curl -X PUT http://localhost:8080/api/notes/{note-id} \ -H "Content-Type: application/json" \ -d '{ "title": "Updated Title", "text": "Updated content", "tags": ["PERSONAL"] }' -
Delete Note
curl -X DELETE http://localhost:8080/api/notes/{note-id}
| Method | Endpoint | Description |
|---|---|---|
| POST | /api/notes | Create a new note |
| GET | /api/notes | Get all notes (paginated, filtered by tags) |
| GET | /api/notes/{id} | Get specific note details |
| GET | /api/notes/{id}/statistics | Get word statistics for a note |
| PUT | /api/notes/{id} | Update a note |
| DELETE | /api/notes/{id} | Delete a note |
| GET | /actuator/health | Application health check |
Available tags: BUSINESS, PERSONAL, IMPORTANT
Examples:
- ?tags=BUSINESS - Notes with BUSINESS tag
- ?tags=BUSINESS,PERSONAL - Notes with BUSINESS OR PERSONAL tags
- No tags parameter - All notes
Check stored data inside MongoDB container:
docker exec -it mongodb mongosh notesdb --eval "db.notes.find().pretty()"Stop containers:
docker-compose downStop containers and remove volumes:
docker-compose down -v- Check if Docker Desktop is running
- Check if ports 8080 and 27017 are available
- View logs: docker-compose logs notes-app
- Check if MongoDB container is running: docker ps
- Test MongoDB: docker exec -it mongodb mongosh --eval "db.adminCommand('ping')"
- View MongoDB logs: docker-compose logs mongodb
- Clean build: mvn clean package
- Rebuild containers: docker-compose down && docker-compose up --build
- Stopping the Application
Run the test suite:
mvn test Run specific test:
mvn test -Dtest=NoteControllerTest If you encounter issues:
-
Check the logs: docker-compose logs
-
Verify Docker is running: docker version
-
Ensure ports are not in use
-
Check application health: curl http://localhost:8080/actuator/health
Key Files That Fulfill Requirements 1. **`docker-compose.yml`** - Docker Compose setup 2. **`Dockerfile`** - Application containerization 3. **`RUNNING_INSTRUCTIONS.md`** - Complete running steps 4. **`NoteController.java`** - RESTful API endpoints 5. **`Note.java`** - MongoDB document model 6. **`NoteRepository.java`** - Spring Data MongoDB repository 7. **`application.properties`** - Spring Boot configuration
After running docker-compose up --build, verify everything works:
# Check containers
docker pscurl http://localhost:8080/actuator/health
curl -X POST http://localhost:8080/api/notes
-H "Content-Type: application/json"
-d '{"title": "Test", "text": "Hello world", "tags": ["PERSONAL"]}'
docker exec -it mongodb mongosh notesdb --eval "db.notes.find()"- β Docker Compose orchestration
- β Health checks via Actuator
- β Swagger API documentation
- β MongoDB persistence
- β Clean REST architecture
- β Ready for frontend integration