Skip to content

Commit

Permalink
Merge pull request #15 from WendellAdriel/3.x
Browse files Browse the repository at this point in the history
3.x
  • Loading branch information
WendellAdriel authored Apr 27, 2024
2 parents e368835 + 5e87c68 commit 99e75d2
Show file tree
Hide file tree
Showing 73 changed files with 1,114 additions and 418 deletions.
21 changes: 17 additions & 4 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# APP CONFIG
APP_NAME=ExA
APP_ENV=local
APP_KEY=
Expand All @@ -6,14 +7,23 @@ APP_EXTERNAL_PORT=8000
APP_EXTERNAL_PORT_SSL=4000
APP_URL=http://localhost:${APP_EXTERNAL_PORT}
SWAGGER_EXTERNAL_PORT=8080
JWT_SECRET=

# DOCKER BUILD CONFIG
M1_PROCESSOR=false
XDEBUG_ENABLED=true

# GENERAL CONFIG
FILESYSTEM_DISK=local
BROADCAST_DRIVER=log
QUEUE_CONNECTION=sync

# LOG CONFIG
LOG_CHANNEL=daily
LOG_DEPRECATIONS_CHANNEL=null
LOG_LEVEL=debug

# DATABASE CONFIG
DB_CONNECTION=mysql
DB_HOST=mysql
DB_PORT=3306
Expand All @@ -22,20 +32,21 @@ DB_DATABASE=exa
DB_USERNAME=exa
DB_PASSWORD=secret

BROADCAST_DRIVER=log
CACHE_DRIVER=redis
FILESYSTEM_DISK=local
QUEUE_CONNECTION=sync
# SESSION CONFIG
SESSION_DRIVER=redis
SESSION_LIFETIME=120

# CACHE CONFIG
CACHE_DRIVER=redis
MEMCACHED_HOST=127.0.0.1

# REDIS CONFIG
REDIS_HOST=redis
REDIS_PASSWORD=null
REDIS_PORT=6379
REDIS_EXTERNAL_PORT=9000

# MAIL CONFIG
MAIL_MAILER=smtp
MAIL_HOST=mailpit
MAIL_PORT=1025
Expand All @@ -47,12 +58,14 @@ MAIL_FROM_NAME="${APP_NAME}"
MAILPIT_EXTERNAL_PORT_SMTP=1025
MAILPIT_EXTERNAL_PORT_HTTP=8025

# AWS CONFIG
AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=
AWS_USE_PATH_STYLE_ENDPOINT=false

