Skip to content
torisKRPublic

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

34 Commits

Folders and files

Repository files navigation

K-Notice

Turn Korean notices into clear actions. — knotice.pages.dev

K-Notice helps foreign residents in Korea understand Korean life notices from schools, apartments, hospitals, and public offices. When users paste text or upload a photo, K-Notice converts it into an action plan rather than a literal translation: plain explanation → required actions → deadlines → fees → items to bring → source evidence → local mobile reminders.

Scope and behavior are defined by PRODUCT.md, and visual direction is defined by DESIGN.md. For what is included and excluded, read PRODUCT.md first.

Current status: Web is the launch product (live). Mobile (Flutter, Android-first) is implemented and launch-ready.

System overview

Area Stack Status
Web (web/) Astro static site → Cloudflare Pages ✅ Live
Web API (edge/) Cloudflare Worker + D1 + Workers AI ✅ Live
Mobile (apps/mobile/) Flutter, on-device OCR (ML Kit), local notifications 🟡 Pending release
Server pipeline (apps/api/, infra/) NestJS + codex exec, PostgreSQL, Caddy, AWS EC2 (Seoul) ✅ Deployed, private

Web analysis uses Workers AI, while mobile uses the Codex pipeline for higher-quality analysis. Both pipelines enforce evidence verification against source text.


OpenAI Build Week — Codex + GPT-5.6

K-Notice was built during OpenAI Build Week with Codex as the primary engineering agent and GPT-5.6 as the reasoning model in the high-quality notice-analysis workflow.

  • Codex as the builder: Codex implemented the product scope into the Astro web demo, Flutter mobile app, NestJS analysis API, PostgreSQL job queue, JSON Schema, evidence validator, CI/configuration work, and final demo assets.
  • GPT-5.6 as the reasoner: The mobile/premium path sends OCR-recognized Korean text to codex exec, where GPT-5.6 extracts required actions, deadlines, fees, items, events, uncertainties, and a ready Korean inquiry message.
  • Evidence-grounded output: Every generated item must include an exact sentence fragment from the source notice. The server validates model output against JSON Schema and removes any item whose evidence cannot be found in the source.
  • Privacy and isolation: The model receives only recognized text, not the original photo. Codex runs in an ephemeral, read-only sandbox with minimal environment variables and no inherited app secrets.
  • Model configuration: For the Build Week submission, Codex used GPT-5.6 via authenticated Codex runtime. Model selection is intentionally not stored in source credentials or deployment config.

Key implementation links:

Server pipeline (mobile path: apps/api + infra)

This documents the NestJS + Codex backend pipeline. It was originally authored for Oracle A1 and is currently deployed with the same architecture on AWS EC2 (t4g, Seoul) using scripts/deploy.sh.

Architecture

Flutter App (on-device OCR, local notifications)
   │ HTTPS
   ▼
Caddy (TLS, reverse proxy)
   │
   ▼
NestJS API ──spawn──▶ codex exec (read-only, ephemeral, schema-enforced)
   │
   ▼
PostgreSQL 16 (job queue FOR UPDATE SKIP LOCKED, analysis results)

Core design:

  • On-device OCR — only recognized text is sent to the server, minimizing privacy risk.
  • Async analysis — POST /v1/analyses returns 202 + analysisId, then poll at 1.5–2 second intervals.
  • PostgreSQL job queue — no Redis required; uses FOR UPDATE SKIP LOCKED, with one active Codex execution at a time.
  • Isolated Codex execution — --sandbox read-only --ephemeral --ignore-user-config, empty temp directory, minimal environment, stdin prompt delivery (no shell composition), 90s timeout.
  • Output validation — --output-schema plus server-side Ajv re-check and evidence matching; unmatched items are removed and returned as warnings.
  • Local reminders — no server push; reminders are scheduled on-device after users confirm dates.
  • AI abstraction — NoticeAnalyzer interface (CodexCliNoticeAnalyzer / MockNoticeAnalyzer); production transition only requires DI replacement.

Repository structure

