Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
a558b3c
refactor: replace manual getters/setters with Lombok annotations
TUT888 Oct 6, 2025
05e5772
refactor(db): change id type to int, change table names from plural t…
TUT888 Oct 14, 2025
7eedaa2
refactor: standardize model filename format
TUT888 Oct 17, 2025
77eba0d
:hammer: feat: Initialize GlobalExceptionHander with ApiResponse, Err…
pvdev1805 Oct 21, 2025
0d005cf
:hammer: feat: Update ErrorCode for the register feature in case user…
pvdev1805 Oct 21, 2025
a484d21
feat(note): add note creation and deletion
TUT888 Oct 22, 2025
e03092d
:wrench: chore(auth): Adjust the ErrorCode in case a user already exists
pvdev1805 Oct 23, 2025
76ca226
feat(note): add note update and fix indentation
TUT888 Oct 23, 2025
ccadf30
refactor(document): remove note entity, adding new fields to document…
TUT888 Oct 23, 2025
4c23fdb
feat(validation): apply validation groups to unify note DTO for creat…
TUT888 Oct 24, 2025
0b00ef7
Feature/auth register (#1)
pvdev1805 Oct 24, 2025
3a12cda
refactor(document): standardize api response
TUT888 Oct 24, 2025
20a2128
refactor(ai-quiz): unify request/response DTOs and improve service logic
TUT888 Oct 25, 2025
64a6cd6
feat(ai-quiz): use RestClient for sending request to inference provider
TUT888 Oct 26, 2025
0eb2ce7
Feature/auth login (#2)
pvdev1805 Oct 26, 2025
aa9b9a3
Feature/auth logout (#3)
pvdev1805 Oct 27, 2025
c459057
feat(ai-quiz): add quiz service with quiz creation and deletion
TUT888 Oct 28, 2025
c08cc94
fix(ai-quiz): fix unstable ai inference response
TUT888 Oct 29, 2025
6c91388
Merge pull request #4 from TUT888/feature/auth
TUT888 Oct 29, 2025
3f59993
Merge branch 'develop' of https://github.com/TUT888/SmartNotes into f…
TUT888 Oct 29, 2025
8da8968
feat(note): add proper error handling and ownership verification
TUT888 Oct 30, 2025
e50b94e
db: add dump-v3.sql with up-to-date database schema
TUT888 Oct 30, 2025
e16fee0
docs: update README with new note endpoints
TUT888 Oct 30, 2025
5cfeb40
Merge pull request #5 from TUT888/feature/notes-basic-crud
pvdev1805 Oct 30, 2025
69088a5
Merge branch 'develop' of https://github.com/TUT888/SmartNotes into f…
TUT888 Oct 31, 2025
6c69852
feat(ai-quiz): add AI properties configuration and error handling wit…
TUT888 Nov 2, 2025
c7d8500
feat(quiz): add quiz set entity to group quizzes
TUT888 Nov 4, 2025
1723494
feat(ai-quiz): add quiz generation with multiple notes
TUT888 Nov 4, 2025
a58768f
feat(quiz): handle unsorted quizzes using default set
TUT888 Nov 5, 2025
f5eb990
fix(quiz): resolve syntax error, minor business logic and dto issues
TUT888 Nov 6, 2025
2020b7a
feat(quiz): change authorization handling method, add json view level…
TUT888 Nov 6, 2025
62d8ed9
feat(quiz): expose crud operation endpoints for quizzes
TUT888 Nov 6, 2025
775a385
refactor(quiz): rename quiz upsert dto and separate quiz mapper
TUT888 Nov 7, 2025
461565a
docs(ai-quiz): add Javadoc comments and remove redundant code/comments
TUT888 Nov 7, 2025
de33a7f
refactor(ai-quiz): add default access level for quiz-related classes
TUT888 Nov 7, 2025
e9f854e
:hammer: feat(flashcard): Implement basic CRUD Operations on Flashcar…
pvdev1805 Nov 7, 2025
b5f588c
Merge pull request #8 from TUT888/feature/flashcard-basic-crud
TUT888 Nov 7, 2025
3e1311a
:wrench: feat(cors): Configure CORS with FrontEnd for local dev envir…
pvdev1805 Nov 7, 2025
ac6bd17
Merge branch 'develop' of https://github.com/TUT888/SmartNotes into f…
TUT888 Nov 7, 2025
6e5cddf
refactor(quiz): add origin type in quiz set response and minor bug fix
TUT888 Nov 7, 2025
6446761
refactor: minor bug fixes and replace post query ownership-validation…
TUT888 Nov 7, 2025
65f4ff9
:wrench: feat(cors): Configure profiles for development and productio…
pvdev1805 Nov 7, 2025
6f0693a
Merge pull request #9 from TUT888/feature/ai-quiz-generation
pvdev1805 Nov 7, 2025
2009d45
Merge pull request #10 from TUT888/feature/cors-config
TUT888 Nov 8, 2025
cf5f9cc
feat(quiz-attempt): add create, read one, read all and read answer fo…
TUT888 Nov 8, 2025
72c55a9
feat(quiz-attempt): add update functionality and calculate attempt re…
TUT888 Nov 8, 2025
b7b3852
feat(quiz-attempt): add delete quiz attempt endpoint
TUT888 Nov 8, 2025
f045d32
refactor(quiz-attempt): simplify update mapping with ignoreByDefault
TUT888 Nov 9, 2025
4c1c04d
refactor(ai-quiz-attempt): restructure json views for clarity and upd…
TUT888 Nov 9, 2025
73590d5
refactor(ai-quiz): ignore unknown fields in requests
TUT888 Nov 9, 2025
03efa34
feat(quiz): remove source document id mapping to restrict update for …
TUT888 Nov 9, 2025
9960cc9
docs(quiz-attempt): update Javadoc for attempt service
TUT888 Nov 9, 2025
36f7a54
Merge pull request #11 from TUT888/feature/quiz-attempt-basic-crud
pvdev1805 Nov 9, 2025
3d0d024
feat(note): add get all notes and date time format inn response
TUT888 Nov 10, 2025
68633b1
fix(note): aresolve long text warning issue usingcolumn definition f…
TUT888 Nov 10, 2025
c00e4b5
refactor(note): change update note endpoint from PUT to PATCH
TUT888 Nov 10, 2025
ca625d2
feat(quiz-set): add default set request
TUT888 Nov 10, 2025
aa03180
Merge pull request #12 from TUT888/feature/notes-basic-crud
pvdev1805 Nov 10, 2025
2faefdc
test(note): add unit test for note service
TUT888 Dec 2, 2025
3d6a7e4
test(note): add testing for note repository and resolve potential que…
TUT888 Dec 8, 2025
5efb580
test(note): reorganise test display, utilising tree structure
TUT888 Dec 9, 2025
c079413
test(note): add integration test for note controller with testcontainers
TUT888 Dec 9, 2025
32b6ac8
test(note): replace Testcontainers and Containers annotations with Be…
TUT888 Dec 9, 2025
12f91ee
test(note): reorganise test structure
TUT888 Dec 9, 2025
70ae97e
test(note): add comments and documentation for existing tests
TUT888 Dec 10, 2025
784b922
docs: update README
TUT888 Dec 10, 2025
56f9b41
test(note): add junit tag for feature-based testing
TUT888 Dec 16, 2025
2b47d24
feature(workflow): add auto test run on note feature branch
TUT888 Dec 16, 2025
7bd8d78
feature(workflow): fix missing checkout repository
TUT888 Dec 16, 2025
6c3ec3c
feature(workflow): add workflow for develop branch
TUT888 Dec 16, 2025
270887a
feature(workflow): fix ci develop requiring successful tests before p…
TUT888 Dec 16, 2025
4907df5
feat(workflow): change trigger condition of feature test workflow
TUT888 Dec 17, 2025
18dfe3e
docs: update main README with CI/CD info
TUT888 Dec 17, 2025
d15340f
Merge pull request #13 from TUT888/feature/notes-basic-crud
TUT888 Dec 30, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .github/scripts/detect-branch-name.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

# Exit immediately if any command fails
set -e

echo "Detecting Branch Name..."

if [[ "$BRANCH_NAME" == *"note"* ]]; then
echo "test_tag=note" >> $GITHUB_OUTPUT
fi
34 changes: 34 additions & 0 deletions .github/workflows/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# CI/CD workflows

## Convention and Standard
### Naming
- Each workflow should have a unique name and filename.
- Name the **main** workflows as `workflow-filename.yml`
- Name the **reusable** workflows as `_reusable-workflow.yml` (with `_` prefix)
- A workflow’s name should **not** be changed once it has been committed to the repository, as this may cause history mismatches and unexpected errors.
Therefore, it is recommended to consider changes carefully before modifying existing workflows.

### Directory structure
- `.github/workflows`: All **runnable workflows** must be placed in this directory, as required by the official GitHub Actions documentation. Otherwise, they may not execute correctly.
- `.github/scripts`: Place **reusable or lengthy bash scripts** in this directory so they can be referenced and reused in workflows.

### Workflows (Planned)
- Changes on `feature` branch: Run unit tests, linting, security check, etc
- PR on `develop` branch (for integration/staging):
- Unit + Integration tests (API, DB, UI, etc)
- Build and push staging images
- Deploy to staging environment and test (optional)
- PR on `main` branch (for production): Final build verification
- Completed merge on `main` branch (for production):
- Build and push production-ready images with version tags
- Deploy to production environment

## Reference
### GitHub Actions Workflows
- Official documentation: [GitHub Actions Docs - How To](https://docs.github.com/en/actions/how-tos)
- Advanced customization: [Mert Mengü - Guide to GitHub Actions for Advanced CI/CD Workflows](https://medium.com/@mertmengu/guide-to-github-actions-for-advanced-ci-cd-workflows-1e494271ac22)
- GitHub Actions with Spring Boot: [Pudding Entertainment - GitHub Actions: Spring Boot Application Build and Deployment](https://pudding-entertainment.medium.com/github-actions-spring-boot-application-build-and-deployment-c52a2a233cb9)

### Branching Strategy
- Different branching strategies, including using develop and main branch: [Devtron - Branching Strategy for CI/CD](https://devtron.ai/blog/best-branching-strategy-for-ci-cd/)
- Run tests on feature and master branch: [TeamCity - Branching Strategy for CI/CD](https://www.jetbrains.com/teamcity/ci-cd-guide/concepts/branching-strategy/)
47 changes: 47 additions & 0 deletions .github/workflows/_reusable-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Reusable Test Workflow

on:
# Workflow only runs when being called by others
workflow_call:
inputs:
test-level: # select between [unit, integration, all]
required: true
type: string
test-tag: # not required, but will automatically run all tests if left empty
required: false
type: string

jobs:
build-and-test:
name: Build and Run Tests
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup Java JDK 17
uses: actions/setup-java@v3
with:
distribution: 'corretto'
java-version: 17

- name: Build with Maven
run: mvn clean install

- name: Run All Unit Tests
run: |
if [ -n "${{ inputs.test-tag }}" ]; then
mvn test -Punit-test -Dgroups="${{ inputs.test-tag }}"
else
mvn test -Punit-test
fi

- name: Run All Integration Tests
if: inputs.test-level != 'unit'
run: |
if [ -n "${{ inputs.test-tag }}" ]; then
mvn verify -Pintegration-test -Dgroups="${{ inputs.test-tag }}"
else
mvn verify -Pintegration-test
fi
30 changes: 30 additions & 0 deletions .github/workflows/ci-cd-develop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: CI/CD on Develop Branch

on:
# Workflow runs whenever a new PR to develop is created
pull_request:
branches:
- develop

jobs:
# Build and run test based on the branch detection result
build-and-test:
name: Build and Run All Tests
uses: ./.github/workflows/_reusable-test.yml
secrets: inherit
with:
test-level: 'all'

# Build and push image (placeholder only since the app is not completed yet)
build-images:
name: Build Images and Deploy to Docker Hub
needs: build-and-test
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Build and push
run: |
echo "Building images..."
echo "Published to Docker Hub!"
39 changes: 39 additions & 0 deletions .github/workflows/feature-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Feature Branch Test

on:
# Workflow runs whenever the source code changes on the target feature branch
push:
branches:
- "feature/**"
- "fix/**"
paths:
- "src/**"

jobs:
# Detect feature changes based on branch name
detect-changes:
name: Detect Feature Changes
runs-on: ubuntu-latest
outputs:
test_tag: ${{ steps.detect.outputs.test_tag }}
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Detect Changes
id: detect
env:
BRANCH_NAME: ${{ github.ref_name }}
run: |
chmod +x .github/scripts/detect-branch-name.sh
./.github/scripts/detect-branch-name.sh

# Build and run test based on the branch detection result
build-and-test:
name: Build and Run Tests
needs: detect-changes
uses: ./.github/workflows/_reusable-test.yml
secrets: inherit
with:
test-level: 'unit'
test-tag: ${{ needs.detect-changes.outputs.test_tag }}
165 changes: 155 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,88 @@
# SmartNotes Backend
> **Active development** happens on [develop](https://github.com/TUT888/SmartNotes/tree/develop) branch.
> The [main](https://github.com/TUT888/SmartNotes/tree/main) branch contains **stable release code**.

Personal project for smart note taking application
Backend service for **SmartNotes**, a personal project that enables smart note-taking with AI integration to
help individuals have a better experience in note-taking, organizing, and revising knowledge.

**SmartNotes Frontend Repository:** [https://github.com/pvdev1805/SmartNotes](https://github.com/pvdev1805/SmartNotes)

## Table of Contents

- [Project Info](#project-info)
- [Tech Stack](#tech-stack)
- [Branching Strategy with CI/CD](#branching-strategy-with-cicd)
- [Supported Features](#supported-features)
- [User Authentication](#1-user-authentication)
- [AI-Powered Quiz Generation](#2-ai-powered-quiz-generation)
- [CRUD Management Features](#3-crud-management-features)
- [Project Setup](#project-setup)
- [Prerequisites](#prerequisites)
- [HuggingFace API](#huggingface-api)
- [Environment Variables](#environment-variables)
- [How to Test](#how-to-test)
- [Test Commands](#test-commands-windows)
- [Test Structure](#test-structure)
- [Test Notes](#test-notes)
- [Contributors](#contributors)

## Project Info
### Tech Stack
- **Java 17** + **Spring Boot 3.5.5** for backend services
- **Maven** for build and dependency management
- **HuggingFace API** for AI quiz generation
- **MySQL** for database and persistence
- **Redis** for caching and session management
- **Docker** for containerization
- **Cloud and Deployment**: AWS (planned)
- **CI/CD**: GitHub Actions

### Branching Strategy with CI/CD
> For detail documentation about CI/CD process, please refer to another [dedicated README](./.github/workflows/README.md)

- **main**: stable, production‑ready code
- **develop**: integration branch with the latest completed features
- **feature/***: branches for individual features or fixes, merged into `develop` via pull requests

[Back to top](#smartnotes-backend)

## Supported Features
| Module | Method | API | Description |
| -------- | -------- | -------- | ------- |
| Document | GET | `/api/document/all` | List all available documents |
| Note | GET | `/api/note/{id}` | Get note content using its id |
| | POST | `/api/note/create` | Create new note |
| AI | GET | `/api/ai/generateQuiz/sample` | Get a sample quiz from sample response, this API does not require API TOKEN |
| | GET | `/api/ai/generateQuiz/{noteId}` | Generate relevant quizzes based on 1 note, this feature **requires HuggingFace API TOKEN** to run |
### 1. User Authentication
- Register, login, logout, and refresh tokens
- JWT-based secure authentication
- Secure access to user profile information

### 2. AI-Powered Quiz Generation
- Generate quizzes from notes using HuggingFace models
- Sample endpoint for testing without authentication

### 3. CRUD Management Features
**Document Management (CRUD)**: All types of documents including notes, flashcards, and quizzes:
- List all documents by user, or delete specific document

**Note Management**:
- Create, update, retrieve, and delete notes

**Flashcard & Flashcard Sets Management**:
- Create, update, retrieve, and delete flashcards
- Organize flashcards into sets

**Quiz & Quiz Sets Management**:
- Create, update, retrieve, and delete quizzes
- Organize quizzes into sets
- Track quiz attempts and scores

[Back to top](#smartnotes-backend)

## Project Setup
### Prerequisites
- **Java 17** or higher
- **MySQL**
- **Docker**
- For integration tests with Testcontainers
- For Redis (optional for local development on Windows)
- **HuggingFace Account** (for AI features)

### HuggingFace API
- Create a HuggingFace account
- Create Access Token:
Expand All @@ -25,6 +96,7 @@ Personal project for smart note taking application
### Environment variables
In project root directory, create `.env` file and paste your **ACCESS TOKEN** here
```
# AI INFERENCE
API_TOKEN=<YOUR-TOKEN-HERE>
API_URL=<YOUR-INFERENCE-PROVIDER>
MODEL=<YOUR-SELECTED-MODEL>
Expand All @@ -33,10 +105,83 @@ AI_API_USER_ROLE=user
AI_API_SYSTEM_ROLE=system
AI_API_TEMPERATURE=<YOUR-CUSTOM-VALUE>
AI_API_TOP_P=<YOUR-CUSTOM-VALUE>

# Database
DB_PORT=<YOUR-DATABASE-PORT>
DB_NAME=<YOUR-DATABASE-NAME>
DB_USERNAME=<YOUR-DATABASE-DB_USERNAME>
DB_PASSWORD=<YOUR-DATABASE-DB_PASSWORD>
```

# JWT Config
JWT_KEYSTORE_PASSWORD=<YOUR-KEYSTORE>
JWT_KEY_PASSWORD=<YOUR-PASSWORD>

# Redis Config
REDIS_HOST=<YOUR-HOST>
REDIS_PORT=<YOUR-PORT>
```

[Back to top](#smartnotes-backend)

## How to test
### Test commands (Windows)
Run all tests
```bash
# Run all tests (unit + integration)
./mvnw.cmd verify
```

Run specific type of test
```bash
# Run specific test file
./mvnw.cmd test -Dtest=NoteServiceTest

# Run all unit tests (service tests with mocks)
./mvnw.cmd test -Punit-test

# Run all integration tests (repository + controller with containers)
./mvnw.cmd verify -Pintegration-test
```

Run specific test group with tag, use **boolean expression** for tags combination
```bash
# Run test with "note" tag
./mvnw.cmd test -Dgroups="note"

# Run tests with "note" or "document" tags
./mvnw.cmd test -Dgroups="note | document"

# Combine with test type: run all unit tests with "note" tag
./mvnw.cmd test -Punit-test -Dgroups="note | document"
```

### Test Structure
```
src/test/java/
├── unit/ # Fast tests (Surefire)
│ └── service/ # Service unit tests with mocked dependencies
└── integration/ # Slower tests (Failsafe)
├── repository/ # Repository tests with H2
└── controller/ # Full-stack tests with MySQL + Redis containers
```

### Test Notes
- **Unit tests** run with Surefire and use mocked dependencies
- **Integration tests** run with Failsafe and use Testcontainers
- Docker must be running for integration tests (uses MySQL and Redis containers)
- First integration test run may take longer (downloads container images)

[Back to top](#smartnotes-backend)

## Contributors
**Project Maintainers:** This project (both frontend and backend) is developed and maintained by:

- **Alice Tat** ([@TUT888](https://github.com/TUT888))
- **Phu Vo** ([@pvdev1805](https://github.com/pvdev1805))

**Project Repositories:**
- Backend: [SmartNotes Backend](https://github.com/TUT888/SmartNotes)
- Frontend: [SmartNotes Frontend](https://github.com/pvdev1805/SmartNotes)

[Back to top](#smartnotes-backend)
Loading