Skip to content

Create countries table in backend with API endpoints #20

Closed

Description

@khaira777

Summary

Create a countries table in the backend database with API endpoints. This moves the countries data from a static frontend list to a backend-driven system.

Part of epic: #18
Blocked by: #19 (Phase 1 — phone input fix)

Scope

  • SQLite migration: create countries table
  • Seed with 31 countries from countries.ts
  • API routes: GET /api/countries, GET /api/countries/:code
  • Update frontend to fetch from API (keep countries.ts as offline fallback)

Schema

CREATE TABLE countries (
  id INTEGER PRIMARY KEY AUTOINCREMENT,
  code TEXT NOT NULL UNIQUE,          -- ISO 3166-1 alpha-2 (e.g., 'IN', 'US')
  name TEXT NOT NULL,                  -- Country name (e.g., 'India')
  dial_code TEXT NOT NULL,             -- International dialing code (e.g., '+91')
  phone_digit_min INTEGER NOT NULL,    -- Minimum phone digits (e.g., 10)
  phone_digit_max INTEGER NOT NULL,    -- Maximum phone digits (e.g., 12)
  phone_placeholder TEXT,              -- Display placeholder (e.g., 'XXXXX XXXXX')
  currency_code TEXT NOT NULL,         -- Currency code (e.g., 'INR')
  currency_symbol TEXT NOT NULL,       -- Currency symbol (e.g., '₹')
  timezone TEXT NOT NULL               -- IANA timezone (e.g., 'Asia/Kolkata')
);

Files Touched

  • main/db.ts (migration)
  • New: main/routes/countries.ts (API routes)
  • main/server.ts (register routes)
  • frontend/src/lib/countries.ts (add API fetch with fallback)

Acceptance Criteria

  • countries table exists with 31 seeded countries
  • GET /api/countries returns all countries
  • GET /api/countries/:code returns a single country
  • Frontend fetches from API, falls back to static list on error
  • Existing frontend code works unchanged (API is additive)

Notes

  • This is a backend-only change — no frontend UI changes needed
  • The static countries.ts remains as offline fallback
  • Future phases will extend this table with more fields

Activity

  1. added
    enhancement
    on Jul 6, 2026
  2. khaira777 commented on Jul 6, 2026

    @khaira777
    ContributorAuthor

    Part of epic #18 — Internationalization

  3. added theissue type on Jul 6, 2026
  4. khaira777 commented on Jul 18, 2026

    @khaira777
    ContributorAuthor

    Closing as won't fix.

    Countries remain a static TypeScript bundle (frontend/src/lib/countries.ts + main/countries.ts), built at import time from libphonenumber-js + Intl.DisplayNames. 35 supported countries with locale, currency, timezone, dial codes.

    Rationale: ISO country data is effectively immutable. A DB table + API endpoint adds latency and maintenance burden with no benefit for a single-tenant cafe POS. Static bundle is faster (zero network calls), type-safe, and trivially updatable via code change.

    Reopen if: multi-tenant admin UI needs to manage supported countries at runtime.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions