Setup Guide

Google Document AI Setup

Step-by-step guide to create a GCP project, enable Document AI, generate a service account key, and wire everything into DocuWealth.

1
Create a Google Cloud Project
You need a GCP project to enable APIs and create credentials
GCP Console โ–ถ
1

Open the Google Cloud Console and sign in with your Google account.

โ†— console.cloud.google.com
2

Click the project dropdown at the top of the page (next to the Google Cloud logo).

3

Click New Project in the top-right of the dialog.

4

Enter a Project Name (e.g. docuwealth-ai) and click Create.

Note the Project ID shown below the name โ€” it looks like docuwealth-ai-123456. You'll need this later.

5

Wait for project creation (15โ€“30 seconds), then select the new project from the dropdown.

2
Enable the Document AI API
The API must be enabled before you can create processors or call it
API Library โ–ถ
1

In the Cloud Console, go to APIs & Services โ†’ Library (left sidebar).

โ†— API Library
2

Search for "Document AI" and click the result.

3

Click Enable. Wait a few seconds for the API to activate.

You may be prompted to enable billing. Document AI has a free tier of 1,000 pages/month โ€” more than enough for personal use.

3
Create a Service Account & Download Key
The server uses this key to authenticate API calls โ€” never share it
IAM & Admin โ–ถ
1

Go to IAM & Admin โ†’ Service Accounts in the left sidebar.

โ†— Service Accounts
2

Click + Create Service Account.

3

Fill in the details:

Name: docuwealth-docai
ID: docuwealth-docai (auto-filled)
Description: DocuWealth Document AI service account

Click Create and Continue.

4

On the Grant this service account access step, click Select a role and choose:

Cloud Document AI โ†’ Cloud Document AI API User

Click Continue, then Done.

5

Click on the service account you just created to open it.

6

Go to the Keys tab โ†’ Add Key โ†’ Create new key.

7

Select JSON and click Create. A JSON file downloads automatically โ€” this is your credentials file.

Keep this file secret. It grants full Document AI access to your GCP project. Never commit it to Git or share it publicly.

8

Upload the JSON file to your server (e.g. via SCP) and place it at a secure path:

scp service-account.json user@your-server:/var/docuwealth/docai-key.json
chmod 600 /var/docuwealth/docai-key.json
4
Create a Document AI Processor
The processor defines what type of document parsing to perform
Document AI โ–ถ
1

Go to Document AI โ†’ Overview in the Cloud Console.

โ†— Document AI Console
2

Click + Create Processor.

3

Choose a processor type. For DocuWealth (passports, Aadhaar, PAN, driving licences), the best options are:

ProcessorBest forRecommendation
Identity Document Parser Passports, driving licences, national IDs โœ“ Best choice
Form Parser General structured forms, insurance docs Good fallback
Document OCR Plain text extraction from any document Basic

Tip: Start with Identity Document Parser. It extracts structured fields (name, doc number, issue/expiry dates, nationality) directly from identity documents without needing custom training.

4

Fill in processor details:

Name: docuwealth-id-parser
Region: us (or eu if you prefer data in Europe)

Click Create.

5

After creation you'll see the processor detail page. Note the Processor ID โ€” it looks like a1b2c3d4e5f6a7b8 (a 16-character hex string).

The full processor path shown in the UI is:
projects/{PROJECT_ID}/locations/{LOCATION}/processors/{PROCESSOR_ID}
You only need the last segment as DOCUMENT_AI_PROCESSOR_ID.

5
Update .env on Your Server
Add the four variables to activate AI extraction in DocuWealth
Server Config โ–ถ
1

SSH into your server and open the .env file in the project root:

nano /home/waheed/WealthManagement/.env
2

Find the Document AI section (already added) and uncomment + fill in your values:

โ”€โ”€ Google Document AI โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
GOOGLE_APPLICATION_CREDENTIALS= /var/docuwealth/docai-key.json
DOCUMENT_AI_PROJECT_ID= your-project-id # e.g. docuwealth-ai-123456
DOCUMENT_AI_LOCATION= us # us or eu โ€” must match processor region
DOCUMENT_AI_PROCESSOR_ID= a1b2c3d4e5f6a7b8 # 16-char hex from processor page

LOCATION must match the processor region. If you created the processor in us, set DOCUMENT_AI_LOCATION=us. Using eu with a us processor will fail with a 404.

3

Restart the server to pick up the new env vars:

pm2 restart docuwealth-server
4

Check the server log to confirm AI is active:

pm2 logs docuwealth-server --lines 20

When you upload a document now, you'll see AI field extraction working in the upload flow โ€” confidence bar appears and fields are pre-filled.

6
Verify the Integration Works
Test with a real document to confirm fields are extracted correctly
Testing โ–ถ
1

Open DocuWealth and go to Documents โ†’ Upload Document.

2

Upload a passport or driving licence (PDF or JPG). After upload, the confirm form should appear with:

  • A confidence bar showing the AI confidence percentage
  • Pre-filled fields (name, document number, expiry date, etc.) with an AI badge next to each AI-filled field
3

If confidence is below 70%, the form shows an amber warning and the document will be saved with status review_needed, appearing in the AI Review filter on the documents list.

4

You can also test the API directly using curl:

curl -X POST https://wealth.justsimple.online/api/documents/preview \
  -H "Authorization: Bearer <your-token>" \
  -F "file=@/path/to/passport.pdf"
