feat: add initial backend and frontend structure with models, DTOs, and WebSocket events
This commit is contained in:
56
apps/backend/prisma/models/character.prisma
Normal file
56
apps/backend/prisma/models/character.prisma
Normal file
@@ -0,0 +1,56 @@
|
||||
// Character model and character knowledge
|
||||
|
||||
enum ImportSourceType {
|
||||
file
|
||||
url
|
||||
manual
|
||||
}
|
||||
|
||||
enum ImportStatus {
|
||||
pending
|
||||
processing
|
||||
completed
|
||||
failed
|
||||
}
|
||||
|
||||
model Character {
|
||||
id String @id @default(uuid())
|
||||
name String
|
||||
avatarUrl String?
|
||||
personalityPrompt String
|
||||
attributes Json @default("{}")
|
||||
config Json @default("{}")
|
||||
isPublic Boolean @default(false)
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
|
||||
userId String
|
||||
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||||
conversations Conversation[]
|
||||
knowledgeSources CharacterKnowledge[]
|
||||
vectorMemories VectorMemory[]
|
||||
|
||||
@@index([userId])
|
||||
@@index([name])
|
||||
}
|
||||
|
||||
model CharacterKnowledge {
|
||||
id String @id @default(uuid())
|
||||
name String
|
||||
sourceType ImportSourceType
|
||||
sourceName String
|
||||
mimeType String?
|
||||
fileSize BigInt?
|
||||
rawContent String?
|
||||
status ImportStatus @default(pending)
|
||||
processingInfo Json?
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
|
||||
characterId String
|
||||
character Character @relation(fields: [characterId], references: [id], onDelete: Cascade)
|
||||
vectorMemories VectorMemory[]
|
||||
|
||||
@@index([characterId])
|
||||
@@index([status])
|
||||
}
|
||||
38
apps/backend/prisma/models/conversation.prisma
Normal file
38
apps/backend/prisma/models/conversation.prisma
Normal file
@@ -0,0 +1,38 @@
|
||||
// Conversation and participant models
|
||||
|
||||
model Conversation {
|
||||
id String @id @default(uuid())
|
||||
title String?
|
||||
messageCount Int @default(0)
|
||||
totalTokens Int @default(0)
|
||||
settings Json @default("{}")
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
|
||||
userId String
|
||||
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||||
characterId String
|
||||
character Character @relation(fields: [characterId], references: [id], onDelete: Cascade)
|
||||
messages Message[]
|
||||
vectorMemories VectorMemory[]
|
||||
storyBranches StoryBranch[]
|
||||
participants ConversationParticipant[]
|
||||
|
||||
@@index([userId])
|
||||
@@index([characterId])
|
||||
@@index([createdAt])
|
||||
}
|
||||
|
||||
model ConversationParticipant {
|
||||
id String @id @default(uuid())
|
||||
isActive Boolean @default(true)
|
||||
autoRespond Boolean @default(true)
|
||||
createdAt DateTime @default(now())
|
||||
|
||||
conversationId String
|
||||
conversation Conversation @relation(fields: [conversationId], references: [id], onDelete: Cascade)
|
||||
characterId String
|
||||
|
||||
@@unique([conversationId, characterId])
|
||||
@@index([conversationId])
|
||||
}
|
||||
21
apps/backend/prisma/models/importDocument.prisma
Normal file
21
apps/backend/prisma/models/importDocument.prisma
Normal file
@@ -0,0 +1,21 @@
|
||||
// General import documents (not linked to characters)
|
||||
|
||||
model ImportDocument {
|
||||
id String @id @default(uuid())
|
||||
sourceType ImportSourceType
|
||||
sourceName String
|
||||
mimeType String?
|
||||
fileSize BigInt?
|
||||
content String?
|
||||
status ImportStatus @default(pending)
|
||||
errorMessage String?
|
||||
metadata Json?
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
|
||||
userId String
|
||||
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||||
|
||||
@@index([userId])
|
||||
@@index([status])
|
||||
}
|
||||
24
apps/backend/prisma/models/message.prisma
Normal file
24
apps/backend/prisma/models/message.prisma
Normal file
@@ -0,0 +1,24 @@
|
||||
// Message model
|
||||
|
||||
enum MessageRole {
|
||||
user
|
||||
assistant
|
||||
system
|
||||
}
|
||||
|
||||
model Message {
|
||||
id String @id @default(uuid())
|
||||
role MessageRole
|
||||
content String
|
||||
tokensUsed Int?
|
||||
model String?
|
||||
metadata Json?
|
||||
createdAt DateTime @default(now())
|
||||
|
||||
conversationId String
|
||||
conversation Conversation @relation(fields: [conversationId], references: [id], onDelete: Cascade)
|
||||
|
||||
@@index([conversationId])
|
||||
@@index([createdAt])
|
||||
@@index([conversationId, createdAt])
|
||||
}
|
||||
21
apps/backend/prisma/models/storyBranch.prisma
Normal file
21
apps/backend/prisma/models/storyBranch.prisma
Normal file
@@ -0,0 +1,21 @@
|
||||
// Story branching for narrative generation (Phase 2)
|
||||
|
||||
model StoryBranch {
|
||||
id String @id @default(uuid())
|
||||
title String?
|
||||
content String
|
||||
userDirection String
|
||||
generationParams Json?
|
||||
depth Int @default(0)
|
||||
branchOrder Int @default(0)
|
||||
createdAt DateTime @default(now())
|
||||
|
||||
conversationId String
|
||||
conversation Conversation @relation(fields: [conversationId], references: [id], onDelete: Cascade)
|
||||
parentId String?
|
||||
parent StoryBranch? @relation("BranchTree", fields: [parentId], references: [id], onDelete: Cascade)
|
||||
children StoryBranch[] @relation("BranchTree")
|
||||
|
||||
@@index([conversationId])
|
||||
@@index([parentId])
|
||||
}
|
||||
25
apps/backend/prisma/models/user.prisma
Normal file
25
apps/backend/prisma/models/user.prisma
Normal file
@@ -0,0 +1,25 @@
|
||||
// User model and related enums
|
||||
|
||||
enum UserRole {
|
||||
USER
|
||||
ADMIN
|
||||
}
|
||||
|
||||
model User {
|
||||
id String @id @default(uuid())
|
||||
email String @unique
|
||||
username String @unique
|
||||
passwordHash String?
|
||||
keycloakSub String? @unique
|
||||
role UserRole @default(USER)
|
||||
isActive Boolean @default(true)
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
|
||||
characters Character[]
|
||||
conversations Conversation[]
|
||||
importDocs ImportDocument[]
|
||||
|
||||
@@index([email])
|
||||
@@index([keycloakSub])
|
||||
}
|
||||
29
apps/backend/prisma/models/vectorMemory.prisma
Normal file
29
apps/backend/prisma/models/vectorMemory.prisma
Normal file
@@ -0,0 +1,29 @@
|
||||
// Vector memory for embeddings (conversation and character knowledge)
|
||||
|
||||
enum MemoryType {
|
||||
conversation
|
||||
character
|
||||
}
|
||||
|
||||
model VectorMemory {
|
||||
id String @id @default(uuid())
|
||||
content String
|
||||
embedding Unsupported("vector")?
|
||||
memoryType MemoryType @default(conversation)
|
||||
metadata Json?
|
||||
createdAt DateTime @default(now())
|
||||
|
||||
conversationId String?
|
||||
conversation Conversation? @relation(fields: [conversationId], references: [id], onDelete: Cascade)
|
||||
|
||||
characterId String?
|
||||
character Character? @relation(fields: [characterId], references: [id], onDelete: Cascade)
|
||||
|
||||
knowledgeId String?
|
||||
knowledge CharacterKnowledge? @relation(fields: [knowledgeId], references: [id], onDelete: Cascade)
|
||||
|
||||
@@index([conversationId])
|
||||
@@index([characterId])
|
||||
@@index([knowledgeId])
|
||||
@@index([memoryType])
|
||||
}
|
||||
8
apps/backend/src/app.module.ts
Normal file
8
apps/backend/src/app.module.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
|
||||
@Module({
|
||||
imports: [],
|
||||
controllers: [],
|
||||
providers: [],
|
||||
})
|
||||
export class AppModule {}
|
||||
20
apps/backend/src/main.ts
Normal file
20
apps/backend/src/main.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import { NestFactory } from '@nestjs/core';
|
||||
import { AppModule } from './app.module';
|
||||
|
||||
async function bootstrap() {
|
||||
const app = await NestFactory.create(AppModule);
|
||||
|
||||
app.enableCors({
|
||||
origin: ['http://localhost:5173'],
|
||||
credentials: true,
|
||||
});
|
||||
|
||||
app.setGlobalPrefix('api');
|
||||
|
||||
const port = process.env.PORT || 3000;
|
||||
await app.listen(port);
|
||||
|
||||
console.log(`🚀 Backend running on: http://localhost:${port}/api`);
|
||||
}
|
||||
|
||||
bootstrap();
|
||||
Reference in New Issue
Block a user