Skip to content

fms-faisal/DayMate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DayMate - AI Daily Planning Assistant

DayMate Banner Python React FastAPI

An AI-powered assistant that helps users plan their day by combining real-time weather data, local news, and intelligent recommendations.

Live Application URLs

Service URL
Frontend https://day-mate-navy.vercel.app/
Backend API https://daymate-backend-5f7j.onrender.com
API Documentation https://daymate-backend-5f7j.onrender.com/docs

Features

Core Features

  • Real-time Weather Integration - Fetches current weather data from Open-Meteo API (FREE, no key needed)
  • Real-time Traffic Updates - Shows road congestion levels and incidents using TomTom Traffic API (Open Traffic - World Bank)
  • News Aggregation - Retrieves local news via NewsAPI
  • AI Planning Agent - Generates personalized daily recommendations using Google Gemini
  • Clean User Interface - Modern React UI with Tailwind CSS styling

Bonus Features

  • Docker Containerization - Ready-to-deploy Dockerfiles
  • Unit Tests - Comprehensive test coverage for backend services
  • Fallback Mechanisms - Rule-based plans when AI is unavailable

Technology Choices

Backend: FastAPI

  • Why FastAPI?
    • High performance with async support
    • Automatic OpenAPI documentation
    • Built-in data validation with Pydantic
    • Easy to test and deploy

Frontend: React + Vite

  • Why React?

    • Component-based architecture for maintainability
    • Large ecosystem and community support
    • Excellent developer experience with hooks
  • Why Vite?

    • Lightning-fast development server
    • Optimized production builds
    • Modern ES modules support

Styling: Tailwind CSS

  • Why Tailwind?
    • Utility-first approach for rapid development
    • Highly customizable design system
    • Small production bundle with purging

Project Structure

DayMate/
├── backend/                    # FastAPI Backend
│   ├── app/
│   │   ├── __init__.py
│   │   ├── main.py            # Application entry point
│   │   ├── models.py          # Pydantic data schemas
│   │   └── services/
│   │       ├── __init__.py
│   │       ├── weather.py     # Open-Meteo integration (FREE)
│   │       ├── news.py        # NewsAPI integration
│   │       └── ai_agent.py    # OpenAI integration
│   ├── tests/
│   │   └── test_services.py   # Unit tests
│   ├── .env.example           # Environment template
│   ├── requirements.txt       # Python dependencies
│   └── Dockerfile             # Container configuration
│
├── frontend/                   # React + Vite Frontend
│   ├── src/
│   │   ├── components/
│   │   │   ├── WeatherCard.jsx
│   │   │   ├── NewsFeed.jsx
│   │   │   ├── PlanDisplay.jsx
│   │   │   ├── LoadingSpinner.jsx
│   │   │   └── ErrorMessage.jsx
│   │   ├── App.jsx            # Main application
│   │   ├── main.jsx           # Entry point
│   │   └── index.css          # Tailwind styles
│   ├── .env.example           # Environment template
│   ├── package.json
│   ├── vite.config.js
│   └── tailwind.config.js
│
└── README.md                   # This file

Local Setup Instructions

Prerequisites

  • Python 3.11+
  • Node.js 18+
  • npm or yarn

API Keys Required (All FREE)

  1. Weather API - Using Open-Meteo - NO API KEY NEEDED! Completely free.
  2. NewsAPI Key - Get FREE key here - Free for development
  3. Google Gemini API Key - Get FREE key here - Free tier available

Backend Setup

# 1. Navigate to backend directory
cd backend

# 2. Create virtual environment
python -m venv venv

# 3. Activate virtual environment
# Windows:
venv\Scripts\activate
# macOS/Linux:
source venv/bin/activate

# 4. Install dependencies
pip install -r requirements.txt

# 5. Create environment file
copy .env.example .env  # Windows
# cp .env.example .env  # macOS/Linux

# 6. Edit .env and add your API keys (Weather is FREE - no key needed!)
# NEWS_API_KEY=your_key
# GEMINI_API_KEY=your_key

# 7. Run the server
uvicorn app.main:app --reload --port 8000

The backend will be available at http://localhost:8000

  • API Documentation: http://localhost:8000/docs

Frontend Setup

# 1. Navigate to frontend directory
cd frontend

# 2. Install dependencies
npm install

# 3. Create environment file
copy .env.example .env  # Windows
# cp .env.example .env  # macOS/Linux

# 4. Run development server
npm run dev

The frontend will be available at http://localhost:5173

Running Tests

# Navigate to backend directory
cd backend

# Run tests
pytest tests/ -v

API Endpoints

Method Endpoint Description
GET / Health check
GET /health Service health status
POST /api/plan Generate daily plan
GET /api/weather/{city} Get weather for city
GET /api/news/{city} Get news for city

Example Request

curl -X POST "http://localhost:8000/api/plan" \
     -H "Content-Type: application/json" \
     -d '{"city": "London"}'

