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 generateand 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_CODESinapps/web/utils/localePath.ts) - Clinic landings: a hosted page is a
clinic_sitesrow. That id is what an account (clinic_memberships) and a future CRM attach to. The showcase directory facility isc32c316a-a368-499b-abaf-c5c973cb67e5. The seed leaves that row unresolved, because the page has no municipality. The address to share ishttps://{slug}.findadoc.jp/. That host opens the clinic at/. Book always opens the Find a Doc surface at/book/{facilityId}(a clinic hostname/bookredirects 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 areduration,start,practitioner,form, andservice. 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 shortretain_until, and thefindadoc-booking-purgeLambda 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 — seeapps/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 — seeapps/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=1cookie as the clinic landings whileCLINIC_LANDING_MODEispreview: 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/managelink 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=1sets 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 sameclinic_sites.themejsonb holds the clinic branding:displayName,wordmark(jaanden), andlogoPath(a static path, likehero_path; there is no logo upload).BookingForm,BookingClinic, andPatientBookingViewreturn it asbranding, which is null without a non-draft clinic site./book/{facilityId},/book/manage, and/clinic-dashboard/{facilityId}use theclinic-brandedlayout: 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 whenbrandingis null. Each clinic chooses its page languages: the page exists only in the site locales that have aclinic_site_localesrow. 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/migrationsapplied on every deploy. The API queries it with Kysely - Production: AWS Lambda behind CloudFront at
api.findadoc.jp, deployed with the CDK app ininfra/ - Caching:
apps/server/src/publicCache.tssetsCache-Controlon every response (#242). A response ispublic, max-age=60only when the caller sent no token, every root field is onPUBLIC_CACHEABLE_QUERY_FIELDS, and nothing failed. Everything else isprivate, 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.tschecks the list - CSRF: Apollo's built-in check is off and
csrfPreventionPluginkeeps its rule. A request without a preflight (a form post, or a GET with nox-apollo-operation-nameheader) 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, andlanguagesreturn the specialty, category, and language codes with English and Japanese labels (#24). Clients read them instead of introspecting the schema.languagesreturns only the search facets unlesspublishedOnlyis false. The labels and the category map live inpackages/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, andAuthorization. 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
- Users search for healthcare providers on findadoc.jp
- The website sends GraphQL queries to the API
- The API resolves queries against the PostgreSQL database on Amazon RDS
- 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
useQueryin a composable, such asapps/web/composables/useSearchDirectory.ts. ItsqueryFncallsrequestQueryDatainapps/web/utils/queryClient.ts, which sends the request throughgraphQLClientRequestWithRetryand 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
localStorageorsessionStorage. - Reads run in the browser only. A prerendered page ships its loading state, then loads.
nuxi generatewrites 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 bumpSEARCH_DIRECTORY_SNAPSHOT_VERSIONinapps/web/utils/searchDirectorySnapshot.ts.- A read on the API's public list (
PUBLIC_CACHEABLE_QUERY_FIELDS) goes throughpublicReadRequest()inapps/web/utils/graphql.ts, orpublicRead: trueforrequestQueryData. 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 repoapps/server/docs/city-rules.md: how search cities are namedapps/server/docs/places-storage.md: what Google Places data may be stored