Skip to content

Commit 4d26432

Browse files
committed
fix: copilot comment
1 parent 5614cda commit 4d26432

1 file changed

Lines changed: 23 additions & 17 deletions

File tree

frontend/AGENTS.md

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ The Silva frontend is a **React + TypeScript** application built with **Vite**,
1111
- IBM Carbon components
1212
- TanStack Query (React Query) for data fetching
1313
- Playwright for E2E testing
14-
- Jest for unit testing
14+
- Vitest for unit testing
1515

1616
**Deployment:** Docker container on OpenShift via GitHub Actions
1717

@@ -655,18 +655,21 @@ Use **TanStack Query** (React Query) for all API data fetching, caching, and sta
655655

656656
### API Client
657657

658-
The API client is **auto-generated** from the backend's OpenAPI specification:
658+
The API client is generated from the backend's OpenAPI specification:
659+
660+
- **`src/services/OpenApi/**`** — Auto-generated service classes (DO NOT MODIFY). Regenerate after backend changes.
661+
- **`src/services/API.ts`** — Hand-maintained wrapper. Configures and re-exports generated services for easy access throughout the app.
662+
663+
**Example API.ts structure:**
659664

660665
```typescript
661-
// src/services/API.ts - DO NOT MODIFY (auto-generated)
662-
export class API {
663-
static getOpenings(filters?: OpeningFilters) {
664-
return fetch('/api/openings', { /* ... */ });
665-
}
666+
// src/services/API.ts - hand-maintained wrapper
667+
import { OpeningsService } from './OpenApi/services/OpeningsService'; // Auto-generated
668+
import { ActivitiesService } from './OpenApi/services/ActivitiesService'; // Auto-generated
666669

667-
static updateOpening(id: string, data: Partial<Opening>) {
668-
return fetch(`/api/openings/${id}`, { /* ... */ });
669-
}
670+
export class API {
671+
static openings = new OpeningsService();
672+
static activities = new ActivitiesService();
670673
}
671674
```
672675

@@ -677,7 +680,7 @@ cd frontend
677680
npm run generate:openapi
678681
```
679682

680-
**This command is run by the developer after the backend is implemented and confirmed working.**
683+
**This command is run by the developer after the backend is implemented and confirmed working.** The generated files in `src/services/OpenApi/**` are replaced, while `src/services/API.ts` (the wrapper) remains unchanged unless new services need to be registered.
681684

682685
### Query Key Convention
683686

@@ -761,22 +764,25 @@ const OpeningsList: React.FC = () => {
761764

762765
## Services Folder
763766

764-
The `/src/services/` folder is **auto-generated** from the backend's OpenAPI specification.
767+
The `/src/services/` folder contains API client code:
768+
769+
- **`OpenApi/`** — Auto-generated service classes from the backend's OpenAPI spec (DO NOT MODIFY)
770+
- **`API.ts`** — Hand-maintained wrapper that configures and re-exports generated services
765771

766772
### Rules
767773

768-
- **Never modify auto-generated files** (e.g., individual service files)
769-
- **Only modify `API.ts`** to register new services in the API constructor if needed
774+
- **Never modify auto-generated files** in `OpenApi/` folder
775+
- **Only modify `API.ts`** to register new services in the API wrapper class when the backend adds new controllers
770776
- **Regenerate after backend changes:** Run `npm run generate:openapi`
771777

772778
### Example: Adding a New Service
773779

774-
If the backend adds a new controller, the OpenAPI generator creates a new service file. You may need to add it to the API constructor:
780+
If the backend adds a new controller, the OpenAPI generator creates a new service file in `OpenApi/`. Register it in `API.ts`:
775781

776782
```typescript
777783
// src/services/API.ts
778-
import { OpeningsService } from './OpeningsService'; // Auto-generated
779-
import { ActivitiesService } from './ActivitiesService'; // Auto-generated
784+
import { OpeningsService } from './OpenApi/services/OpeningsService'; // Auto-generated
785+
import { ActivitiesService } from './OpenApi/services/ActivitiesService'; // Auto-generated
780786

781787
export class API {
782788
static openings = new OpeningsService();

0 commit comments

Comments
 (0)