Documentation server APIs and notes
The documentation application's server side supplies small data APIs beside the rendered Angular pages. Nitro exposes a GitHub repository summary and a tRPC endpoint. The tRPC endpoint gives the app a typed path to a PostgreSQL-backed notes store.
Server API surface
The server API surface has two roles. A direct Nitro route supplies public repository data for the site header. A catch-all tRPC route dispatches typed procedure calls for application data.
Nitro route boundary
Nitro maps files under the server routes area to HTTP endpoints. The GitHub route is available at /api/github-info, while the [trpc] route accepts procedure paths below /api/trpc. This keeps simple read-only site data separate from the grouped tRPC API.
References: apps/…/github-info.ts• L25-45 apps/…/[trpc].ts• L1-8 apps/…/nitro.config.ts• L91-93
Client connections
The Angular app registers one tRPC client at /api/trpc and uses the same data transformer on both sides. The app configuration provides that client during browser and server application setup. Direct HTTP resources use the GitHub path when the header needs the current star count.
The request path can be viewed as two related flows:
flowchart LR
Header[Documentation header] -->|GET /api/github-info| GitHub[Nitro GitHub route]
GitHub -->|cached repository summary| Header
Angular[Angular app] -->|tRPC call /api/trpc/...| Handler[Nitro tRPC route]
Handler --> Router[Application router]
Router --> Notes[Notes procedures]
Notes --> Database[(PostgreSQL note table)]
References: apps/…/trpc-client.ts• L1-14 apps/…/app.config.ts• L10-22 apps/…/header.ts• L121-129
tRPC request flow
tRPC provides the typed procedure boundary for application data. The documentation app builds one application router and passes it to a Nitro adapter, which turns an HTTP request into a tRPC request and returns the procedure result.
Request context
The tRPC context is the request-scoped value available to procedures. The current context is empty, so procedures do not receive a user or other request service from it. The context function still provides the extension point for future request data.
References: apps/…/context.ts• L1-7
Procedure foundation
The tRPC foundation creates the router and procedure builders for the app and uses SuperJSON as the data transformer. The current notes procedures use the public procedure builder, so the foundation does not add an authentication gate to them.
References: apps/…/trpc.ts• L1-13 apps/…/notes.ts• L4-7
Router assembly
The application router is the public tRPC contract for this app. It currently exposes the notes router under the note namespace, and its inferred type is shared with the Angular client so client calls follow the server router shape.
References: apps/…/index.ts• L1-8 apps/…/trpc-client.ts• L1-10
Nitro dispatch
The Nitro adapter reads the procedure path from the route parameter and passes the request method, headers, query, and body to tRPC. It creates the configured context before resolving the procedure, then applies the tRPC response status and headers to the Nitro response. A missing route parameter is treated as a server configuration error.
The server-side tRPC path follows this sequence:
sequenceDiagram
participant Client as Angular tRPC client
participant Nitro as Nitro [trpc] route
participant Adapter as tRPC Nitro adapter
participant Router as Application router
participant Context as Request context
participant Notes as Notes router
Client->>Nitro: Request procedure path
Nitro->>Adapter: Forward HTTP request
Adapter->>Context: Create context
Context-->>Adapter: Empty request context
Adapter->>Router: Resolve procedure
Router->>Notes: Select note procedure
Notes-->>Adapter: Procedure result
Adapter-->>Client: tRPC response
References: apps/…/[trpc].ts• L1-8 libs/…/server.ts• L51-63 libs/…/server.ts• L65-127
Database integration
The database layer gives server procedures a shared PostgreSQL connection and a typed description of the note table. Drizzle maps the table shape to database operations, while the DATABASE_URL value selects the database at runtime.
References: apps/…/db.ts• L1-17
Note data model
The note record has a generated numeric identifier, a required title, optional content, and a creation timestamp with a database default. The database module also exports types for rows read from the table and values used to create rows.
References: apps/…/db.ts• L6-14
Schema setup
Drizzle Kit uses the same database module as its schema source and targets PostgreSQL. The repository's installation guide presents the table creation as an explicit database step and documents both managed Supabase and local Supabase connection paths. This means a running app needs a reachable PostgreSQL database whose note table matches the shared schema.
References: apps/…/drizzle.config.ts• L1-12 apps/…/installation.page.ts• L226-253 apps/…/installation.page.ts• L358-375
GitHub information endpoint
The GitHub endpoint turns repository metadata into a small response for the documentation header. In development it returns stable local placeholder data. In other environments it reads the Spartan repository from GitHub and exposes only the fields the header needs. References: apps/…/github-info.ts• L25-45, apps/…/header.ts• L121-129
Repository lookup
The route requests spartan-ng/spartan from the GitHub API and maps the repository response to its name, full name, description, star count, URL, and fetch time. A failed GitHub response raises an API error instead of returning a partial result.
References: apps/…/github-info.ts• L6-22 apps/…/github-info.ts• L36-44
Cache behavior
The route keeps fetched repository data in process memory for one day. Nitro also declares a one-day cache rule for the public path. These two layers reduce repeated GitHub requests, but neither represents durable application state.
References: apps/…/github-info.ts• L3-4 apps/…/github-info.ts• L8-20 apps/…/nitro.config.ts• L91-93
Persisted notes
The notes feature demonstrates a complete public data flow from a typed tRPC procedure to PostgreSQL. It supports creating notes, reading the note list, and removing a note by identifier. The procedures are public, so the current server does not apply an access check before these operations. References: apps/…/notes.ts• L6-28
Note procedures
The note router groups three operations under the application router:
| Procedure | Role | Input and result |
|---|---|---|
create | Adds a note to the database | A title and content object. Returns inserted rows. |
list | Reads the stored notes | No input. Returns notes with numeric identifiers. |
remove | Deletes one stored note | A numeric identifier. Returns deleted rows. |
Each input object is checked with Zod before the database action runs. The list operation converts the database identifier to a number for the client-facing result.
References: apps/…/notes.ts• L1-4 apps/…/notes.ts• L6-28
Persistence lifecycle
When a client changes notes, the request crosses the tRPC route and reaches the notes router. The router validates the input, asks Drizzle to write or read the note table, and returns the database result through the typed client boundary. References: apps/…/notes.ts• L6-28, apps/…/[trpc].ts• L1-8
flowchart TD
A[Client note action] --> B[Public tRPC procedure]
B --> C{Input valid?}
C -->|no| D[Validation error]
C -->|yes| E[Drizzle database action]
E --> F[(PostgreSQL note table)]
F --> G[Typed procedure result]
G --> H[Client note state]
The documentation application also teaches this persistence pattern in its installation page. That page explains the move from in-memory note data to a Drizzle schema and a PostgreSQL service, so it is a product-facing guide to the same server concepts rather than a second runtime path.
References: apps/…/installation.page.ts• L102-107 apps/…/installation.page.ts• L155-181 apps/…/installation.page.ts• L220-223
Related documentation
The documentation application gives the parent-level view of the Angular and Nitro site. The content rendering and navigation page covers the page-facing side of the app. The Angular tRPC integration page explains the shared client and server adapter in more detail.
Change checklist
When these files or sections are changed, remember to consider these:
- Keep the
AppRoutertype and the Angular tRPC client aligned when the router namespace or procedure contract changes. - Keep the Nitro route path, client URL, and route parameter name aligned when the tRPC endpoint moves.
- Keep the Drizzle table schema, explicit database setup, and note procedure fields aligned when note columns change.
- Recheck both the in-process GitHub cache and Nitro route cache when the freshness period or response shape changes.
- Reassess access control when a procedure changes from public data to user-owned data.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
DATABASE_URL is missing or points to an unavailable PostgreSQL service | Note procedures fail when they try to use the database | Provide a valid database connection and create the note table before using the feature. |
The database note table does not match db.ts | Inserts, reads, or deletes fail at the database boundary | Change the schema and database setup together. |
| A tRPC request does not include the expected route parameter | The Nitro adapter returns a server configuration error | Keep the catch-all route name and tRPC URL contract intact. |
| GitHub returns a non-success response | The GitHub information request raises an error and the header has no fresh repository data | Keep the endpoint available and review cache behavior when GitHub access changes. |
| A note input fails its Zod shape | The database action does not run and the caller receives a validation error | Send a title and content for creation, or a numeric id for removal. |
Key files
| File | Why to read it |
|---|---|
| apps/…/[trpc].ts | Shows the documentation app's tRPC HTTP entry point. |
| apps/…/context.ts | Defines the request context available to server procedures. |
| apps/…/index.ts | Shows how the app's tRPC contract is assembled. |
| apps/…/notes.ts | Shows the persisted notes capability and its public procedures. |
| apps/…/db.ts | Defines the shared note schema, database client, and data types. |
| apps/…/github-info.ts | Shows the GitHub metadata route and its cache behavior. |
| apps/…/nitro.config.ts | Defines the public GitHub route cache rule. |
| apps/…/trpc-client.ts | Connects the Angular client to the server router contract. |
| apps/…/trpc.ts | Defines the shared tRPC router, procedure, and data-transform rules. |
| libs/…/server.ts | Shows the shared adapter that translates Nitro requests into tRPC responses. |
| apps/…/installation.page.ts | Explains the documented Drizzle, Supabase, and note persistence setup. |