https://github.com/asenajs/asena
IoC web framework for bun
https://github.com/asenajs/asena
bun hono ioc ioc-framework typescript-framework web-framework websockets
Last synced: 6 months ago
JSON representation
IoC web framework for bun
- Host: GitHub
- URL: https://github.com/asenajs/asena
- Owner: AsenaJs
- License: mit
- Created: 2024-08-29T13:36:23.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2025-03-04T22:02:46.000Z (about 1 year ago)
- Last Synced: 2025-03-27T17:11:25.647Z (12 months ago)
- Topics: bun, hono, ioc, ioc-framework, typescript-framework, web-framework, websockets
- Language: TypeScript
- Homepage:
- Size: 607 KB
- Stars: 32
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Asena
Asena is a NestJS-like IoC web framework built on top of Bun. It combines the power of dependency injection
with the performance of Bun runtime and the flexibility of Adapter design system.
## Documentation
For detailed documentation, please visit [not ready yet](https://asena.sh). Documentation is still in progress, but updates are being made regularly. You can check this project [AsenaExample](https://github.com/LibirSoft/AsenaExample). I am always updating it to latest usages.
## Key Features
- **Dependency Injection**: Built-in IoC container for managing dependencies
- **Decorator-based Development**: Similar to NestJS, using TypeScript decorators for routing and DI
- **High Performance**: Leverages Bun runtime for optimal performance
- **WebSocket Support**: Built-in WebSocket handling capabilities
- **Middleware System**: Flexible middleware architecture
- **HTTP Adapters**: Extensible adapter system with Hono as default
- **Zero Dependencies**: Only uses reflect-metadata for dependency injection
- **TypeScript Support**: Full TypeScript support with strict mode
- **Modular Architecture**: Easy to extend and customize
## Quick Start
The easiest way to create a new Asena project is using the CLI:
```bash
# Create a new project
bun add -D @asenajs/asena-cli
asena create
```
This will create a new project with the following structure:
```
├── src/
│ ├── controllers/
│ │ └── AsenaController.ts
│ └── index.ts
├── package.json
├── tsconfig.json
├── .eslintrc.js
├── .eslintignore
└── .prettierrc.js
```
## Alternative start
Alternatively, you can create a project manually:
First, create a new project using Bun:
```bash
bun init
```
For decorators working properly, you need to add some settings to your tsconfig. Here is a recommended file:
```json
{
"compilerOptions": {
// Enable latest features
"lib": ["ESNext", "DOM"],
"target": "ESNext",
"module": "ESNext",
"moduleDetection": "force",
"jsx": "react-jsx",
"allowJs": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
// Bundler mode
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"verbatimModuleSyntax": true,
"noEmit": true,
// Best practices
"strict": true,
"skipLibCheck": true,
"noFallthroughCasesInSwitch": true,
// Some stricter flags
"noUnusedLocals": true,
"noUnusedParameters": true,
"noPropertyAccessFromIndexSignature": true
}
}
```
After that you need to make sure to edit your tsConfig.json it should look like this
Then, install these packages:
* `@asenajs/asena`: Base package
* `@asenajs/hono-adapter`: For web-server. Asena currently only support hono adapter.
* `@asenajs/asena-logger`: For better logs
```bash
bun install @asenajs/asena @asenajs/hono-adapter @asenajs/asena-logger
```
* `@asenajs/asena-cli`: This package provides a CLI for creating and managing Asena projects.
```bash
bun install -D @asenajs/asena-cli
```
After installation, you need to create asena-config.ts file you can create it with asena-cli
```bash
asena init
```
this will create you asena-config file.
`Note`: Built options directly copy of bun options, you can check bun documentation for more
options. [Bun Documentation](https://bun.sh/docs/bundler#reference)
Create index.ts file under your src folder:
```typescript
// src/index.ts
import {AsenaServer} from '@asenajs/asena';
import {createHonoAdapter} from '@asenajs/hono-adapter';
import {logger} from './logger/logger';
const [honoAdapter,asenaLogger] = createHonoAdapter(logger);
await new AsenaServer(honoAdapter, asenaLogger).port(3000).start();
```
To run asena you need at least one controller. Create a new controller:
```typescript
// src/controllers/TestController.ts
import type { Context } from '@asenajs/hono-adapter';
import { Controller } from '@asenajs/asena/server';
import { Get } from '@asenajs/asena/web';
@Controller('/hello')
export class TestController {
@Get('/world')
public async getHello(context: Context) {
return context.send('Hello World');
}
}
```
Finally, run the project:
```bash
## only for fast developing purposes
asena dev start
```
```bash
## or you can simply build then run your bundled project
asena build
## then go to dist folder and run the project this way it will consume less memory and it will be faster.
bun index.asena.js
```
## CLI Commands
For more information about CLI commands and usage, please visit:
[Asena CLI Documentation](https://asena.sh/docs/cli/overview.html)
## Project Structure
```
lib/
├── adapter/ # HTTP adapter implementations
├── server/ # Core server functionality
├── ioc/ # Dependency injection container
├── utils/ # Utility functions
├── test/ # Test utilities
```
## Core Concepts
- **Controllers**: Handle incoming requests using decorators
- **Services**: Business logic containers that can be injected
- **Middleware**: Request/Response interceptors
- **WebSocket**: Built-in WebSocket support
- **HTTP Status**: Standard HTTP status codes and utilities
## Performance
Built on Bun runtime, Asena provides:
- Fast startup time
- Low memory footprint
- Quick request processing
- Efficient WebSocket handling
Here is the benchmark result of Asena with Hono adapter (Basic hello world example) in every test we used bun to run
the project:
### Performance Comparison (Fastest to Slowest)
| Framework | Requests/sec | Latency (avg) | Transfer/sec |
| ------------------------------------ | ------------ | ------------- | ------------ |
| Hono | 147,031.08 | 2.69ms | 18.09MB |
| Asena + Hono-adapter | 137,148.80 | 2.89ms | 16.74MB |
| NestJS (Bun + Fastify) | 81,652.05 | 6.01ms | 13.78MB |
| NestJS (Bun) | 64,435.83 | 6.14ms | 11.80MB |
| NestJS (Bun + kiyasov/platform-hono) | 45,082.27 | 8.79ms | 5.55MB |
| NestJS (Node) | 17,649.89 | 24.43ms | 4.02MB |
> Benchmark conditions:
>
> - 12 threads
> - 400 connections
> - 120 seconds duration
> - Simple "Hello World" endpoint
> - Running on same hardware
_Note: Lower latency and higher requests/sec indicate better performance_
## Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
## License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
## Support
If you encounter any issues or have questions, please open an issue on the [GitHub repository](https://github.com/AsenaJs/Asena/issues).