Skip to content

Backend for Apocalypse Simulator game, built with Spring Boot. Manages player data, events, and authentication (OAuth2 - Google) using PostgreSQL.

License

Notifications You must be signed in to change notification settings

gorocode/as-spring-boot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Apocalypse Simulator (as-spring-boot)

Apocalypse Simulator

📝 Description

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.

🚀 Live Demo

🔗 Play Now

🚨 Backend Information (Render Deployment)

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.

Please be patient while it initializes.

📦 Related Repositories

⚡ Features

  • 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.

🛠️ Technologies Used

  • 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

📂 Installation and Configuration

🔧 Prerequisites

  • Java 21 or higher
  • Maven (or another build tool)
  • PostgreSQL Database (can be replaced with another database)
  • Google OAuth2 Credentials for user authentication

📥 Installation

  1. Clone the repository:

    git clone https://github.com/gorocode/as-spring-boot.git
    cd as-spring-boot
  2. Set up the environment variables: Create an .env file (or use application.properties or application.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>
  3. Install dependencies:

    mvn clean install
  4. Run the application:

    mvn spring-boot:run

    The server will be available at http://localhost:8080 by default.

⚙️ Database Configuration

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.

🛠️ Docker Deployment

This project is configured for deployment using Docker. The Dockerfile allows building and running the application in an isolated environment.

  1. Build the Docker image:

    docker build -t apocalypse-simulator-backend .
  2. Run the Docker container:

    docker run -p 8080:8080 apocalypse-simulator-backend

    The application will run on port 8080 within the container.

🎮 Game API

The backend exposes several APIs to interact with the game and users. Here are some important endpoints:

Player:

  • POST /player/new: Create a new player.
    • Body: name, userId (Long)
  • PUT /player: Update a player's details.
    • Body: {id: Long, name: String, health: Integer, food: Integer, moral: Integer, survivedDays, finished: Boolean} (complete player object)
  • GET /player/user/{userId}: Get the list of players for a specific user.
    • Params: userId (Long)
  • DELETE /player/{playerId}: Delete a player.
    • Params: playerId (Long)
  • POST /player/action: Send an action for a player.
    • Body: {playerId: Long, eventId: Long, option: Integer} (action data)

Event:

  • GET /event/random: Get a random event.

User:

  • PUT /user: Update the authenticated user's details.
    • Body: {id: Long, name: String, username: String, email: String, profilePicture: String} (user data)
  • 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)
  • GET /oauth2/authorization/google: Log in with Google OAuth2.
  • POST /user/logout: Log out the user.

Contact Form:

  • POST /email/contact: Send a contact form submission.
    • Body: {name: String, email: String, message: String} (contact form data)

👥 Contributing

Contributions are welcome! To contribute:

  1. Fork the repository.
  2. Create a branch for your feature (git checkout -b feature-new).
  3. Make your changes (git commit -m "Add new feature").
  4. Push your branch (git push origin feature-new).
  5. Open a Pull Request.

📝 License

This project is licensed under the MIT License. See the LICENSE file for more details.

About

Backend for Apocalypse Simulator game, built with Spring Boot. Manages player data, events, and authentication (OAuth2 - Google) using PostgreSQL.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published