Skip to content

Toanapr/ai-backend

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Habit Tracker Quote Backend

Express.js backend that generates AI-powered motivational quotes using Google Gemini API.

Setup

  1. Install dependencies:

    npm install
  2. Create .env file:

    cp .env.example .env
  3. Get Gemini API Key:

  4. Run the server:

    npm start

    For development with auto-reload:

    npm run dev

API Endpoints

Generate Motivational Quote

Endpoint: POST /api/quote

Request Body:

{
  "totalHabits": 5,
  "completedYesterday": 3,
  "bestStreak": 12,
  "bestStreakHabitName": "Reading",
  "averageStreak": 5
}

Response:

{
  "quote": "Your Reading streak is unstoppable! 12 days of growth - keep shining!"
}

Health Check

Endpoint: GET /health

Response:

{
  "status": "ok",
  "message": "Habit Tracker Quote API is running"
}

Testing with Android App

Android Emulator

Use the special IP address that maps to your computer's localhost:

http://10.0.2.2:3000/api/quote

Physical Device

Use your computer's local IP address:

http://192.168.x.x:3000/api/quote

To find your local IP:

  • Linux/Mac: ifconfig or ip addr
  • Windows: ipconfig

Deployment

This backend can be deployed to:

  • Vercel (recommended for Express apps)
  • Railway
  • Render
  • Heroku
  • DigitalOcean App Platform

Remember to set the GEMINI_API_KEY environment variable in your deployment platform.

Example Usage

curl -X POST http://localhost:3000/api/quote \
  -H "Content-Type: application/json" \
  -d '{
    "totalHabits": 5,
    "completedYesterday": 3,
    "bestStreak": 12,
    "bestStreakHabitName": "Reading",
    "averageStreak": 5
  }'

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors