2.1.8 • Published 2 years ago
@vcsc/node-core v2.1.8
Directories
Project yêu cầu tuân thủ việc sử dụng standard folder naming convention đưới đây.
Note: trường hợp việc phân mục của application bạn làm không hợp lý khi sử dụng các folder dưới đây, vui lòng raise với team
Project Structure
Sử dụng các tên folder dưới đây với các mục đích như sau:
- Controllers: /controllers/ -- Các root controller, sử dụng để lưu controller cho endpoint
- Models: /models/ -- Lưu raw db model từ ORM, SQL, etc, raw table từ db
- Modules: /modules/ -- Các modules khác
- Schema: /schemas/ -- Schema, Graphql Schema
- Services: /services/ -- Business / Process Logic / Custom Logic
- Views: /views/ -- views for view engine
- Public: /public/ -- public assets (png/pdf/jpg/json)
- Private: /private/ -- private assets
- Temporary: /tmp/ -- temporary, use for tempory cache, generated contents,
- Worker: /workers/ -- contain worker script, cronjob script
- Migration: /migrations/ -- db migrations
- Bin: /bin/ -- executable script (.sh, etc)
- Build: /build/ -- build js version
- Log: /logs/ -- logs if has
- Config: /configs/ -- constant, configs if have (for constant please use Enum)
- @Types: /@types/ -- autoload type/interface
- Packages: /packages/ -- some imported code, khả năng không biết đến từ đâu
- decorators: /decorators/ -- Custom decorator functions để ở đây
- Lib /lib/
Nested module pattern
- Đảm bảo tính đóng gói các Application logic thông qua việc tạo folder cho từng module:
- Ví dụ
/services/serviceName
và có nested strucures như@types
vàdecorators
- Ví dụ
Nested Structures:
- /services/user
- /services/user/@types
- /services/user/decorators
Front-End
Trên front-end, 2 folders dưới đây được thêm vào danh sách
- Components: /components/ -- shared components
- Page: /pages/ -- router theo trang (sử dụng thay cho /controllers/)
Files
1. Index.ts tại root - Yêu cầu 1 file index.ts để boot dự án ở root
2. Tách môi trường development và production
Code structure standard
1. Mỗi Module hoặc Service sẽ có 1 folder riêng, trừ các case có file duy nhất.
// Service User gồm 1 file index "services/user/index.ts" chứa class như sau
export default class User {
}
2. Không trực tiếp import từ trong các module(folder) hoặc nested module. Các function/class phải expose ra ngoài cần declare export trong file index.ts
KHÔNG NÊN
// Không import trực tiếp module từ file bên trong module
import someController from 'services/users/someController.ts'
import someUtil from 'serviecs/users/util/someUtil.ts'
NÊN
// Export thông qua file index.ts để highlight các chức năng hỗ trợ
export someController from 'services/users/someController.ts' (trong "services/users/index.ts")
export someUtil from 'services/users/someUtil.ts' (trong "serviecs/users/util/index.ts")
// Import các file từ index only
import someController from 'services/users'
import someUtil from 'services/users/util'
3. Các shared type, interface đặt trong folder @types
4. Sử dụng class và static properties cho singleton, hạn chế sử dụng functional ngoại trừ các function dùng kết nối với lib khác
// services/users/index.ts
class User {
static singleton = "something only declare once or has one instance";
authenticate() {
// Do something with sharing singleton;
User.singleton();
}
}
2.1.8
2 years ago
2.1.6
2 years ago
2.1.7
2 years ago
2.1.4
2 years ago
2.1.3
2 years ago
2.1.5
2 years ago
1.0.2
2 years ago
1.0.3
2 years ago
2.1.2
2 years ago
2.0.3
2 years ago
2.1.1
2 years ago
2.0.2
2 years ago
2.0.13
2 years ago
2.0.5
2 years ago
2.0.4
2 years ago
2.0.11
2 years ago
2.0.7
2 years ago
2.0.12
2 years ago
2.0.6
2 years ago
2.0.9
2 years ago
2.0.10
2 years ago
2.0.8
2 years ago
2.1.0
2 years ago
2.0.1
2 years ago
2.0.0
2 years ago
1.0.0
2 years ago