Modern, scalable microservices architecture with TypeScript, Express.js, and gRPC following golden ratio design principles
This project serves as the API Gateway for a comprehensive logistics management system. It provides RESTful HTTP endpoints that communicate with backend microservices via gRPC, offering a unified interface for managing logistics operations including shipments, inventory, tracking, and order management.
- π RESTful API Gateway: Clean HTTP endpoints for client applications
- β‘ gRPC Communication: High-performance inter-service communication
- ποΈ Database Integration: MariaDB with TypeORM for robust data persistence
- π¦ TypeScript: Full type safety and modern development experience
- ποΈ Microservices Architecture: Scalable and maintainable service design
- π Enterprise-Ready: Built for production logistics systems
| Technology | Purpose | Version |
|---|---|---|
| TypeScript | Primary programming language | Latest |
| Express.js | Web framework for API endpoints | 4.x |
| gRPC | Microservices communication protocol | Latest |
| MariaDB | Relational database management | 10.x+ |
| TypeORM | Database ORM and migration management | Latest |
Enterprise logistics architecture following Ο proportions for optimal system visualization
graph TB
%% Golden Ratio Client Layer (Ο = 1.618 user interaction priority)
subgraph "π Client Layer - Ο Priority Interface"
direction LR
WebApp[π± Web Application<br/>Angular/React<br/>Ο User Experience]
MobileApp[π² Mobile App<br/>React Native/Flutter<br/>Ο Mobile Priority]
AdminUI[π¨βπ» Admin Dashboard<br/>Analytics & Reports<br/>1.0 Management]
IoT[π IoT Devices<br/>Sensors & Trackers<br/>1/Ο Automation]
end
%% Golden Ratio Gateway Layer (1.0 balanced processing)
subgraph "πͺ API Gateway Layer - Balanced Processing"
direction TB
Gateway[β‘ Express.js Gateway<br/>Request Routing<br/>Load Balancing]
Auth[π Authentication<br/>JWT & OAuth<br/>Security Layer]
RateLimit[β±οΈ Rate Limiting<br/>Traffic Control<br/>Protection]
Swagger[π API Documentation<br/>OpenAPI Spec<br/>Developer Portal]
end
%% Golden Ratio Microservices Layer (Ο core business logic)
subgraph "βοΈ Microservices Layer - Ο Business Logic"
direction TB
subgraph "π Logistics Core Services"
Shipment[π¦ Shipment Service<br/>Package Management<br/>Ο Priority]
Tracking[π Tracking Service<br/>Real-time Location<br/>Ο Priority]
Inventory[π Inventory Service<br/>Stock Management<br/>1.0 Priority]
end
subgraph "πΌ Business Support Services"
Order[π Order Service<br/>Order Processing<br/>1.0 Priority]
User[π₯ User Service<br/>Account Management<br/>1/Ο Priority]
Notification[π Notification Service<br/>Alerts & Messages<br/>1/Ο Priority]
end
end
%% Golden Ratio Data Layer (1/Ο = 0.618 persistence)
subgraph "ποΈ Data Persistence Layer - Ο Storage"
direction LR
MariaDB[(ποΈ MariaDB Cluster<br/>Primary Database<br/>Ο Write Load)]
Redis[(β‘ Redis Cache<br/>Session & Performance<br/>38.2% Cache)]
FileSystem[(π File Storage<br/>Documents & Assets<br/>38.2% Files)]
end
%% Golden Spiral Communication Flow (Primary - 61.8%)
WebApp ==>|Primary Traffic<br/>Ο Load| Gateway
MobileApp ==>|Primary Traffic<br/>Ο Load| Gateway
AdminUI -->|Management Traffic<br/>Standard Load| Gateway
IoT -.->|Sensor Data<br/>Background Load| Gateway
%% Gateway Processing (Balanced - 1.0)
Gateway ==>|Request Processing| Auth
Auth ==>|Authenticated Requests| RateLimit
RateLimit ==>|Controlled Traffic| Shipment
RateLimit ==>|Controlled Traffic| Tracking
RateLimit ==>|Controlled Traffic| Order
%% gRPC Communication (Ο distributed)
Shipment -.->|gRPC Calls<br/>Service Mesh| Inventory
Tracking -.->|gRPC Calls<br/>Location Updates| Shipment
Order -.->|gRPC Calls<br/>Order Processing| User
User -.->|gRPC Calls<br/>Notifications| Notification
%% Data Layer Connections (Ο distributed load)
Shipment ==>|Write Operations<br/>Ο Priority| MariaDB
Tracking ==>|Write Operations<br/>Ο Priority| MariaDB
Order ==>|Write Operations<br/>Standard| MariaDB
Gateway -.->|Session Management| Redis
Auth -.->|Token Caching| Redis
Shipment -.->|Document Storage| FileSystem
%% Golden Ratio Color Scheme (Ο visual hierarchy)
style WebApp fill:#3498db,stroke:#2980b9,stroke-width:5px,color:#ffffff
style MobileApp fill:#e74c3c,stroke:#c0392b,stroke-width:5px,color:#ffffff
style AdminUI fill:#f39c12,stroke:#e67e22,stroke-width:3px,color:#ffffff
style IoT fill:#95a5a6,stroke:#7f8c8d,stroke-width:2px,color:#ffffff
style Gateway fill:#2c3e50,stroke:#1a252f,stroke-width:4px,color:#ffffff
style Auth fill:#27ae60,stroke:#229954,stroke-width:4px,color:#ffffff
style RateLimit fill:#8e44ad,stroke:#7d3c98,stroke-width:3px,color:#ffffff
style Swagger fill:#16a085,stroke:#138d75,stroke-width:2px,color:#ffffff
style Shipment fill:#e74c3c,stroke:#c0392b,stroke-width:4px,color:#ffffff
style Tracking fill:#3498db,stroke:#2980b9,stroke-width:4px,color:#ffffff
style Inventory fill:#f39c12,stroke:#e67e22,stroke-width:3px,color:#ffffff
style Order fill:#27ae60,stroke:#229954,stroke-width:3px,color:#ffffff
style User fill:#9b59b6,stroke:#8e44ad,stroke-width:2px,color:#ffffff
style Notification fill:#34495e,stroke:#2c3e50,stroke-width:2px,color:#ffffff
style MariaDB fill:#4caf50,stroke:#388e3c,stroke-width:5px,color:#ffffff
style Redis fill:#ff5722,stroke:#e64a19,stroke-width:3px,color:#ffffff
style FileSystem fill:#607d8b,stroke:#455a64,stroke-width:3px,color:#ffffff
gRPC communication patterns optimized with Ο proportions for efficient data flow
sequenceDiagram
participant C as π± Client
participant G as πͺ API Gateway
participant A as π Auth Service
participant S as π¦ Shipment Service
participant T as π Tracking Service
participant D as ποΈ Database
Note over C,D: Golden Ratio Request Flow (Ο = 1.618 optimization)
%% Primary Flow (61.8% - Ο priority)
C->>+G: 1. HTTP Request<br/>Ο Priority Traffic
G->>+A: 2. Validate Token<br/>Security Check
A-->>-G: 3. Auth Success<br/>User Context
%% Business Logic Flow (1.0 - balanced)
G->>+S: 4. gRPC Call<br/>Business Logic
S->>+T: 5. Location Update<br/>Service Communication
T-->>-S: 6. Tracking Data<br/>Real-time Info
%% Data Layer Flow (1/Ο - 38.2% persistence)
S->>+D: 7. Database Query<br/>Data Persistence
D-->>-S: 8. Query Result<br/>Retrieved Data
%% Response Flow (Ο spiral pattern)
S-->>-G: 9. gRPC Response<br/>Processed Data
G-->>-C: 10. HTTP Response<br/>JSON Payload
%% Golden Ratio Timing Annotations
Note over C,G: Ο Response Time: <100ms
Note over G,S: 1.0 Processing: <200ms
Note over S,D: 1/Ο Query Time: <50ms
Advanced microservices communication mesh using Ο proportions for optimal service interaction
graph TB
%% Golden Ratio Service Discovery Layer (Ο = 1.618 priority)
subgraph "π Service Discovery - Ο Priority Layer"
direction TB
ServiceRegistry[π Service Registry<br/>Consul/Eureka<br/>Ο Discovery Priority]
LoadBalancer[βοΈ Load Balancer<br/>HAProxy/Nginx<br/>Ο Traffic Distribution]
HealthCheck[π Health Monitoring<br/>Service Mesh<br/>1.0 Monitoring]
end
%% Golden Ratio gRPC Services Layer (Ο core services)
subgraph "β‘ gRPC Services Mesh - Ο Business Core"
direction TB
subgraph "π Logistics Domain Services"
ShipmentGRPC[π¦ Shipment gRPC<br/>Proto: shipment.proto<br/>Ο Core Service]
TrackingGRPC[π Tracking gRPC<br/>Proto: tracking.proto<br/>Ο Core Service]
InventoryGRPC[π Inventory gRPC<br/>Proto: inventory.proto<br/>1.0 Service]
end
subgraph "πΌ Support Domain Services"
OrderGRPC[π Order gRPC<br/>Proto: order.proto<br/>1.0 Service]
UserGRPC[π₯ User gRPC<br/>Proto: user.proto<br/>1/Ο Service]
NotificationGRPC[π Notification gRPC<br/>Proto: notification.proto<br/>1/Ο Service]
end
end
%% Golden Ratio Message Queue Layer (1/Ο = 0.618 async)
subgraph "π¨ Message Queue Layer - Async Communication"
direction LR
EventBus[π Event Bus<br/>Apache Kafka<br/>Ο Event Priority]
MessageQueue[π¬ Message Queue<br/>RabbitMQ<br/>38.2% Async Load]
StreamProcessor[π Stream Processing<br/>Apache Flink<br/>38.2% Real-time]
end
%% Golden Ratio Data Persistence (1/Ο distributed)
subgraph "ποΈ Distributed Data Layer - Ο Storage"
direction TB
subgraph "π Primary Databases"
ShipmentDB[(π¦ Shipment DB<br/>MariaDB Cluster<br/>Ο Write Load)]
TrackingDB[(π Tracking DB<br/>TimeSeries DB<br/>Ο Write Load)]
InventoryDB[(π Inventory DB<br/>PostgreSQL<br/>1.0 Load)]
end
subgraph "β‘ Cache & Search"
RedisCluster[(β‘ Redis Cluster<br/>Distributed Cache<br/>38.2% Cache)]
ElasticSearch[(π Elasticsearch<br/>Search Engine<br/>38.2% Search)]
end
end
%% Service Discovery Connections (Ο priority)
ServiceRegistry ==>|Service Registration<br/>Ο Priority| ShipmentGRPC
ServiceRegistry ==>|Service Registration<br/>Ο Priority| TrackingGRPC
ServiceRegistry -->|Service Registration<br/>Standard| OrderGRPC
ServiceRegistry -.->|Service Registration<br/>Background| UserGRPC
LoadBalancer ==>|Traffic Distribution<br/>Ο Load Balancing| ShipmentGRPC
LoadBalancer ==>|Traffic Distribution<br/>Ο Load Balancing| TrackingGRPC
LoadBalancer -->|Traffic Distribution<br/>Standard| InventoryGRPC
%% gRPC Inter-Service Communication (Ο mesh)
ShipmentGRPC -.->|gRPC Stream<br/>Real-time Updates| TrackingGRPC
TrackingGRPC -.->|gRPC Call<br/>Location Data| ShipmentGRPC
ShipmentGRPC -.->|gRPC Call<br/>Stock Check| InventoryGRPC
OrderGRPC -.->|gRPC Call<br/>Order Processing| ShipmentGRPC
UserGRPC -.->|gRPC Call<br/>User Context| OrderGRPC
NotificationGRPC -.->|gRPC Stream<br/>Event Notifications| UserGRPC
%% Event-Driven Communication (1/Ο async)
ShipmentGRPC ==>|Publish Events<br/>Shipment Created| EventBus
TrackingGRPC ==>|Publish Events<br/>Location Updated| EventBus
EventBus -.->|Subscribe Events<br/>Async Processing| NotificationGRPC
EventBus -.->|Subscribe Events<br/>Analytics| StreamProcessor
%% Data Layer Connections (Ο distributed)
ShipmentGRPC ==>|Write/Read<br/>Ο Priority| ShipmentDB
TrackingGRPC ==>|Write/Read<br/>Ο Priority| TrackingDB
InventoryGRPC -->|Write/Read<br/>Standard| InventoryDB
OrderGRPC -->|Write/Read<br/>Standard| ShipmentDB
%% Cache Layer Connections
ShipmentGRPC -.->|Cache Operations<br/>Performance| RedisCluster
TrackingGRPC -.->|Search Operations<br/>Location Queries| ElasticSearch
InventoryGRPC -.->|Cache Operations<br/>Stock Levels| RedisCluster
%% Golden Ratio Color Scheme (Ο visual hierarchy)
style ServiceRegistry fill:#2c3e50,stroke:#1a252f,stroke-width:5px,color:#ffffff
style LoadBalancer fill:#27ae60,stroke:#229954,stroke-width:4px,color:#ffffff
style HealthCheck fill:#3498db,stroke:#2980b9,stroke-width:3px,color:#ffffff
style ShipmentGRPC fill:#e74c3c,stroke:#c0392b,stroke-width:5px,color:#ffffff
style TrackingGRPC fill:#3498db,stroke:#2980b9,stroke-width:5px,color:#ffffff
style InventoryGRPC fill:#f39c12,stroke:#e67e22,stroke-width:3px,color:#ffffff
style OrderGRPC fill:#27ae60,stroke:#229954,stroke-width:3px,color:#ffffff
style UserGRPC fill:#9b59b6,stroke:#8e44ad,stroke-width:2px,color:#ffffff
style NotificationGRPC fill:#34495e,stroke:#2c3e50,stroke-width:2px,color:#ffffff
style EventBus fill:#ff6b6b,stroke:#ee5a52,stroke-width:4px,color:#ffffff
style MessageQueue fill:#4ecdc4,stroke:#45b7aa,stroke-width:3px,color:#ffffff
style StreamProcessor fill:#45b7d1,stroke:#3498db,stroke-width:3px,color:#ffffff
style ShipmentDB fill:#4caf50,stroke:#388e3c,stroke-width:5px,color:#ffffff
style TrackingDB fill:#ff9800,stroke:#f57c00,stroke-width:5px,color:#ffffff
style InventoryDB fill:#607d8b,stroke:#455a64,stroke-width:3px,color:#ffffff
style RedisCluster fill:#ff5722,stroke:#e64a19,stroke-width:3px,color:#ffffff
style ElasticSearch fill:#795548,stroke:#5d4037,stroke-width:3px,color:#ffffff
- Node.js (v16+ recommended)
- npm or yarn
- MariaDB Server (v10.5+)
- Basic understanding of gRPC and microservices
-
Clone the repository
git clone https://github.com/abdoElHodaky/logisticsassgrpc.git cd logisticsassgrpc -
Install dependencies
npm install # or yarn install -
Configure environment variables
cp .env.example .env
Update
.envwith your configuration:PORT=3000 DB_HOST=localhost DB_PORT=3306 DB_USER=your_user DB_PASSWORD=your_password DB_NAME=logistics_db GRPC_SERVICE_HOST=localhost GRPC_SERVICE_PORT=50051
-
Run database migrations
npm run migration:run
-
Start the development server
npm run dev
The API Gateway exposes the following endpoint categories:
- π¦ Shipments: Create, track, and manage shipments
- π Inventory: Monitor and update inventory levels
- π Tracking: Real-time shipment tracking and status updates
- π Orders: Order processing and management
- π₯ Users: User authentication and profile management
GET /api/shipments - List all shipments
POST /api/shipments - Create new shipment
GET /api/shipments/:id - Get shipment details
PUT /api/shipments/:id - Update shipment
DELETE /api/shipments/:id - Delete shipment
GET /api/tracking/:id - Track shipment status
GET /api/inventory - View inventory
POST /api/orders - Create new order
npm run dev # Start development server with hot reload
npm run build # Build for production
npm run start # Start production server
npm run test # Run test suite
npm run lint # Lint code
npm run migration:generate # Generate new migration
npm run migration:run # Run pending migrationslogisticsassgrpc/
βββ src/
β βββ controllers/ # Request handlers
β βββ services/ # Business logic & gRPC clients
β βββ entities/ # TypeORM database entities
β βββ routes/ # API route definitions
β βββ middleware/ # Express middleware
β βββ config/ # Configuration files
β βββ proto/ # gRPC protocol buffer definitions
βββ migrations/ # Database migrations
βββ tests/ # Test files
βββ package.json
- Input validation and sanitization
- Rate limiting on API endpoints
- CORS configuration
- SQL injection protection via TypeORM
- Environment-based configuration
# Run all tests
npm test
# Run tests with coverage
npm run test:coverage
# Run specific test suite
npm test -- shipments.test.ts- gRPC Protocol: Binary protocol for efficient service-to-service communication
- Connection Pooling: Optimized database connections
- Async/Await: Non-blocking asynchronous operations
- Caching: Redis integration ready for response caching
Contributions are welcome! Please follow these steps:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
abdoElHodaky
- GitHub: @abdoElHodaky
- Express.js community for the robust web framework
- gRPC team for the efficient RPC framework
- TypeORM contributors for the excellent ORM
- MariaDB Foundation for the reliable database
For issues, questions, or contributions, please open an issue on GitHub or contact the maintainer.
β Star this repository if you find it helpful!
Made with β€οΈ for the logistics industry
A production-ready TypeScript API Gateway that bridges RESTful HTTP clients with gRPC-based logistics microservices (shipments, inventory, tracking, orders) using Express.js for routing and TypeORM with MariaDB for type-safe data persistence in an enterprise-grade, scalable microservices architecture.