Apocalypse Simulator is an interactive question-and-action game where your choices affect your stats.
This Backend is the server that powers the Apocalypse Simulator, an interactive decision-making game. The backend is built with Spring Boot and handles the game logic, user authentication via OAuth2 with Google, and the persistent storage of data regarding characters, events, and their effects on the character stats.
This backend also interacts with a PostgreSQL database (hosted on Supabase), though it can be easily configured to work with any other database.
🔗 Play Now
The backend of this project is deployed on Render and may enter sleep mode after a period of inactivity. The first request after the backend is in sleep mode may take a few moments to start up.
- 🔗 Frontend: as-react
- 🔗 Backend: as-spring-boot
- User Authentication: Supports OAuth2 with Google to sign in and manage profiles.
- Character Management: Stores the information of created characters, their stats, and their progress.
- Events: Manages game events (questions and decisions) and their effects on character stats.
- Database: Uses PostgreSQL (on Supabase, but easily configurable for other providers).
- RESTful API: Exposes endpoints for the frontend to interact with the game and users.
- Backend Framework: Spring Boot
- Database: PostgreSQL
- Authentication: OAuth2 with Google
- API: RESTful APIs with Spring Data JPA
- Email: Integration with SMTP (e.g., Gmail)
- Containerization: Docker
- Java 21 or higher
- Maven (or another build tool)
- PostgreSQL Database (can be replaced with another database)
- Google OAuth2 Credentials for user authentication
-
Clone the repository:
git clone https://github.com/gorocode/as-spring-boot.git cd as-spring-boot
-
Set up the environment variables: Create an
.env
file (or useapplication.properties
orapplication.yml
) at the root of the project with the following variables:FRONTEND_URL=<YOUR_FRONTEND_URL> SPRING_DATASOURCE_URL=<YOUR_DATABASE_URL> SPRING_SECURITY_OAUTH2_CLIENT_REGISTRATION_GOOGLE_CLIENT_ID=<YOUR_GOOGLE_CLIENT_ID> SPRING_SECURITY_OAUTH2_CLIENT_REGISTRATION_GOOGLE_CLIENT_SECRET=<YOUR_GOOGLE_CLIENT_SECRET> SPRING_MAIL_USERNAME=<YOUR_EMAIL> SPRING_MAIL_PASSWORD=<YOUR_PASSWORD>
-
Install dependencies:
mvn clean install
-
Run the application:
mvn spring-boot:run
The server will be available at
http://localhost:8080
by default.
The project is set up to use PostgreSQL, but you can change the configurations in application.properties
and the driver in pom.xml
to connect to any other database supported by JPA.
This project is configured for deployment using Docker. The Dockerfile
allows building and running the application in an isolated environment.
-
Build the Docker image:
docker build -t apocalypse-simulator-backend .
-
Run the Docker container:
docker run -p 8080:8080 apocalypse-simulator-backend
The application will run on port
8080
within the container.
The backend exposes several APIs to interact with the game and users. Here are some important endpoints:
POST /player/new
: Create a new player.- Body:
name
,userId (Long)
- Body:
PUT /player
: Update a player's details.- Body:
{id: Long, name: String, health: Integer, food: Integer, moral: Integer, survivedDays, finished: Boolean}
(complete player object)
- Body:
GET /player/user/{userId}
: Get the list of players for a specific user.- Params:
userId (Long)
- Params:
DELETE /player/{playerId}
: Delete a player.- Params:
playerId (Long)
- Params:
POST /player/action
: Send an action for a player.- Body:
{playerId: Long, eventId: Long, option: Integer}
(action data)
- Body:
GET /event/random
: Get a random event.
PUT /user
: Update the authenticated user's details.- Body:
{id: Long, name: String, username: String, email: String, profilePicture: String}
(user data)
- Body:
GET /user
: Get the authenticated user's details.GET /user/email-in-use/{email}
: Check if an email is already in use by another user.- Params:
email (String)
- Params:
GET /oauth2/authorization/google
: Log in with Google OAuth2.POST /user/logout
: Log out the user.
POST /email/contact
: Send a contact form submission.- Body:
{name: String, email: String, message: String}
(contact form data)
- Body:
Contributions are welcome! To contribute:
- Fork the repository.
- Create a branch for your feature (
git checkout -b feature-new
). - Make your changes (
git commit -m "Add new feature"
). - Push your branch (
git push origin feature-new
). - Open a Pull Request.
This project is licensed under the MIT License. See the LICENSE
file for more details.