Sentinel Portfolio - Module 0 (Professional Notes)
Why Design Data Layer First?
Backend logic depends on data relationships. A bad schema causes bugs, security issues, and
messy code. Fixing schema later is very hard in production.
Relational Flow
User → Portfolio → Asset → Transaction
Database Tables
Users: id (PK), email, passwordHash, createdAt
Portfolios: id (PK), name, userId (FK → Users.id)
Assets: id (PK), symbol, name, portfolioId (FK → Portfolios.id)
Transactions: id (PK), type, quantity, price, assetId (FK → Assets.id)
Cascading Delete
ON DELETE CASCADE ensures when a parent is deleted, all child records are deleted
automatically to avoid orphaned data.
IDOR Security (Insecure Direct Object Reference)
Ensure a user cannot access another user's data by verifying ownership chain: Transaction →
Asset → Portfolio → User.
Mental Model
Each table knows only its parent, not the full chain. Never duplicate data. Always derive
relationships.
Layman Explanation
Don't store the same information in multiple places. If ownership changes, duplicate data will
mismatch and break the system.
SQL Example (Join)
SELECT * FROM transactions t JOIN assets a ON t.assetId = a.id JOIN portfolios p ON
a.portfolioId = p.id WHERE p.userId = 'USER_ID';
Prisma Preview
model Portfolio { id String @id userId String user User @relation(fields: [userId], references: [id]) }
Interview Answers
Normalization: Avoid duplication and maintain single source of truth.
Ownership verification: Use relational chain joins to confirm data belongs to user.