This guide takes you from a fresh clone to a running Panahashi Backend server with a verified API call. You will configure Firebase, start the Ktor server on port 8080, and authenticate your first request using a real Firebase ID token.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.
Prerequisites
Before you begin, make sure you have the following installed and ready:- JDK 17 or later — the server targets JVM 17. Run
java -versionto check. - Gradle 8 or later — the project ships with the Gradle wrapper, so a global install is optional.
- A Firebase project — you need owner or editor access to create a service account and enable services.
- Git — to clone the repository.
Setup steps
Clone the repository
Clone the Panahashi Backend source to your machine:The project root contains
build.gradle.kts, gradlew, and the src/ directory with the Ktor application.Create and configure your Firebase project
Panahashi Backend relies on four Firebase services. Enable all of them before running the server.
- Open the Firebase Console and create a new project (or use an existing one).
- Firestore — go to Build → Firestore Database and create a database in production mode. Choose the region closest to your users.
- Authentication — go to Build → Authentication → Sign-in method and enable at least one provider. Email/Password and Google are recommended for testing.
- Storage — go to Build → Storage and set up the default bucket. The backend defaults to the bucket name
panahashi.appspot.com; setFIREBASE_STORAGE_BUCKETif your bucket name differs. - Cloud Messaging (FCM) — FCM is enabled automatically for every Firebase project. No extra steps are needed.
The Firestore security rules you configure for client SDKs do not affect server-side Admin SDK calls. The Firebase Admin SDK bypasses client-facing rules and uses your service account’s IAM permissions instead.
Download and place your service account key
The server authenticates to Firebase using a service account JSON key.Alternatively, point the
- In the Firebase Console, go to Project Settings → Service accounts.
- Click Generate new private key and confirm. A JSON file downloads to your machine.
- Rename the file to
serviceAccountKey.jsonand place it in the project root (the same directory asbuild.gradle.kts):
GOOGLE_APPLICATION_CREDENTIALS environment variable at the file path, or set FIREBASE_SERVICE_ACCOUNT_PATH to override the config default. The server falls back to Application Default Credentials when no file is found.Set up Firestore collections
The backend reads and writes to these Firestore collections. You can let the server create them on first write, or initialize them manually in the Firebase Console by adding a placeholder document to each.
| Collection | Purpose |
|---|---|
users | User profiles with roles and FCM tokens |
bakeries | Bakery storefronts and metadata |
products | Products belonging to bakeries |
orders | Customer orders and their lifecycle status |
reviews | Customer reviews scoped to bakeries |
favorites | Per-user favorited bakeries |
carts | Active shopping carts |
promotions | Discount promotions scoped to bakeries |
loyalty | Stamp card records per user per bakery |
payments | Payment records linked to orders |
Run the server
Start the Ktor server using the Gradle wrapper. No configuration files need editing if you placed On the first run, Gradle downloads all dependencies — Ktor 3.1.3, Firebase Admin SDK 9.4.2, and others. Subsequent runs are faster.When the server is ready, you will see output similar to:The server binds to
serviceAccountKey.json in the project root:0.0.0.0:8080 by default. Override the port with the PORT environment variable:Check the health endpoint
Verify the server is running by calling the public health endpoint — no authentication required:Expected response:If you get a connection error, check that the Gradle build finished without errors and that no other process is using port 8080.
Get a Firebase ID token
Protected API endpoints require a Firebase ID token in the
Authorization header. Obtain one from a Firebase-connected client application.The examples below show two approaches — the Firebase JavaScript SDK for web apps, and the Firebase Admin SDK for server-to-server testing:Firebase ID tokens expire after 1 hour. See the Authentication guide for details on refreshing tokens automatically.
Make your first authenticated API call
With your ID token, call a protected endpoint. A successful If you receive a
GET /api/v1/users/me returns the profile for the authenticated user:200 response returns the user’s profile:401 Unauthorized response, your token has likely expired or was formatted incorrectly. Confirm the Authorization header starts with Bearer (including the trailing space) followed by the raw token string.What’s next
Now that your server is running and you have made your first authenticated call, explore the rest of the documentation.Authentication
Understand token lifecycle, refresh strategies, and which endpoints require authentication.
API reference
Browse every endpoint grouped by resource — bakeries, orders, users, and more.
Roles & permissions
Learn how the CUSTOMER, BAKER, and ADMIN roles control access across the API.