Welcome to MeAI Banana Recognizer POC docs
This is just a brief showcase of how we'd like to proceed with documenting the code later, once we win the POC beauty contest.
This documentation is deployed using MkDocs with Read The Docs Theme and is hosted on Cloudflare Pages.
About the Banana Recognizer
Banana Recognizer is an application which allows blockchain users to check if there is a banana on their picture.
Login flow
To sign-in it is required to pass a sign challenge. Backend is generating a new challenge each time user wants to log in. In case of success or failure it is no longer possible to complete the same challenge.
Challenge flow
- client app (mobile/web) requests a new challenge, challenge is associate with wallet address
- new challenge is generated with a random message
- message has to be signed with private key of the previously passed wallet address
- client app sends challenge id and signature back to the backend
- backend verifies wallet address based on the signature
- if wallet address matches then JWT token is being generated (token contains wallet address)
Image recognition
For the image recognition we use Google Vision API for the PoC purposes (fast start). In longer term it would be better to train dedicated network and publish it as a docker container in the same cluster.
Also fake CounterfeitingDetectionProcessor was implemented with fixed 150ms delay to demonstrate concurrent programming.
Blockchain data synchronization
Application periodically (every 10 minutes by default) synchronize the data with blockchain:
- token balance
- user score
Token balance is synchronized using the Alchemy HTTP API - one request for all balances.
User score is synchronized using contract defined function getScoreForUser. We have to ask about data for each user separately.
Scheduler has been defined in the app. To be able to scale the application we should move the trigger to the Kubernetes Cron Job.
Persistence
Because of lack of time there is no persistence in the project. App restart will clean up the data but users with token balance will be restored during the app start (with sync) but username will be lost.
No persistence allows fast prototyping and move the technical decisions for later.
Deployment
Service is deployed using helm on internal DAC K8S cluster. Env variables:
AUTH_AUDIENCE- jwt audienceAUTH_ISSUER- jwt issuerAUTH_REALM- jwt realAUTH_SECRET- jwt secretADMIN_WALLET_ADDRESSES- comma separated addresses with admin accessGOOGLE_APPLICATION_CREDENTIALS- location of the credentials file (secret deployed separatly, not included in deployment scripts)ALCHEMY_RPC_URL- alchemy url with api keySCORE_SERVICE_ADDRESS- score service contract addressBANANA_NFT_ADDRESS- banana nft contract addressSYNC_SCHEDULER_DELAY- duration in ISO 8601 (default PT10m - refresh every 10 minutes)