Этап 1: каркас монорепо, Docker Compose, Prisma-схема, healthcheck

- pnpm workspaces: apps/web, apps/api, packages/md, packages/shared
- docker compose: db (PostgreSQL 16), api, web (nginx)
- Prisma-схема и первая миграция (pg_trgm, GIN-индексы поиска)
- GET /api/health, ESLint + Prettier, .env.example, README

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
deonisii
2026-10-04 12:09:44 +03:00
co-authored by Claude Opus 5.5
parent 9ed4d4ce43
commit 521533a8e3
37 changed files with 9290 additions and 0 deletions
+32
View File
@@ -0,0 +1,32 @@
{
"name": "@kb/md",
"version": "0.1.0",
"private": true,
"type": "module",
"main": "./src/index.ts",
"types": "./src/index.ts",
"exports": {
".": "./src/index.ts"
},
"scripts": {
"typecheck": "tsc -p tsconfig.json",
"test": "vitest run"
},
"dependencies": {
"hast-util-to-string": "^3.0.1",
"rehype-sanitize": "^6.0.0",
"rehype-stringify": "^10.0.1",
"remark-directive": "^4.0.0",
"remark-gfm": "^4.0.1",
"remark-parse": "^11.0.0",
"remark-rehype": "^11.1.2",
"unified": "^11.0.5",
"unist-util-visit": "^5.1.0"
},
"devDependencies": {
"@types/hast": "^3.0.5",
"@types/mdast": "^4.0.4",
"typescript": "^5.9.0",
"vitest": "^5.0.3"
}
}
+2
View File
@@ -0,0 +1,2 @@
// Общий Markdown-рендер (сервер + клиент). Наполняется на этапе 2.
export const MD_PACKAGE = '@kb/md';
+1
View File
@@ -0,0 +1 @@
{ "extends": "../../tsconfig.base.json", "include": ["src"] }
+11
View File
@@ -0,0 +1,11 @@
{
"name": "@kb/shared",
"version": "0.1.0",
"private": true,
"type": "module",
"main": "./src/index.ts",
"types": "./src/index.ts",
"exports": { ".": "./src/index.ts" },
"scripts": { "typecheck": "tsc -p tsconfig.json" },
"devDependencies": { "typescript": "^5.9.0" }
}
+159
View File
@@ -0,0 +1,159 @@
// Общие типы API: их импортируют и сервер, и клиент, чтобы формат ответов не расходился.
export type Role = 'ADMIN' | 'EDITOR' | 'VIEWER';
export type ArticleStatus = 'DRAFT' | 'PUBLISHED';
export type Visibility = 'PRIVATE' | 'PUBLIC';
/** Ключ цвета плашки раздела. Сами цвета лежат в CSS-токенах (--plq-*). */
export type PlaqueColor = 'yellow' | 'orange' | 'blue' | 'green' | 'ink';
export const PLAQUE_COLORS: PlaqueColor[] = ['yellow', 'orange', 'blue', 'green', 'ink'];
export interface HealthResponse {
status: 'ok';
db: 'ok';
time: string;
}
export interface UserDto {
id: string;
email: string;
name: string;
role: Role;
}
export interface SpaceDto {
id: string;
name: string;
slug: string;
icon: string | null;
order: number;
}
export interface SectionDto {
id: string;
spaceId: string;
name: string;
slug: string;
/** Короткий код на плашке: «ВВ», «ВОК». */
code: string;
color: PlaqueColor;
icon: string | null;
order: number;
}
/** Статья в списках: без тела. */
export interface ArticleListItem {
id: string;
slug: string;
title: string;
summary: string;
sectionId: string;
order: number;
tags: string[];
equipment: string[];
docCode: string | null;
pinned: boolean;
status: ArticleStatus;
visibility: Visibility;
version: number;
updatedAt: string;
/** Сколько рисунков в статье и сколько они весят (для «Скачать раздел»). */
imageCount: number;
bytes: number;
}
export interface AttachmentDto {
id: string;
filename: string;
url: string;
size: number;
}
export interface FactDto {
/** Подпись: «Запас при зачистке кабеля». */
label: string;
/** Значение с **жирным** в Markdown-разметке. */
value: string;
}
export interface ArticleDto extends ArticleListItem {
bodyMd: string;
bodyHtml: string;
attachments: AttachmentDto[];
/** Адреса картинок статьи (полные и превью): нужны для офлайн-кеша. */
images: string[];
authorName: string | null;
}
/** Всё дерево одним запросом: его хватает для главной, меню и офлайна. */
export interface TreeResponse {
spaces: SpaceDto[];
sections: SectionDto[];
articles: ArticleListItem[];
}
export interface Highlight {
t: string;
hit: boolean;
}
export interface SearchFact {
value: Highlight[];
label: Highlight[];
articleSlug: string;
articleTitle: string;
}
export interface SearchArticle {
slug: string;
title: Highlight[];
section: string;
sectionId: string;
snippet: Highlight[];
pinned: boolean;
}
export interface SearchResponse {
q: string;
facts: SearchFact[];
articles: SearchArticle[];
}
export interface RevisionDto {
id: string;
version: number;
createdAt: string;
authorName: string | null;
comment: string | null;
}
export interface AdminUserDto extends UserDto {
blocked: boolean;
createdAt: string;
lastSeenAt: string | null;
}
export interface InviteDto {
id: string;
token: string;
role: Role;
expiresAt: string;
usedAt: string | null;
url: string;
}
export const ROLE_LABEL: Record<Role, string> = {
ADMIN: 'Админ',
EDITOR: 'Редактор',
VIEWER: 'Читатель',
};
/** Русское склонение: plural(3, ['статья','статьи','статей']) → «статьи». */
export function plural(n: number, forms: [string, string, string]): string {
const a = Math.abs(n) % 100;
const b = a % 10;
if (a > 10 && a < 20) return forms[2];
if (b > 1 && b < 5) return forms[1];
if (b === 1) return forms[0];
return forms[2];
}
+1
View File
@@ -0,0 +1 @@
{ "extends": "../../tsconfig.base.json", "include": ["src"] }