A secure and scalable RESTful API built using Spring Boot and Spring Security. Implements JWT-based authentication, role-based access control (Admin/User), and salary management functionalities. Designed with clean architecture and modular service-repository layers, making it ideal for HR, payroll, or employee management systems.
- User Management: Register, update, delete, and fetch users.
- Authentication: Login with email/password to get a JWT token.
- Role-Based Access: Restrict endpoints to
ADMINorUSERroles. - Salary Management: Add and retrieve salary details with automatic 10% tax calculation.
- API Documentation: Swagger UI for easy testing.
- Java: Core language.
- Spring Boot: Framework for REST APIs and dependency management.
- Spring Security: JWT authentication and role-based authorization.
- Spring Data JPA: Database operations with Hibernate.
- JWT (io.jsonwebtoken): Token generation and validation.
- BCrypt: Password hashing.
- Swagger: API documentation.
- Database: Relational DB (e.g., MySQL/PostgreSQL, configurable).
- Lombok: Boilerplate reduction.
- Java 17+
- Maven
- A relational database (e.g., MySQL or PostgreSQL)
- IDE (e.g., IntelliJ IDEA, Eclipse)
-
Clone the Repository:
git clone https://github.com/[your-username]/paysecure-api.git cd paysecure-api -
Clone the Repository: Update src/main/resources/application.properties with your DB details:
spring.datasource.url=jdbc:mysql://localhost:3306/paysecure_db spring.datasource.username=your_username spring.datasource.password=your_password spring.jpa.hibernate.ddl-auto=update
-
Build and Run:
mvn clean install mvn spring-boot:run
-
Access the API:
Base URL: http://localhost:8080
Swagger UI: http://localhost:8080/swagger-ui/index.html
| Method | Endpoint | Description | Access Roles |
|---|---|---|---|
| POST | /auth/login |
Login and get JWT token | Public |
| POST | /api/users/register |
Register a new user | Public |
| GET | /api/users/all |
Get all users | ADMIN |
| PUT | /api/users/update/{id} |
Update user details | ADMIN, USER |
| DELETE | /api/users/delete/{id} |
Delete a user | ADMIN |
| POST | /salary/add/{userId} |
Add salary for a user | ADMIN |
| GET | /salary/get/{userId} |
Get salary details | ADMIN, USER |
Example Request (Login)
curl -X POST http://localhost:8080/auth/login \
-H "Content-Type: application/json" \
-d '{"email": "john@example.com", "password": "pass123"}'Response:
{
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
}Example Request (Get Salary)
curl -X GET http://localhost:8080/salary/get/1 \
-H "Authorization: Bearer <your-jwt-token>"Response:
{
"userId": 1,
"username": "john",
"basicSalary": 5000.0,
"taxDeduction": 500.0,
"netSalary": 4500.0
}src/main/java/in/Mrityunjay/
├── Configuration # Security config (JWT, Spring Security)
├── Controller # REST controllers for users, salary, auth
├── Entity # JPA entities (User, Salary)
├── JwtUtil # JWT generation, validation, and filtering
├── Repo # JPA repositories
├── Service # Business logic interfaces
├── ServiceImpl # Service implementations
└── MineProjecApplication.java # Main Spring Boot appHow to Contribute:
Fork the repo.
Create a branch (git checkout -b feature/your-feature).
Commit your changes (git commit -m "Add your feature").
Push to your branch (git push origin feature/your-feature).
Open a Pull Request.
Future Improvements:
Add unit/integration tests with JUnit and Mockito.
Improve error handling with custom exceptions.
Deploy to a cloud platform (e.g., Heroku).
Pair with a simple frontend (e.g., React).
This project is licensed under the MIT License - see the file for details.
Contact
Built by a fresher learning the ropes! Feedback welcome!
GitHub: [mannk26] LinkedIn: [https://www.linkedin.com/in/man-s-8757a5204/]








