Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 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
f9b8161
Update `getRecommendedProducts` to use POST request for AI API, adjus…
OmmrGAZAR315 Jun 12, 2025
bf62a91
setup gRPC server
OmmrGAZAR315 Jun 12, 2025
af53eee
Remove all gRPC-related implementations, configurations, and dependen…
OmmrGAZAR315 Jun 13, 2025
1445922
Refactor gRPC-related components: update service names in `proxyReque…
OmmrGAZAR315 Jun 13, 2025
8afc0d4
Update `proxyRequest` calls to use proper gRPC service names (`UserSe…
OmmrGAZAR315 Jun 13, 2025
6fed70a
Refactor ProductController and gRPC routes: update proxyRequest to us…
OmmrGAZAR315 Jun 13, 2025
c584020
Enhance error handling in ApiGatewayController: return a specific JSO…
OmmrGAZAR315 Jun 13, 2025
2c7901d
Add AuthController with gRPC methods, refactor UserController to exte…
OmmrGAZAR315 Jun 13, 2025
8eda816
Refactor gRPC service integration: replace `proxyRequest` with `creat…
OmmrGAZAR315 Jun 13, 2025
bb76a64
Refactor gRPC integration: update method names and service references…
OmmrGAZAR315 Jun 14, 2025
0521f1e
Refactor UserApiController: replace hardcoded gRPC service and method…
OmmrGAZAR315 Jun 14, 2025
325d04b
Remove all gRPC DTOs along with their implementations, clearing out u…
OmmrGAZAR315 Jun 14, 2025
9731fcc
Update service naming convention in BaseGrpcController for clarity
OmmrGAZAR315 Jun 14, 2025
686e34b
Add user authentication check in InjectUser trait to ensure user is l…
OmmrGAZAR315 Jun 14, 2025
b629d58
Remove unused 'top_n' parameter from API request in ApiGatewayController
OmmrGAZAR315 Jun 14, 2025
28617fa
Refactor AuthApiController and GrpcService: replace hardcoded service…
OmmrGAZAR315 Jun 14, 2025
d19be66
Update percentage conversion logic in ApiGatewayController and improv…
OmmrGAZAR315 Jun 14, 2025
dce6ed0
Add supervisor configuration for PHP-FPM and gRPC server in Docker setup
OmmrGAZAR315 Jun 14, 2025
02be0fb
Update Dockerfile: replace php-fpm with supervisor to manage processes
OmmrGAZAR315 Jun 14, 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
142 changes: 92 additions & 50 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,61 +1,82 @@
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 \
supervisor \
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 \
supervisor \
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 +86,37 @@ RUN composer install \
--classmap-authoritative \
&& composer clear-cache

# Copy application files
# Copy supervisor configuration
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
# 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
# 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\
echo "Starting supervisor..."\n\
exec /usr/bin/supervisord -c /etc/supervisor/supervisord.conf\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"]
40 changes: 40 additions & 0 deletions app/Console/Commands/GrpcServeCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

// app/Console/Commands/GrpcServeCommand.php
namespace App\Console\Commands;

use Grpc\RpcServer;
use Illuminate\Console\Command;

class GrpcServeCommand extends Command
{
protected $signature = 'grpc:serve {--port=50051} {--host=0.0.0.0}';
protected $description = 'Start the gRPC server for User Service';

public function handle(): int
{
$host = $this->option('host');
$port = (int)$this->option('port');

$this->info("Starting gRPC User Service on {$host}:{$port}");

try {
$server = new RpcServer([]);
$server->addHttp2Port("{$host}:{$port}");

// Register the User service
$server->handle(app(\App\Grpc\Services\GatewayService::class));

$this->info('gRPC User Service started successfully');
$this->info('Listening for requests...');

// Start the server (this will block)
$server->run();

} catch (\Exception $e) {
$this->error('Failed to start gRPC server: ' . $e->getMessage());
return 1;
}
return 0;
}
}
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
Loading