Skip to content

Commit c4c3a9c

Browse files
committed
feat: changed copilot instructions
1 parent f621349 commit c4c3a9c

File tree

8 files changed

+82
-31
lines changed

8 files changed

+82
-31
lines changed

.github/copilot-instructions.md

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,11 @@ This repository is a boilerplate for building Node.js applications using TypeScr
3535
│ ├── shared/ # Shared utilities and helpers
3636
│ ├── tests/ # Integration tests files
3737
│ │ └── bootstrap.ts # Test bootstrap file
38-
│ └── migrations/ # TypeORM migrations
39-
├── src/
40-
│ ├── index.ts # Application entry point
41-
│ ├── server.ts # Server setup and configuration
42-
│ ├── container.ts # Dependency injection container setup
43-
│ ├── config.ts # Application configuration
44-
│ ├── logger.ts # Logging setup
45-
│ ├── database.ts # Database connection setup
46-
│ └── shared/ # Shared utilities and helpers
38+
│ ├── migrations/ # TypeORM migrations
39+
│ ├── router.ts # Registering all feature routes
40+
│ └── app.ts # Express app setup and initialization, application routing setup
41+
├── index.ts # Application entry point
42+
└── container.ts # Dependency injection container setup
4743
```
4844

4945
### Key Libraries and Functionalities
@@ -74,6 +70,8 @@ This repository is a boilerplate for building Node.js applications using TypeScr
7470
- Always use TypeScript for type safety and modern JavaScript features.
7571
- Follow the project's coding conventions and architecture patterns.
7672
- Use dependency injection for managing dependencies, avoiding direct instantiation of classes.
73+
- All environment variables has to be extracted and validated using `dotenv` and `joi` packages. Store them in config files like `.env` or `.env.test` and process them in your application startup in `src/config/app.ts`.
74+
- Never use `npm run plop` to generate code, use the provided boilerplate structure and manually create files as needed.
7775
- Never run any commands with `docker-compose` command, use npm scripts instead (e.g., `npm run lint`, `npm run lint-fix`, `npm run forma`).
7876

7977
#### Naming Guidelines
@@ -100,13 +98,5 @@ This repository is a boilerplate for building Node.js applications using TypeScr
10098
- Every utility function must have a corresponding unit test.
10199

102100
#### Security Guidelines
103-
- Use `helmet` for security headers in Express.
104-
- Use `celebrate` for input validation in REST endpoints.
105-
- Use global error handling middleware for catching and formatting errors.
106-
- Add logging for important events and errors using injected logger in handlers and actions.
107101
- Never expose sensitive information in error messages or responses.
108-
- Use environment variables for sensitive configuration (e.g., database credentials, API keys) and load them using `dotenv`.
109102
- Use HTTPS for secure communication, especially in production environments.
110-
- Implement proper authentication and authorization mechanisms for protected routes.
111-
- Regularly update dependencies to patch security vulnerabilities.
112-
- Use `cors` middleware to control cross-origin requests, allowing only trusted origins.

.github/instructions/actions.instructions.md

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,9 @@ applyTo: "**/actions/*.action.ts"
1010
- `delete-user.action.ts` for deleting a user
1111
- `get-users.action.ts` for retrieving users
1212
- Use appropriate HTTP status codes for different actions (e.g., 200 for success, 201 for created, 204 for no content).
13-
- For errors use appropriate HTTP status codes (e.g., 400 for bad request, 404 for not found, 500 for internal server error).:
14-
- All errors must return a structured JSON response with an error message and code:
15-
```json
16-
{
17-
"error": {
18-
"message": "Error message",
19-
"code": "ERROR_CODE"
20-
}
21-
}
22-
```
13+
- For errors use appropriate HTTP status codes (e.g., 400 for bad request, 404 for not found, 500 for internal server error).
2314
- Validation errors are handled by `celebrate` in `src/middleware/error-handler.ts` don't change that
15+
- Add logging for important events and errors using injected logger in handlers and actions.
2416

2517
- Use `GET` method for list endpoints.
2618
- Use `src/shared/pagination-utils.ts` for creating TypeORM options for list endpoints.

.github/instructions/handlers.instructions.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,12 @@ export class UserHandler {
4040
}
4141
```
4242
- Never create tests for handlers.
43-
- Don't use `@CacheQuery` decorator in any handlers unless explicitly stated otherwise.
43+
- Don't use `@CacheQuery` decorator in any handlers unless explicitly stated otherwise.
44+
- Erorrs should be thrown as exceptions, not returned as responses. They will be handled by the global error handler.
45+
- There are built-in error classes in `src/shared/errors` that you can use to throw errors with appropriate HTTP status codes and messages.
46+
- Use HttpError classes from `src/shared/errors` for throwing HTTP errors.
47+
- The AppError shouldn't be used in handlers, as it is a generic error class for internal errors.
48+
- The NotFoundError should be used for 404 errors.
49+
- The Validation Errors are handled by `celebrate` in `src/middleware/error-handler.ts`, so you don't need to handle them in handlers.
50+
- In case you need to handle specific errors, you can create custom error classes in `src/shared/errors` and throw them in handlers, but remember for them to extend the `AppError` class.
51+
- Add logging for important events and errors using injected logger in handlers and actions.

