Mongoose schemas enforce strict type validation, enum restrictions, and reference indexing. Pre-save hooks eliminate manual date math by deterministically computing renewal intervals.
Collection: users
Guaranteed uniqueness via unique index. Lowercased, whitespace trimmed, and validated against standard email regex format.
Minimum 6 characters. Never stored in plaintext; salted and hashed via bcryptjs.hash() during registration transactions.
Auto-generates ISO-8601 createdAt and updatedAt metadata.
Collection: subscriptions
Indexed foreign key referencing User. Enables O(log N) lookup speeds when querying /subscriptions/user/:id.
Strict enums prevent malformed inputs: currencies (USD, EUR, GBP), frequencies (daily, weekly, monthly, yearly), and categories (8 distinct domains).
Custom validator rejects future start dates (startDate <= new Date()) and verifies renewal occurs after start.