Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
dbdf2c6
Migrate User API to gRPC architecture
OmmrGAZAR315 Jun 5, 2025
93942a6
Add GrpcServiceProvider for gRPC service registration
OmmrGAZAR315 Jun 5, 2025
04590ca
Remove gRPC support and simplify Docker setup
OmmrGAZAR315 Jun 5, 2025
d77ebf6
Add gRPC and protobuf support in Docker setup
OmmrGAZAR315 Jun 5, 2025
b33ae9d
Introduce GrpcTransformer for gRPC DTO handling and enhance UserGrpcS…
OmmrGAZAR315 Jun 5, 2025
b62dacd
Refactor system to remove Redis dependencies and migrate User API to …
OmmrGAZAR315 Jun 5, 2025
d165cc3
Migrate User API to gRPC and remove Redis dependencies
OmmrGAZAR315 Jun 6, 2025
1878e76
Refactor `UserGrpcService` to leverage `UserResource` for consistent …
OmmrGAZAR315 Jun 6, 2025
f0e3cf4
Refactor gRPC service methods and controllers for consistent request,…
OmmrGAZAR315 Jun 6, 2025
f865fab
Refactor `UserGrpcService` to enhance metadata handling, improve erro…
OmmrGAZAR315 Jun 6, 2025
e6afbcc
Update `UserProfileResponse` to rename `photo_url` to `photo_path` fo…
OmmrGAZAR315 Jun 6, 2025
233838d
Update `UserProfileResponse` to rename `photo_url` to `photo_path` an…
OmmrGAZAR315 Jun 6, 2025
f164cb4
Refactor `UserGrpcService` to improve error handling, enhance `GetUse…
OmmrGAZAR315 Jun 7, 2025
e329a0e
Introduce `GatewayService` with protobuf definitions and generated PH…
OmmrGAZAR315 Jun 7, 2025
51960b8
Refactor gRPC integration to replace HTTP-based logic with `GrpcServi…
OmmrGAZAR315 Jun 7, 2025
1bc03fb
Refactor `AuthController` to utilize `GrpcService` for login and sign…
OmmrGAZAR315 Jun 7, 2025
19f0190
Refactor `AuthController` to remove unused `UserService` dependency, …
OmmrGAZAR315 Jun 7, 2025
e3aa9b5
Refactor `GrpcService` response formatting for JSON consistency and s…
OmmrGAZAR315 Jun 7, 2025
901d6cd
Refactor `GrpcService` and `GatewayService` for improved metadata han…
OmmrGAZAR315 Jun 7, 2025
8f2d5ed
Refactor `ShoppingCartController` to use `GrpcService` for `addToCart…
OmmrGAZAR315 Jun 7, 2025
84d1b9b
Refactor `ShoppingCartController` to replace HTTP-based logic with `G…
OmmrGAZAR315 Jun 7, 2025
ea66519
Refactor `AuthController` to proxy `logout` operation through `GrpcSe…
OmmrGAZAR315 Jun 7, 2025
988725a
Refactor `OfferController` and `ProductController` to utilize `GrpcSe…
OmmrGAZAR315 Jun 9, 2025
0e861a1
Refactor `InjectUser` trait to return `user_id` instead of modifying …
OmmrGAZAR315 Jun 9, 2025
0af389e
Refactor `InjectUser` trait to make `injectUserId` method public and …
OmmrGAZAR315 Jun 10, 2025
60ae5f8
Add `clear` method to `WishListController` and corresponding route fo…
OmmrGAZAR315 Jun 10, 2025
adb28fc
Refactor `GrpcService` and `GatewayService` to improve response handl…
OmmrGAZAR315 Jun 11, 2025
8793167
Rename controllers and routes to align with `*ApiController` naming c…
OmmrGAZAR315 Jun 12, 2025
1c00257
Remove Laravel Octane and related configurations, update `composer.js…
OmmrGAZAR315 Jun 12, 2025
71bfae0
Add `AIApi` for AI recommendations service, implement `ApiGatewayCont…
OmmrGAZAR315 Jun 12, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,6 @@ CACHE_STORE=database

MEMCACHED_HOST=127.0.0.1

REDIS_CLIENT=phpredis
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

MAIL_MAILER=log
MAIL_SCHEME=null
MAIL_HOST=127.0.0.1
Expand Down
140 changes: 90 additions & 50 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,61 +1,80 @@
FROM php:8.4.4-fpm-alpine AS builder
FROM php:8.4.4-fpm AS builder

# Install necessary build dependencies
RUN apk add --no-cache \
mysql-dev \
postgresql-dev \
# Install system dependencies including protobuf
RUN apt-get update && apt-get install -y \
libpq-dev \
libzip-dev \
unzip \
git \
openssl-dev \
brotli-dev \
curl \
wget \
libcurl4-openssl-dev \
libssl-dev \
pkg-config \
protobuf-compiler \
protobuf-compiler-grpc \
libprotobuf-dev \
build-essential \
autoconf \
automake \
make \
gcc \
g++ \
libc-dev \
pcre-dev \
$PHPIZE_DEPS

# Install PHP extensions
RUN docker-php-ext-install pdo_mysql pdo_pgsql zip \
&& docker-php-ext-configure pcntl --enable-pcntl \
&& docker-php-ext-install pcntl \
&& docker-php-ext-install opcache

# Install Swoole via PECL
RUN pecl install swoole \
&& docker-php-ext-enable swoole \
&& pecl install redis \
&& docker-php-ext-enable redis

FROM php:8.4.4-fpm-alpine AS production