knotice/
├── apps/
│   ├── api/            # NestJS API + worker + Codex runner
│   │   ├── src/
│   │   │   ├── analyses/   # POST/GET/DELETE /v1/analyses
│   │   │   ├── auth/       # installation token issue/verification (POST /v1/installations)
│   │   │   ├── ai/         # NoticeAnalyzer interfaces, validators, mock
│   │   │   ├── codex/      # Codex runner, prompt builder, health
│   │   │   ├── jobs/       # PostgreSQL queue worker
│   │   │   ├── usage/      # usage history
│   │   │   └── health/     # GET /health
│   │   ├── schemas/notice-analysis.schema.json
│   │   └── Dockerfile      # ARM64 image with Codex CLI
│   └── mobile/         # Flutter app (Android-first)
├── infra/              # docker-compose.yml, Caddyfile
├── migrations/         # PostgreSQL schema
├── samples/            # 3 demo notices
└── .env.example

Server runbook (Oracle A1)

# Compose reads only infra/.env in its execution directory.
cp .env.example infra/.env   # only POSTGRES_PASSWORD is required
cd infra
docker compose up -d --build

# verify
docker compose exec api uname -m          # expect aarch64
docker compose exec api codex --version

Codex authentication (device code)

docker compose exec api codex login --device-auth
docker compose exec api codex login status

Auth data is stored in the codex_home named volume (/var/lib/codex) and is not included in the container image. Do not mount this volume to other containers.

For file-based auth storage, use /var/lib/codex/config.toml:

cli_auth_credentials_store = "file"

Local development without Codex

cd apps/api
npm install
NOTICE_ANALYZER=mock DATABASE_URL=postgres://... npm run build && npm start

Set NOTICE_ANALYZER=mock to run the full flow with deterministic mock outputs.

API summary

Method Path Description
POST /v1/installations register installation and issue Bearer token
POST /v1/analyses request analysis → 202 + analysisId
GET /v1/analyses/{id} fetch status (queued/processing/completed/failed)
DELETE /v1/analyses/{id} delete analysis data
GET /health check DB / Codex / queue health

Default limits: queue capacity 20, one active job per device (DB-level atomic enforcement), 10 analyses per device/day, one Codex execution at a time, 90-second timeout, one retry. IP rate limits: 60 req/min on all routes, 5 req/hour for install registration. If the server returns 409 (ANALYSIS_ALREADY_ACTIVE), it includes the in-progress analysisId so clients can continue polling.

Retention policy (auto-clean): OCR source text is deleted after 7 days; full analyses after 30 days (or on user deletion). The worker performs cleanup every hour.

Mobile app runbook

cd apps/mobile
flutter pub get
flutter run --dart-define=KNOTICE_API_BASE=https://api.your-domain.example
  • Default is http://10.0.2.2:3000 for Android emulator.
  • Use Sample notice walkthrough on home screen to demo end-to-end flow without a camera.
  • Resident/alien registration number-like patterns are masked in-app before sending any text.

Security principles (summary)

  • The notice text is never inserted directly into shell commands (spawn, shell: false, stdin delivery).
  • Codex runs with read-only sandbox, empty temp directories, and minimal environment variables.
  • Prompt injection mitigation: notice text is isolated in a <notice_input> data block.
  • ChatGPT-authenticated Codex execution is for hackathon/private testing only. For public production, switch to OpenAiApiNoticeAnalyzer (OpenAI API) by DI; no product behavior change required.

Spec-alignment notes

  • Added notices.result_json (JSONB) to store the full result payload (fees, events, warnings, inquiryMessage) because the original 13-page table schema could not reconstruct GET responses alone.
  • Added error codes ANALYSIS_ALREADY_ACTIVE (409) and DAILY_LIMIT_EXCEEDED (429).
  • Added installation_id to analysis_jobs and enforced “one active job per installation” through a partial unique index.
  • Removed cancelled job status from schema: there is no cancel endpoint today, and deletion cascades remove the job itself.

MVP features intentionally excluded

  • Image crop/rotation (§14.3) is replaced by re-capture.
  • PDF input (§4).
  • Secondary upload flow for low-quality OCR (§5.1) — text analysis only.
  • Re-translation on inquiry-message edits — users can edit/copy only Korean source text.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages