-
Notifications
You must be signed in to change notification settings - Fork 0
feat(lfx): scaffold angular 20 ssr app with express server #338
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
asithade
wants to merge
8
commits into
main
Choose a base branch
from
feat/lfx-self-serve
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
2b9918f
feat(lfx): scaffold Angular 20 SSR app with Express server
asithade c58fe5c
build(lfx): complete phase 1 and phase 2 remaining items
asithade 35fbd48
feat(lfx): add design system components, Storybook, and skill routing
asithade 69c472c
fix(lfx): address PR review comments
asithade e70aaea
fix(lfx): revert compression to require for type compatibility
asithade b86ec95
Merge branch 'main' into feat/lfx-self-serve
asithade 34988e5
fix(lfx): address PR review comments from automated reviewers
asithade f3d0310
Merge branch 'main' into feat/lfx-self-serve
asithade File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,196 @@ | ||
| --- | ||
| name: lfx-backend-builder | ||
| description: > | ||
| Generate Express proxy code for apps/lfx — services, controllers, routes, and | ||
| shared TypeScript types. Encodes the controller-service-route pattern, logger | ||
| service usage, MicroserviceProxyService conventions, and shared package structure. | ||
| allowed-tools: Bash, Read, Write, Edit, Glob, Grep, AskUserQuestion | ||
| --- | ||
|
|
||
| <!-- Copyright The Linux Foundation and each contributor to LFX. --> | ||
| <!-- SPDX-License-Identifier: MIT --> | ||
|
|
||
| # LFX Backend Code Generation | ||
|
|
||
| You generate Express proxy code and shared TypeScript types for `apps/lfx`. This skill handles the backend layer — the thin proxy between the Angular frontend and the upstream Go microservices. | ||
|
|
||
| **Prerequisites:** The upstream API contract must be validated before generating proxy code. No mock data, no placeholder responses. | ||
|
|
||
| ## Input Validation | ||
|
|
||
| | Required | If Missing | | ||
| | ---------------------------------------------------- | ---------------------------------------- | | ||
| | Specific task (what to build/modify) | Stop and ask | | ||
| | Absolute repo path | Stop and ask | | ||
| | Upstream API endpoint (path, method, response shape) | Stop — cannot build a proxy without this | | ||
|
|
||
| **If invoked with a `FIX:` prefix**, read the error, find the file, apply the fix, re-validate. | ||
|
|
||
| ## Read Before Generating — MANDATORY | ||
|
|
||
| 1. **Read the target file** (if modifying) | ||
| 2. **Read an existing example** in the same domain | ||
| 3. **Read the relevant interface file** in `packages/shared/src/interfaces/` | ||
|
|
||
| ```bash | ||
| ls apps/lfx/src/server/services/ | ||
| ls apps/lfx/src/server/controllers/ | ||
| ls packages/shared/src/interfaces/ | ||
| ``` | ||
|
|
||
| ## Build Order | ||
|
|
||
| **Strict order — do not skip ahead:** | ||
|
|
||
| ```text | ||
| Shared Types → Service → Controller → Route | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ### 1. Shared Types (`packages/shared/src/interfaces/<name>.interface.ts`) | ||
|
|
||
| ```typescript | ||
| // Copyright The Linux Foundation and each contributor to LFX. | ||
| // SPDX-License-Identifier: MIT | ||
|
|
||
| export interface MyItem { | ||
| uid: string; | ||
| name: string; | ||
| description?: string; | ||
| created_at: string; | ||
| } | ||
| ``` | ||
|
|
||
| - License header required | ||
| - `interface` for object shapes, `type` for literal unions | ||
| - `as const` for constant objects | ||
| - Export from barrel `index.ts` in the same directory | ||
| - File suffixes: `.interface.ts`, `.enum.ts`, `.constants.ts` | ||
|
|
||
| --- | ||
|
|
||
| ### 2. Service (`apps/lfx/src/server/services/<name>.service.ts`) | ||
|
|
||
| ```typescript | ||
| // Copyright The Linux Foundation and each contributor to LFX. | ||
| // SPDX-License-Identifier: MIT | ||
|
|
||
| import { QueryServiceResponse } from '@lfx-one/shared/interfaces'; | ||
| import { Request } from 'express'; | ||
|
|
||
| import { logger } from './logger.service'; | ||
| import { MicroserviceProxyService } from './microservice-proxy.service'; | ||
|
|
||
| class MyService { | ||
| private microserviceProxy = new MicroserviceProxyService(); | ||
|
|
||
| public async getItems(req: Request): Promise<MyItem[]> { | ||
| logger.debug(req, 'get_items', 'Fetching items from upstream', {}); | ||
|
|
||
| const { resources } = await this.microserviceProxy.proxyRequest<QueryServiceResponse<MyItem>>(req, 'LFX_V2_SERVICE', '/query/resources', 'GET', { | ||
| resource_type: 'my_items', | ||
| }); | ||
|
|
||
| logger.debug(req, 'get_items', 'Fetched items', { count: resources.length }); | ||
| return resources.map((r: any) => r.data); | ||
| } | ||
| } | ||
|
|
||
| export const myService = new MyService(); | ||
| ``` | ||
|
|
||
| Service rules: | ||
|
|
||
| - `MicroserviceProxyService` for ALL external API calls — never raw `fetch` or `axios` | ||
| - Default to user bearer token (`req.bearerToken`) — M2M tokens only for `/public/api/` endpoints | ||
| - `logger.debug()` for step-by-step tracing | ||
|
asithade marked this conversation as resolved.
|
||
| - `logger.info()` for significant operations (transformations, enrichments) | ||
| - `logger.warning()` for recoverable errors (returning null/empty) | ||
| - Never use `serverLogger` directly — always `logger` from `./logger.service` | ||
|
|
||
| --- | ||
|
|
||
| ### 3. Controller (`apps/lfx/src/server/controllers/<name>.controller.ts`) | ||
|
|
||
| ```typescript | ||
| // Copyright The Linux Foundation and each contributor to LFX. | ||
| // SPDX-License-Identifier: MIT | ||
|
|
||
| import { NextFunction, Request, Response } from 'express'; | ||
|
|
||
| import { logger } from '../services/logger.service'; | ||
| import { myService } from '../services/my.service'; | ||
|
|
||
| export const getItems = async (req: Request, res: Response, next: NextFunction) => { | ||
| const startTime = logger.startOperation(req, 'get_items', {}); | ||
|
|
||
| try { | ||
| const items = await myService.getItems(req); | ||
| logger.success(req, 'get_items', startTime, { count: items.length }); | ||
| return res.json(items); | ||
| } catch (error) { | ||
| logger.error(req, 'get_items', startTime, error, {}); | ||
| return next(error); | ||
| } | ||
| }; | ||
| ``` | ||
|
|
||
| Controller rules: | ||
|
|
||
| - `logger.startOperation()` → `try/catch` → `logger.success()` or `next(error)` | ||
| - Never `res.status(500).json()` — always `next(error)` | ||
| - Operation names in `snake_case` | ||
| - One `startOperation` per HTTP endpoint | ||
|
|
||
| --- | ||
|
|
||
| ### 4. Route (`apps/lfx/src/server/routes/<name>.route.ts`) | ||
|
|
||
| ```typescript | ||
| // Copyright The Linux Foundation and each contributor to LFX. | ||
| // SPDX-License-Identifier: MIT | ||
|
|
||
| import { Router } from 'express'; | ||
|
|
||
| import { getItems, createItem } from '../controllers/my.controller'; | ||
|
|
||
| const router = Router(); | ||
|
|
||
| router.get('/items', getItems); | ||
| router.post('/items', createItem); | ||
|
|
||
| export default router; | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ### 5. Route Registration | ||
|
|
||
| `server.ts` is a **protected file**. Always tell the contributor: | ||
|
|
||
| > "The route file is created. It needs to be registered in `apps/lfx/src/server/server.ts` — a protected infrastructure file. Include this change in your PR for code owner review." | ||
|
|
||
| ## Checklist | ||
|
|
||
| - [ ] Shared types created/updated in `packages/shared/src/interfaces/` | ||
| - [ ] Shared types exported from barrel `index.ts` | ||
| - [ ] Service uses `MicroserviceProxyService` (not raw fetch/axios) | ||
| - [ ] Service uses `logger` (not `serverLogger`) | ||
| - [ ] Controller uses `logger.startOperation()` / `logger.success()` / `logger.error()` | ||
| - [ ] Controller passes errors to `next(error)` (never `res.status(500)`) | ||
| - [ ] License headers on all files | ||
| - [ ] Contributor informed about `server.ts` registration | ||
|
|
||
| ## Scope Boundaries | ||
|
|
||
| **This skill DOES:** | ||
|
|
||
| - Generate Express proxy services, controllers, and routes for `apps/lfx` | ||
| - Create/update shared TypeScript types in `packages/shared` | ||
|
|
||
| **This skill does NOT:** | ||
|
|
||
| - Generate Angular frontend code — use `/lfx-ui-builder` or `/lfx-design` | ||
| - Modify `apps/lfx-one` — use the existing `/develop` skill for that | ||
| - Modify `server.ts` directly — flag for code owner | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.