Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/AndrewwCO/Panahashi-Backend/llms.txt

Use this file to discover all available pages before exploring further.

The Panahashi backend is a Ktor application running on the Netty engine. It binds to 0.0.0.0:8080 by default and can be run directly with Gradle during development or packaged as a self-contained fat JAR for production deployments.

Prerequisites

Before deploying, make sure you have the following in place:

JDK 17

The application requires Java 17 or later. Verify with java -version.

Gradle 8+

The build uses Gradle wrapper (./gradlew). No local Gradle installation required.

Firebase configured

Complete the Firebase setup guide before running the server.

Local development

Running with Gradle starts the server in development mode, which enables hot reload and verbose logging.
./gradlew run
The server starts at http://localhost:8080. Confirm it is running:
curl http://localhost:8080/health
The JVM flag -Dio.ktor.development=true is set automatically when using ./gradlew run via applicationDefaultJvmArgs in build.gradle.kts. Do not set this flag in production.

Building and running a production JAR

The Gradle build task produces a fat JAR that bundles the application and all its dependencies into a single file.
./gradlew build
After the build completes, run the JAR:
java -jar build/libs/panahashi-backend-1.0.0-all.jar
Pass environment variables inline if you do not want to export them to the shell session:
PORT=9090 FIREBASE_SERVICE_ACCOUNT_PATH=/secrets/key.json \
  java -jar build/libs/panahashi-backend-1.0.0-all.jar

Environment variables

All configuration can be overridden at runtime using environment variables. The values in application.conf serve as defaults when a variable is not set.
VariableDefaultDescription
PORT8080TCP port the server listens on
FIREBASE_SERVICE_ACCOUNT_PATHserviceAccountKey.jsonPath to the Firebase service account JSON file
FIREBASE_DATABASE_URLhttps://panahashi-default-rtdb.firebaseio.comFirebase Realtime Database URL
FIREBASE_STORAGE_BUCKETpanahashi.appspot.comFirebase Storage bucket name

Docker deployment

The following multi-stage Dockerfile builds the fat JAR and packages it into a minimal JRE image.
FROM eclipse-temurin:17-jdk AS builder
WORKDIR /app
COPY . .
RUN ./gradlew build --no-daemon

FROM eclipse-temurin:17-jre
WORKDIR /app
COPY --from=builder /app/build/libs/*-all.jar app.jar
COPY serviceAccountKey.json .
EXPOSE 8080
CMD ["java", "-jar", "app.jar"]
Build and run the image:
docker build -t panahashi-backend .
docker run -p 8080:8080 \
  -e FIREBASE_SERVICE_ACCOUNT_PATH=/app/serviceAccountKey.json \
  panahashi-backend
Baking serviceAccountKey.json into the Docker image is convenient for quick tests but is not safe for production. In production, mount the file as a secret volume or use Application Default Credentials (see below).

Using Application Default Credentials on Google Cloud

When deploying to a Google Cloud environment such as Cloud Run, GKE, or Compute Engine, you can attach a service account to the compute resource instead of shipping a key file. The Firebase Admin SDK will automatically use Application Default Credentials (ADC) from the environment.
1

Attach a service account to your Cloud resource

In the Google Cloud Console, assign a service account with the Firebase Admin role (or equivalent Firestore/Storage/FCM permissions) to your Cloud Run service, GKE workload identity, or VM instance.
2

Remove the key file reference

Do not set FIREBASE_SERVICE_ACCOUNT_PATH. When the environment variable is absent and serviceAccountKey.json does not exist on disk, the Firebase Admin SDK falls back to ADC automatically.
3

Still set the other variables

FIREBASE_DATABASE_URL and FIREBASE_STORAGE_BUCKET must still be provided as environment variables since they are not inferred from ADC.
ADC eliminates the need to manage or rotate service account key files. It is the recommended approach for any Google Cloud deployment.

Build docs developers (and LLMs) love