News Fetcher is a Laravel-based application that fetches news articles from multiple providers (NewsAPI, The Guardian, and The New York Times) and provides structured APIs for public and authenticated users. The project follows clean code principles and design patterns for maintainability and scalability.
| Technology | Description |
|---|---|
| Backend Framework | |
| Database | |
| Caching & Queues | |
| Containerization | |
| Queue Workers Management |
git clone https://github.com/elsayed85/news-fetcher.git
cd news-fetchercp .env.example .envdocker compose -f docker-compose-services.yml up -ddocker compose up -ddocker exec -it news-app-container shcomposer install
php artisan key:generate
php artisan migrate
php artisan db:seedchmod -R 777 storage- Each provider has a dedicated command that runs on a schedule to fetch news.
- Commands dispatch provider jobs to a Redis queue for processing.
- Supervisor manages queue workers to handle jobs efficiently.
- Fetches data from provider APIs using a Request Builder to structure API calls.
- Uses Adapters & DTOs to transform API responses into a standardized format.
- Caches categories, sources, and authors to reduce database queries.
- Saves transformed data into the database efficiently.
- Articles: List & Show
- Categories: List
- Sources: List
- Authors: List
- Articles: List filtered by user preferences (Categories, Sources, Authors)
π Full API Documentation: Postman Docs
- Filament Admin Panel for managing users, articles, categories, sources, and authors.
- to access the admin panel, visit
/admin/loginand login with the default credentials:- Email:
admin@news.com - Password:
password
- Email:
- Laravel Horizon provides a dashboard to monitor queue jobs.
- To access the dashboard, visit
/horizonand login to admin first using the previous credentials.
- Service Layer: Business logic is encapsulated in service classes.
- Repository Pattern: Data access is abstracted using repositories.
- Adapter Pattern: Each news provider has an adapter to normalize its response format.
- Builder Pattern: Request parameters are dynamically constructed.
- DTOs (Data Transfer Objects): Ensures data consistency across layers.
- Factory Pattern: Used for object instantiation and dependency injection.
- Filter Pattern: Query filtering is handled dynamically for various models.
To test authenticated API requests, generate an access token:
php artisan generate:user-tokenThis will create a test user and return an API token that can be used for authentication.
To simulate user-specific news filtering, attach preferences (categories, sources, authors) to a test user:
php artisan attach:user-preferencesThis ensures the API correctly filters news articles based on user settings.
---
## π οΈ Testing Scheduled Commands
To manually test the scheduled commands before running them in production, use:
```sh
php artisan schedule:testThis will prompt you to select a command from the available scheduled tasks, allowing you to verify that each provider fetches news correctly.
β Which command would you like to run? ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β βΊ β '/usr/bin/php82' 'artisan' guardian:fetch-and-save 'technology' --from-date='2024-01-01' --page='1' β
β β '/usr/bin/php82' 'artisan' news-api:fetch-and-save 'technology' β
β β '/usr/bin/php82' 'artisan' nyt:fetch-and-save 'technology' β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Running ['artisan' guardian:fetch-and-save 'technology' --from-date='2024-01-01' --page='1'] ... DONE (114ms)1οΈβ£ Add a Custom Logging Layer for Tracking
2οΈβ£ Filament Admin Panel for Full Control β
3οΈβ£ Generalized Category Mapping
4οΈβ£ Filter by API Source
5οΈβ£ Authentication Routes (Login, Register, Forgot Password, Reset, Logout)
6οΈβ£ User Preferences Update API
7οΈβ£ Setup Laravel Horizon for Queue Monitoring β


