single-pages-foundation Specification
Purpose
TBD - created by archiving change bootstrap-single-pages-foundation. Update Purpose after archive.
Requirements
Requirement: Project directories are established
The system SHALL establish workspace/single-pages/front, workspace/single-pages/backend, workspace/single-pages/docs, and workspace/single-pages/openspec as the authoritative project directories for the single-pages project.
Scenario: Project directory boundary exists
-
WHEN a developer inspects the
workspace/single-pagesproject after this change is implemented -
THEN the front-end code is located under
front, the back-end code is located underbackend, project documentation is located underdocs, and project OpenSpec artifacts are located underopenspec
Scenario: Page implementation is not mixed into the foundation
- WHEN this change is completed
- THEN prelearning business behavior and SOP material preview behavior are not implemented as part of this foundation change
Requirement: Front-end foundation supports independent pages
The front-end foundation SHALL use React, TypeScript, Vite, and Tailwind CSS, and SHALL provide a Vite multi-entry structure for independent single-page applications.
Scenario: Front-end stack is verifiable
- WHEN the front-end project is installed and checked
- THEN the project exposes commands to typecheck, test, and build React TypeScript Vite entries with Tailwind CSS enabled
Scenario: Independent page entries can be added
- WHEN a later change adds the prelearning page or SOP material preview page
- THEN the page can be added as an independent Vite entry without sharing business initialization payload or page state with other pages
Requirement: Back-end foundation supports typed Fastify services
The back-end foundation SHALL use Node.js 20 LTS or above, TypeScript, Fastify, Prisma, and MySQL as the service baseline, and SHALL limit service responsibilities to querying, updating, and inserting MySQL database records.
Scenario: Back-end stack is verifiable
- WHEN the back-end project is installed and checked
- THEN the project exposes commands to typecheck, test, and build the TypeScript Fastify service
Scenario: Health endpoint verifies service boot
- WHEN the back-end service starts successfully
- THEN a health check endpoint returns a successful structured response without requiring page-specific business data
Scenario: Back-end responsibility is limited to database access
- WHEN the foundation back-end is implemented
- THEN it provides service and repository boundaries for database query, update, and insert operations
- THEN it does not introduce queue consumers, cache synchronization, third-party API clients, remote notification dispatch, or cross-system orchestration as foundation responsibilities
Requirement: Shared contracts define front-end facing models
The system SHALL provide shared TypeScript contracts for cross-boundary request, response, and error models, and front-end facing models SHALL use camelCase field names.
Scenario: Contracts are shared across front-end and back-end
- WHEN front-end and back-end code reference common request, response, or error shapes
- THEN they import or derive them from the project shared contract layer instead of duplicating incompatible definitions
Scenario: Database field names stay behind the back-end boundary
-
WHEN the back-end reads database fields such as
activity_id,product_type, ordeleted_flag -
THEN the API-facing model exposes stable camelCase fields such as
activityId,productType, ordeletedFlagwhen those values cross into front-end contracts
Requirement: Back-end errors are structured consistently
The back-end foundation SHALL provide a unified structured error response shape for validation errors, business errors, dependency errors, and unexpected errors.
Scenario: Validation error returns structured details
- WHEN a request fails parameter validation
- THEN the response includes a stable error code, human-readable message, and machine-readable details sufficient for front-end failure states
Scenario: Unexpected error does not leak internals
- WHEN an unexpected server error occurs
- THEN the response uses the unified error shape without exposing stack traces or database internals to the client
Requirement: Configuration is centralized and environment driven
The system SHALL provide centralized configuration loading for front-end and back-end runtime values, including page entry configuration, API base URL, database connection configuration, and future deployment-specific allowlists.
Scenario: Missing required back-end configuration fails fast
- WHEN a required back-end configuration value is missing at service startup
- THEN the service fails fast with a structured startup error instead of booting with an invalid partial configuration
Scenario: Page-specific configuration remains page-scoped
-
WHEN a later page change defines APP bridge or SOP
postMessageconfiguration - THEN the configuration is added under the page-specific module while reusing the centralized configuration loader
Scenario: Deployed front-end routes API requests through backend prefix
-
WHEN the single-pages front-end runs on a non-local host such as
single-pages.test.glsx.com.cn -
THEN front-end calls to same-origin back-end API paths MUST use the
/backendprefix before/api -
AND a request for
/api/prelearning/initMUST be sent as/backend/api/prelearning/init -
AND a request for
/api/sop-material-previewMUST be sent as/backend/api/sop-material-preview
Scenario: Local front-end runtime keeps unprefixed API requests
-
WHEN the single-pages front-end runs on local development hosts such as
localhost,127.0.0.1, or a private LAN IP -
THEN front-end calls to same-origin back-end API paths MUST NOT add the
/backendprefix -
AND local requests MUST continue to use
/api/...so the existing Vite proxy remains valid
Scenario: API base path can be explicitly overridden
- WHEN a deployment provides an explicit front-end API base path configuration
- THEN the front-end MUST use that configured base path instead of the hostname default
- AND an explicitly empty base path MUST keep requests unprefixed
Requirement: Prisma lifecycle is managed by the Fastify service
The back-end foundation SHALL manage Prisma Client lifecycle through a Fastify plugin or equivalent service-level integration.
Scenario: Prisma client is created once per service lifecycle
- WHEN the back-end service boots
- THEN the Prisma Client is initialized through the service lifecycle instead of being recreated inside individual route handlers
Scenario: Service shutdown closes database connections
- WHEN the back-end service shuts down
- THEN the Prisma Client disconnect hook runs through the service lifecycle
Requirement: Foundation verification commands are available
The project SHALL provide documented verification commands for the foundation, including type checking, unit tests, and build checks for the front-end and back-end.
Scenario: Verification commands run from documented locations
- WHEN a developer follows the project documentation for foundation verification
- THEN the documented commands can be run from the expected project directories and cover front-end and back-end foundation checks
Scenario: Later changes can extend verification
- WHEN a later fixed change adds page-specific behavior, whether or not OpenSpec is selected
- THEN that change can add page-specific tests without replacing the foundation verification commands
Requirement: Back-end startup commands are standardized
The system SHALL provide separate npm commands for standard back-end startup and watch-mode development startup in workspace/single-pages/backend.
Scenario: Standard startup command is available
- WHEN a developer needs to start the single-pages back-end without watch mode
-
THEN the back-end project MUST provide
npm start -
AND
npm startMUST start the existing service entrypoint successfully without requiring code changes
Scenario: Development watch command remains available
- WHEN a developer needs local hot-reload development for the single-pages back-end
-
THEN the back-end project MUST continue to provide
npm run dev -
AND
npm run devMUST remain the watch-mode development command