@ccci/micro-server 1.0.146 → 1.0.148

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 CHANGED
@@ -1,15 +1,133 @@
1
- # micro-server
1
+ # Microserver - Node.js, Express.js, WebSockets, and Bun.js
2
2
 
3
- To install dependencies:
3
+ This Microserver is built with **Node.js**, **Express.js**, **WebSockets**, and **Bun.js** to streamline the development of modern web applications. It incorporates an organized directory structure for managing API endpoints, request handlers, and database models.
4
4
 
5
- ```bash
6
- bun install
5
+ ---
6
+
7
+ ## Features
8
+
9
+ - **Node.js and Express.js**: Core technologies for building the server.
10
+ - **WebSockets**: Integrated support for real-time communication.
11
+ - **Bun.js**: High-performance runtime for modern JavaScript.
12
+ - **Sequelize ORM**: Simplifies database interaction with models and migrations.
13
+ - **Automatic API Endpoint Generation**: Auto-creates endpoints from files in the `/routes` directory.
14
+
15
+ ---
16
+
17
+ ## Directory Structure
18
+
19
+ ```
20
+ .
21
+ ├── /routes # API endpoint definitions
22
+ ├── /controller # Request handler logic
23
+ ├── /models # Sequelize models for database interaction
24
+ ├── /utils # Utility functions and helpers
25
+ ├── app.ts # Main application entry point
26
+ ├── db.config.ts # Database Connection
27
+ ├── package.json # Project dependencies and scripts
28
+ ```
29
+
30
+ ### `/routes`
31
+ Each file in the `/routes` directory corresponds to an API endpoint. The file name defines the route path, and its exported module maps to request methods (e.g., `GET`, `POST`, `PUT`, `DELETE`).
32
+
33
+ Example: `/routes/user.js`
34
+ ```js
35
+ module.exports = {
36
+ 'GET /': 'controller.userController.getAllUsers',
37
+ 'POST /': 'controller.userController.createUser',
38
+ };
39
+ ```
40
+
41
+ ### `/controller`
42
+ Request handlers for the routes. Each controller handles business logic and interacts with models.
43
+
44
+ Example: `/controller/userController.js`
45
+ ```js
46
+ const User = require('../models/User');
47
+
48
+ module.exports = {
49
+ getAllUsers: async (req, res) => {
50
+ const users = await User.findAll();
51
+ res.json(users);
52
+ },
53
+
54
+ createUser: async (req, res) => {
55
+ const user = await User.create(req.body);
56
+ res.status(201).json(user);
57
+ },
58
+ };
7
59
  ```
8
60
 
9
- To run:
61
+ ### `/models`
62
+ Sequelize ORM models representing database tables. Models include definitions for fields, data types, and relationships.
63
+
64
+ Example: `/models/User.js`
65
+ ```js
66
+ const { Model, DataTypes } = require('sequelize');
67
+ const sequelize = require('../config/database');
68
+
69
+ class User extends Model {}
10
70
 
11
- ```bash
12
- bun run index.ts
71
+ User.init(
72
+ {
73
+ name: DataTypes.STRING,
74
+ email: DataTypes.STRING,
75
+ },
76
+ { sequelize, modelName: 'User' }
77
+ );
78
+
79
+ module.exports = User;
13
80
  ```
14
81
 
15
- This project was created using `bun init` in bun v1.0.30. [Bun](https://bun.sh) is a fast all-in-one JavaScript runtime.
82
+ ---
83
+
84
+ ## Getting Started
85
+
86
+ ### Prerequisites
87
+ Ensure you have the following installed:
88
+ - **Node.js** (v16 or higher)
89
+ - **Bun.js** (latest version)
90
+ - **Sequelize CLI** for managing migrations
91
+
92
+ ### Start a new project using @ccci/run (Recommended)
93
+ ```bash
94
+ bunx @ccci/run init <projectName>
95
+ ```
96
+
97
+ ### Install as a dependency in an existing project
98
+ ```bash
99
+ bun install @ccci/micro-server
100
+ ```
101
+ ---
102
+
103
+ ## Usage
104
+
105
+ ### Adding an API Endpoint
106
+ 1. Create a new file in `/routes`, e.g., `/routes/product.js`.
107
+ 2. Define route methods and associate them with controllers.
108
+
109
+ ### Adding a Model
110
+ 1. Create a new file in `/models`, e.g., `/models/Product.js`.
111
+ 2. Define the model fields and configurations.
112
+ 3. Generate a migration using Sequelize CLI to apply the model to the database.
113
+
114
+ ### Real-Time Communication
115
+ Use WebSockets for real-time communication. The WebSocket server is integrated into the application for managing connections and events.
116
+
117
+ ---
118
+
119
+ ## Scripts
120
+ - `bun run app.js`: Start the server
121
+ - `npx sequelize-cli db:migrate`: Run database migrations
122
+ - `npx sequelize-cli db:seed`: Seed the database (optional)
123
+
124
+ ---
125
+
126
+ ## License
127
+ This project is licensed under the MIT License.
128
+
129
+ ---
130
+
131
+ ## Contributing
132
+ Contributions are welcome! Feel free to submit a pull request or open an issue for suggestions or bug reports.
133
+