Skip to content

Architecture

System Overview

Find a Doc is three apps in one monorepo, sharing the types generated from one GraphQL schema:

┌─────────────────┐     GraphQL     ┌──────────────────┐     SQL      ┌─────────────────┐
│    apps/web     │ ◄─────────────► │   apps/server    │ ◄──────────► │  Amazon RDS     │
│  (Nuxt 4 site)  │                 │ (Apollo GraphQL) │              │  (PostgreSQL)   │
└─────────────────┘                 └──────────────────┘              └─────────────────┘
                                             ▲
                                             │ GraphQL
                                    ┌────────┴─────────┐
                                    │    apps/mcp      │ ◄── MCP / REST ── AI assistants
                                    │   (MCP server)   │
                                    └──────────────────┘

Website (apps/web)

  • Framework: Nuxt 4, prerendered with nuxi generate and hosted on AWS Amplify
  • UI: Vue 3 Composition API with Tailwind CSS
  • State: Pinia stores for UI state only (filters, modals, unsaved edits)
  • Server data: TanStack Query (@tanstack/vue-query). See Fetching data in the web app
  • API: GraphQL via graphql-request
  • Auth: Auth0 (used for the moderation dashboard)
  • Maps: Google Maps API for provider locations
  • i18n: Nuxt i18n supporting 13 languages. Clinic and doctor pages are prerendered in English and Japanese. Hub and facet pages are prerendered in English, Japanese, Chinese, Vietnamese, and Korean (HUB_PRERENDER_LOCALE_CODES in apps/web/utils/localePath.ts)
  • Clinic landings: a hosted page is a clinic_sites row. That id is what an account (clinic_memberships) and a future CRM attach to. The showcase directory facility is c32c316a-a368-499b-abaf-c5c973cb67e5. The seed leaves that row unresolved, because the page has no municipality. The address to share is https://{slug}.findadoc.jp/. That host opens the clinic at /. Book always opens the Find a Doc surface at /book/{facilityId} (a clinic hostname /book redirects there). The same URL works for a directory clinic with no hosted page. Find a Doc owns the intake fields. The clinic owns allowed visit lengths (15, 30, 45, or 60 minutes), weekly hours in Japan time, extra open windows, and closures. Optional query params are duration, start, practitioner, form, and service. Submissions store answers, S3 (or local) uploads, and a SES notify when configured. Open starts are weekly hours plus painted extra windows, minus closures and held appointments (apps/server/docs/booking-access.md). Staff set weekly hours in Settings and close days or blocks on a FullCalendar editor, for the whole clinic or one doctor; each doctor with their own hours is booked separately. Patients filter by language, pick a doctor or any doctor, and pick a start that fits the chosen duration. Starts are every 15 minutes when the clinic offers a 15- or 45-minute visit, and every 30 minutes from each doctor's start time otherwise (slotStepMinutes); the API refuses a start off that grid. My-page lists booking submissions read-only (no answer editing). Identity / insurance uploads get a short retain_until, and the findadoc-booking-purge Lambda deletes them once a day. The same Lambda erases booking answers 90 days after the visit, and a cancel or decline erases them at once. It clears a cancel or decline note 90 days after the visit or the status change, whichever is first — see apps/server/docs/booking-retention.md. It also clears submission notes (submissions.notes) 180 days after a moderator decides, or 365 days after submit when nobody does, and keeps notes out of the audit log — see apps/server/docs/submission-retention.md. The booking form, open slots, upload, and submit need no sign-in, but the Book page sits behind the same ?preview=1 cookie as the clinic landings while CLINIC_LANDING_MODE is preview: without it /book/{facilityId} is a 404, and the directory clinic page adds its Book button in the browser only, so it is never in the prerendered HTML. The patient's /book/manage link is not gated. The staff booking list and the availability calendar require a signed-in session. The clinic landing has no Find a Doc header, only the Find a Doc “Powered by” footer. The canonical clinic URL is the subdomain. DNS stays in Route 53. ?preview=1 sets a cookie. Without it the page is a 404, stays noindex, and stays out of the sitemap. There is no environment variable. The clinic breadcrumb, /clinic/{slug}, and /clinic/{prefecture}/{city}/{slug}--{id} redirect to it. The link preview uses the clinic’s icon. A stored theme primary recolors that page’s header and buttons. The same clinic_sites.theme jsonb holds the clinic branding: displayName, wordmark (ja and en), and logoPath (a static path, like hero_path; there is no logo upload). BookingForm, BookingClinic, and PatientBookingView return it as branding, which is null without a non-draft clinic site. /book/{facilityId}, /book/manage, and /clinic-dashboard/{facilityId} use the clinic-branded layout: the clinic logo or wordmark in the header, its colour, and the “Powered by” footer. It falls back to the Find a Doc header and footer while the page loads and when branding is null. Each clinic chooses its page languages: the page exists only in the site locales that have a clinic_site_locales row. Its language switcher, generated HTML, sitemap rows, and hreflang list only those, and any other locale redirects to English.

