How pig-mesh/pig works
Main Components
• Frontend & API Layer: Although the project includes a separate pig-ui repository (hosted externally on Gitee), the core backend is exposed via the gateway.
• API Gateway (pig-gateway): Acts as the front door for external requests. It routes and filters traffic via Spring Cloud Gateway on port [9999].
• Authorization Service (pig-auth): Provides OAuth2–based authentication/authorization, issuing tokens and handling login–related endpoints (port 3000).
• User Management Module (pig-upms): Divided between an API module (common interfaces) and a business processing module (pig-upms-biz, on port [4000]), handling user, role and permission logic.
• Service Discovery/Registry (pig-register): Implements a Nacos server (port [8848]) allowing the dynamic discovery of microservices.
• Boot Starter (pig-boot): In a monolithic setting this module can bootstrap the entire application.
• Common Modules (pig-common): A suite of shared libraries (dependency management, logging, datasource, security, mybatis enhancements, file upload/OSS, distributed transactions with Seata, swagger documentation and XSS protection) that many services depend on.
• Visual Management & DevOps Tools (pig-visual): Contains submodules for monitoring (pig-monitor, port [5001]), code generation (pig-codegen, port [5002]), and scheduled task management (pig-quartz, port [5007]).
• Infrastructure & Database: The “db” folder contains the Docker deployment files and SQL scripts (pig.sql, pig_config.sql); a docker-compose.yml file is available for container orchestration during development. Also, integration with container orchestration systems like Kubernetes or Rancher2 is mentioned in the README.
Relationships and Interactions
• External clients first hit the API Gateway, which forwards requests according to routing rules.
• The gateway routes secured requests to the pig-auth service for token validation and the pig-upms module for permission checks.
• When microservices need to communicate, they make use of the pig-common libraries and the service registry (pig-register) for dynamic discovery.
• Pig-boot can be used in a monolith mode, aggregating many of the microservices internally when a simpler deployment is preferred.
• Shared concerns such as logging, security, distributed transactions, and file storage are abstracted into the pig-common modules.
• Visual modules (monitoring, code generation, quartz for scheduled tasks) provide supporting dashboards and administrative interfaces.
Architectural Patterns and Design Principles
• Microservices Architecture: Separate services (auth, gateway, user management, etc.) communicate through REST APIs and use a centralized service registry.
• Separation of Concerns: Each module (authorization, user management, gateway, etc.) handles a discrete responsibility.
• Shared Common Libraries: The pig-common modules define cross-cutting concerns that benefit from reusability and reduced code duplication.
• Containerization: The presence of Dockerfiles for almost every service and a docker-compose configuration file indicates that container orchestration (and eventual deployment to Kubernetes or similar platforms) is a key architectural element.
• Security and RBAC: The project uses Spring Authorization Server techniques, OAuth2 access token management (with custom generators and converters), and security filters to enforce application security.