This project is a backend for a CRUD Notes application, developed using Kotlin and Spring Boot. It follows a standard MVC architecture, featuring controllers, services, repositories, and models. The application is secured with JWT-based authentication and user session management, and uses MongoDB as its database.
- User registration with email/password validation
- Secure login returning JWT tokens
- Refresh token mechanism for session maintenance
- Password hashing for security
- JWT-based authentication and session management
- CRUD operations for notes
- Modular MVC structure
- Global validation handling
- Ready for integration with databases and security modules
POST /auth/register
— Register a new user (with email/password validation)POST /auth/login
— Login and receive JWT access and refresh tokensPOST /auth/refresh
— Refresh access token using a valid refresh token
GET /notes
— Retrieve all notes for the authenticated userPOST /notes
— Create a new noteDELETE /notes/{id}
— Delete a note by ID
- Access Token: Valid for 15 minutes
- Refresh Token: Valid for 15 days
If the refresh token expires, MongoDB will automatically generate and update the refresh token. Access tokens can be regenerated using a valid refresh token.
├── build.gradle.kts # Gradle build script (Kotlin DSL)
├── src/
│ ├── main/
│ │ ├── kotlin/ # Application source code
│ │ │ └── com/tandon_ksb/backend_kotlin_springboot/
│ │ │ ├── controller/
│ │ │ ├── database/
│ │ │ ├── security/
│ │ │ ├── BackendKotlinSpringbootApplication.kt
│ │ │ └── GlobalValidationHandler.kt
│ │ └── resources/
│ │ └── application.properties
│ └── test/
│ └── kotlin/ # Test source code
│ └── com/tandon_ksb/backend_kotlin_springboot/
│ └── BackendKotlinSpringbootApplicationTests.kt
├── gradle/ # Gradle wrapper files
├── build/ # Build output (generated)
└── ...
- JDK 17+
- Gradle (or use the included wrapper)
- MongoDB Atlas or local MongoDB instance
Create a .env
file or set the following environment variables:
MONGODB_CONNECTION_STRING=mongodb+srv://<username>:<pswd>@<project_name>.2fqeq6f.mongodb.net/notes?retryWrites=true&w=majority&appName=tandonExpCKO&tls=true&socketTimeoutMS=6000000&connectTimeoutMS=3000000&tlsAllowInvalidCertificates=true&tlsAllowInvalidHostnames=true
JWT_SECRET_BASE64=b3F5ZHV0ZXI3ODIzeXI4OTM2N3J0MjM4ZGVyeTg5MjN5ZTc4MmY=
- Replace
<uname>
and<pswd>
with your MongoDB Atlas credentials.
./gradlew build
./gradlew bootRun
The application will start on http://localhost:8080 by default.
Edit src/main/resources/application.properties
to configure application settings.
You can test the API endpoints using Postman. Import the API collection and use the provided endpoints for authentication and notes management.
Run tests with:
./gradlew test
This project is licensed under the MIT License.