{"id":25085625,"url":"https://github.com/shuaib-code/blog-server","last_synced_at":"2026-04-12T00:08:28.811Z","repository":{"id":268907835,"uuid":"905726526","full_name":"shuaib-code/blog-server","owner":"shuaib-code","description":"A robust and scalable blogging platform backend built with TypeScript, Node.js, and MongoDB. It supports secure authentication, role-based access control, and public APIs for seamless blog management.","archived":false,"fork":false,"pushed_at":"2024-12-27T18:58:04.000Z","size":82,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-07T08:34:48.345Z","etag":null,"topics":["cors","dotenv","express","jsonwebtoken","mongoose","nodejs","pnpm","typescript","zod-validation"],"latest_commit_sha":null,"homepage":"https://blog-server-auth.vercel.app","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/shuaib-code.png","metadata":{"files":{"readme":"Readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-12-19T12:00:44.000Z","updated_at":"2024-12-27T18:58:07.000Z","dependencies_parsed_at":null,"dependency_job_id":"79f7bf2f-b4f4-40b6-884b-0cbd150bc850","html_url":"https://github.com/shuaib-code/blog-server","commit_stats":null,"previous_names":["shuaib-code/blog-server"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shuaib-code%2Fblog-server","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shuaib-code%2Fblog-server/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shuaib-code%2Fblog-server/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shuaib-code%2Fblog-server/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shuaib-code","download_url":"https://codeload.github.com/shuaib-code/blog-server/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246650951,"owners_count":20811989,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cors","dotenv","express","jsonwebtoken","mongoose","nodejs","pnpm","typescript","zod-validation"],"created_at":"2025-02-07T08:29:20.329Z","updated_at":"2025-10-28T02:16:42.060Z","avatar_url":"https://github.com/shuaib-code.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Blog Project\n\n\u003cdiv style=\"margin: 0; padding: 0; height: 100%; display: flex; justify-content: center; align-items: center;\"\u003e\n  \u003cimg src=\"https://img.freepik.com/free-photo/toy-bricks-table-with-word-blog_144627-47465.jpg?t=st=1734634375~exp=1734637975~hmac=4220c3ff4fc6af864b1085c7a9569fb760e324e11864b123cff27fdc3e8fea07\u0026w=1380\" alt=\"Blog Platform\" style=\"width: 100%; height: auto;\"\u003e\n\u003c/div\u003e\n\n## Overview\n\nThis project is a backend system for a blogging platform where users can create, update, and delete blogs. The system features secure authentication, role-based access control, and a public API for viewing blogs with search, sort, and filter functionalities.\n\n---\n\n## Features\n\n### User Roles\n\n- **Admin**:\n  - Can block users and delete any blog.\n  - Cannot create or update blogs.\n- **User**:\n  - Can register, log in, and manage their own blogs.\n  - Cannot perform admin-specific actions.\n\n### Authentication \u0026 Authorization\n\n- **Authentication**: Secure JWT-based authentication.\n- **Authorization**: Role-based access control (Admin and User roles).\n\n### Blog Management\n\n- Create, update, and delete blogs (User-specific).\n- Public API for viewing blogs with advanced query options:\n  - Search by title or content.\n  - Sort by fields like `createdAt` or `title`.\n  - Filter by author or published status.\n\n---\n\n## Technologies\n\n- **Language**: TypeScript\n- **Backend Framework**: Node.js with Express.js\n- **Database**: MongoDB with Mongoose ODM\n- **Authentication**: JSON Web Token (JWT)\n\n---\n\n## Project Setup\n\n1. Clone the repository:\n\n   ```bash\n   git clone https://github.com/yourusername/blog-server.git\n   cd blog-server\n   ```\n\n2. Install dependencies:\n\n   ```bash\n      npm install\n   ```\n\n3. Set up environment variables:\n\n- Create a `.env` file at the root of the project.\n- Add the following variables:\n\n```bash\nNODE_ENV=development\nPORT=5000\nDATABASE_URL=\u003cyour-mongodb-uri\u003e\nJWT_SECRET=\u003cjwt-secret\u003e\nBCRYPT_SALT=11\nJWT_EXPIRATION=24h\n```\n\n4. Start the server:\n\n```bash\nnpm run start:dev\n```\n\n# Models and API Endpoints for Blog Project\n\n---\n\n## Models\n\n### User Model\n\n- **Fields**:\n  - `name`: Full name of the user.\n  - `email`: Email for authentication.\n  - `password`: Securely hashed password.\n  - `role`: Either `\"admin\"` or `\"user\"`. Default is `\"user\"`.\n  - `isBlocked`: Boolean flag to block a user. Default is `false`.\n  - **Timestamps**: Automatically tracks `createdAt` and `updatedAt`.\n\n### Blog Model\n\n- **Fields**:\n  - `title`: Title of the blog.\n  - `content`: Content of the blog.\n  - `author`: Reference to the `User` model.\n  - `isPublished`: Boolean flag to indicate publishing status. Default is `true`.\n  - **Timestamps**: Automatically tracks `createdAt` and `updatedAt`.\n\n---\n\n## API Endpoints\n\n### Authentication\n\n- `POST /api/auth/register`: Register a new user.\n- `POST /api/auth/login`: Log in and generate a JWT token.\n\n### Blog Management\n\n- `POST /api/blogs`: Create a blog (User only).\n- `PATCH /api/blogs/:id`: Update a blog (Owner only).\n- `DELETE /api/blogs/:id`: Delete a blog (Owner only).\n- `GET /api/blogs`: Fetch all blogs (Public API).\n\n### Admin Actions\n\n- `PATCH /api/admin/users/:userId/block`: Block a user.\n- `DELETE /api/admin/blogs/:id`: Delete any blog.\n\n---\n\n## Query Parameters for Public API\n\n- `search`: Filter blogs by title or content.\n- `sortBy`: Sort by fields (e.g., `createdAt`, `title`).\n- `sortOrder`: Sort direction (`asc` or `desc`).\n- `filter`: Filter by author or other fields.\n\n---\n\n## Error Handling\n\n### Structured Error Responses\n\n- Consistent format for error messages.\n- Includes details, status codes, and stack traces.\n\n### Common Error Types\n\n- Validation errors (e.g., invalid data inputs).\n- Authentication and authorization errors.\n- Resource not found (e.g., non-existent blog or user).\n- Internal server errors.\n\n# Future Enhancements\n\n- Add unit and integration tests.\n- Implement rate limiting and request throttling for security.\n- Add email notifications for blocked users.\n\n---\n\n**Created by [Mohammad Shuaib]**\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshuaib-code%2Fblog-server","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshuaib-code%2Fblog-server","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshuaib-code%2Fblog-server/lists"}