@kozojs/cli 0.1.4

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/README.md ADDED
@@ -0,0 +1,213 @@
1
+ # @kozojs/cli
2
+
3
+ ๐Ÿ”ฅ **CLI to scaffold new Kozo Framework projects** - The next-gen TypeScript Backend Framework with **Zod Native Integration**
4
+
5
+ ## Quick Start
6
+
7
+ ```bash
8
+ # Using npx
9
+ npx @kozojs/cli my-app
10
+
11
+ # Or install globally
12
+ npm install -g @kozojs/cli
13
+ kozo my-app
14
+ ```
15
+
16
+ ## Features
17
+
18
+ - ๐Ÿš€ **Interactive Setup** - Choose database, template, and more
19
+ - ๐Ÿ“ฆ **Zero Config** - Works out of the box
20
+ - ๐Ÿ”ฅ **Hono-powered** - Fastest HTTP framework
21
+ - ๐Ÿ›ก๏ธ **Type-safe** - Full TypeScript inference with Zod
22
+ - โšก **High Performance** - Ajv validation + fast-json-stringify serialization
23
+ - ๐Ÿ“š **OpenAPI Auto-gen** - Swagger docs out of the box
24
+ - ๐Ÿ—„๏ธ **Drizzle ORM** - Best-in-class database toolkit
25
+
26
+ ## Usage
27
+
28
+ ### Create a new project
29
+
30
+ ```bash
31
+ npx @kozojs/cli
32
+ ```
33
+
34
+ Or with a project name:
35
+
36
+ ```bash
37
+ npx @kozojs/cli my-awesome-api
38
+ ```
39
+
40
+ ### Interactive prompts
41
+
42
+ The CLI will ask you:
43
+
44
+ 1. **Project name** - Name of your new project
45
+ 2. **Template** - Choose from available templates:
46
+ - **Complete Server** - Full production-ready app (Auth, CRUD, Stats, Pagination)
47
+ - **Starter** - Minimal setup with database integration
48
+ - **SaaS** - Auth + Stripe + Email (coming soon)
49
+ - **E-commerce** - Products + Orders (coming soon)
50
+ 3. **Database** - PostgreSQL, MySQL, or SQLite (skipped for Complete template)
51
+ 4. **Package source** - npm registry or local workspace
52
+ 5. **Install dependencies** - Auto-run `pnpm install`
53
+
54
+ ## Project Structure
55
+
56
+ ### Starter Template (with Database)
57
+ ```
58
+ my-app/
59
+ โ”œโ”€โ”€ src/
60
+ โ”‚ โ”œโ”€โ”€ db/
61
+ โ”‚ โ”‚ โ”œโ”€โ”€ schema.ts # Drizzle schema
62
+ โ”‚ โ”‚ โ””โ”€โ”€ index.ts # Database client
63
+ โ”‚ โ”œโ”€โ”€ services/
64
+ โ”‚ โ”‚ โ””โ”€โ”€ index.ts # Service definitions
65
+ โ”‚ โ””โ”€โ”€ index.ts # Entry point with Zod native API
66
+ โ”œโ”€โ”€ drizzle.config.ts
67
+ โ”œโ”€โ”€ package.json
68
+ โ””โ”€โ”€ tsconfig.json
69
+ ```
70
+
71
+ ### Complete Server Template
72
+ ```
73
+ my-app/
74
+ โ”œโ”€โ”€ src/
75
+ โ”‚ โ”œโ”€โ”€ data/
76
+ โ”‚ โ”‚ โ””โ”€โ”€ store.ts # In-memory data store
77
+ โ”‚ โ”œโ”€โ”€ routes/
78
+ โ”‚ โ”‚ โ”œโ”€โ”€ auth/
79
+ โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ index.ts # Auth routes (login, me)
80
+ โ”‚ โ”‚ โ”œโ”€โ”€ users/
81
+ โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ index.ts # User CRUD routes
82
+ โ”‚ โ”‚ โ”œโ”€โ”€ posts/
83
+ โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ index.ts # Post routes
84
+ โ”‚ โ”‚ โ”œโ”€โ”€ health.ts # Health check
85
+ โ”‚ โ”‚ โ””โ”€โ”€ stats.ts # Statistics
86
+ โ”‚ โ”œโ”€โ”€ schemas/
87
+ โ”‚ โ”‚ โ”œโ”€โ”€ user.ts # User schemas
88
+ โ”‚ โ”‚ โ”œโ”€โ”€ post.ts # Post schemas
89
+ โ”‚ โ”‚ โ””โ”€โ”€ common.ts # Common schemas
90
+ โ”‚ โ”œโ”€โ”€ utils/
91
+ โ”‚ โ”‚ โ””โ”€โ”€ helpers.ts # Helper functions
92
+ โ”‚ โ””โ”€โ”€ index.ts # Entry point
93
+ โ”œโ”€โ”€ package.json
94
+ โ”œโ”€โ”€ tsconfig.json
95
+ โ””โ”€โ”€ README.md
96
+ ```
97
+
98
+ ## ๐Ÿš€ Complete Server Template
99
+
100
+ The **Complete Server** template generates a **production-ready** Kozo application with:
101
+
102
+ ### Features
103
+ - โœ… **Authentication** - Login endpoint with mock JWT
104
+ - โœ… **User Management** - Full CRUD (Create, Read, Update, Delete)
105
+ - โœ… **Posts System** - With authors, tags, and filtering
106
+ - โœ… **Pagination** - Query-based pagination for lists
107
+ - โœ… **Statistics** - System stats endpoint (users, posts, performance)
108
+ - โœ… **Health Check** - Fast-path health endpoint
109
+ - โœ… **In-Memory Store** - Ready-to-run without database setup
110
+
111
+ ### API Endpoints
112
+ - `POST /auth/login` - Authenticate user
113
+ - `GET /auth/me` - Get current user
114
+ - `GET /users?page=1&limit=10` - List users (paginated)
115
+ - `GET /users/:id` - Get user by ID
116
+ - `POST /users` - Create new user
117
+ - `PUT /users/:id` - Update user
118
+ - `DELETE /users/:id` - Delete user
119
+ - `GET /posts?published=true&tag=framework` - List posts (filtered)
120
+ - `GET /posts/:id` - Get post with author
121
+ - `POST /posts` - Create new post
122
+ - `GET /stats` - System statistics
123
+ - `GET /health` - Health check
124
+
125
+ ### Performance Optimized
126
+ - Pre-compiled Zod schemas (no runtime overhead)
127
+ - Optimized handler closures
128
+ - Fast-path routes for simple endpoints
129
+ - Minimal context allocation
130
+
131
+ ### Perfect For
132
+ - Learning Kozo framework features
133
+ - Prototyping and demos
134
+ - Benchmarking and performance testing
135
+ - Starting point for production apps
136
+
137
+ ## โœจ New Zod Native API
138
+
139
+ Kozo now features a **brand new API** with automatic TypeScript inference:
140
+
141
+ ```typescript
142
+ import { createKozo } from '@kozojs/core';
143
+ import { z } from 'zod';
144
+
145
+ const app = createKozo({
146
+ port: 3000,
147
+ openapi: {
148
+ info: { title: 'My API', version: '1.0.0' }
149
+ }
150
+ });
151
+
152
+ // Define schemas (compile-time only!)
153
+ const UserSchema = z.object({
154
+ id: z.string(),
155
+ name: z.string(),
156
+ email: z.string()
157
+ });
158
+
159
+ const CreateUserSchema = z.object({
160
+ name: z.string().min(2),
161
+ email: z.string().email()
162
+ });
163
+
164
+ // Routes with automatic type inference
165
+ app.get('/users', {
166
+ response: z.array(UserSchema)
167
+ }, (c) => {
168
+ // TypeScript SA che il return รจ UserSchema[]
169
+ return users;
170
+ });
171
+
172
+ app.post('/users', {
173
+ body: CreateUserSchema,
174
+ response: UserSchema
175
+ }, (c) => {
176
+ // TypeScript SA che c.body ha name: string, email: string
177
+ const newUser = {
178
+ id: Date.now().toString(),
179
+ name: c.body.name, // โœ… Type-checked
180
+ email: c.body.email // โœ… Type-checked
181
+ };
182
+ return newUser;
183
+ });
184
+
185
+ app.get('/users/:id', {
186
+ params: z.object({ id: z.string() }),
187
+ response: UserSchema
188
+ }, (c) => {
189
+ // TypeScript SA che c.params.id รจ string
190
+ const user = users.find(u => u.id === c.params.id);
191
+ return user;
192
+ });
193
+
194
+ console.log('๐Ÿš€ Server: http://localhost:3000');
195
+ console.log('๐Ÿ“š API Docs: http://localhost:3000/swagger');
196
+ app.listen();
197
+ ```
198
+
199
+ ## Performance Benefits
200
+
201
+ - **Validation**: Ajv compiled (5x faster than Zod runtime)
202
+ - **Serialization**: fast-json-stringify (2x faster than JSON.stringify)
203
+ - **Type Safety**: Complete TypeScript inference
204
+ - **Zero Overhead**: No runtime Zod parsing
205
+
206
+ ## Requirements
207
+
208
+ - Node.js >= 18.0.0
209
+ - pnpm (recommended) or npm
210
+
211
+ ## License
212
+
213
+ MIT
package/lib/index.d.ts ADDED
@@ -0,0 +1,2 @@
1
+
2
+ export { }