MCPcopy Index your code
hub / github.com/comuline/api

github.com/comuline/api @main

Chat with this repo
repository ↗ · DeepWiki ↗ · + Follow
23 symbols 92 edges 24 files 0 documented · 0%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

@comuline/api

An API to get the schedule of KRL commuter line in Jakarta and Yogyakarta using Hono and Bun, deployed to Cloudflare Workers. This API is primarily used on the web app (source code).

How does it work?

This API uses a daily cron job (at 00:00) to fetch the schedule of KRL commuter line in Jakarta and Yogyakarta from the official website of PT. KAI. The data is then processed and stored in a PostgreSQL database and cached in a Redis (for every once read request). All endpoints can be found in the docs.

Technology stacks

  1. Hono API framework
  2. Bun runtime
  3. (Serverless) PostgresSQL (Neon)
  4. (Serverless) Redis (Upstash)
  5. Cloudflare Workers deployment platform
  6. Drizzle ORM

Getting Started

Development

  1. Clone the repository
git clone https://github.com/comuline/api.git
  1. Install the dependencies
bun install
  1. Copy the .dev.example.vars to .dev.vars
cp .dev.example.vars .dev.vars
  1. Generate UPSTASH_REDIS_REST_TOKEN using openssl rand -hex 32 and copy it to your .dev.vars file

  2. Run database locally

docker-compose up -d
  1. Run the database migration
bun run migrate:apply
  1. Sync the data and populate it into your local database (once only as you needed)
# Please do this in order
# 1. Sync station data and wait until it's done
bun run sync:station
# 2. Sync schedule data
bun run sync:schedule

Deployment

  1. Rename the wrand.example.toml to wrangler.toml and fill the necessary information

  2. Create a new PostgreSQL database in Neon and copy the connection string value as DATABASE_URL in your .production.vars file

  3. Run the database migration

bun run migrate:apply
  1. Sync the data and populate it into your remote database (once only as you needed)
# Please do this in order
# 1. Sync station data and wait until it's done
bun run sync:station
# 2. Sync schedule data
bun run sync:schedule
  1. Add COMULINE_ENV to your .production.vars file
COMULINE_ENV=production
  1. Create a new Redis database in Upstash and copy the value of UPSTASH_REDIS_REST_TOKEN and UPSTASH_REDIS_REST_URL to your .production.vars file

  2. Save your .production.vars file to your environment variables in your Cloudflare Workers using wrangler

bunx wrangler secret put --env production $(cat .production.vars)
  1. Deploy the API to Cloudflare Workers
bun run deploy

Database schema

TBD

Extension points exported contracts — how you extend this code

BaseResponseSchema (Interface)
(no doc)
src/utils/response.ts
DataResponseSchema (Interface)
(no doc)
src/utils/response.ts
MetadataResponseSchema (Interface)
(no doc)
src/utils/response.ts

Core symbols most depended-on inside this repo

set
called by 7
src/modules/v1/cache.ts
get
called by 6
src/modules/v1/cache.ts
createAPI
called by 5
src/modules/api.ts
buildResponseSchemas
called by 4
src/utils/response.ts
getSecsToMidnight
called by 4
src/utils/time.ts
createStationKey
called by 4
src/sync/station.ts
parseTime
called by 2
src/utils/time.ts
fixName
called by 2
src/sync/schedule.ts

Shape

Function 12
Class 4
Method 4
Interface 3

Languages

TypeScript100%

Modules by API surface

src/utils/response.ts6 symbols
src/modules/v1/cache.ts5 symbols
src/modules/v1/database.ts4 symbols
src/utils/time.ts2 symbols
src/sync/station.ts2 symbols
src/sync/schedule.ts2 symbols
src/modules/api.ts1 symbols
src/db/migrate.ts1 symbols

For agents

$ claude mcp add api \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact