Git Product home page Git Product logo

laravel-blog's Introduction

Simple Blog written in Laravel

Below are the high level project structure.

  • All Admin related controllers reside in the namespace 'App\Http\Controllers\Admin'.
  • All request mostly will go through the Interceptors.
  • Interceptor is a Plain PHP Class which validates the request, creates required DTO and assigns the values to DTO Object.
  • Interceptors are coupled with Controllers. So a Web Controller will have its own Interceptor. And an API Controller will have its own Interceptor. Since the validations, and few fields might change for an Web and API request. However, the DTO stays same.
  • DTO is a Plain PHP Class which will have fields mapping to the DataBase and also any other required fields. Getter and Setter methods for the fields. A Model can have its own DTO. A Module could also have its own DTO. Ex: If Payment is a Module and if we need multile fields from multiple tables we could create one DTO for complete Payment Journey.
  • DTO are individual entity. Both Web and API interceptor will create the same DTO for same tasks. Few realed fields might very. Ex: setting user id in Web flow is from auth(), but in API it could be different.
  • Controller and Interceptors are the only starting point and there should not be any business logic in it.
  • Services are Plain PHP classes. Service classes are architectured for the module. Ex: All Post related actions will be done by PostService.
  • Services can work individually. The parameters should only be DTOs. That we both Web and API controller could use same methods from the Service just by passing DTO. Also, it will be easy to write Test Cases.
  • All Business Logic must reside in Service.
  • All Database transactions must reside in Models. Models only deal with DB transactions with try{} catch{} block and will not do any validations.

Few Modules and misc.

  • Login with Google. Add required values in .env file.
  • For development purpose you can use Fake Login or Fake Register. THIS SHOULD NOT WORK IN PROD ENV. A check has been implemented in Routes, Controllers. However, extra care must be taken for this.
  • By default logged in users are assigned with End User Usertype. So they will not have any routes to perform any additional actions. Ideally no about should be able to Register. We can see the UserType Seeder and also in constants.php
  • Admin can create category, create posts mapping to category.
  • Listing pages are cached.
  • Log proper Exceptions, Security Issues. Helper methods are in config/log_helper.php. A log will get created every day. Exceptions and Security are different directories containing relavent Log Details.

DB

Run Migrations. Run Seeders [ usertype, category, post ]. Register a user using fake register.

Coding Standards.

  • All methods must obey Single Responsibility Principle.
  • Any Fetching/Updating/Insertion operations must follow Interceptor(Validations and DTO prepare) -> Services(with DTO) -> Models(DB operations).
  • Any Errors/Info Messages must be set to DTOs.
  • All Business logic should reside only in Services. And Service layer should be re-usable from both Web and API controllers.

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.