Skip to content

Repository files navigation

NewsRoom API

Overview

NewsRoom is a scalable RESTful API built with Laravel using advanced backend architecture concepts and clean code principles.

The project simulates a real-world newsroom/content management platform where users can create, manage, publish, and organize articles with a fully event-driven backend architecture.

The system demonstrates:

  • Clean Architecture
  • SOLID Principles
  • Service Layer Pattern
  • Event-Driven Design
  • Queue Processing
  • Notifications System
  • API Versioning
  • Authentication & Authorization
  • Rate Limiting
  • Validation & Security Best Practices

Tech Stack

  • Laravel 12
  • PHP 8+
  • MySQL
  • Laravel Sanctum
  • Queue System
  • Notifications
  • REST API

Main Features

Authentication System

Implemented using Laravel Sanctum.

Features:

  • Register
  • Login
  • Logout
  • Protected API routes
  • Token authentication

User Management

Full CRUD system for users.

Features:

  • Create user
  • Update user
  • Delete user
  • List users
  • Role management
  • Policy authorization د

Article Management

Advanced article system with:

  • Create article
  • Update article
  • Delete article
  • Publish article
  • Slug generation
  • Pagination
  • Tag support
  • Reading time calculation
  • Comments count

Tag Management

Complete CRUD implementation for article tags.

Features:

  • Create tag
  • Update tag
  • Delete tag
  • Slug support
  • Validation rules

API Versioning

The API supports multiple versions.

V1

Basic article structure.

V2

Enhanced article response with:

  • Reading time
  • Comments count
  • Optimized writer response
  • Simplified tags structure

Architecture

The project follows layered architecture:

Controllers

Handle HTTP requests and responses.

Services

Contain business logic.

Contracts (Interfaces)

Decouple implementations using dependency injection.

Requests

Handle validation and authorization.

Policies

Manage access control.

Resources

Transform API responses.

Actions

Single responsibility application actions.

Events / Listeners

Handle asynchronous system reactions.

Observers

Watch model lifecycle changes.

Notifications

Send email/database notifications.

Jobs

Execute background processing.


Event-Driven System

The application uses Laravel Events, Listeners, and Observers.

Examples:

Article Published

Flow:

  1. Article status changes to published
  2. Observer detects update
  3. Event dispatched
  4. Listener triggered
  5. Notification queued
  6. User notified asynchronously

Queue System

Implemented using Laravel Queues.

Features:

  • Queueable notifications
  • Background jobs
  • Failed jobs handling
  • Multiple queues

Queues:

  • emails
  • notifications

Example Job:

  • SendWeeklyArticlesReportJob

Notification System

Context-aware notification system.

Supported channels:

  • Email notifications
  • Database notifications

Implemented using:

  • Notification classes
  • Contextual binding
  • Queueable notifications

Validation & Security

Implemented security best practices:

  • Form Request validation
  • Policy authorization
  • Forbidden content filtering
  • Input sanitization
  • API rate limiting
  • Protected routes

Custom validation:

  • CleanContentRule

Rate Limiting

API requests are protected using Laravel Rate Limiter.

Example:

  • 60 requests/minute per user or IP

Design Patterns Used

  • Service Layer Pattern
  • Strategy Pattern
  • Observer Pattern
  • Action Pattern
  • Dependency Injection
  • Event-Driven Architecture
  • Contextual Binding

Installation

Clone Repository

git clone <[repository-url](https://github.com/Ebla-a/NewsRoom)>

Install Dependencies

composer install

Environment Setup

cp .env.example .env

Configure Database

Update .env

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=newsroom
DB_USERNAME=root
DB_PASSWORD=

Generate Application Key

php artisan key:generate

Run Migrations

php artisan migrate --seed

Sanctum Setup

php artisan vendor:publish --provider="Laravel\Sanctum\SanctumServiceProvider"
php artisan migrate

Queue Setup

Create Queue Tables

php artisan queue:table
php artisan queue:failed-table
php artisan migrate

Configure Queue

Inside .env

QUEUE_CONNECTION=rdeis

Run Queue Worker

php artisan queue:work --queue=emails,notifications,low

Example API Endpoints

Auth

Method Endpoint
POST /api/register
POST /api/login
POST /api/logout

Articles

Method Endpoint
GET /api/v1/articles
POST /api/v1/articles
GET /api/v1/articles/{id}
PUT /api/v1/articles/{id}
DELETE /api/v1/articles/{id}
POST /api/v1/articles/{id}/publish

Developed using Laravel and modern backend engineering practices.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages