You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: .github/copilot-instructions.md
+92-39Lines changed: 92 additions & 39 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,7 +11,8 @@ This repository is a boilerplate for building Node.js applications using TypeScr
11
11
-**Dependency Injection**: Uses Awilix for managing dependencies, promoting loose coupling and easier testing.
12
12
-**Event-driven architecture**: Utilizes an event dispatcher for handling domain events, enabling asynchronous processing and decoupling of components.
13
13
-**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.
15
16
16
17
### Project Structure
17
18
```src/
@@ -45,58 +46,110 @@ This repository is a boilerplate for building Node.js applications using TypeScr
45
46
### Key Libraries and Functionalities
46
47
-**TypeScript**: For static typing and modern JavaScript features.
47
48
-**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.
52
54
-**@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.
-`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.
54
61
-**UUID v4**: For unique identifiers in database entities.
55
62
-**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.
58
67
59
68
### Key Development Guidelines
60
69
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
68
89
69
90
#### 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
76
107
77
108
#### 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`)
86
127
87
128
#### 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/`
95
136
96
137
#### 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
99
140
100
141
#### 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