A blog is, above all, data
Behind any blog there are two entities that relate to each other:
- Posts: the articles. Each one has
id,title,slug,contentanddate. - Comments: what readers write. Each one has
id,author,textand, most importantly, apost_idthat points to the post it belongs to.
This is a one-to-many (1:N) relationship: a post has many comments,
but each comment belongs to a single post. The post_id column of the
comments table is the foreign key that materializes that relationship.
posts ──< (post_id) comments
1 N
The slug: a readable URL
A post's title is for people: "My first post". But a URL
with spaces and accents is fragile. That's why we generate a slug: a version of the
title suitable for URLs, in lowercase and with hyphens instead of spaces.
"Learning SQL" → /posts/learning-sql
The slug is stable and unique: even if you change the visible title, the link can keep working. And it's readable, which helps people and SEO.
Pagination: don't load it all
A blog with hundreds of posts can't send them all at once. Pagination
splits the listing into pages of a fixed size (e.g. 10 per page) and the client
requests the one it wants: /posts?page=2. In SQL this is LIMIT + OFFSET; in
JavaScript, a slice over the array.