Coder Social home page Coder Social logo

php-clean-code-api's Introduction

PHP clean code architecture example

Requirements

  1. Create recipies API without using any framework but can use packages
  2. Use clean code concepts while building architecture
  3. Document API's very well

Basic Details & instructions

  • Since I had some other serivce running on 80 port, I've made chage in docker-compose.yml to run nginx on 82 port, so the application will be accessible on http://localhost:82 url. You can find it on develop branch.
  • Composer Install - If you have composer installed on your local you can directly do composer install else can use my docker image script cd web && bash composer_update.sh.
  • DB Migrations - Short command bash migrate.sh or ssh into php container & run phpmig migrate command
  • Unit Test - To Run Unit tests use composer test or use bash phpunit.sh
  • API DOC - You can access swagger API doc on http://localhost:82/doc/index.html URL
  • GET API with search, pagination all in this eample - http://localhost:82/recipes?search=K&orderBy=id&orderDirection=desc&offset=0&limit=3

Clean code architecture

  • I've followed Clean Code Architecture in PHP by Kristopher Wilson. (A free version)
  • Bellow are few concepts I've focused & followed while building this architecture
    • SOLID Principles
    • The Onion Architecture
    • Factory Pattern & Static Factories
    • Adapter Pattern
    • Repository Pattern
  • The main benefit of having this kind of architecture is to keep your core business logic testable

Resources/plugins used

Directory Structure

  • web - Everything related to business
    • core - The main business logic & persistance part
      • Adapter - Define rules using interfaces for business logic
      • Factory - The business logic access point for mediator
      • Service - Wrappers for third party plugins & applications
      • Usecase - A specefic business usecase will be coded here
    • migrations - All migrations and its log used phpmig package for that
    • public - Entry point of the project. Only this part is accessible to outside world
    • src - Mediator to serve the request & connect business logic & DB
    • tests - All tests written for the project. (Right now I've only written for /core/Usecases part)

php-clean-code-api's People

Contributors

mhetreramesh avatar olvlvl avatar italolelis avatar kieranajp avatar mandoz avatar nsimaria avatar

Stargazers

Juan Morales avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.