Skip to main content

Domain Entity Relationship Diagram

The data model for this full-stack application is built using Database Schema and Table Definitions, which integrates SQLAlchemy ORM with Pydantic validation. The core of the domain consists of two primary database entities: User and Item.

Key Entities

  • User: Represents a registered user in the system. It includes authentication details (email, hashed_password), authorization flags (is_active, is_superuser), and profile information (full_name). Users are uniquely identified by a UUID.
  • Item: Represents a resource owned by a user. Each item has a title, an optional description, and a timestamp. It is linked to a User via a foreign key.
  • Token: A non-persistent model used for authentication responses, containing the JWT access_token.
  • Message: A utility model used for generic API responses (e.g., success messages).

Relationships

  • User to Item: A one-to-many relationship where one User can own multiple Items. This is enforced by a foreign key constraint on item.owner_id with a cascade delete policy, meaning if a user is deleted, all their items are also removed.
  • Authentication: While not a direct database relationship, the TokenPayload (decoded from the JWT) contains a sub field that corresponds to the User.id, allowing the system to identify the current user for each request.

Key Architectural Findings:

  • The codebase uses SQLModel to define both database tables and API schemas in a single class definition.
  • Primary keys were migrated from Integers to UUIDs to improve security and scalability.
  • The User entity includes both authentication (hashed_password) and authorization (is_superuser) fields.
  • A one-to-many relationship exists between User and Item, with cascade delete enabled at the database level.
  • Utility models like Token and Message are used for standardized API communication but are not persisted in the database.
Loading diagram...