Skip to content

Commit 9e00cf1

Browse files
authored
feat: Added common configurations (#2)
* Refactor npm configuration and add issue/bug report templates * Add tests for UserController and update Dependabot configuration * Add CodeQL workflow for automated code analysis * Update CodeQL workflow to trigger only on pull requests
1 parent dcbdb43 commit 9e00cf1

File tree

13 files changed

+1356
-8
lines changed

13 files changed

+1356
-8
lines changed

.github/DISCUSSION_TEMPLATE.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
title: "[DISCUSSION] "
2+
labels: ["discussion"]
3+
body:
4+
- type: markdown
5+
attributes:
6+
value: |
7+
## Discussion Guidelines
8+
- Be respectful
9+
- Stay on topic
10+
- Reference existing issues
11+
- type: textarea
12+
attributes:
13+
label: "Discussion Topic"
14+
description: "What would you like to discuss?"
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: Bug Report
2+
description: File a bug report
3+
labels: ["bug", "triage"]
4+
projects: ["hono-routing-controller"]
5+
assignees:
6+
- hasib-devs
7+
body:
8+
- type: textarea
9+
id: what-happened
10+
attributes:
11+
label: Bug Description
12+
description: In a few sentences or paragraphs, describe the bug in detail. Include information such as what the bug does, what was expected, steps to reproduce the bug, any error messages, and the impact of the bug on the application.
13+
validations:
14+
required: true
15+
- type: textarea
16+
id: logs
17+
attributes:
18+
label: Step To Reproduce
19+
description: List step-by-step instructions to reproduce the bug. This helps the assigned team member understand and replicate the issue.
20+
value: |
21+
1. Go to '...'
22+
2. Click on '....'
23+
3. Scroll down to '....'
24+
4. See error
25+
- type: textarea
26+
id: logs2
27+
attributes:
28+
label: Expected Behaviour
29+
description: Describe what you expected to happen when performing the steps listed above.
30+
validations:
31+
required: true
32+
- type: textarea
33+
id: logs3
34+
attributes:
35+
label: Actual Behaviour
36+
description: Describe what actually happened when performing the steps, highlighting the bug's behavior.
37+
validations:
38+
required: true
39+
- type: textarea
40+
id: logs4
41+
attributes:
42+
label: Additional Information or Expected Working Example
43+
description: Include any other relevant information or expected example, any images or videos, such as related issues, links to documentation, or any workarounds if they exist.
44+
- type: dropdown
45+
id: browsers
46+
attributes:
47+
label: What browsers are you seeing the problem on?
48+
multiple: true
49+
options:
50+
- Firefox
51+
- Chrome
52+
- Brave
53+
- Safari
54+
- Microsoft Edge

.github/dependabot.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: npm
4+
directory: "/"
5+
schedule:
6+
interval: weekly
7+
time: "10:00"
8+
timezone: "Asia/Dhaka"
9+
open-pull-requests-limit: 5
10+
versioning-strategy: increase
11+
commit-message:
12+
prefix: "chore(deps)"

.github/semantic.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
titleAndCommits: true
2+
allowMergeCommits: false
3+
scopes:
4+
- deps
5+
- deps-dev
6+
types:
7+
- feat
8+
- fix
9+
- docs
10+
- style
11+
- refactor
12+
- perf
13+
- test
14+
- build
15+
- ci
16+
- chore
17+
- revert
18+
- merge

.github/workflows/codeql.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: CodeQL
2+
on: [pull_request]
3+
4+
jobs:
5+
analyze:
6+
name: Analyze
7+
runs-on: ubuntu-latest
8+
steps:
9+
- name: Checkout repository
10+
uses: actions/checkout@v3
11+
12+
- name: Initialize CodeQL
13+
uses: github/codeql-action/init@v2
14+
with:
15+
languages: typescript
16+
17+
- name: Perform CodeQL Analysis
18+
uses: github/codeql-action/analyze@v2

.npmrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
@hasib-devs:registry=https://registry.npmjs.org
1+
registry=https://registry.npmjs.org

docs/ARCHITECTURE.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Hono Routing Controller - Architecture
2+
3+
## 📌 Overview
4+
This package provides a **NestJS-like controller architecture** for the [Hono](https://hono.dev/) framework. It enables **decorator-based routing, middleware support, and dependency injection**, making it easier to organize and manage routes in Hono.
5+
6+
---
7+
8+
## 🏗️ Design Principles
9+
- **Decorator-Based Routing** → Define routes using class decorators.
10+
- **Middleware Integration** → Use middleware with controllers.
11+
- **Dependency Injection (DI)** → Inject dependencies into controllers.
12+
- **TypeScript First** → Fully typed API with TypeScript.
13+
- **Lightweight & Fast** → Minimal runtime overhead.
14+
15+
---
16+
17+
## 📂 Directory Structure
18+
19+
```
20+
hono-routing-controller/
21+
│── src/
22+
│ ├── decorators/ # Custom decorators for routes and middleware
23+
│ │ ├── Controller.ts
24+
│ │ ├── HttpMethods.ts
25+
│ │
26+
│ ├── core/ # Core logic for routing and DI
27+
│ │ ├── DIContainer.ts
28+
| |
29+
│ ├── types/ # Type definitions
30+
│ │ ├── index.ts
31+
│ │
32+
│ ├── constants.ts # Constants used in the package
33+
│ ├── index.ts # Entry point for package exports
34+
35+
├── tests/ # Unit and integration tests
36+
├── package.json
37+
├── tsup.config.ts
38+
└── tsconfig.json
39+
```
40+
---
41+
42+
## 🛠️ Components
43+
44+
### **1️⃣ Decorators**
45+
These are used to define controllers, routes, and middleware.
46+
47+
- `@Controller(path: string)`: Defines a controller with a base path.
48+
- `@Get(path: string)`: Defines a `GET` route.
49+
- `@Post(path: string)`: Defines a `POST` route.
50+
- `@Middleware(middlewareFn)`: Attaches middleware to a route.
51+
52+
## 🚀 How It Works
53+
1. Define Controllers & Routes → Use decorators.
54+
2. Register Controllers → The package scans and registers controllers.
55+
3. Handle Requests → Routes are automatically wired in Hono.
56+
4. Use Dependency Injection → Inject services into controllers.
57+
58+
## 🙌 Contributing
59+
We welcome contributions! Please check the CONTRIBUTING.md for guidelines.

docs/CONTRIBUTING.md

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
# Contributing to hono-routing-controller
2+
3+
We are excited that you're interested in contributing to the `hono-routing-controller` project! This guide will help you get started with contributing to the project. Whether you're submitting a bug fix, a new feature, or an improvement, we appreciate your help!
4+
5+
## Table of Contents
6+
7+
- [How to Contribute](#how-to-contribute)
8+
- [Code of Conduct](#code-of-conduct)
9+
- [Issue Reporting](#issue-reporting)
10+
- [Pull Request Process](#pull-request-process)
11+
- [Development Setup](#development-setup)
12+
13+
## How to Contribute
14+
15+
We welcome contributions from the community! To contribute, follow these steps:
16+
17+
1. **Fork the Repository**
18+
19+
First, fork the repository by clicking the "Fork" button at the top right of the repo page.
20+
21+
2. **Clone Your Fork**
22+
23+
Clone your fork to your local machine:
24+
```bash
25+
git clone https://github.com/hasib-devs/hono-routing-controller.git
26+
cd hono-routing-controller
27+
```
28+
3. **Create a New Branch**
29+
30+
Always create a new branch for your feature or fix:
31+
```
32+
git checkout -b feat/your-feature-name
33+
```
34+
35+
always use semantic branch name.
36+
- feat
37+
- fix
38+
- docs
39+
- style
40+
- refactor
41+
- perf
42+
- test
43+
- build
44+
- ci
45+
- chore
46+
- revert
47+
- merge
48+
49+
4. **Commit Your Changes**
50+
51+
Write clear and concise commit messages:
52+
```bash
53+
git commit -m "Add feature/bugfix description"
54+
```
55+
5. **Push to Your Fork**
56+
57+
Push your changes to your fork:
58+
```bash
59+
git push origin feature/your-feature-name
60+
```
61+
62+
6. **Create a Pull Request**
63+
64+
After pushing your changes, go to the original repository and create a pull request (PR) from your fork.
65+
66+
## Code of Conduct
67+
We follow a Code of Conduct in this project. By participating, you are expected to honor the code of conduct and engage with the community respectfully.
68+
69+
## Issue Reporting
70+
If you encounter a bug or have an idea for a new feature, feel free to open an issue. Please include:
71+
72+
A clear description of the problem or feature request.
73+
Steps to reproduce the issue, if applicable.
74+
Any relevant log or error messages.
75+
Information about your environment (e.g., Node.js version, operating system).
76+
77+
## Pull Request Process
78+
We use the following steps for accepting pull requests:
79+
80+
1. **Ensure Tests Pass**
81+
82+
All tests must pass before we can merge your PR.
83+
84+
2. **Code Review**
85+
86+
Once you submit your PR, a maintainer will review it and may suggest changes.
87+
88+
3. **Merge**
89+
90+
Once your PR is approved, it will be merged into the main branch.
91+
92+
**Please ensure your PR follows these guidelines:**
93+
94+
- Write clear and concise commit messages.
95+
- Keep the changes focused on a single issue or feature.
96+
- If adding new features, consider writing tests to cover them.
97+
- Ensure that existing functionality and tests remain unaffected.
98+
99+
## Development Setup
100+
To set up your local environment for development:
101+
102+
1. **Clone the Repository**
103+
104+
```bash
105+
git clone https://github.com/hasib-devs/hono-routing-controller.git
106+
```
107+
108+
2. **Install Dependencies**
109+
110+
Install the required dependencies:
111+
```bash
112+
pnpm install
113+
```
114+
115+
3. **Start Development**
116+
117+
To run the application locally during development:
118+
```bash
119+
pnpm dev
120+
```
121+
122+
4. **Build**
123+
124+
To create a production build of the application:
125+
```bash
126+
pnpm build
127+
```
128+
129+
5. **Run Tests**
130+
131+
To run the test suite and ensure everything is working:
132+
```bash
133+
pnpm test
134+
```
135+
___
136+
Thanks for your contributions to the hono-routing-controller project!
137+
___

eslint.config.mjs

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import tsEslint from '@typescript-eslint/eslint-plugin';
2+
import tsParser from '@typescript-eslint/parser';
3+
import globals from 'globals';
4+
5+
export default [
6+
{
7+
files: ['**/*.ts'],
8+
languageOptions: {
9+
sourceType: 'module',
10+
parser: tsParser,
11+
parserOptions: {
12+
project: true,
13+
tsconfigRootDir: import.meta.dirname
14+
},
15+
globals: {
16+
...globals.node,
17+
...globals.es2022
18+
}
19+
},
20+
plugins: {
21+
'@typescript-eslint': tsEslint
22+
},
23+
rules: {
24+
// TypeScript rules
25+
'@typescript-eslint/consistent-type-imports': 'error',
26+
'@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '^_' }],
27+
'@typescript-eslint/no-explicit-any': 'warn',
28+
'@typescript-eslint/ban-ts-comment': 'warn',
29+
'@typescript-eslint/prefer-nullish-coalescing': 'error',
30+
'@typescript-eslint/prefer-optional-chain': 'error',
31+
32+
// Base ESLint rules
33+
'no-console': 'warn',
34+
'no-debugger': 'error',
35+
'eqeqeq': ['error', 'always'],
36+
'curly': 'error',
37+
'arrow-body-style': ['error', 'as-needed'],
38+
39+
// New ESLint 9.x rules
40+
'no-constant-binary-expression': 'error',
41+
'prefer-object-has-own': 'error',
42+
'logical-assignment-operators': 'error'
43+
},
44+
settings: {
45+
'import/resolver': {
46+
typescript: {}
47+
}
48+
}
49+
},
50+
{
51+
ignores: [
52+
'**/node_modules/',
53+
'dist/',
54+
'tests/',
55+
'coverage/',
56+
'*.d.ts',
57+
'*.config.js',
58+
'*.config.ts',
59+
'*.config.mjs',
60+
]
61+
}
62+
];

0 commit comments

Comments
 (0)