Example Response

{
  "weather": {
    "temp": 15.5,
    "feels_like": 14.2,
    "humidity": 72,
    "condition": "Clouds",
    "description": "overcast clouds",
    "icon": "04d",
    "wind_speed": 5.2,
    "city_name": "London",
    "country": "GB"
  },
  "news": [
    {
      "title": "Local News Headline",
      "description": "News description...",
      "url": "https://...",
      "source": "BBC News",
      "published_at": "2024-01-01T12:00:00Z"
    }
  ],
  "ai_plan": "## Daily Plan for London\n\n### Morning\n- ...",
  "city": "London"
}

Deployment Instructions

Backend Deployment (Render)

  1. Push your code to GitHub

  2. Create a new Web Service on Render

  3. Connect your GitHub repository

  4. Configure settings:

    • Build Command: pip install -r requirements.txt
    • Start Command: uvicorn app.main:app --host 0.0.0.0 --port $PORT
    • Root Directory: backend
  5. Add Environment Variables in Render dashboard:

    • NEWS_API_KEY
    • GEMINI_API_KEY
    • (Weather uses Open-Meteo - NO KEY NEEDED!)
  6. Deploy!

Environment & Deployment

This section outlines the configuration required to run DayMate locally and in production.

  • TOMTOM_API_KEY
  • NEWS_API_KEY
  • GEMINI_API_KEY
  • ALLOWED_ORIGINS (comma-separated list of allowed front-end origins)

For local development: copy backend/.env.example to backend/.env and fill in values. For production, set these values in your host's environment configuration (for example, Render's Service Environment settings).

  • ALLOWED_ORIGINS should contain the exact origins your frontend will use (for example http://localhost:5173,https://day-mate-navy.vercel.app).

  • Do not use a wildcard (*) when your frontend relies on credentials (cookies or auth headers), since browsers require an explicit origin when credentials are allowed.

  • Firebase / Firestore:

    • Enable Authentication (Google provider) and add your deployed frontend domain to Authorized Domains in the Firebase Console.
    • Structure chat data under users/{uid}/chatHistory so records are user-scoped.
    • Apply Firestore security rules that restrict access to authenticated users acting on their own data; an example rule is shown below. Frontend build-time variables: On Vercel set VITE_API_URL to your backend URL (for example https://daymate-backend-5f7j.onrender.com) and the VITE_FIREBASE_* values from your Firebase project settings. These are read at build time — update them in Vercel and redeploy the site. Recommended Firestore rules (example - restrict reads/writes to authenticated users under their UID):
rules_version = '2';

service cloud.firestore {
  match /databases/{database}/documents {
    match /users/{userId}/{collection}/{docId} {
      allow read, write: if request.auth != null && request.auth.uid == userId;
    }
    match /{document=**} {
      allow read, write: if false;
    }
  }
}

If secrets are committed inadvertently, rotate affected keys and follow best-practice guidance from your provider to remove them from history.

Frontend Deployment (Vercel)

  1. Import your GitHub repository on Vercel

  2. Configure settings:

    • Framework Preset: Vite
    • Root Directory: frontend
  3. Add Environment Variable:

  • VITE_API_URL = Your Render backend URL (e.g., https://daymate-backend-5f7j.onrender.com)
  1. Deploy!

Docker Deployment

# Backend
cd backend
docker build -t daymate-backend .
docker run -p 8000:8000 --env-file .env daymate-backend

# Or use docker-compose (create docker-compose.yml first)

Screenshots

Home Page

Home Page Home Page

Results View

Results Results Results

Add your screenshots to a screenshots/ folder

Architecture Diagram

┌─────────────────┐     ┌─────────────────┐
│   React App     │────▶│   FastAPI       │
│   (Frontend)    │◀────│   (Backend)     │
└─────────────────┘     └────────┬────────┘
                                 │
         ┌───────────────────────┼───────────────────────┐
         │                       │                       │
         ▼                       ▼                       ▼
┌─────────────────┐     ┌─────────────────┐     ┌─────────────────┐
│   Open-Meteo    │     │    NewsAPI      │     │  Google Gemini  │
│   (FREE!)       │     │                 │     │      API        │
└─────────────────┘     └─────────────────┘     └─────────────────┘

Environment Variables

Backend (.env)

# Weather: Uses Open-Meteo - NO API KEY NEEDED!
# Traffic: Uses TomTom Traffic API (Open Traffic - World Bank)
# Based on OSM and Telenav data - Free developer tier available
TOMTOM_API_KEY=your_tomtom_api_key
NEWS_API_KEY=your_newsapi_key
GEMINI_API_KEY=your_gemini_api_key
ALLOWED_ORIGINS=http://localhost:5173

Frontend (.env)

VITE_API_URL=http://localhost:8000

Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

This project is licensed under the MIT License.

Acknowledgments