Copilot instructions
.github/instructions/typescript.instructions.mdTypeScript and Node.js backend specific coding instructions for server-side development.
Copilot instructions
Quality
92/100
Scores the file, not the repository.Length
733 words
11 headings · 7 code blocksRepository
14
— · pushed 0 days agoLast changed
3 days ago
First indexed 3 days ago.123456# TypeScript / Node.js Backend Instructions78> **Note**: For React/TSX frontend code, see `react.instructions.md` which applies to `**.tsx` and `**.jsx` files.910## Code Style1112- Enable strict mode in `tsconfig.json` (`"strict": true`)13- Use ESM imports (`import`/`export`), not CommonJS (`require`)14- Maximum line length: 100 characters (Prettier)15- Use `biome` or `eslint` + `prettier` for linting and formatting1617## Type Safety1819```typescript20// [PASS] Strict typing - no `any`21interface CreateUserRequest {22 readonly email: string;23 readonly name: string;24 readonly role: "admin" | "user" | "viewer";25}2627// [PASS] Use branded types for domain IDs28type UserId = string & { readonly __brand: "UserId" };29type OrderId = string & { readonly __brand: "OrderId" };3031// [PASS] Use discriminated unions for state machines32type RequestState =33 | { status: "idle" }34 | { status: "loading" }35 | { status: "success"; data: Response }36 | { status: "error"; error: Error };37```3839## Naming Conventions4041| Type | Convention | Example |42|------|------------|---------|43| Interface | PascalCase | `UserService` |44| Type alias | PascalCase | `CreateUserRequest` |45| Function | camelCase | `getUserById` |46| Variable | camelCase | `userCount` |47| Constant | UPPER_SNAKE | `MAX_RETRIES` |48| Enum | PascalCase | `HttpStatus.Ok` |49| File | kebab-case | `user-service.ts` |5051## Error Handling5253```typescript54// [PASS] Use custom error classes55class AppError extends Error {56 constructor(57 message: string,58 public readonly statusCode: number,59 public readonly code: string,60 ) {61 super(message);62 this.name = "AppError";63 }64}6566class NotFoundError extends AppError {67 constructor(resource: string, id: string) {68 super(`${resource} with id ${id} not found`, 404, "NOT_FOUND");69 }70}7172// [PASS] Catch specific errors, log and re-throw73try {74 const user = await userService.getById(id);75} catch (error) {76 if (error instanceof NotFoundError) {77 logger.warn({ error, id }, "User not found");78 return res.status(404).json({ error: error.message });79 }80 logger.error({ error }, "Unexpected error fetching user");81 throw error; // Don't swallow unknown errors82}83```8485## Async/Await8687```typescript88// [PASS] Always use async/await over raw Promises89async function fetchUsers(ids: string[]): Promise<User[]> {90 const results = await Promise.allSettled(91 ids.map((id) => userRepository.findById(id)),92 );9394 return results95 .filter((r): r is PromiseFulfilledResult<User> => r.status === "fulfilled")96 .map((r) => r.value);97}9899// [PASS] Use AbortController for timeouts100async function fetchWithTimeout(url: string, timeoutMs = 5000): Promise<Response> {101 const controller = new AbortController();102 const timeout = setTimeout(() => controller.abort(), timeoutMs);103104 try {105 return await fetch(url, { signal: controller.signal });106 } finally {107 clearTimeout(timeout);108 }109}110```111112## Project Structure (Backend)113114```115src/116+-- routes/ # Route definitions (Express/Fastify/Hono)117+-- controllers/ # Request handling (thin - delegates to services)118+-- services/ # Business logic119+-- repositories/ # Data access layer120+-- middleware/ # Auth, logging, error handling121+-- types/ # Shared TypeScript types/interfaces122+-- utils/ # Pure utility functions123+-- config/ # Environment and app configuration124-- index.ts # Application entry point125```126127## Dependency Injection128129```typescript130// [PASS] Constructor injection with interfaces131interface UserRepository {132 findById(id: string): Promise<User | null>;133 create(data: CreateUserRequest): Promise<User>;134}135136class UserService {137 constructor(138 private readonly userRepo: UserRepository,139 private readonly logger: Logger,140 ) {}141142 async getById(id: string): Promise<User> {143 const user = await this.userRepo.findById(id);144 if (!user) throw new NotFoundError("User", id);145 return user;146 }147}148```149150## Environment Configuration151152```typescript153// [PASS] Validate env at startup, fail fast154import { z } from "zod";155156const envSchema = z.object({157 NODE_ENV: z.enum(["development", "production", "test"]),158 PORT: z.coerce.number().default(3000),159 DATABASE_URL: z.string().url(),160 API_KEY: z.string().min(1),161});162163export const env = envSchema.parse(process.env);164```165166## Testing167168- Use **Vitest** (preferred) or Jest for unit/integration tests169- Use **Supertest** for HTTP endpoint testing170- Name tests: `describe("UserService")` -> `it("should return user by id")`171- Mock external dependencies, never call live APIs in tests172173```typescript174import { describe, it, expect, vi } from "vitest";175176describe("UserService", () => {177 it("should return user by id", async () => {178 const mockRepo: UserRepository = {179 findById: vi.fn().mockResolvedValue({ id: "1", name: "Test" }),180 create: vi.fn(),181 };182183 const service = new UserService(mockRepo, mockLogger);184 const user = await service.getById("1");185186 expect(user.name).toBe("Test");187 expect(mockRepo.findById).toHaveBeenCalledWith("1");188 });189190 it("should throw NotFoundError when user missing", async () => {191 const mockRepo: UserRepository = {192 findById: vi.fn().mockResolvedValue(null),193 create: vi.fn(),194 };195196 const service = new UserService(mockRepo, mockLogger);197198 await expect(service.getById("999")).rejects.toThrow(NotFoundError);199 });200});201```202203## Security204205- Validate all inputs with `zod` schemas at the boundary (routes/controllers)206- Use `helmet` middleware for HTTP security headers207- Use `cors` with explicit origin allowlists (never `*` in production)208- Rate limit API endpoints (`express-rate-limit` or framework equivalent)209- Never log sensitive data (passwords, tokens, PII)210
Also in jnPiyush/AgentX
Diff this repo’s formatsOne repository carrying more than one format is the comparison this product exists for: does anyone actually write different content in each file, or is one a copy of the other?
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| jnPiyush/AgentX.cursor/rules/000-agentx-core.mdc · 14 | Cursor rules | styleapido-notagent-behaviour | 55/100 | 3 days ago | |
| jnPiyush/AgentX.cursor/rules/ai.mdc · 14 | Cursor rules | no sections | 16/100 | 3 days ago | |
| jnPiyush/AgentX.cursor/rules/csharp.mdc · 14 | Cursor rules | no sections | 16/100 | 3 days ago | |
| jnPiyush/AgentX.cursor/rules/python.mdc · 14 | Cursor rules | testlint-format | 32/100 | 3 days ago | |
| jnPiyush/AgentX.cursor/rules/react.mdc · 14 | Cursor rules | no sections | 16/100 | 3 days ago | |
| jnPiyush/AgentX.cursor/rules/typescript.mdc · 14 | Cursor rules | types | 16/100 | 3 days ago | |
| jnPiyush/AgentX.github/copilot-instructions.md · 14 | Copilot instructions | stylegitdo-notagent-behaviour | 67/100 | 3 days ago | |
| jnPiyush/AgentX.github/instructions/ai.instructions.md · 14 | Copilot instructions | testing-strategydo-notagent-behaviour | 50/100 | 3 days ago | |
| jnPiyush/AgentX.github/instructions/csharp.instructions.md · 14 | Copilot instructions | teststylesecuritydo-not+1 | 59/100 | 3 days ago | |
| jnPiyush/AgentX.github/instructions/memory.instructions.md · 14 | Copilot instructions | lint-formatperformance | 54/100 | 3 days ago | |
| jnPiyush/AgentX.github/instructions/project-conventions.instructions.md · 14 | Copilot instructions | stylegitdo-not | 59/100 | 3 days ago | |
| jnPiyush/AgentX.github/instructions/python.instructions.md · 14 | Copilot instructions | testlint-formatsecuritydo-not+1 | 67/100 | 3 days ago | |
| jnPiyush/AgentX.github/instructions/react.instructions.md · 14 | Copilot instructions | testtypessecuritydo-not+1 | 63/100 | 3 days ago | |
| jnPiyush/AgentXAGENTS.md · 14 | AGENTS.md | lint-formatstylegitsecurity+2 | 69/100 | 3 days ago | |
| jnPiyush/AgentXCLAUDE.md · 14 | CLAUDE.md | lint-formatstylegitsecurity+2 | 81/100 | 3 days ago | |
| jnPiyush/AgentXvscode-extension/.github/AGENTS.md · 14 | AGENTS.md | lint-formatstylegitsecurity+2 | 69/100 | 3 days ago |
Diff against .cursor/rules/000-agentx-core.mdc Diff against .cursor/rules/ai.mdc Diff against .cursor/rules/csharp.mdc Diff against .cursor/rules/python.mdc Diff against .cursor/rules/react.mdc Diff against .cursor/rules/typescript.mdc Diff against .github/copilot-instructions.md Diff against .github/instructions/ai.instructions.md Diff against .github/instructions/csharp.instructions.md Diff against .github/instructions/memory.instructions.md Diff against .github/instructions/project-conventions.instructions.md Diff against .github/instructions/python.instructions.md Diff against .github/instructions/react.instructions.md Diff against AGENTS.md Diff against CLAUDE.md Diff against vscode-extension/.github/AGENTS.md
Similar configs
Same format, overlapping stack, ranked by quality.
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| HerringtonDarkholme/megarepo.github/copilot-instructions.md · 17 | Copilot instructions | setupbuildtestlint-format+7 | 100/100 | 3 days ago | |
| chihebnabil/lovable-boilerplate.github/instructions/global.instructions.md · 63 | Copilot instructions | buildlint-formatstylearch+4 | 100/100 | 3 days ago | |
| louislam/uptime-kuma.github/copilot-instructions.md · 90k | Copilot instructions | setupbuildtestlint-format+9 | 100/100 | 3 days ago | |
| bagisto/bagisto.github/copilot-instructions.md · 28k | Copilot instructions | setupbuildteststyle+5 | 97/100 | 3 days ago | |
| JCodesMore/ai-website-cloner-template.github/copilot-instructions.md · 31k | Copilot instructions | buildlint-formatstylearch+3 | 97/100 | 2 days ago | |
| thangaram611/second-brain.github/copilot-instructions.md · 0 | Copilot instructions | setupteststylearch+4 | 96/100 | 3 days ago | |
| nerolis-lab/nerolis-lab.github/copilot-instructions.md · 32 | Copilot instructions | setupbuildtestlint-format+11 | 96/100 | 3 days ago | |
| darkmatter/nixmac.github/copilot-instructions.md · 24 | Copilot instructions | setupbuildtestlint-format+8 | 96/100 | 3 days ago |
