SecretBase/bus-realtime-info

โ˜… 0Forks 0SvelteGitHub โ†—Compare

Project website โ†—

README

Bus Realtime Info (Bus ETA)

A modern Progressive Web App (PWA) for checking real-time bus arrival times (ETA) for Hong Kong bus services. Built with SvelteKit, this application provides a fast and user-friendly interface to browse routes, view stops, and check bus arrival times from multiple bus companies.

Features

  • ๐ŸšŒ Multi-Company Support: Browse routes from CTB (Citybus), KMB, and NWFB
  • ๐Ÿ” Route Search: Quickly find bus routes with real-time filtering
  • ๐Ÿ“ Stop Information: View detailed stop information and real-time ETA
  • โฑ๏ธ Auto-Refresh: ETA data automatically refreshes every 10 seconds
  • โญ Favorites: Save your frequently used stops for quick access
  • ๐Ÿ”„ Direction Switching: Switch between inbound and outbound directions
  • ๐Ÿ“ฑ PWA Support: Install as a mobile app with offline capabilities
  • โšก Performance Optimized: Virtual scrolling for smooth performance with large route lists
  • ๐ŸŽจ Modern UI: Clean, responsive design with Tailwind CSS

Tech Stack

  • Framework: SvelteKit with Svelte 5
  • Language: TypeScript
  • Styling: Tailwind CSS 4
  • Data Fetching: TanStack Query (formerly React Query)
  • Virtualization: TanStack Virtual
  • HTTP Client: Axios
  • Date Formatting: date-fns
  • PWA: Workbox
  • Deployment: Netlify (Edge Functions)

Data Sources

The application fetches real-time bus data from official Hong Kong government APIs:

  • CTB/Citybus: https://rt.data.gov.hk/v2/transport/citybus
  • KMB: https://data.etabus.gov.hk/v1/transport/kmb

Getting Started

Prerequisites

  • Bun (v1.3 or higher)

Installation

  1. Clone the repository:
git clone <repository-url>
cd bus-realtime-info
  1. Install dependencies:
bun install

Development

Start the development server:

bun run dev

The app will open automatically in your browser at http://localhost:5173.

Building

Build the production version:

bun run build

Preview the production build:

bun run preview

Code Quality

Check TypeScript types:

bun run check

Lint code:

bun run lint

Format code:

bun run format

Project Structure

src/
โ”œโ”€โ”€ app.html              # HTML template
โ”œโ”€โ”€ routes/               # SvelteKit routes
โ”‚   โ”œโ”€โ”€ +page.svelte      # Home page (route list)
โ”‚   โ”œโ”€โ”€ favorites/        # Favorites page
โ”‚   โ””โ”€โ”€ [companyId]/      # Dynamic routes
โ”‚       โ””โ”€โ”€ route/
โ”‚           โ””โ”€โ”€ [route]/
โ”‚               โ”œโ”€โ”€ +page.svelte        # Route detail page
โ”‚               โ””โ”€โ”€ stop/
โ”‚                   โ””โ”€โ”€ [stopId]/
โ”‚                       โ””โ”€โ”€ +page.svelte # Stop detail page
โ”œโ”€โ”€ lib/
โ”‚   โ”œโ”€โ”€ api/              # API clients
โ”‚   โ”‚   โ”œโ”€โ”€ ctb/          # Citybus API
โ”‚   โ”‚   โ”œโ”€โ”€ kmb/          # KMB API
โ”‚   โ”‚   โ””โ”€โ”€ common/       # Shared API types
โ”‚   โ”œโ”€โ”€ components/       # Reusable Svelte components
โ”‚   โ”œโ”€โ”€ stores/           # Svelte stores (favorites)
โ”‚   โ””โ”€โ”€ utils/            # Utility functions (ETA formatting)
โ””โ”€โ”€ service-worker.ts     # PWA service worker

Key Features Explained

Route Browsing

  • Browse all available routes from supported bus companies
  • Search/filter routes by route number
  • Virtual scrolling for optimal performance with large lists

Stop Details

  • View all stops along a route
  • See real-time ETA for each stop
  • Switch between inbound and outbound directions

ETA Display

  • Shows arrival time in minutes for buses arriving in more than 1 minute
  • Displays "ๅณๅฐ‡ๅˆฐ้”" (Arriving Soon) for buses arriving within 1 minute
  • Automatically refreshes every 10 seconds
  • Sorted by arrival time

Favorites

  • Save frequently used stops
  • Access favorites from the dedicated favorites page
  • Favorites are stored in browser local storage
  • Filter favorites by route number

Deployment

The project is configured for deployment on Netlify using the Netlify adapter with Edge Functions enabled.

Build configuration is defined in netlify.toml:

[build]
  command = "bun run build"
  publish = "build"

Browser Support

  • Modern browsers with ES6+ support
  • Mobile browsers (iOS Safari, Chrome Mobile)
  • PWA installation supported on compatible browsers

License

This project is private.

Contributing

This is a private project. Contributions are not currently accepted.


Built with โค๏ธ using SvelteKit

Contributors

SecretBase

Issues