A RESTful API built with Spring Boot that implements core features of Stack Overflow, including user authentication, question and answer management.
- Java 17
- Spring Boot 3.x
- MySQL
- Docker
- JWT Authentication
- Swagger/OpenAPI
- Flyway Migration
- Lombok
- Docker and Docker Compose
- Java 17 or higher
- Maven/Gradle (optional, if running without Docker)
git clone https://github.com/yourusername/stackoverflow-clone.git
cd stackoverflow-clone- Build and start the containers:
docker-compose up --build- Stop the containers:
docker-compose down- Stop and remove all containers, networks, and volumes:
docker-compose down -v- View logs:
docker-compose logs -f- Rebuild a specific service:
docker-compose up -d --build appOnce the application is running, you can access the Swagger UI documentation at:
http://localhost:8080/api/swagger-ui.html
The OpenAPI specification is available at: http://localhost:8080/api/api-docs
The API uses JWT tokens for authentication. To use protected endpoints:
- Register a new user:
curl -X POST http://localhost:8080/api/auth/register \
-H "Content-Type: application/json" \
-d '{
"username": "your_username",
"password": "your_password",
"email": "your_email@example.com"
}'- Login to get a token:
curl -X POST http://localhost:8080/api/auth/login \
-H "Content-Type: application/json" \
-d '{
"username": "your_username",
"password": "your_password"
}'- Use the token in subsequent requests:
curl -X POST http://localhost:8080/api/questions \
-H "Authorization: Bearer your_token_here" \
-H "Content-Type: application/json" \
-d '{
"title": "Your Question Title",
"description": "Your Question Description"
}'- User Authentication (Register/Login)
- JWT Token Based Security
- Question Management (Create, Read, Update, Delete)
- Answer Management (Create, Read, Update, Delete)
- Error Handling with Custom Responses
- Database Migration with Flyway
- API Documentation with Swagger/OpenAPI
Migrations are handled automatically by Flyway when the application starts. Migration files are located in:
src/main/resources/db/migration/
The following environment variables can be configured in your .env file:
MYSQL_DATABASE=stackoverflow
MYSQL_USER=user
MYSQL_PASSWORD=password
MYSQL_ROOT_PASSWORD=rootpassword
JWT_SECRET=your_jwt_secret
JWT_EXPIRATION=86400000The API uses a standardized error response format:
{
"success": false,
"message": "Error message here",
"data": null,
"errorCode": "ERROR_CODE"
}- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE.md file for details
- Spring Boot Documentation
- Stack Overflow API Documentation
- Docker Documentation