Stop rewriting authentication, security, and configuration logic in every new project. Start with a solid, production-grade backend foundation. A modern backend foundation with JWT, OAuth2, Rate Limiting, and Dev/Prod profiles. so you never start from scratch again.
This project is a modern Spring Boot starter template designed to eliminate repetitive setup work and enforce best practices from day one.
Instead of rebuilding:
- Security configuration
- JWT authentication
- OAuth2 login (Google)
- Role management
- Exception handling
- Rate limiting
- Environment profiles
It is built to be:
- 🔐 Secure by default
- 🧱 Architecturally clean
- 🌍 Environment-aware (Dev / Prod separation)
- 🚀 Easy to extend
- 🧩 Free of business logic
You can plug this into any new project and immediately focus on real application features.
By default dev profile is active and on dev profile we use h2 DB so you can just clone and run the project direct with out any issues Clone and run locally in seconds:
# Clone the repository
git clone https://github.com/yuosef33/Spring-boot-starter-template.git
# Navigate into project directory
cd Spring-boot-starter-template
# Run the application (dev profile by default)
./mvnw spring-boot:runApplication runs at:
http://localhost:8080
Swagger (dev profile only):
http://localhost:8080/swagger-ui.html
For Windows (PowerShell):
mvnw.cmd spring-boot:runPostman collection link
https://www.postman.com/me4444-5137/spring-boot-starter-template/collection/39139361-bd03fc7a-8e53-460b-8df5-59f0e22e061b?action=share&source=copy-link&creator=39139361
- JWT Authentication (Access + Refresh Tokens)
- Refresh token stored in database with real logout
- OAuth2 Google login fully integrated with JWT
- Role-based authorization (USER / ADMIN)
- Stateless security configuration
- Bucket4j rate limiting (per IP)
- Production-grade security headers
- Profile-based CORS configuration
- Clean layered structure
- DTO + Mapper separation
- Global ApiResponse wrapper
- Centralized exception handling
- Entity auditing (createdAt, updatedAt, createdBy)
- Dev and Prod security configurations
- H2 (dev profile)
- PostgreSQL (prod profile)
- Swagger enabled in dev only
- Actuator monitoring endpoints
- Environment variable driven configuration
- Docker Compose for PostgreSQL
- Production-safe defaults
- Ready for container deployment
com.yuosef.springbootstartertemplate
│
├── config
│ ├── JWT
│ ├── Bucket4J
│ ├── SecurityConfig (dev)
│ ├── SecurityConfigProd (prod)
│ └── SwaggerConfig
│
├── controller
├── service
│ └── impl
├── repository
├── model
│ ├── dto
│ └── mapper
Start PostgreSQL container:
docker-compose up -dRun application with production profile:
./mvnw spring-boot:run -Dspring-boot.run.profiles=prod| Variable | Description |
|---|---|
JWT_SECRET_KEY |
JWT signing secret (minimum 32 characters recommended) |
DB_URL |
PostgreSQL JDBC URL |
DB_USERNAME |
Database username |
DB_PASSWORD |
Database password |
GOOGLE_CLIENT_ID |
Google OAuth2 Client ID |
GOOGLE_CLIENT_SECRET |
Google OAuth2 Client Secret |
ALLOWED_ORIGINS |
Allowed frontend origins |
- Register user
- Login → receive access + refresh token
- Use access token in
Authorization: Bearer <token> - Refresh token when expired
- Logout → refresh token removed from database
- Redirect to
/oauth2/authorization/google - Authenticate with Google
- Receive short-lived exchange code
- Exchange code for JWT tokens
- Continue using stateless JWT authentication
No session-based authentication. Everything remains fully stateless.
| Endpoint | Limit |
|---|---|
/auth/** |
5 requests per minute per IP |
| All other endpoints | 100 requests per minute per IP |
Designed for easy upgrade to Redis-backed implementation for multi-instance environments.
Available endpoints:
/actuator/health/actuator/info
Dev profile:
- Full exposure
Prod profile:
- Restricted exposure (health + info only)
Default profile:
spring:
profiles:
active: devSwitch to production using:
SPRING_PROFILES_ACTIVE=prod- Secure by default
- No business logic included
- Clean separation of concerns
- Easy to extend
- No over-engineering
- Production-ready configuration
This project is licensed under the MIT License — see the LICENSE file for details.
Pull requests are welcome.
If this template saved you time, consider giving it a ⭐.