create-buntok 0.1.0 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-buntok",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "CLI tool to create new Buntok projects",
5
5
  "type": "module",
6
6
  "bin": {
@@ -1,8 +1,10 @@
1
1
  {
2
2
  "editor.formatOnSave": true,
3
3
  "editor.defaultFormatter": "biomejs.biome",
4
- "editor.tabSize": 2,
5
- "editor.insertSpaces": false,
4
+ "editor.codeActionsOnSave": {
5
+ "source.organizeImports.biome": "explicit",
6
+ "quickfix.biome": "explicit"
7
+ },
6
8
  "[typescript]": {
7
9
  "editor.defaultFormatter": "biomejs.biome"
8
10
  },
@@ -0,0 +1,291 @@
1
+ # Buntok Project
2
+
3
+ > High-performance web framework for [Bun](https://bun.sh) runtime
4
+
5
+ ## Getting Started
6
+
7
+ ```bash
8
+ # Development
9
+ bun run dev
10
+
11
+ # Production
12
+ bun run start
13
+ ```
14
+
15
+ Server starts on port `3000` (or `PORT` env var).
16
+
17
+ ## Project Structure
18
+
19
+ ```
20
+ src/
21
+ ├── controllers/ # Request handlers
22
+ ├── db/
23
+ │ └── schemas/ # Drizzle ORM schemas
24
+ ├── repositories/ # Database queries
25
+ ├── routes/ # Route definitions
26
+ ├── services/ # Business logic
27
+ └── index.ts # Entry point
28
+ ```
29
+
30
+ ## Code Generation
31
+
32
+ Generate CRUD files for an entity:
33
+
34
+ ```bash
35
+ # Generate all files
36
+ bunx buntok create user
37
+
38
+ # Generate specific files
39
+ bunx buntok create user --schema
40
+ bunx buntok create user --repo --service
41
+ bunx buntok create user --controller
42
+ bunx buntok create user --route
43
+ ```
44
+
45
+ ### What Gets Generated
46
+
47
+ | File | Description |
48
+ |------|-------------|
49
+ | `src/db/schemas/user.ts` | Drizzle schema |
50
+ | `src/repositories/user.repository.ts` | Database queries |
51
+ | `src/services/user.service.ts` | Business logic |
52
+ | `src/controllers/user.controller.ts` | Request handlers |
53
+ | `src/routes/user.routes.ts` | Route definitions + DI registration |
54
+
55
+ ### After Generation
56
+
57
+ 1. Add columns to schema in `src/db/schemas/user.ts`
58
+ 2. Run migrations:
59
+ ```bash
60
+ bun run db:push # Push schema to database
61
+ bun run db:generate # Generate migration files
62
+ bun run db:migrate # Run migrations
63
+ bun run db:studio # Open Drizzle Studio
64
+ ```
65
+
66
+ 3. Register routes in `src/index.ts`:
67
+ ```ts
68
+ import { registerUserRoutes } from "@/routes/user.routes";
69
+
70
+ registerUserRoutes(app);
71
+ ```
72
+
73
+ ## Basic Usage
74
+
75
+ ### Simple Route
76
+
77
+ ```ts
78
+ import { App } from "buntok";
79
+
80
+ const app = new App();
81
+
82
+ app.get("/", (ctx) => {
83
+ return ctx.json({ message: "Hello!" });
84
+ });
85
+ ```
86
+
87
+ ### Route with Params
88
+
89
+ ```ts
90
+ app.get("/users/:id", (ctx) => {
91
+ const { id } = ctx.params;
92
+ return ctx.json({ id });
93
+ });
94
+ ```
95
+
96
+ ### POST with Body
97
+
98
+ ```ts
99
+ app.post("/users", async (ctx) => {
100
+ const body = await ctx.body<{ name: string }>();
101
+ return ctx.json({ created: true, data: body }, 201);
102
+ });
103
+ ```
104
+
105
+ ### Route Group
106
+
107
+ ```ts
108
+ const api = app.group("/api");
109
+
110
+ api.get("/users", getUsers);
111
+ api.post("/users", createUser);
112
+ ```
113
+
114
+ ### Middleware
115
+
116
+ ```ts
117
+ // Global middleware
118
+ app.use(async (ctx, next) => {
119
+ console.log(`→ ${ctx.request.method}`);
120
+ const response = await next();
121
+ console.log(`← ${response.status}`);
122
+ return response;
123
+ });
124
+
125
+ // Per-route middleware
126
+ app.get("/admin", authMiddleware, (ctx) => {
127
+ return ctx.json({ message: "Admin only" });
128
+ });
129
+ ```
130
+
131
+ ### Dependency Injection
132
+
133
+ ```ts
134
+ // Register
135
+ app.set("userService", new UserService());
136
+
137
+ // Access in handler
138
+ app.get("/users", (ctx) => {
139
+ const users = ctx.di.userService.getAll();
140
+ return ctx.json({ data: users });
141
+ });
142
+ ```
143
+
144
+ ## Built-in Middlewares
145
+
146
+ ### CORS
147
+
148
+ ```ts
149
+ import { cors } from "buntok";
150
+
151
+ app.use(cors({ origin: "*" }));
152
+ ```
153
+
154
+ ### Rate Limiter
155
+
156
+ ```ts
157
+ import { rateLimiter } from "buntok";
158
+
159
+ app.use(rateLimiter({ max: 100, windowMs: 60000 }));
160
+ ```
161
+
162
+ ### Request ID
163
+
164
+ ```ts
165
+ import { requestId } from "buntok";
166
+
167
+ app.use(requestId());
168
+
169
+ // Access: ctx.store.requestId
170
+ ```
171
+
172
+ ### Response Time
173
+
174
+ ```ts
175
+ import { responseTime } from "buntok";
176
+
177
+ app.use(responseTime());
178
+
179
+ // Access: ctx.store.responseTime
180
+ ```
181
+
182
+ ### Health Check
183
+
184
+ ```ts
185
+ import { healthCheck } from "buntok";
186
+
187
+ app.use(healthCheck({
188
+ path: "/health",
189
+ checks: {
190
+ database: async () => {
191
+ await db.query("SELECT 1");
192
+ return { status: "ok" };
193
+ },
194
+ },
195
+ }));
196
+ ```
197
+
198
+ ## Context Methods
199
+
200
+ ```ts
201
+ app.get("/example", async (ctx) => {
202
+ // Body
203
+ const body = await ctx.body<{ name: string }>();
204
+
205
+ // Params
206
+ const id = ctx.params.id;
207
+
208
+ // JSON response
209
+ return ctx.json({ data: "ok" });
210
+
211
+ // Text response
212
+ return ctx.text("Hello");
213
+
214
+ // HTML response
215
+ return ctx.html("<h1>Hello</h1>");
216
+
217
+ // Status only
218
+ return ctx.status(204);
219
+
220
+ // Redirect
221
+ return ctx.redirect("/login", 302);
222
+
223
+ // Cookies
224
+ const token = ctx.getCookie("token");
225
+ });
226
+ ```
227
+
228
+ ## Error Handling
229
+
230
+ ```ts
231
+ import { NotFoundError, BadRequestError } from "buntok";
232
+
233
+ // Throw errors - automatically returns proper status code
234
+ throw new NotFoundError("User not found"); // 404
235
+ throw new BadRequestError("Invalid data"); // 400
236
+
237
+ // Or use asyncHandler in controllers (auto-catches errors)
238
+ import { asyncHandler } from "buntok";
239
+
240
+ export class UserController {
241
+ getAll = asyncHandler(async (ctx) => {
242
+ const users = await this.service.getAll();
243
+ return ctx.json({ data: users });
244
+ });
245
+ }
246
+ ```
247
+
248
+ ## Database Commands
249
+
250
+ ```bash
251
+ bun run db:push # Push schema to database
252
+ bun run db:generate # Generate migration files
253
+ bun run db:migrate # Run migrations
254
+ bun run db:studio # Open Drizzle Studio
255
+ ```
256
+
257
+ ## Configuration
258
+
259
+ ### Environment Variables
260
+
261
+ ```bash
262
+ # .env
263
+ DATABASE_URL=postgresql://user:password@localhost:5432/mydb
264
+ PORT=3000
265
+ NODE_ENV=development
266
+ ```
267
+
268
+ ### tsconfig.json
269
+
270
+ Path aliases are configured:
271
+ ```json
272
+ {
273
+ "paths": {
274
+ "@/*": ["./src/*"]
275
+ }
276
+ }
277
+ ```
278
+
279
+ Use `@/` for imports:
280
+ ```ts
281
+ import { UserService } from "@/services/user.service";
282
+ ```
283
+
284
+ ## Learn More
285
+
286
+ - [Buntok Documentation](https://www.npmjs.com/package/buntok)
287
+ - [Bun Documentation](https://bun.sh/docs)
288
+
289
+ ## License
290
+
291
+ MIT
@@ -15,11 +15,12 @@
15
15
  },
16
16
  "dependencies": {
17
17
  "buntok": "latest",
18
- "drizzle-orm": "^0.38.0"
18
+ "drizzle-orm": "^0.45.2"
19
19
  },
20
20
  "devDependencies": {
21
21
  "@biomejs/biome": "2.5.3",
22
22
  "@types/bun": "latest",
23
+ "@types/node": "^22",
23
24
  "drizzle-kit": "^0.30.0",
24
25
  "typescript": "^5"
25
26
  }
@@ -1,5 +1,5 @@
1
1
  import { drizzle } from "drizzle-orm/bun-sql";
2
- import * as schema from "./schemas";
2
+ import * as schema from "./schemas/index";
3
3
 
4
4
  // TODO: Update DATABASE_URL in .env file
5
5
  // Example: DATABASE_URL=postgresql://user:password@localhost:5432/mydb
@@ -0,0 +1,3 @@
1
+ // Export your schemas here
2
+ // Example:
3
+ // export * from "./user";
@@ -3,9 +3,5 @@ import { App } from "buntok";
3
3
  const app = new App();
4
4
 
5
5
  app.get("/", (ctx) => {
6
- return ctx.json({ message: "Welcome to {PROJECT_NAME}!" });
7
- });
8
-
9
- app.listen(3000, () => {
10
- console.log("Server running on http://localhost:3000");
6
+ return ctx.json({ message: "Welcome to BUNTOK!" });
11
7
  });
@@ -12,7 +12,11 @@
12
12
  "verbatimModuleSyntax": true,
13
13
  "noEmit": true,
14
14
  "strict": true,
15
- "skipLibCheck": true
15
+ "skipLibCheck": true,
16
+ "baseUrl": ".",
17
+ "paths": {
18
+ "@/*": ["./src/*"]
19
+ }
16
20
  },
17
21
  "include": ["src/**/*"]
18
22
  }