Skip to content

Repository files navigation

📝 Simple Blog App - Backend

A modern Laravel-based blog application with RESTful API architecture, featuring user authentication, post management, and image handling capabilities. This repository contains a complete RESTful API for a blogging system that manages users, posts, images, and content publishing workflows. The project demonstrates clean code design, repository pattern implementation, API documentation, and modern Laravel development practices.


📑 About this Project

This project showcases modern backend development expertise, with a focus on designing and implementing robust, scalable, and maintainable blog APIs. Laravel is a highly popular framework widely adopted in production environments. It offers numerous built-in features that simplify handling a variety of use cases. The project implements advanced features like SEO optimization, content publishing workflows, and comprehensive API documentation.

Tech Stack

  • Language: PHP 8.2
  • Framework: Laravel 12.x
  • Database: SQLite (development) / MySQL/PostgreSQL (production)
  • Authentication: Laravel Sanctum
  • Documentation: L5-Swagger
  • Testing: PHPUnit

Design Pattern

I use the Repository Design Pattern in this project. The Repository Design Pattern in Laravel is utilized to separate data access logic from the business logic of the application. This approach offers benefits such as more structured code, easier testing, and flexibility to accommodate changes. By using a repository, you can replace or modify the data source (e.g., switching from a database to an external API) without altering the business logic in controllers or services. Additionally, this pattern facilitates the implementation of SOLID principles, particularly the Dependency Inversion Principle, as controllers or services depend only on contracts (interfaces) rather than direct implementations.

⚡ Getting Started

Requirements

  • PHP >= 8.2
  • Composer
  • SQLite (for development)

Installation

  1. Clone the repository:

    git clone <repository-url> simple-blog-api
  2. Navigate to the project directory:

    cd simple-blog-api
  3. Install PHP dependencies:

    composer install
  4. Set up the environment file:

    cp .env.example .env

    Configure the database and other environment variables as needed.

  5. Generate app key for encryption:

    php artisan key:generate
  6. Set up the database:

    touch database/database.sqlite
    php artisan migrate --seed
  7. Create storage symlink:

    php artisan storage:link
  8. Generate API documentation:

    php artisan l5-swagger:generate

Running the Project

To start the project locally, use the following command:

# Start the Laravel server
php artisan serve

# Or run with queue worker
php artisan serve &
php artisan queue:work

🔖 API Documentation

The API documentation is available via Swagger. Once the project is running, visit the following URL to explore the endpoints:

http://localhost:8000/api/documentation

API Endpoints Overview

Authentication

  • POST /api/v1/auth/register - User registration
  • POST /api/v1/auth/login - User login
  • GET /api/v1/auth/me - Get current user (protected)
  • DELETE /api/v1/auth/logout - Logout (protected)

Posts (Public)

  • GET /api/v1/posts/published - Get all published posts
  • GET /api/v1/posts/{slugOrId}/public - Get single published post

Posts (Protected)

  • GET /api/v1/posts - List user's posts
  • POST /api/v1/posts - Create new post
  • GET /api/v1/posts/{id} - Get specific post
  • PUT /api/v1/posts/{id} - Update post
  • DELETE /api/v1/posts/{id} - Delete post
  • POST /api/v1/posts/{id}/publish - Publish post
  • POST /api/v1/posts/{id}/unpublish - Unpublish post

Users (Protected)

  • GET /api/v1/users - List users
  • GET /api/v1/users/{userId}/posts - Get posts by user

Images (Protected)

  • POST /api/v1/images/upload - Upload image
  • DELETE /api/v1/images/delete - Delete image

📝 Testing

Unit and feature tests are implemented using PHPUnit to ensure the reliability of the API. Run tests using:

⚠️ Testing Requirements

Before running tests, ensure you have a dedicated testing database configured. This prevents your development data from being affected during testing.

# Run all tests
composer test

# Run with coverage
php artisan test --coverage

🏗️ Project Structure

The project follows Laravel's conventional structure with additional repository pattern implementation:

app/
├── Http/Controllers/     # API Controllers
├── Models/              # Eloquent Models
├── Repositories/        # Repository Pattern Implementation
├── Interfaces/          # Repository Interfaces
└── Helpers/            # Helper Classes

database/
├── migrations/         # Database Migrations
├── seeders/           # Database Seeders
└── factories/         # Model Factories

routes/
└── api.php            # API Routes

storage/
└── api-docs/          # Generated API Documentation

Repository Pattern Implementation

This project implements the Repository Pattern for better code organization and testability:

  • AuthRepository - User authentication logic
  • PostRepository - Post management operations
  • UserRepository - User-related operations

🗄️ Database Schema

Users Table

  • Standard Laravel user fields
  • Email verification support

Posts Table

  • Title, content, excerpt
  • SEO fields (meta_title, meta_description, meta_keywords)
  • Publishing workflow (status, is_published, published_at)
  • Categorization (category_code, tags)
  • Reading time calculation
  • Featured image support

⚙️ Environment Configuration

Key environment variables to configure:

APP_NAME="Simple Blog App"
APP_URL=http://localhost:8000
DB_CONNECTION=sqlite
DB_DATABASE=/path/to/database.sqlite
SANCTUM_STATEFUL_DOMAINS=localhost:3000

✨ Features

  • User Authentication: Registration, login, logout with Laravel Sanctum
  • Post Management: Create, read, update, delete blog posts
  • Content Publishing: Draft and publish workflow for posts
  • Image Upload: Support for featured images and content images
  • SEO Optimization: Meta titles, descriptions, and keywords
  • Search & Filtering: Posts by category, tags, and search terms
  • Reading Time: Automatic calculation based on content length
  • API Documentation: Swagger/OpenAPI documentation with L5-Swagger

📧 Contact

I would greatly appreciate any feedback on my work, as it will help me improve and grow as a developer. If you have any comments, suggestions, or questions regarding this project, please feel free to reach out:

Thank you for taking the time to review this project!

About

RESTful API for a Sales & Order.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages