create-featurebased-architecture-backend 1.0.0

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.
Files changed (77) hide show
  1. package/README.md +89 -0
  2. package/dist/index.js +828 -0
  3. package/package.json +42 -0
  4. package/templates/blank-hono/.env.example +4 -0
  5. package/templates/blank-hono/README.md +53 -0
  6. package/templates/blank-hono/package.json +18 -0
  7. package/templates/blank-hono/src/config/database.ts +4 -0
  8. package/templates/blank-hono/src/config/env.ts +5 -0
  9. package/templates/blank-hono/src/config/index.ts +2 -0
  10. package/templates/blank-hono/src/features/.gitkeep.ts +21 -0
  11. package/templates/blank-hono/src/index.ts +22 -0
  12. package/templates/blank-hono/src/routes/index.ts +8 -0
  13. package/templates/blank-hono/src/shared/index.ts +2 -0
  14. package/templates/blank-hono/src/shared/types/index.ts +16 -0
  15. package/templates/blank-hono/src/shared/utils/index.ts +1 -0
  16. package/templates/blank-hono/src/shared/utils/response.ts +10 -0
  17. package/templates/blank-hono/tsconfig.json +22 -0
  18. package/templates/blank-ts/README.md +30 -0
  19. package/templates/blank-ts/package.json +15 -0
  20. package/templates/blank-ts/src/features/.gitkeep.ts +16 -0
  21. package/templates/blank-ts/src/index.ts +7 -0
  22. package/templates/blank-ts/src/shared/utils/index.ts +3 -0
  23. package/templates/blank-ts/tsconfig.json +21 -0
  24. package/templates/react/README.md +34 -0
  25. package/templates/react/index.html +12 -0
  26. package/templates/react/package.json +22 -0
  27. package/templates/react/src/App.tsx +10 -0
  28. package/templates/react/src/features/home/components/HomePage.tsx +8 -0
  29. package/templates/react/src/features/home/index.ts +1 -0
  30. package/templates/react/src/index.css +10 -0
  31. package/templates/react/src/main.tsx +13 -0
  32. package/templates/react/src/shared/components/Button.tsx +29 -0
  33. package/templates/react/src/shared/components/index.ts +1 -0
  34. package/templates/react/tsconfig.json +27 -0
  35. package/templates/react/tsconfig.node.json +11 -0
  36. package/templates/react/vite.config.ts +12 -0
  37. package/templates/user-management-backend/.env.example +4 -0
  38. package/templates/user-management-backend/README.md +105 -0
  39. package/templates/user-management-backend/package.json +19 -0
  40. package/templates/user-management-backend/src/config/database.ts +4 -0
  41. package/templates/user-management-backend/src/config/env.ts +5 -0
  42. package/templates/user-management-backend/src/config/index.ts +2 -0
  43. package/templates/user-management-backend/src/features/users/controller.ts +100 -0
  44. package/templates/user-management-backend/src/features/users/index.ts +6 -0
  45. package/templates/user-management-backend/src/features/users/repository.ts +57 -0
  46. package/templates/user-management-backend/src/features/users/routes.ts +10 -0
  47. package/templates/user-management-backend/src/features/users/schema.ts +15 -0
  48. package/templates/user-management-backend/src/features/users/service.ts +40 -0
  49. package/templates/user-management-backend/src/features/users/types.ts +17 -0
  50. package/templates/user-management-backend/src/index.ts +22 -0
  51. package/templates/user-management-backend/src/routes/index.ts +8 -0
  52. package/templates/user-management-backend/src/shared/index.ts +2 -0
  53. package/templates/user-management-backend/src/shared/types/index.ts +16 -0
  54. package/templates/user-management-backend/src/shared/utils/index.ts +1 -0
  55. package/templates/user-management-backend/src/shared/utils/response.ts +10 -0
  56. package/templates/user-management-backend/tsconfig.json +22 -0
  57. package/templates/user-management-frontend/.env.example +1 -0
  58. package/templates/user-management-frontend/README.md +53 -0
  59. package/templates/user-management-frontend/index.html +12 -0
  60. package/templates/user-management-frontend/package.json +22 -0
  61. package/templates/user-management-frontend/src/App.tsx +19 -0
  62. package/templates/user-management-frontend/src/config/env.ts +1 -0
  63. package/templates/user-management-frontend/src/config/index.ts +1 -0
  64. package/templates/user-management-frontend/src/features/users/components/UserFormPage.tsx +76 -0
  65. package/templates/user-management-frontend/src/features/users/components/UsersPage.tsx +61 -0
  66. package/templates/user-management-frontend/src/features/users/components/index.ts +2 -0
  67. package/templates/user-management-frontend/src/features/users/hooks/index.ts +1 -0
  68. package/templates/user-management-frontend/src/features/users/hooks/useUsers.ts +45 -0
  69. package/templates/user-management-frontend/src/features/users/index.ts +4 -0
  70. package/templates/user-management-frontend/src/features/users/services/index.ts +1 -0
  71. package/templates/user-management-frontend/src/features/users/services/userService.ts +48 -0
  72. package/templates/user-management-frontend/src/features/users/types.ts +24 -0
  73. package/templates/user-management-frontend/src/index.css +108 -0
  74. package/templates/user-management-frontend/src/main.tsx +13 -0
  75. package/templates/user-management-frontend/tsconfig.json +27 -0
  76. package/templates/user-management-frontend/tsconfig.node.json +11 -0
  77. package/templates/user-management-frontend/vite.config.ts +12 -0
package/package.json ADDED
@@ -0,0 +1,42 @@
1
+ {
2
+ "name": "create-featurebased-architecture-backend",
3
+ "version": "1.0.0",
4
+ "description": "CLI to scaffold feature-based architecture projects with Bun, Hono, React",
5
+ "type": "module",
6
+ "bin": {
7
+ "create-featurebased-architecture-backend": "./dist/index.js"
8
+ },
9
+ "files": [
10
+ "dist",
11
+ "templates"
12
+ ],
13
+ "scripts": {
14
+ "build": "bun build ./src/index.ts --outdir ./dist --target node",
15
+ "dev": "bun run ./src/index.ts",
16
+ "prepublishOnly": "bun run build"
17
+ },
18
+ "keywords": [
19
+ "cli",
20
+ "scaffold",
21
+ "feature-based",
22
+ "architecture",
23
+ "hono",
24
+ "bun",
25
+ "typescript",
26
+ "react",
27
+ "boilerplate"
28
+ ],
29
+ "author": "",
30
+ "license": "MIT",
31
+ "devDependencies": {
32
+ "@types/bun": "latest",
33
+ "@types/node": "^20.10.0"
34
+ },
35
+ "peerDependencies": {
36
+ "typescript": "^5"
37
+ },
38
+ "dependencies": {
39
+ "@clack/prompts": "^0.7.0",
40
+ "picocolors": "^1.0.0"
41
+ }
42
+ }
@@ -0,0 +1,4 @@
1
+ # Environment Variables
2
+ DATABASE_URL=postgresql://user:password@your-neon-host.neon.tech/dbname?sslmode=require
3
+ PORT=3000
4
+ NODE_ENV=development
@@ -0,0 +1,53 @@
1
+ # {{PROJECT_NAME}}
2
+
3
+ A feature-based architecture backend built with Bun and Hono.
4
+
5
+ ## Project Structure
6
+
7
+ ```
8
+ src/
9
+ ├── config/ # Configuration (env, database)
10
+ ├── features/ # Feature modules
11
+ │ └── [feature]/
12
+ │ ├── routes.ts
13
+ │ ├── controller.ts
14
+ │ ├── service.ts
15
+ │ ├── repository.ts
16
+ │ └── types.ts
17
+ ├── routes/ # Route aggregation
18
+ ├── shared/ # Shared utilities and types
19
+ │ ├── types/
20
+ │ └── utils/
21
+ └── index.ts # Application entry
22
+ ```
23
+
24
+ ## Getting Started
25
+
26
+ ```bash
27
+ # Install dependencies
28
+ bun install
29
+
30
+ # Copy environment file
31
+ cp .env.example .env
32
+
33
+ # Run development server
34
+ bun run dev
35
+ ```
36
+
37
+ ## Environment Variables
38
+
39
+ | Variable | Description |
40
+ |----------|-------------|
41
+ | `DATABASE_URL` | NeonDB PostgreSQL connection string |
42
+ | `PORT` | Server port (default: 3000) |
43
+ | `NODE_ENV` | Environment (development/production) |
44
+
45
+ ## Database Setup (NeonDB)
46
+
47
+ Create your tables in NeonDB console or using a migration tool.
48
+
49
+ ## Adding a New Feature
50
+
51
+ 1. Create a folder in `src/features/[feature-name]`
52
+ 2. Add the required files (routes, controller, service, repository, types)
53
+ 3. Register the routes in `src/routes/index.ts`
@@ -0,0 +1,18 @@
1
+ {
2
+ "name": "{{PROJECT_NAME}}",
3
+ "version": "1.0.0",
4
+ "type": "module",
5
+ "scripts": {
6
+ "dev": "bun run --watch src/index.ts",
7
+ "start": "bun run src/index.ts",
8
+ "build": "bun build src/index.ts --outdir ./dist --target bun"
9
+ },
10
+ "dependencies": {
11
+ "hono": "^4.11.3",
12
+ "@neondatabase/serverless": "^0.9.0"
13
+ },
14
+ "devDependencies": {
15
+ "@types/bun": "latest",
16
+ "typescript": "^5.0.0"
17
+ }
18
+ }
@@ -0,0 +1,4 @@
1
+ import { neon } from "@neondatabase/serverless";
2
+ import { env } from "./env";
3
+
4
+ export const sql = neon(env.DATABASE_URL);
@@ -0,0 +1,5 @@
1
+ export const env = {
2
+ DATABASE_URL: process.env.DATABASE_URL || "",
3
+ PORT: Number(process.env.PORT) || 3000,
4
+ NODE_ENV: process.env.NODE_ENV || "development",
5
+ } as const;
@@ -0,0 +1,2 @@
1
+ export * from "./env";
2
+ export * from "./database";
@@ -0,0 +1,21 @@
1
+ /*
2
+ Feature-Based Architecture
3
+
4
+ Each feature folder should contain:
5
+ - routes.ts - Route definitions
6
+ - controller.ts - Request handlers
7
+ - service.ts - Business logic
8
+ - repository.ts - Database operations
9
+ - types.ts - Feature-specific types
10
+ - schema.ts - Validation schemas (optional)
11
+
12
+ Example structure:
13
+ features/
14
+ users/
15
+ routes.ts
16
+ controller.ts
17
+ service.ts
18
+ repository.ts
19
+ types.ts
20
+ */
21
+ export {};
@@ -0,0 +1,22 @@
1
+ import { Hono } from "hono";
2
+ import { cors } from "hono/cors";
3
+ import { logger } from "hono/logger";
4
+ import { env } from "./config/env";
5
+ import { appRouter } from "./routes";
6
+
7
+ const app = new Hono();
8
+
9
+ // Middleware
10
+ app.use("*", logger());
11
+ app.use("*", cors());
12
+
13
+ // Routes
14
+ app.route("/api", appRouter);
15
+
16
+ // Health check
17
+ app.get("/health", (c) => c.json({ status: "ok", timestamp: new Date().toISOString() }));
18
+
19
+ export default {
20
+ port: env.PORT,
21
+ fetch: app.fetch,
22
+ };
@@ -0,0 +1,8 @@
1
+ import { Hono } from "hono";
2
+
3
+ export const appRouter = new Hono();
4
+
5
+ // Register feature routes here
6
+ // Example: appRouter.route("/users", usersRouter);
7
+
8
+ appRouter.get("/", (c) => c.json({ message: "API is running" }));
@@ -0,0 +1,2 @@
1
+ export * from "./types";
2
+ export * from "./utils";
@@ -0,0 +1,16 @@
1
+ // Shared types across features
2
+ export interface ApiResponse<T> {
3
+ success: boolean;
4
+ data?: T;
5
+ error?: string;
6
+ message?: string;
7
+ }
8
+
9
+ export interface PaginatedResponse<T> extends ApiResponse<T[]> {
10
+ pagination: {
11
+ page: number;
12
+ limit: number;
13
+ total: number;
14
+ totalPages: number;
15
+ };
16
+ }
@@ -0,0 +1 @@
1
+ export * from "./response";
@@ -0,0 +1,10 @@
1
+ import type { Context } from "hono";
2
+ import type { ApiResponse } from "../types";
3
+
4
+ export function successResponse<T>(c: Context, data: T, message?: string, status = 200) {
5
+ return c.json<ApiResponse<T>>({ success: true, data, message }, status);
6
+ }
7
+
8
+ export function errorResponse(c: Context, error: string, status = 400) {
9
+ return c.json<ApiResponse<never>>({ success: false, error }, status);
10
+ }
@@ -0,0 +1,22 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "module": "ESNext",
5
+ "moduleResolution": "bundler",
6
+ "strict": true,
7
+ "esModuleInterop": true,
8
+ "skipLibCheck": true,
9
+ "forceConsistentCasingInFileNames": true,
10
+ "outDir": "./dist",
11
+ "rootDir": "./src",
12
+ "baseUrl": ".",
13
+ "paths": {
14
+ "@/*": ["src/*"],
15
+ "@/features/*": ["src/features/*"],
16
+ "@/shared/*": ["src/shared/*"],
17
+ "@/config/*": ["src/config/*"]
18
+ }
19
+ },
20
+ "include": ["src/**/*"],
21
+ "exclude": ["node_modules", "dist"]
22
+ }
@@ -0,0 +1,30 @@
1
+ # {{PROJECT_NAME}}
2
+
3
+ A feature-based TypeScript project built with Bun.
4
+
5
+ ## Project Structure
6
+
7
+ ```
8
+ src/
9
+ ├── features/ # Feature modules
10
+ │ └── [feature]/
11
+ │ ├── index.ts
12
+ │ ├── types.ts
13
+ │ └── utils.ts
14
+ ├── shared/ # Shared utilities
15
+ │ └── utils/
16
+ └── index.ts # Application entry
17
+ ```
18
+
19
+ ## Getting Started
20
+
21
+ ```bash
22
+ # Install dependencies
23
+ bun install
24
+
25
+ # Run development
26
+ bun run dev
27
+
28
+ # Build
29
+ bun run build
30
+ ```
@@ -0,0 +1,15 @@
1
+ {
2
+ "name": "{{PROJECT_NAME}}",
3
+ "version": "1.0.0",
4
+ "type": "module",
5
+ "scripts": {
6
+ "dev": "bun run --watch src/index.ts",
7
+ "start": "bun run src/index.ts",
8
+ "build": "bun build src/index.ts --outdir ./dist --target bun"
9
+ },
10
+ "dependencies": {},
11
+ "devDependencies": {
12
+ "@types/bun": "latest",
13
+ "typescript": "^5.0.0"
14
+ }
15
+ }
@@ -0,0 +1,16 @@
1
+ /*
2
+ Feature-Based Architecture
3
+
4
+ Each feature folder should contain:
5
+ - index.ts - Feature entry point
6
+ - types.ts - Feature-specific types
7
+ - utils.ts - Feature utilities (optional)
8
+
9
+ Example structure:
10
+ features/
11
+ my-feature/
12
+ index.ts
13
+ types.ts
14
+ utils.ts
15
+ */
16
+ export {};
@@ -0,0 +1,7 @@
1
+ import { greet } from "./shared/utils";
2
+
3
+ function main(): void {
4
+ console.log(greet("World"));
5
+ }
6
+
7
+ main();
@@ -0,0 +1,3 @@
1
+ export function greet(name: string): string {
2
+ return `Hello, ${name}!`;
3
+ }
@@ -0,0 +1,21 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "module": "ESNext",
5
+ "moduleResolution": "bundler",
6
+ "strict": true,
7
+ "esModuleInterop": true,
8
+ "skipLibCheck": true,
9
+ "forceConsistentCasingInFileNames": true,
10
+ "outDir": "./dist",
11
+ "rootDir": "./src",
12
+ "baseUrl": ".",
13
+ "paths": {
14
+ "@/*": ["src/*"],
15
+ "@/features/*": ["src/features/*"],
16
+ "@/shared/*": ["src/shared/*"]
17
+ }
18
+ },
19
+ "include": ["src/**/*"],
20
+ "exclude": ["node_modules", "dist"]
21
+ }
@@ -0,0 +1,34 @@
1
+ # {{PROJECT_NAME}}
2
+
3
+ A feature-based React application built with Vite and Bun.
4
+
5
+ ## Project Structure
6
+
7
+ ```
8
+ src/
9
+ ├── features/ # Feature modules
10
+ │ └── [feature]/
11
+ │ ├── components/
12
+ │ ├── hooks/
13
+ │ ├── services/
14
+ │ ├── types.ts
15
+ │ └── index.ts
16
+ ├── shared/ # Shared components and utilities
17
+ │ └── components/
18
+ ├── App.tsx
19
+ ├── main.tsx
20
+ └── index.css
21
+ ```
22
+
23
+ ## Getting Started
24
+
25
+ ```bash
26
+ # Install dependencies
27
+ bun install
28
+
29
+ # Run development server
30
+ bun run dev
31
+
32
+ # Build for production
33
+ bun run build
34
+ ```
@@ -0,0 +1,12 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
+ <title>{{PROJECT_NAME}}</title>
7
+ </head>
8
+ <body>
9
+ <div id="root"></div>
10
+ <script type="module" src="/src/main.tsx"></script>
11
+ </body>
12
+ </html>
@@ -0,0 +1,22 @@
1
+ {
2
+ "name": "{{PROJECT_NAME}}",
3
+ "version": "1.0.0",
4
+ "type": "module",
5
+ "scripts": {
6
+ "dev": "bunx --bun vite",
7
+ "build": "bunx --bun vite build",
8
+ "preview": "bunx --bun vite preview"
9
+ },
10
+ "dependencies": {
11
+ "react": "^18.2.0",
12
+ "react-dom": "^18.2.0",
13
+ "react-router-dom": "^6.20.0"
14
+ },
15
+ "devDependencies": {
16
+ "@types/react": "^18.2.0",
17
+ "@types/react-dom": "^18.2.0",
18
+ "@vitejs/plugin-react": "^4.2.0",
19
+ "typescript": "^5.0.0",
20
+ "vite": "^5.0.0"
21
+ }
22
+ }
@@ -0,0 +1,10 @@
1
+ import { Routes, Route } from "react-router-dom";
2
+ import { HomePage } from "./features/home";
3
+
4
+ export function App() {
5
+ return (
6
+ <Routes>
7
+ <Route path="/" element={<HomePage />} />
8
+ </Routes>
9
+ );
10
+ }
@@ -0,0 +1,8 @@
1
+ export function HomePage() {
2
+ return (
3
+ <div style={{ padding: "2rem", textAlign: "center" }}>
4
+ <h1>Welcome</h1>
5
+ <p>Feature-based React architecture</p>
6
+ </div>
7
+ );
8
+ }
@@ -0,0 +1 @@
1
+ export * from "./components/HomePage";
@@ -0,0 +1,10 @@
1
+ * {
2
+ margin: 0;
3
+ padding: 0;
4
+ box-sizing: border-box;
5
+ }
6
+
7
+ body {
8
+ font-family: system-ui, -apple-system, sans-serif;
9
+ line-height: 1.5;
10
+ }
@@ -0,0 +1,13 @@
1
+ import React from "react";
2
+ import ReactDOM from "react-dom/client";
3
+ import { BrowserRouter } from "react-router-dom";
4
+ import { App } from "./App";
5
+ import "./index.css";
6
+
7
+ ReactDOM.createRoot(document.getElementById("root")!).render(
8
+ <React.StrictMode>
9
+ <BrowserRouter>
10
+ <App />
11
+ </BrowserRouter>
12
+ </React.StrictMode>
13
+ );
@@ -0,0 +1,29 @@
1
+ import type { ReactNode } from "react";
2
+
3
+ interface ButtonProps {
4
+ children: ReactNode;
5
+ onClick?: () => void;
6
+ variant?: "primary" | "secondary";
7
+ }
8
+
9
+ export function Button({ children, onClick, variant = "primary" }: ButtonProps) {
10
+ const styles = {
11
+ primary: { background: "#0070f3", color: "white" },
12
+ secondary: { background: "#eaeaea", color: "#333" },
13
+ };
14
+
15
+ return (
16
+ <button
17
+ onClick={onClick}
18
+ style={{
19
+ ...styles[variant],
20
+ padding: "0.5rem 1rem",
21
+ border: "none",
22
+ borderRadius: "4px",
23
+ cursor: "pointer",
24
+ }}
25
+ >
26
+ {children}
27
+ </button>
28
+ );
29
+ }
@@ -0,0 +1 @@
1
+ export * from "./Button";
@@ -0,0 +1,27 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2020",
4
+ "useDefineForClassFields": true,
5
+ "lib": ["ES2020", "DOM", "DOM.Iterable"],
6
+ "module": "ESNext",
7
+ "skipLibCheck": true,
8
+ "moduleResolution": "bundler",
9
+ "allowImportingTsExtensions": true,
10
+ "resolveJsonModule": true,
11
+ "isolatedModules": true,
12
+ "noEmit": true,
13
+ "jsx": "react-jsx",
14
+ "strict": true,
15
+ "noUnusedLocals": true,
16
+ "noUnusedParameters": true,
17
+ "noFallthroughCasesInSwitch": true,
18
+ "baseUrl": ".",
19
+ "paths": {
20
+ "@/*": ["src/*"],
21
+ "@/features/*": ["src/features/*"],
22
+ "@/shared/*": ["src/shared/*"]
23
+ }
24
+ },
25
+ "include": ["src"],
26
+ "references": [{ "path": "./tsconfig.node.json" }]
27
+ }
@@ -0,0 +1,11 @@
1
+ {
2
+ "compilerOptions": {
3
+ "composite": true,
4
+ "skipLibCheck": true,
5
+ "module": "ESNext",
6
+ "moduleResolution": "bundler",
7
+ "allowSyntheticDefaultImports": true,
8
+ "strict": true
9
+ },
10
+ "include": ["vite.config.ts"]
11
+ }
@@ -0,0 +1,12 @@
1
+ import { defineConfig } from "vite";
2
+ import react from "@vitejs/plugin-react";
3
+ import path from "path";
4
+
5
+ export default defineConfig({
6
+ plugins: [react()],
7
+ resolve: {
8
+ alias: {
9
+ "@": path.resolve(__dirname, "./src"),
10
+ },
11
+ },
12
+ });
@@ -0,0 +1,4 @@
1
+ # Environment Variables
2
+ DATABASE_URL=postgresql://user:password@your-neon-host.neon.tech/dbname?sslmode=require
3
+ PORT=3000
4
+ NODE_ENV=development