𝗕𝘂𝗶𝗹𝗱𝗶𝗻𝗴 𝗮 𝗣𝗿𝗼𝗷𝗲𝗰𝘁 𝗠𝗮𝗻𝗮𝗴𝗲𝗺𝗲𝗻𝘁 𝗧𝗼𝗼𝗹 𝘄𝗶𝘁𝗵 𝗣𝗿𝗶𝘀𝗺𝗮
I am building a collaborative project management tool like Trello. I am using React, Express.js, PostgreSQL, and Socket.io.
The first step is the database schema. I designed six models to handle users, projects, boards, tasks, comments, and notifications.
Here are the key technical choices and lessons from my Prisma schema design:
• Use CUID for IDs I use @default(cuid()) for all IDs. These are better than simple numbers for public URLs. They prevent people from guessing how many records you have.
• Explicit Relation Names When two fields point to the same model, Prisma gets confused. For example, a task has a creator and an assignee. Both are Users. I must name these relations explicitly using @relation names to prevent migration errors.
• Junction Tables for Many-to-Many Relations A user can belong to many projects. A project can have many users. I created a ProjectMember model to link them. I added a unique constraint on userId and projectId. This prevents the same user from joining a project twice.
• Hierarchy and Logic Tasks do not live in projects. They live in boards. Boards live in projects. This makes drag-and-drop simple. To move a task, you only update its boardId.
• Nullable Relations Some relations are required, and some are optional. A task must have a creator, so I do not use a question mark. An assignee is optional, so I use User? and String?. You must include both for the schema to work.
Common mistakes I found:
- Using single quotes for defaults. Prisma requires double quotes.
- Forgetting the colon in the references syntax.
- Applying @default(now()) to an ID field by mistake.
Next, I will build the Express backend and set up Socket.io for real-time updates.