-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathshowcase.zmodel
More file actions
342 lines (296 loc) · 11.6 KB
/
showcase.zmodel
File metadata and controls
342 lines (296 loc) · 11.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
datasource db {
provider = 'sqlite'
url = 'file:./dev.db'
}
plugin policy {
provider = '../../policy/plugin.zmodel'
}
// ─── Enums ───────────────────────────────────────────────
/// Defines the access level of a user within an organization.
enum Role {
/// Full administrative access — can manage billing, members, and settings.
OWNER
/// Can manage projects and team members.
ADMIN
/// Standard team member with project access.
MEMBER
/// View-only access to public resources.
GUEST
}
/// Priority levels for tasks.
enum Priority {
LOW
MEDIUM
HIGH
CRITICAL
}
/// Lifecycle status of a task.
enum TaskStatus {
/// Waiting to be started.
TODO
/// Actively being worked on.
IN_PROGRESS
/// Submitted for peer review.
IN_REVIEW
/// Completed and closed.
DONE
}
// ─── Mixins ──────────────────────────────────────────────
type Timestamps {
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
// ─── Core Models ─────────────────────────────────────────
/// An organization is the top-level tenant in the system.
/// All users, teams, and projects belong to exactly one organization.
model Organization with Timestamps {
id String @id @default(cuid())
/// The public display name of the organization.
name String @length(2, 100)
/// URL-safe identifier used in routing.
slug String @unique @length(3, 40) @meta('doc:example', 'acme-corp')
/// Primary contact email for the organization.
email String? @email
/// Total number of users across all teams.
memberCount Int @computed
users User[]
teams Team[]
projects Project[]
@@allow('read', true)
@@allow('update,delete', users?[role == 'OWNER'])
@@index([slug])
@@meta('doc:category', 'Core')
@@meta('doc:since', '1.0')
}
/// A registered user in the platform.
/// Users belong to an organization and may be members of multiple teams.
model User with Timestamps {
id String @id @default(cuid())
/// Email address used for login.
email String @unique @email @meta('doc:example', 'jane@acme.com')
/// Full name displayed in the UI.
name String @length(1, 120)
/// URL to the user's avatar image.
avatarUrl String? @url
role Role @default(MEMBER)
taskCount Int @computed
organization Organization @relation(fields: [organizationId], references: [id])
organizationId String
memberships TeamMember[]
assignedTasks Task[]
comments Comment[]
activities Activity[]
@@allow('read', true)
@@allow('update', this == auth())
@@deny('delete', role == 'OWNER')
@@index([email])
@@unique([email, organizationId])
@@meta('doc:category', 'Identity')
@@meta('doc:since', '1.0')
}
/// A team groups users within an organization for project collaboration.
model Team with Timestamps {
id String @id @default(cuid())
/// Team display name.
name String @length(1, 80)
/// Optional description of the team's purpose.
description String?
organization Organization @relation(fields: [organizationId], references: [id])
organizationId String
members TeamMember[]
projects Project[]
@@allow('read', true)
@@allow('create,update,delete', members?[role == 'ADMIN' || role == 'OWNER'])
@@meta('doc:category', 'Identity')
@@meta('doc:since', '1.0')
}
/// Represents a user's membership in a team with a specific role.
model TeamMember with Timestamps {
id String @id @default(cuid())
user User @relation(fields: [userId], references: [id])
userId String
team Team @relation(fields: [teamId], references: [id])
teamId String
role Role @default(MEMBER)
@@unique([userId, teamId])
@@allow('read', true)
@@meta('doc:category', 'Identity')
}
// ─── Work Models ─────────────────────────────────────────
/// A project organizes tasks under a team within an organization.
model Project with Timestamps {
id String @id @default(cuid())
/// The project name.
name String @length(1, 100)
/// Detailed description of the project scope and goals.
description String?
archived Boolean @default(false)
/// Total number of tasks in this project.
taskCount Int @computed
/// Percentage of completed tasks (0.0–1.0).
completionRate Float @computed
/// Whether the project has any tasks past their due date.
hasOverdueTasks Boolean @computed
organization Organization @relation(fields: [organizationId], references: [id])
organizationId String
team Team? @relation(fields: [teamId], references: [id])
teamId String?
tasks Task[]
tags Tag[]
@@allow('read', true)
@@allow('create,update', true)
@@deny('delete', archived)
@@index([organizationId])
@@meta('doc:category', 'Work')
@@meta('doc:since', '1.0')
}
/// A unit of work within a project.
/// Tasks support self-referential parent/child hierarchy for sub-tasks.
model Task with Timestamps {
id String @id @default(cuid())
/// Short summary of the task.
title String @length(1, 200) @trim @meta('doc:example', 'Fix login redirect bug')
/// Rich-text body with full details.
body String?
/// Unique slug for URL-friendly references.
slug String? @regex('^[a-z0-9-]+$')
status TaskStatus @default(TODO)
priority Priority @default(MEDIUM)
dueDate DateTime?
/// Estimated effort in hours.
estimatedHours Float? @gt(0) @lte(1000)
/// Number of comments on this task.
commentCount Int @computed
project Project @relation(fields: [projectId], references: [id])
projectId String
assignee User? @relation(fields: [assigneeId], references: [id])
assigneeId String?
/// Parent task — allows nesting sub-tasks.
parent Task? @relation("SubTasks", fields: [parentId], references: [id])
parentId String?
children Task[] @relation("SubTasks")
comments Comment[]
tags Tag[]
activities Activity[]
@@allow('read', true)
@@allow('create,update', true)
@@deny('delete', status == 'DONE')
@@validate(estimatedHours == null || estimatedHours > 0, "Estimated hours must be positive when set")
@@index([projectId])
@@index([assigneeId])
@@meta('doc:category', 'Work')
@@meta('doc:since', '1.0')
}
/// A comment on a task. Comments do not have descriptions intentionally
/// to test the plugin's handling of undocumented fields.
model Comment with Timestamps {
id String @id @default(cuid())
body String
task Task @relation(fields: [taskId], references: [id])
taskId String
author User @relation(fields: [authorId], references: [id])
authorId String
@@allow('read', true)
@@allow('create', true)
@@allow('update,delete', author == auth())
@@meta('doc:category', 'Work')
}
/// A label that can be attached to tasks and projects for categorization.
model Tag {
id String @id @default(cuid())
name String @unique @length(1, 50)
color String? @meta('doc:example', '#3b82f6')
tasks Task[]
projects Project[]
}
// ─── Activity / Audit ────────────────────────────────────
/// Records significant events for audit and activity feed purposes.
model Activity with Timestamps {
id String @id @default(uuid())
action String
detail String?
user User @relation(fields: [userId], references: [id])
userId String
task Task? @relation(fields: [taskId], references: [id])
taskId String?
@@allow('read', true)
@@deny('update,delete', true)
@@meta('doc:category', 'Audit')
@@meta('doc:since', '2.0')
}
// ─── Custom Types ────────────────────────────────────────
/// Aggregated statistics for a project dashboard.
type ProjectStats {
taskCount Int
completedCount Int
memberCount Int
}
// ─── Procedures ─────────────────────────────────────────
/// Register a new user in the platform.
/// Creates the user record and sends a welcome email.
mutation procedure signUp(email: String, name: String, role: Role?): User
/// Retrieve a user by their unique identifier.
procedure getUser(id: String): User
/// List all users belonging to a given organization.
procedure listOrgUsers(organizationId: String): User[]
/// Create a new task and assign it to a user in one step.
mutation procedure createAndAssignTask(title: String, projectId: String, assigneeId: String?, priority: Priority?): Task
/// Get aggregated statistics for a project.
procedure getProjectStats(projectId: String): ProjectStats
/// Bulk-update the status of multiple tasks at once.
mutation procedure bulkUpdateTaskStatus(taskIds: String[], status: TaskStatus): Void
/// Archive a project and all its tasks.
mutation procedure archiveProject(projectId: String): Project
// ─── Views ──────────────────────────────────────────────
/// Flattened user profile for reporting dashboards.
/// Backed by a SQL view joining User, Organization, and TeamMember.
view UserProfile {
id Int
/// Full name of the user.
name String
/// Email address of the user.
email String
/// Name of the organization the user belongs to.
organizationName String
/// Number of teams the user is a member of.
teamCount Int
}
/// Aggregated task metrics per project for analytics dashboards.
view ProjectTaskSummary {
projectId String
/// Name of the project.
projectName String
totalTasks Int
completedTasks Int
openTasks Int
/// Average days to completion for finished tasks.
avgDaysToClose Float
}
/// Leaderboard view ranking users by completed task count.
view UserLeaderboard {
userId String
userName String
completedTasks Int
rank Int
}
// ─── Internal / Ignored Models ───────────────────────────
/// Tracks background job execution. Internal only — not part of the public API.
model JobRun {
id String @id @default(cuid())
jobName String
status String
startedAt DateTime @default(now())
payload Json?
@@ignore
@@meta('doc:category', 'Internal')
}
/// Stores API keys for service-to-service authentication.
/// Deprecated in favor of OAuth2 client credentials.
model ApiToken {
id String @id @default(cuid())
token String @unique
expiresAt DateTime
revoked Boolean @default(false)
@@ignore
@@meta('doc:deprecated', 'Use OAuth2 client credentials instead')
}