|
1 | 1 | --- |
2 | | -title: Setting up and working on the Submit Service |
| 2 | +title: Working on the Submit Service |
3 | 3 | --- |
4 | 4 |
|
5 | | -### Architecture |
6 | | -- Runs on [Datasette](datasette.planning.data.gov.uk) currently for all data queries,with an interest to move all queries to pipeline API / platform API for speed and cost savings. |
7 | | -- All requests are made to the async service, can be run locally or with the docker file. |
| 5 | +## How the app is wired |
| 6 | +- The service is a Node + Express app, started from `index.js`. |
| 7 | +- App setup is split into small “setup” modules (middleware, routes, templating, session, error handling). |
| 8 | +- Runtime config comes from `config/` based on `NODE_ENV` (with `.env` overrides via `dotenv`). |
| 9 | +- All requests are sent to the [async service](https://github.com/digital-land/async-request-backend), this can be run locally or with the docker file. This actual 'computation' happens in this service with the idea that no business logic other than UI is done on this service. |
8 | 10 |
|
9 | | -### Important Links |
| 11 | +## Middleware structure (how routes work) |
| 12 | +- Most pages are built as **middleware chains**: small, focused middleware functions composed in order. |
| 13 | +- Common responsibilities are split up (validate inputs → fetch data → transform into template params → render). |
| 14 | +- Shared helpers live in `src/middleware/common.middleware.js` and the “builder” helpers live in `src/middleware/middleware.builders.js`. |
| 15 | + |
| 16 | +## Datasette |
| 17 | +- The service reads most of its data by querying [**Datasette**](datasette.planning.data.gov.uk). |
| 18 | +- Some queries are dataset-scoped (e.g. `digital-land`, `performance`), and a small set of reads use a platform API instead of SQL. |
| 19 | +- There is a interest to move all queries to (pipeline API)[https://github.com/digital-land/pipeline-internal-api] / or use the main platform API for speed and cost savings. |
| 20 | + |
| 21 | +## Data Storage |
| 22 | +- **Sessions**: User journey state (including HMPO wizard state) is stored in the Express session. When Redis is configured and available, sessions are persisted in Redis; otherwise the app falls back to an in-memory session store. |
| 23 | +- **Redis-backed caches (performance)**: Redis is also used to cache a few “reference lists” to reduce repeat work and expensive queries. |
| 24 | + - Organisation list for the organisations page: cached for **6 hours**. |
| 25 | + - Dataset subject map (the grouped dataset list shown in the UI): cached with a shorter TTL in `local`/`development` and a longer TTL in other environments (currently **~1 minute** locally vs **~1 hour** elsewhere). |
| 26 | +- **What’s stored**: These caches store non-sensitive, derived data (lists/mappings) rather than uploaded files. |
| 27 | +- **Failure mode**: If Redis is unavailable, the service will still run, but will rebuild these lists more often (slower page loads, more upstream calls). |
| 28 | + |
| 29 | +## HMPO form wizard (multi-step journeys) |
| 30 | +- Multi-page flows use `hmpo-form-wizard`. |
| 31 | +- There are two main wizards: |
| 32 | + - `/check` (the check tool) |
| 33 | + - `/submit` (endpoint submission form; typically feature-flagged) |
| 34 | +- Each wizard is defined by: |
| 35 | + - `steps.js` (the journey / routing between steps) |
| 36 | + - `fields.js` (field validation rules) |
| 37 | + - controllers for step-specific behaviour and session-backed state |
| 38 | + |
| 39 | +## Important Links |
10 | 40 | - [Architecture Diagrams](/architecture-and-infrastructure/solution-design/check-service/) |
11 | | -- [Debugging Async Service](/development/live-service/debugging-live-services/) |
| 41 | +- [Debugging Async Service](/development/live-service/debugging-live-services/) Important to know how to use the Async service as well for this service, Postman is useful for checking what data is being sent between the services. |
0 commit comments