Newspaper Web App: A dynamic online news platform with roles for guests, subscribers, writers, editors, and admins. Features include full-text search, category/tag filters, premium article access, WYSIWYG editor, and secure authentication using Express.js, TypeScript, MongoDB, and EJS
Design the database schemas for core entities in the application, such as articles, users, categories, tags, comments, and subscriptions. These schemas will define the structure of the data stored in the database, relationships between entities, and ensure efficient data retrieval.
1. Article Schema
The Article schema stores information about articles including title, content, category, tags, publication date, status, and related fields.
The User schema stores information about the users, including their roles (e.g., writer, editor, subscriber), authentication details, and personal information.
Articles and Categories: Articles belong to a category, so the category field in the Article schema is a reference (ref) to the Category model.
Articles and Tags: Articles can have multiple tags, so the tags field in the Article schema is an array of references to the Tag model.
Articles and Comments: Each article can have multiple comments, so the article field in the Comment schema is a reference to the Article model.
Users and Comments: Each comment has an author, so the author field in the Comment schema is a reference to the User model.
Users and Subscriptions: Each user has one subscription, so the user field in the Subscription schema is a reference to the User model.
Indexes
For performance optimization, especially for searching, we can add indexes to frequently queried fields, such as email in the User schema, name in the Category and Tag schemas, and publishDate in the Article schema.
Example:
// Add index to email in User schema for quick lookups
userSchema.index({ email: 1 });
// Add index to publishDate in Article schema for fast sorting
articleSchema.index({ publishDate: -1 });
Deliverables
Article Schema: For storing article data with relationships to categories, tags, and users.
User Schema: For storing user data with encryption for passwords and role management.
Category Schema: For managing article categories.
Tag Schema: For managing article tags.
Comment Schema: For storing comments on articles.
Subscription Schema: For managing subscriptions, including premium status.
Acceptance Criteria
Database schemas are defined and connected via Mongoose in Node.js.
Relationships between entities (Articles, Categories, Tags, Users, Comments, Subscriptions) are clearly established using references.
All schemas include proper validation and default values.
Indexes are applied to optimize search and sorting operations.
Objective
Design the database schemas for core entities in the application, such as articles, users, categories, tags, comments, and subscriptions. These schemas will define the structure of the data stored in the database, relationships between entities, and ensure efficient data retrieval.
1. Article Schema
The Article schema stores information about articles including title, content, category, tags, publication date, status, and related fields.
Schema:
2. User Schema
The User schema stores information about the users, including their roles (e.g., writer, editor, subscriber), authentication details, and personal information.
Schema:
3. Category Schema
The Category schema stores information about different article categories.
Schema:
4. Tag Schema
The Tag schema stores information about tags that can be associated with articles.
Schema:
5. Comment Schema
The Comment schema stores user comments on articles, including comment content, author, and related article.
Schema:
6. Subscription Schema
The Subscription schema stores information about subscribers, including subscription type, expiration date, and payment details.
Schema:
Relationships and Indexing
category
field in the Article schema is a reference (ref
) to the Category model.tags
field in the Article schema is an array of references to the Tag model.article
field in the Comment schema is a reference to the Article model.author
field in the Comment schema is a reference to the User model.user
field in the Subscription schema is a reference to the User model.Indexes
For performance optimization, especially for searching, we can add indexes to frequently queried fields, such as
email
in the User schema,name
in the Category and Tag schemas, andpublishDate
in the Article schema.Example:
Deliverables
Acceptance Criteria