# Install runtime dependencies (required for the extensions to work)
RUN apk add --no-cache \
mysql-client \
postgresql-client \
libzip \
git

# Copy PHP extensions from builder stage
libtool \
netcat-openbsd \
&& rm -rf /var/lib/apt/lists/* \
&& apt-get clean

# Install PHP extensions (separate layer for better caching)
RUN docker-php-ext-install \
pdo_mysql \
zip \
sockets \
pcntl \
bcmath \
opcache

# Copy backed up gRPC extension files
COPY grpc-backup/extensions/ /usr/local/lib/php/extensions/
COPY grpc-backup/conf.d/ /usr/local/etc/php/conf.d/

# Install remaining PECL extensions
# docke

FROM php:8.4.4-fpm AS production

# Install runtime dependencies
RUN apt-get update && apt-get install -y \
libpq-dev \
libzip-dev \
unzip \
git \
curl \
libcurl4-openssl-dev \
libssl-dev \
pkg-config \
protobuf-compiler \
protobuf-compiler-grpc \
libprotobuf-dev \
netcat-openbsd \
&& rm -rf /var/lib/apt/lists/* \
&& apt-get clean

# Copy PHP extensions from builder
COPY --from=builder /usr/local/lib/php/extensions/ /usr/local/lib/php/extensions/
COPY --from=builder /usr/local/etc/php/conf.d/ /usr/local/etc/php/conf.d/

# Copy php.ini with OPcache settings
COPY php.ini /usr/local/etc/php/conf.d/opcache.ini
# Clean up PECL cache to reduce image size
RUN rm -rf /tmp/pear

# Install Composer
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
# Install Composer (separate layer)
COPY --from=composer:2.8 /usr/bin/composer /usr/bin/composer

# Set working directory
WORKDIR /var/www

# Copy composer files first for better caching
# Copy PHP configuration early (rarely changes)
COPY php.ini /usr/local/etc/php/conf.d/custom.ini

# Copy composer files (for dependency caching)
COPY composer.json composer.lock ./

# Install dependencies (this layer will be cached if composer files don't change)
# Install dependencies with production optimizations
RUN composer install \
--no-dev \
Expand All @@ -65,16 +84,37 @@ RUN composer install \
--classmap-authoritative \
&& composer clear-cache

# Copy application files
# Copy application files (most frequently changing layer - put last)
COPY . .

# Set permissions
RUN chown -R www-data:www-data /var/www \
# Create necessary directories and set permissions
RUN mkdir -p storage/logs storage/framework/{cache,sessions,views} bootstrap/cache \
&& chown -R www-data:www-data /var/www \
&& chmod -R 755 /var/www/storage \
&& chmod -R 755 /var/www/bootstrap/cache

# Expose Port
EXPOSE 8000
# Create a non-root user for security
RUN groupadd -g 1000 laravel \
&& useradd -u 1000 -g laravel -m laravel

# Expose ports
EXPOSE 50051 8080

# Health check for gRPC service
HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
CMD nc -z localhost 50051 || exit 1

# Create startup script
RUN echo '#!/bin/bash\n\
set -e\n\
echo "Starting Laravel gRPC application..."\n\
php artisan config:cache\n\
php artisan route:cache\n\
php artisan view:cache\n\
php artisan migrate --force\n\
php artisan storage:link\n\
php-fpm\n\
' > /usr/local/bin/start.sh \
&& chmod +x /usr/local/bin/start.sh

# Start Laravel Octane with Swoole
CMD sh -c "php artisan migrate --force && php artisan storage:link && php artisan octane:start --server=swoole --host=0.0.0.0 --port=8000"
CMD ["/usr/local/bin/start.sh"]
19 changes: 19 additions & 0 deletions app/External_Apis/Apis/AIApi.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace App\External_Apis\Apis;

class AIApi extends BasicApi
{

private const string CONFIG_KEY = 'ai_url';

public static function getAIApi(): string
{
return self::getBaseUrl() . 'api/recommendations';
}

protected static function getConfigKey(): string
{
return self::CONFIG_KEY;
}
}
1 change: 0 additions & 1 deletion app/External_Apis/Apis/BasicApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ abstract protected static function getConfigKey(): string;

public static function getBaseUrl(): string
{
// USER_SERVICE_URL=http://user-webserver/
return config('services.microservices.' . static::getConfigKey());
}

Expand Down
2 changes: 1 addition & 1 deletion app/External_Apis/Services/OfferService.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function __construct(OfferRepository $OfferRepository)
*/
public function index(array $data): array
{
$this->injectUserId($data);
$data[] = $this->injectUserId();
$res = $this->OfferRepository->getAll($data);
$data = $this->handlingResErrorAndMessage($res);
if ($res->successful())
Expand Down
2 changes: 1 addition & 1 deletion app/External_Apis/Services/ProductService.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function __construct(
*/
public function index(array $data): array
{
$this->injectUserId($data);
$data[] = $this->injectUserId();
$res = $this->productRepository->getAll($data);
$data = $this->handlingResErrorAndMessage($res);
if ($res->successful())
Expand Down
29 changes: 29 additions & 0 deletions app/Grpc/BaseResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace App\Grpc;

use App\Grpc\User\UserResponse;

class BaseResponse
{
public int $code;
public string $message;
public ?array $data;


public function toArray(): array
{
return [
'code' => $this->code,
'message' => $this->message,
'data' => $this->data,
];
}

protected function buildUserResponse($response, bool $success = true, string $message = '')
{
$response->setSuccess($success);
$response->setMessage($message);
return $response;
}
}
Loading