# SLACK CONFIG
SLACK_NOTIFICATIONS_WEBHOOK=
SLACK_NOTIFICATIONS_CHANNEL="#general"
SLACK_NOTIFICATIONS_BOT_NAME="EXA-BOT"
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,16 @@
* API Documentation with Swagger
* Laravel Pint configuration (very opinionated)
* Pest v2 for Tests
* Type Coverage Tests with 100% type coverage
* Base classes to speed up the development
* DTOs with [Laravel Validated DTO](https://github.com/WendellAdriel/laravel-validated-dto)
* Slack Client for notifications
* API structured in modules
* Laravel Sanctum for Authentication
* JWT for Authentication
* Users management out-of-the-box with simple roles system
* Logs on DB for user logins and for actions made on models
* [Strictus](https://github.com/php-strictus/strictus) for enforcing local variable types
* Models extending from BaseModel use soft deletes by default

## Using the Template

Expand Down
2 changes: 1 addition & 1 deletion app/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;

class Kernel extends ConsoleKernel
final class Kernel extends ConsoleKernel
{
protected $commands = [
MakeModuleCommand::class,
Expand Down
6 changes: 3 additions & 3 deletions app/Exceptions/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use Illuminate\Support\Arr;
use Throwable;

class Handler extends ExceptionHandler
final class Handler extends ExceptionHandler
{
/**
* A list of exception types with their corresponding custom log levels.
Expand Down Expand Up @@ -57,7 +57,7 @@ public function register(): void
});
}

public function render($request, Throwable $exception)
public function render($request, Throwable $exception) // @pest-ignore-type
{
if ($exception instanceof \Illuminate\Auth\AuthenticationException) {
return $this->error($exception, Response::HTTP_UNAUTHORIZED, 'Unauthenticated');
Expand All @@ -81,7 +81,7 @@ public function render($request, Throwable $exception)
return $this->error($exception, Response::HTTP_INTERNAL_SERVER_ERROR);
}

protected function unauthenticated($request, \Illuminate\Auth\AuthenticationException $exception)
protected function unauthenticated($request, \Illuminate\Auth\AuthenticationException $exception) // @pest-ignore-type
{
return $this->error($exception, Response::HTTP_UNAUTHORIZED, 'Unauthenticated');
}
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Routing\Controller as BaseController;

class Controller extends BaseController
abstract class Controller extends BaseController
{
use AuthorizesRequests, ValidatesRequests;
}
3 changes: 1 addition & 2 deletions app/Http/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use Illuminate\Foundation\Http\Kernel as HttpKernel;

class Kernel extends HttpKernel
final class Kernel extends HttpKernel
{
/**
* The application's global HTTP middleware stack.
Expand Down Expand Up @@ -41,7 +41,6 @@ class Kernel extends HttpKernel
],

'api' => [
\Laravel\Sanctum\Http\Middleware\EnsureFrontendRequestsAreStateful::class,
\Illuminate\Routing\Middleware\ThrottleRequests::class . ':api',
\Illuminate\Routing\Middleware\SubstituteBindings::class,
\Exa\Http\Middlewares\BlockViewerUsers::class,
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Middleware/Authenticate.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Illuminate\Auth\Middleware\Authenticate as Middleware;
use Illuminate\Http\Request;

class Authenticate extends Middleware
final class Authenticate extends Middleware
{
/**
* Get the path the user should be redirected to when they are not authenticated.
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Middleware/EncryptCookies.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use Illuminate\Cookie\Middleware\EncryptCookies as Middleware;

class EncryptCookies extends Middleware
final class EncryptCookies extends Middleware
{
/**
* The names of the cookies that should not be encrypted.
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Middleware/PreventRequestsDuringMaintenance.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use Illuminate\Foundation\Http\Middleware\PreventRequestsDuringMaintenance as Middleware;

class PreventRequestsDuringMaintenance extends Middleware
final class PreventRequestsDuringMaintenance extends Middleware
{
/**
* The URIs that should be reachable while maintenance mode is enabled.
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Middleware/RedirectIfAuthenticated.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use Illuminate\Support\Facades\Auth;
use Symfony\Component\HttpFoundation\Response;

class RedirectIfAuthenticated
final class RedirectIfAuthenticated
{
/**
* Handle an incoming request.
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Middleware/TrimStrings.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use Illuminate\Foundation\Http\Middleware\TrimStrings as Middleware;

class TrimStrings extends Middleware
final class TrimStrings extends Middleware
{
/**
* The names of the attributes that should not be trimmed.
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Middleware/TrustHosts.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use Illuminate\Http\Middleware\TrustHosts as Middleware;

class TrustHosts extends Middleware
final class TrustHosts extends Middleware
{
/**
* Get the host patterns that should be trusted.
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Middleware/TrustProxies.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Illuminate\Http\Middleware\TrustProxies as Middleware;
use Illuminate\Http\Request;

class TrustProxies extends Middleware
final class TrustProxies extends Middleware
{
/**
* The trusted proxies for this application.
Expand Down
4 changes: 2 additions & 2 deletions app/Http/Middleware/ValidateSignature.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@

use Illuminate\Routing\Middleware\ValidateSignature as Middleware;

class ValidateSignature extends Middleware
final class ValidateSignature extends Middleware
{
/**
* The names of the query string parameters that should be ignored.
*
* @var array<int, string>
*/
protected $except = [
protected array $except = [
// 'fbclid',
// 'utm_campaign',
// 'utm_content',
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Middleware/VerifyCsrfToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken as Middleware;

class VerifyCsrfToken extends Middleware
final class VerifyCsrfToken extends Middleware
{
/**
* The URIs that should be excluded from CSRF verification.
Expand Down
2 changes: 1 addition & 1 deletion app/Providers/AppServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use Illuminate\Http\Resources\Json\JsonResource;
use Illuminate\Support\ServiceProvider;

class AppServiceProvider extends ServiceProvider
final class AppServiceProvider extends ServiceProvider
{
/**
* Register any application services.
Expand Down
2 changes: 1 addition & 1 deletion app/Providers/AuthServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// use Illuminate\Support\Facades\Gate;
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;

class AuthServiceProvider extends ServiceProvider
final class AuthServiceProvider extends ServiceProvider
{
/**
* The model to policy mappings for the application.
Expand Down
2 changes: 1 addition & 1 deletion app/Providers/EventServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
use Illuminate\Support\Facades\Event;

class EventServiceProvider extends ServiceProvider
final class EventServiceProvider extends ServiceProvider
{
/**
* The event to listener mappings for the application.
Expand Down
26 changes: 20 additions & 6 deletions app/Providers/RouteServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
scheme: 'bearer',
bearerFormat: 'JWT'
)]
class RouteServiceProvider extends ServiceProvider
final class RouteServiceProvider extends ServiceProvider
{
/**
* The path to the "home" route for your application.
Expand Down Expand Up @@ -52,20 +52,34 @@ public function boot(): void
*/
protected function configureRateLimiting(): void
{
RateLimiter::for('api', fn (Request $request) => Limit::perMinute(60)->by($request->user()?->id ?: $request->ip()));
RateLimiter::for(
'api',
fn (Request $request) => Limit::perMinute(60)
->by($request->user()?->id ?: $request->ip())
);
}

private function configureIndexRoute(): void
{
Route::get(self::HOME, function () {
return response()->json([
$data = [
'application' => config('app.name'),
'status' => Response::HTTP_OK,
'datetime' => Carbon::now()->format(Formatter::API_DATETIME_FORMAT),
];

if (! App::environment('local', 'testing')) {
return response()->json($data);
}

$data = [
...$data,
'environment' => config('app.env'),
'php_version' => phpversion(),
'laravel_version' => App::version(),
'status' => Response::HTTP_OK,
'datetime' => Carbon::now()->format(Formatter::API_DATETIME_FORMAT),
]);
];

return response()->json($data);
})->name('login');
}

Expand Down
26 changes: 18 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@
"php": "^8.3",
"ext-curl": "*",
"guzzlehttp/guzzle": "^7.8",
"laravel/framework": "^11.1",
"laravel/sanctum": "^4.0",
"laravel/framework": "^11.5",
"laravel/tinker": "^2.9",
"strictus/strictus": "^1.3",
"tymon/jwt-auth": "^2.1",
"wendelladriel/laravel-validated-dto": "^3.5",
"zircote/swagger-php": "^4.8"
"zircote/swagger-php": "^4.9"
},
"require-dev": {
"fakerphp/faker": "^1.23",
Expand All @@ -38,8 +38,8 @@
"nunomaduro/collision": "^8.1",
"pestphp/pest": "^2.34",
"pestphp/pest-plugin-laravel": "^2.3",
"phpunit/phpunit": "^10.5",
"spatie/laravel-ignition": "^2.4"
"pestphp/pest-plugin-type-coverage": "*",
"spatie/laravel-ignition": "^2.5"
},
"autoload": {
"psr-4": {
Expand All @@ -56,11 +56,21 @@
}
},
"scripts": {
"lint": ["pint"],
"test": ["pest"],
"swagger": ["sh ./tools/swagger.sh"],
"lint": [
"pint"
],
"test": [
"pest"
],
"test:types": [
"pest --type-coverage --min=100"
],
"swagger": [
"sh ./tools/swagger.sh"
],
"prepare": [
"pint --dirty",
"@test:types",
"@swagger"
],
"post-autoload-dump": [
Expand Down
Loading

0 comments on commit 99e75d2

Please sign in to comment.