.github/instructions/models.instructions.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,39 @@ userRepository: asValue(dbDataSource.getRepository(UserEntity)),
1414
- Never add parameters to the `npm run generate-migration` command, as it will fail.
1515
- Never create tests for entities.
1616
- Always validate and sanitize user input to prevent SQL injection and other attacks.
17+
- Every model should have a factory method for creating instances from raw data, e.g.:
18+
```typescript
19+
import { Column, Entity, PrimaryGeneratedColumn } from "typeorm";
20+
21+
export interface UserProps {
22+
id: string;
23+
firstName: string;
24+
lastName: string;
25+
email: string;
26+
}
27+
28+
@Entity({
29+
name: "user",
30+
})
31+
export class UserEntity {
32+
public static create(data: Partial<UserProps>): UserEntity {
33+
const object = new UserEntity();
34+
Object.assign(object, data);
35+
return object;
36+
}
37+
38+
@PrimaryGeneratedColumn("uuid")
39+
id: string;
40+
41+
@Column()
42+
firstName: string;
43+
44+
@Column()
45+
lastName: string;
46+
47+
@Column()
48+
email: string;
49+
}
50+
```
51+
- Use factory methods for creating instances from raw data.
52+
- For CRUD method you can use models props interface in commands as a type
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
applyTo: "**"
3+
---
4+
5+
- Run `npm run lint` to check for linting errors after making changes.
6+
- Run `npm run format` to format the code according to the project's style guide.
7+
- Run `npm run integration` to execute integration tests after making changes.
8+
- Run `npm run units` to execute unit tests after making changes.
9+
- Always ensure that your code passes all tests before finishing.
10+
- Always ensure that code is well-documented, especially public methods and classes.
11+
- Always ensure that your code is formated according to the project's style guide.
12+
- Application supports `/health` endpoint for health checks, which returns 200 OK status if the application is running correctly.
13+
- All errors are handled by `src/middleware/error-handler.ts`, which returns a structured JSON response with an error message and code.
14+
- In case of changing errors, always update the error handler to handle new error types.

.github/instructions/routing.instructions.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,15 @@
22
applyTo: "**/features/**/routing.ts"
33
---
44

5-
- Register routing in `src/app/router.ts`
5+
- Routing is divided into three main areas:
6+
- Feature routing: `src/app/features/{feature}/routing.ts`
7+
- Global routing: `src/app/router.ts`
8+
- Application routing: `src/app/index.ts`
9+
- Use feature routing for individual actions registering and middlewares related to specific action only.
10+
- Use global routing for feature-wide actions, commands, and queries and middlewares that apply to all actions in the feature.
11+
- Use application routing for application-wide actions, commands, and queries and middlewares that apply to all features.
12+
- All application routes starts with `/api/`
13+
- Register feature routing in `src/app/router.ts`
614
- When registering routing in `src/app/router.ts`, always register it with specific path, for example:
715
```typescript
816
router.use("/example", usersRouting);

.github/instructions/security.instructions.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ applyTo: "**"
33
---
44

55
- When implmenting authentication, use JWT tokens for stateless authentication.
6-
- Never store sensitive information (like passwords) in plain text, always hash them using a strong hashing algorithm (e.g., bcrypt).
6+
- Never store sensitive information (like passwords) in plain text, always hash them using a strong hashing algorithm (e.g. SHA-256).
77
- Always implement authentication with proper session management, including token expiration and refresh mechanisms.
88
- The authentication middleware should validate the JWT token and extract user information from it.
99
- Use role-based access control (RBAC) to manage permissions and restrict access to resources based on user roles.
@@ -16,3 +16,5 @@ applyTo: "**"
1616
}
1717
```
1818
- Always implement `me` endpoint to allow users to retrieve their own profile information.
19+
- Use `helmet` for security headers in Express.
20+
- Use `cors` middleware to control cross-origin requests, allowing only trusted origins.

.github/instructions/tests.instructions.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,5 @@ describe("/api/{{kebabCase name}} integration", () => {
2424
- Test bootstrap is in `src/tests/bootstrap.ts`, which sets up the container, database connection, and clears the database before each test.
2525
- Use `clearDb()` function in `src/tests/bootstrap.ts` to clear the database before each test.
2626
- Every repository must be added to `clearDb()` function and cleared with `.delete({})` to avoid TypeORM issues.
27-
- Use `global.container` and `global.dbConnection` in tests for accessing the container and database connection.
27+
- Use `global.container` and `global.dbConnection` in tests for accessing the container and database connection.
28+
- The tests use separate `.env.test` file for environment variables. All environment variables has to be added there too.

0 commit comments

Comments
 (0)