โœ“
All 4 Environment Variables โ€” Quick Reference
Where to find each value
โ–ถ
VariableWhere to find itExample
GOOGLE_APPLICATION_CREDENTIALS Path on your server where you placed the downloaded JSON key file /var/docuwealth/docai-key.json
DOCUMENT_AI_PROJECT_ID GCP Console โ†’ project dropdown โ€” the ID (not name) shown below the project name docuwealth-ai-123456
DOCUMENT_AI_LOCATION Region you selected when creating the processor โ€” must match exactly us  or  eu
DOCUMENT_AI_PROCESSOR_ID Document AI โ†’ your processor โ†’ Processor ID field on the detail page a1b2c3d4e5f6a7b8
Firebase FCM

Firebase Cloud Messaging Setup

Push notifications for the DocuWealth Android app โ€” property alerts, insurance renewals, EMI reminders delivered directly to your phone.

1
Create a Firebase Project
Firebase is Google's mobile backend platform โ€” free for personal use
Firebase Console โ–ถ
1

Go to the Firebase Console and sign in with your Google account.

โ†— console.firebase.google.com
2

Click Add project (or Create a project).

3

Enter a project name: DocuWealth and click Continue.

You can link it to an existing GCP project (the one you created for Document AI) โ€” Firebase will reuse the same project ID.

4

Google Analytics step โ€” you can disable it for a personal project. Click Create project.

5

Wait for the project to be created (~30 seconds), then click Continue.

2
Add an Android App to the Project
Register the DocuWealth Android app with its package name
Android Setup โ–ถ
1

In your Firebase project dashboard, click the Android icon (or go to Project settings โ†’ Add app โ†’ Android).

2

Fill in the registration form:

Android package name: online.justsimple.wealth
App nickname: DocuWealth (optional)
Debug signing cert SHA-1: leave blank for now

Click Register app.

Package name must be exact: online.justsimple.wealth โ€” this matches the android.package in apps/mobile/app.json.

3

Click Download google-services.json to download the config file.

This file contains your Firebase project config, API keys, and sender ID. It is not secret โ€” it can be committed to Git. It's referenced in app.json via android.googleServicesFile.

4

Place the file in the mobile app directory:

cp ~/Downloads/google-services.json /home/waheed/WealthManagement/apps/mobile/google-services.json
5

Click Next โ†’ Next โ†’ Continue to console (the SDK installation steps are handled by Expo automatically).

3
Get Your FCM Server Key (for backend)
The server key lets the API send push notifications to devices
Cloud Messaging โ–ถ
1

In Firebase Console, go to Project Settings (gear icon โš™ top-left).

2

Click the Cloud Messaging tab.

3

Under Firebase Cloud Messaging API (V1), click the 3-dot menu โ†’ Manage service accounts.

The old FCM Server Key (Legacy) is deprecated. Use the V1 API with a service account JSON instead.

4

In the IAM Service Accounts page, find the Firebase service account (it ends in @firebase-adminsdk-*.iam.gserviceaccount.com).

5

Click the service account โ†’ Keys tab โ†’ Add Key โ†’ Create new key โ†’ JSON โ†’ Create.

Download the JSON file and place it securely on your server:

scp firebase-adminsdk.json waheed@wealth.justsimple.online:/var/docuwealth/fcm-key.json
chmod 600 /var/docuwealth/fcm-key.json
6

Add the path to your server .env:

โ”€โ”€ Firebase FCM โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
FCM_SERVICE_ACCOUNT_PATH= /var/docuwealth/fcm-key.json

Then restart the API:

pm2 restart docuwealth-api
4
Build the Android APK with FCM
The google-services.json must be in place before building
EAS Build โ–ถ
1

Confirm apps/mobile/google-services.json exists in the repo.

2

Install EAS CLI if not already installed:

npm install -g eas-cli
eas login
3

Build a preview APK (internal distribution):

cd /home/waheed/WealthManagement/apps/mobile
eas build --platform android --profile preview

EAS handles signing automatically. The APK download link is shown in the EAS dashboard when the build finishes (~10 min).

4

Install the APK on your Android device, open the app, log in โ€” you should be prompted to allow notifications. After granting permission, the device token is automatically sent to the server (PUT /api/users/fcm-token).

5
Test a Push Notification
Send a test notification from the Firebase Console
Testing โ–ถ
1

In Firebase Console go to Engage โ†’ Messaging โ†’ New campaign โ†’ Firebase Notification messages.

2

Fill in Notification title and Text, then click Send test message.

3

Paste your device's FCM token (find it in the server DB) into the test field:

sudo -u postgres psql -d docuwealth -c "SELECT email, fcm_token FROM users;"
4

Click Test โ€” the notification should appear on your Android device within a few seconds.

Once working, all DocuWealth alerts (insurance renewals, EMI dues, FD maturity, etc.) will be delivered as push notifications automatically when the daily cron job runs at 08:00 IST.

โœ“
FCM Quick Reference
Files and env vars needed for push notifications
โ–ถ
ItemWhat it isWhere it goes
google-services.json Android app config โ€” downloaded from Firebase Console after registering the Android app apps/mobile/google-services.json
fcm-key.json Server service account key โ€” allows the API to send push messages via FCM V1 API /var/docuwealth/fcm-key.json
FCM_SERVICE_ACCOUNT_PATH Path to fcm-key.json โ€” read by the server at startup .env on server
fcm_token (DB column) Device token โ€” registered automatically when the user logs in on Android and grants notification permission users.fcm_token in PostgreSQL