Skip to content

Commit ddc2cd1

Browse files
author
Sviatoslav Zhovtiak
committed
chore: improve copilot instructions
1 parent c4c3a9c commit ddc2cd1

File tree

8 files changed

+2319
-187
lines changed

8 files changed

+2319
-187
lines changed

.github/copilot-instructions.md

Lines changed: 92 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ This repository is a boilerplate for building Node.js applications using TypeScr
1111
- **Dependency Injection**: Uses Awilix for managing dependencies, promoting loose coupling and easier testing.
1212
- **Event-driven architecture**: Utilizes an event dispatcher for handling domain events, enabling asynchronous processing and decoupling of components.
1313
- **Feature-based structure**: Organizes code into features, each encapsulating related functionality, making it easier to navigate and maintain.
14-
- **REST API**: Exposes a RESTful API for client interactions, following standard HTTP methods and status codes.
14+
- **RESTful API**: Exposes a RESTful API for client interactions, following standard HTTP methods and status codes.
15+
- **GraphQL API**: Apollo Server integration for GraphQL queries and mutations alongside REST endpoints.
1516

1617
### Project Structure
1718
```src/
@@ -45,58 +46,110 @@ This repository is a boilerplate for building Node.js applications using TypeScr
4546
### Key Libraries and Functionalities
4647
- **TypeScript**: For static typing and modern JavaScript features.
4748
- **Express**: Web framework for building REST APIs.
48-
- **TypeORM**: ORM for database interactions.
49-
- **Awilix**: Dependency injection container.
50-
- **@tshio/command-bus**: Command bus for handling commands.
51-
- **@tshio/query-bus**: Query bus for handling queries.
49+
- **Apollo Server**: GraphQL server implementation for building GraphQL APIs.
50+
- **TypeORM**: ORM for database interactions with PostgreSQL.
51+
- **Awilix**: Dependency injection container for managing dependencies.
52+
- **@tshio/command-bus**: Command bus for handling commands in CQRS pattern.
53+
- **@tshio/query-bus**: Query bus for handling queries in CQRS pattern.
5254
- **@tshio/event-dispatcher**: Event dispatcher for handling domain events.
55+
- **Celebrate**: Request validation middleware using Joi schemas.
56+
- **Helmet**: Security middleware for setting HTTP headers.
57+
- **CORS**: Cross-origin resource sharing middleware.
5358
- `src/shared/pagination-utils`: Utility functions for request parameters to TypeORM options conversion and list endpoint responses.
59+
- `src/shared/cache-decorator`: Caching utilities for query optimization.
60+
- `src/shared/utils`: Common utility functions for various operations.
5461
- **UUID v4**: For unique identifiers in database entities.
5562
- **Docker**: For containerization and consistent development environment.
56-
- **Jest**: For unit and integration testing.
57-
- **Celebrate**: For input validation in REST endpoints.
63+
- **Mocha + Chai + Supertest**: Testing framework stack for unit and integration tests.
64+
- **SWC**: Fast TypeScript/JavaScript transpiler (alternative to tsc).
65+
- **ESLint + Prettier**: Code quality and formatting tools.
66+
- **Husky**: Git hooks for pre-commit quality checks.
5867

5968
### Key Development Guidelines
6069

61-
#### Important commands
62-
- **Linting**: Use `npm run lint` to check code style.
63-
- **Fixing Lint Issues**: Use `npm run lint-fix` to automatically fix lint issues.
64-
- **Formatting**: Use `npm run format` to format code according to the project's style guide.
65-
- **Running Tests**: Use `npm run integration` for integration tests and `npm run units` for unit tests.
66-
- **Generating Migrations**: Use `npm run generate-migration` to create new migrations. Do not run migrations manually, they are auto-executed at application start.
67-
- **Running migrations**: Use `npm run migrations` to run all pending migrations.
70+
#### Important Commands
71+
- **Development Environment**: Use `npm run watch` to start TypeScript compilation in watch mode and `npm start` to run the API server
72+
- **Building**: Use `npm run build` (tsc) or `npm run build-swc` (SWC transpiler) to compile TypeScript
73+
- **Linting**: Use `npm run lint` to check code style and `npm run lint-fix` to automatically fix issues
74+
- **Formatting**: Use `npm run format` to format code using Prettier
75+
- **Testing**: Use `npm run integration` for integration tests and `npm run units` for unit tests
76+
- **Test Coverage**: Use `npm run integration-tests-coverage` and `npm run services-units-coverage` for coverage reports
77+
- **Database Migrations**: Use `npm run generate-migration` to create new migrations
78+
- **Running Migrations**: Use `npm run run-migrations` to execute pending migrations
79+
- **GraphQL Schema**: Use `npm run generate-schema` to generate GraphQL type definitions
80+
- **Docker Management**: Use `npm run down` to stop all containers and volumes
81+
82+
#### Development Workflow
83+
1. **Initial Setup**: Run `./init.sh` or manual Docker setup for first-time environment preparation
84+
2. **Development**: Start `npm run watch` for TypeScript compilation and `npm start` for the API server (in separate terminals)
85+
3. **Code Quality**: Run `npm run lint-fix` and `npm run format` before committing changes
86+
4. **Testing**: Execute `npm run integration` and `npm run units` to ensure all tests pass
87+
5. **Database Changes**: Generate migrations with `npm run generate-migration` after model updates
88+
6. **Pre-commit**: Husky hooks automatically run linting and unit tests before git push
6889

6990
#### General Guidelines
70-
- Always use TypeScript for type safety and modern JavaScript features.
71-
- Follow the project's coding conventions and architecture patterns.
72-
- 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.
75-
- Never run any commands with `docker-compose` command, use npm scripts instead (e.g., `npm run lint`, `npm run lint-fix`, `npm run forma`).
91+
- Always use TypeScript for type safety and modern JavaScript features
92+
- Follow the project's coding conventions and architectural patterns
93+
- Use dependency injection for managing dependencies, avoiding direct instantiation of classes
94+
- All environment variables must be extracted and validated using `dotenv` and `joi` packages in `src/config/app.ts`
95+
- Store environment configuration in `.env` (local) and `.env.test` (testing), use `.env.dist` as template
96+
- Never use `npm run plop` to generate code, create files manually following the established patterns
97+
- Use Docker containers for all development operations - avoid running commands directly on host machine
98+
- All database migrations are auto-executed at application start, do not run them manually
99+
- Follow the detailed instruction files for specific development patterns:
100+
- Actions: REST endpoint implementation patterns
101+
- Handlers: Command/Query handler implementation
102+
- Models: Entity and repository patterns
103+
- Routing: Route registration and middleware
104+
- Tests: Testing requirements and patterns
105+
- Quality: Code quality standards and tools
106+
- Security: Security best practices and implementation
76107

77108
#### Naming Guidelines
78-
- Always think in terms of features, not technical layers.
79-
- Features names should be descriptive and reflect the bounded context (e.g., `planning`, `ordering`, `management`). Avoid naming features by connected entities (e.g., `user`, `product`).
80-
- Use **kebab-case** for directories, filenames and imports (e.g., `user.controller.ts`).
81-
- Use **camelCase** for variables and function names (e.g., `getUserById`).
82-
- Use **PascalCase** for class names and interfaces (e.g., `UserService`).
83-
- use **snake_case** for database columns and TypeORM entity properties (e.g., `first_name`, `last_name`) but use **camelCase** for variable names in TypeScript code.
84-
- Use suffixes like `.handler.ts`, `.command.ts`, `.query.ts`, `.event.ts`, `.subscriber.ts`, `.resolver.ts` for files in features (e.g, `create-user.command.ts`, `user.query.ts`).
85-
- Use suffixes like `Service`, `Repository`, `Controller` for class names (e.g., `UserService`, `UserRepository`, `UserController`).
109+
- Always think in terms of features, not technical layers
110+
- Feature names should be descriptive and reflect the bounded context (e.g., `user-management`, `order-processing`, `notification-service`)
111+
- Avoid naming features by connected entities alone (e.g., avoid just `user`, prefer `user-management`)
112+
- Use **kebab-case** for directories, filenames and imports (e.g., `user-controller.ts`, `create-user.command.ts`)
113+
- Use **camelCase** for variables and function names (e.g., `getUserById`, `processOrder`)
114+
- Use **PascalCase** for class names and interfaces (e.g., `UserService`, `OrderRepository`, `CreateUserCommand`)
115+
- Use **snake_case** for database columns and TypeORM entity properties (e.g., `first_name`, `created_at`)
116+
- Use descriptive suffixes for file types:
117+
- `.action.ts` for REST endpoint handlers
118+
- `.handler.ts` for command/query handlers
119+
- `.command.ts` for command DTOs
120+
- `.query.ts` for query DTOs
121+
- `.event.ts` for domain events
122+
- `.subscriber.ts` for event subscribers
123+
- `.resolver.ts` for GraphQL resolvers
124+
- `.entity.ts` for TypeORM entities
125+
- `.repository.ts` for repository implementations
126+
- Use descriptive suffixes for class names (e.g., `UserService`, `OrderRepository`, `CreateUserHandler`)
86127

87128
#### Database Guidelines
88-
- Use **TypeORM** for database interactions.
89-
- Use **UUID v4** for unique identifiers, avoid auto-increment IDs.
90-
- Use repositories for data access in handlers, not direct TypeORM queries.
91-
- Always generate migrations using the provided npm script (`npm run generate-migration`), do not create them manually.
92-
- Never add parameters to the `npm run generate-migration` command, as it will fail.
93-
- All migrations are auto-executed at application start, do not run them manually.
94-
- Migrations are stored in `src/migrations/`.
129+
- Use **TypeORM** for database interactions
130+
- Use **UUID v4** for unique identifiers, avoid auto-increment IDs
131+
- Use repositories for data access in handlers, not direct TypeORM queries
132+
- Always generate migrations using the provided npm script (`npm run generate-migration`), do not create them manually
133+
- Never add parameters to the `npm run generate-migration` command, as it will fail
134+
- All migrations are auto-executed at application start, do not run them manually
135+
- Migrations are stored in `src/migrations/`
95136

96137
#### Testing Guidelines
97-
- Every endpoint must have a corresponding integration test.
98-
- Every utility function must have a corresponding unit test.
138+
- Every endpoint must have a corresponding integration test
139+
- Every utility function must have a corresponding unit test
99140

100141
#### Security Guidelines
101-
- Never expose sensitive information in error messages or responses.
102-
- Use HTTPS for secure communication, especially in production environments.
142+
- Never expose sensitive information in error messages or responses
143+
- Use HTTPS for secure communication, especially in production environments
144+
145+
## When Adding Features
146+
147+
1. Define domain model in appropriate bounded context
148+
2. Create commands/queries with handlers
149+
3. Add repository interfaces and implementations
150+
4. Wire up event subscribers for cross-context communication
151+
5. Register all components in DI container
152+
6. Add validation and error handling
153+
7. Write integration tests following existing patterns
154+
155+
Focus on maintaining clean boundaries between domain, application, and infrastructure layers while leveraging the established CQRS and event-driven patterns.

0 commit comments

Comments
 (0)