feat(docs): Remove outdated service templates and enhance Vietnamese architecture documentation
- Deleted obsolete service architecture templates in both English and Vietnamese to streamline content. - Updated the Vietnamese architecture documentation with improved Mermaid diagrams for better visual clarity. - Enhanced color coding in diagrams to improve readability and consistency across documentation. - Added a new section detailing visual indicators for better understanding of architecture components.
This commit is contained in:
28
services/_template_nodejs/prisma/prisma.config.ts
Normal file
28
services/_template_nodejs/prisma/prisma.config.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
// Prisma 7 Configuration File
|
||||
// https://www.prisma.io/docs/orm/prisma-client/setup-and-configuration/introduction/configuration
|
||||
|
||||
import { PrismaClient } from '@prisma/client';
|
||||
import { neonConfig } from '@neondatabase/serverless';
|
||||
import { Pool } from '@neondatabase/serverless';
|
||||
import { PrismaNeon } from '@prisma/adapter-neon';
|
||||
|
||||
// EN: Get database URL from environment
|
||||
// VI: Lấy database URL từ environment
|
||||
const databaseUrl = process.env.DATABASE_URL;
|
||||
|
||||
if (!databaseUrl) {
|
||||
throw new Error('DATABASE_URL environment variable is required');
|
||||
}
|
||||
|
||||
// EN: Configure Neon connection pool
|
||||
// VI: Cấu hình connection pool cho Neon
|
||||
neonConfig.webSocketConstructor = globalThis.WebSocket;
|
||||
|
||||
const pool = new Pool({ connectionString: databaseUrl });
|
||||
const adapter = new PrismaNeon(pool);
|
||||
|
||||
// EN: Export configured Prisma Client
|
||||
// VI: Export Prisma Client đã cấu hình
|
||||
export const prisma = new PrismaClient({ adapter });
|
||||
|
||||
export default prisma;
|
||||
48
services/_template_nodejs/prisma/schema.prisma
Normal file
48
services/_template_nodejs/prisma/schema.prisma
Normal file
@@ -0,0 +1,48 @@
|
||||
// EN: Prisma schema for microservice template
|
||||
// VI: Schema Prisma cho template microservice
|
||||
|
||||
generator client {
|
||||
provider = "prisma-client-js"
|
||||
}
|
||||
|
||||
datasource db {
|
||||
provider = "postgresql"
|
||||
}
|
||||
|
||||
|
||||
// EN: Feature model - represents a configurable feature in the system
|
||||
// VI: Model Feature - đại diện cho một tính năng có thể cấu hình trong hệ thống
|
||||
model Feature {
|
||||
// EN: Primary key / Khóa chính
|
||||
id String @id @default(cuid())
|
||||
|
||||
// EN: Feature name (unique identifier) / Tên tính năng (mã định danh duy nhất)
|
||||
name String @unique
|
||||
|
||||
// EN: Human-readable title / Tiêu đề dễ đọc
|
||||
title String?
|
||||
|
||||
// EN: Detailed description / Mô tả chi tiết
|
||||
description String?
|
||||
|
||||
// EN: Feature configuration as JSON / Cấu hình tính năng dạng JSON
|
||||
config Json?
|
||||
|
||||
// EN: Whether the feature is enabled / Tính năng có được bật không
|
||||
enabled Boolean @default(true)
|
||||
|
||||
// EN: Feature version for migration purposes / Phiên bản tính năng cho mục đích migration
|
||||
version String? @default("1.0.0")
|
||||
|
||||
// EN: Timestamps / Dấu thời gian
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
|
||||
// EN: Optional tags for categorization / Tags tùy chọn để phân loại
|
||||
tags String[]
|
||||
|
||||
// EN: Metadata for extensibility / Metadata để mở rộng
|
||||
metadata Json?
|
||||
|
||||
@@map("features")
|
||||
}
|
||||
111
services/_template_nodejs/prisma/seed.ts
Normal file
111
services/_template_nodejs/prisma/seed.ts
Normal file
@@ -0,0 +1,111 @@
|
||||
import { PrismaClient } from '@prisma/client';
|
||||
import { logger } from '@goodgo/logger';
|
||||
|
||||
// EN: Initialize Prisma client for seeding
|
||||
// VI: Khởi tạo Prisma client cho seeding
|
||||
const prisma = new PrismaClient();
|
||||
|
||||
async function main() {
|
||||
logger.info('Starting database seeding / Bắt đầu seeding database');
|
||||
|
||||
// EN: Seed initial features
|
||||
// VI: Seed các tính năng ban đầu
|
||||
const features = [
|
||||
{
|
||||
name: 'health-checks',
|
||||
title: 'Health Checks',
|
||||
description: 'EN: System health monitoring endpoints / VI: Endpoints giám sát sức khỏe hệ thống',
|
||||
enabled: true,
|
||||
version: '1.0.0',
|
||||
tags: ['system', 'monitoring'],
|
||||
config: {
|
||||
endpoints: ['/health', '/health/ready', '/health/live'],
|
||||
interval: 30000, // 30 seconds
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'metrics',
|
||||
title: 'Prometheus Metrics',
|
||||
description: 'EN: Application metrics collection / VI: Thu thập metrics ứng dụng',
|
||||
enabled: true,
|
||||
version: '1.0.0',
|
||||
tags: ['observability', 'monitoring'],
|
||||
config: {
|
||||
endpoint: '/metrics',
|
||||
format: 'prometheus',
|
||||
defaultMetrics: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'rate-limiting',
|
||||
title: 'Rate Limiting',
|
||||
description: 'EN: API rate limiting protection / VI: Bảo vệ giới hạn tốc độ API',
|
||||
enabled: true,
|
||||
version: '1.0.0',
|
||||
tags: ['security', 'performance'],
|
||||
config: {
|
||||
windowMs: 900000, // 15 minutes
|
||||
max: 100, // limit each IP to 100 requests per windowMs
|
||||
standardHeaders: true,
|
||||
legacyHeaders: false,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'cors',
|
||||
title: 'CORS Protection',
|
||||
description: 'EN: Cross-Origin Resource Sharing configuration / VI: Cấu hình Cross-Origin Resource Sharing',
|
||||
enabled: true,
|
||||
version: '1.0.0',
|
||||
tags: ['security', 'api'],
|
||||
config: {
|
||||
origins: ['http://localhost:3000'],
|
||||
credentials: true,
|
||||
methods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'],
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'tracing',
|
||||
title: 'Distributed Tracing',
|
||||
description: 'EN: Jaeger/OpenTelemetry distributed tracing / VI: Distributed tracing với Jaeger/OpenTelemetry',
|
||||
enabled: false,
|
||||
version: '1.0.0',
|
||||
tags: ['observability', 'tracing'],
|
||||
config: {
|
||||
serviceName: 'microservice-template',
|
||||
jaegerEndpoint: 'http://localhost:14268/api/traces',
|
||||
samplingRate: 1.0,
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
// EN: Create features in database
|
||||
// VI: Tạo features trong database
|
||||
for (const feature of features) {
|
||||
await prisma.feature.upsert({
|
||||
where: { name: feature.name },
|
||||
update: {
|
||||
title: feature.title,
|
||||
description: feature.description,
|
||||
enabled: feature.enabled,
|
||||
version: feature.version,
|
||||
tags: feature.tags,
|
||||
config: feature.config,
|
||||
updatedAt: new Date(),
|
||||
},
|
||||
create: feature,
|
||||
});
|
||||
|
||||
logger.info(`Seeded feature: ${feature.name} / Đã seed feature: ${feature.name}`);
|
||||
}
|
||||
|
||||
logger.info('Database seeding completed / Hoàn thành seeding database');
|
||||
}
|
||||
|
||||
main()
|
||||
.catch((e) => {
|
||||
logger.error('Error during database seeding / Lỗi trong quá trình seeding database', { error: e });
|
||||
process.exit(1);
|
||||
})
|
||||
.finally(async () => {
|
||||
await prisma.$disconnect();
|
||||
});
|
||||
Reference in New Issue
Block a user