API (apps/server)

  • Runtime: Node.js with TypeScript
  • API: Apollo Server on Fastify
  • Schema: apps/server/src/typeDefs/schema.graphql, the only GraphQL schema in the repo
  • Database: Amazon RDS for PostgreSQL in Tokyo, with migrations in apps/server/supabase/migrations applied on every deploy. The API queries it with Kysely
  • Production: AWS Lambda behind CloudFront at api.findadoc.jp, deployed with the CDK app in infra/
  • Caching: apps/server/src/publicCache.ts sets Cache-Control on every response (#242). A response is public, max-age=60 only when the caller sent no token, every root field is on PUBLIC_CACHEABLE_QUERY_FIELDS, and nothing failed. Everything else is private, no-store. Add a field to that list only when its answer is the same for every signed-out visitor: it reads no user, IP, country, token, or rate limit. Booking, upload, moderation, and user fields never go there. __tests__/publicCache.test.ts checks the list
  • CSRF: Apollo's built-in check is off and csrfPreventionPlugin keeps its rule. A request without a preflight (a form post, or a GET with no x-apollo-operation-name header) may only run a query on the public list, so a public read can be a plain, cacheable GET
  • Lookup tables: prefecture and city lists stay in Lambda memory for 10 minutes (src/lookupCache.ts)
  • Filter vocabulary: specialties, specialtyCategories, and languages return the specialty, category, and language codes with English and Japanese labels (#24). Clients read them instead of introspecting the schema. languages returns only the search facets unless publishedOnly is false. The labels and the category map live in packages/utils, so these queries read no database and are on the public list
  • Edge: the API's CloudFront distribution caches a GET only when the API marked it public (infra/lib/functionUrlEdge.ts, cachePublicReads). The cache key is the query string, Origin, and Authorization. Error responses are never cached. POST, OPTIONS, booking, and signed-in reads always reach the API. The MCP server sends its reads as GET, so they share the cache

MCP Server (apps/mcp)

  • Protocol: Model Context Protocol over Streamable HTTP and STDIO
  • Purpose: Exposes healthcare provider data to AI assistants, and the same tools as REST endpoints

Shared Packages

Package Purpose
packages/graphql @findadoc/graphql, TypeScript types generated from the schema. Regenerate with pnpm generate
packages/utils @findadoc/utils, checks, helpers, and the specialty and language vocabulary shared by the site and the API
packages/tsconfig Shared TypeScript config

Website Directory Structure

Directory Purpose
apps/web/components/ Reusable Vue components
apps/web/pages/ Route pages (auto-registered by Nuxt)
apps/web/stores/ Pinia stores (UI state)
apps/web/i18n/locales/ Translation files, checked against en.json
apps/web/assets/ Uncompiled assets (CSS, images, fonts)
apps/web/typedefs/ TypeScript type definitions
apps/web/public/ Static files served at root (e.g., robots.txt)

Data Flow

  1. Users search for healthcare providers on findadoc.jp
  2. The website sends GraphQL queries to the API
  3. The API resolves queries against the PostgreSQL database on Amazon RDS
  4. Results are returned and displayed on an interactive map with provider details

Fetching data in the web app

The web app is moving its reads to TanStack Query (#242). The search page uses it now. Other pages still load data in their Pinia stores until they move over.

  • A read is a useQuery in a composable, such as apps/web/composables/useSearchDirectory.ts. Its queryFn calls requestQueryData in apps/web/utils/queryClient.ts, which sends the request through graphQLClientRequestWithRetry and passes vue-query's abort signal. A page that is gone cancels its requests.
  • Build keys with apps/web/utils/queryKeys.ts. Do not write a key array in a component. A write invalidates the keys it changes.
  • The defaults are in createAppQueryClient. A query is retried once, and only after a timeout, a dropped connection, or a 502/503/504. A mutation is never retried.
  • Directory reads stay fresh for 5 minutes (DIRECTORY_STALE_TIME_MS). Every other read is stale at once, so moderation and booking always ask the server again.
  • Sign-out clears the whole cache. Server data stays in memory. It is never written to localStorage or sessionStorage.
  • Reads run in the browser only. A prerendered page ships its loading state, then loads.
  • nuxi generate writes the directory it already fetched to /_directory/search.json, only when it got every page. /search puts that file in the query cache with the build's time, unless the API answered first, and the API answer replaces it. Results show without waiting for the API, and they still show when the API is down. Change the file's shape and you bump SEARCH_DIRECTORY_SNAPSHOT_VERSION in apps/web/utils/searchDirectorySnapshot.ts.
  • A read on the API's public list (PUBLIC_CACHEABLE_QUERY_FIELDS) goes through publicReadRequest() in apps/web/utils/graphql.ts, or publicRead: true for requestQueryData. In the browser that is a GET with no token and no custom header, which CloudFront and the browser may cache for 60 seconds. A prerender keeps POST, so generated HTML is built from fresh data. Any other operation sent this way is refused by the API.

Further Reading

Rules that the code follows live next to it in the monorepo:

  • AGENTS.md: notes for contributors and coding agents across the whole repo
  • apps/server/docs/city-rules.md: how search cities are named
  • apps/server/docs/places-storage.md: what Google Places data may be stored