Deployment & Infrastructure
Relevant source files
The following files were used as context for generating this wiki page:
The deployment and infrastructure of the SecondLayer platform are designed to support a multi-environment lifecycle, ranging from isolated local development to a complex staging environment. The system utilizes Docker and Docker Compose for container orchestration, ensuring consistent runtime environments across different hardware. Central to the infrastructure is a unified management script, manage-gateway.sh, which orchestrates builds, deployments, health checks, and gateway operations.
Sources: deployment/README.md:3-5, deployment/manage-gateway.sh:10-15, deployment/ARCHITECTURE.md:3-5
System Architecture
The infrastructure is categorized into distinct environments, primarily Local and Staging, each with specific network configurations and port allocations. The architecture relies on Nginx as a reverse proxy for SSL termination and request routing in remote environments.
Network and Request Flow
In the staging environment, traffic flows through a System Nginx instance for SSL termination before being routed to specific service containers. Internally, services communicate over a dedicated Docker network.
The diagram above illustrates the request flow from the public internet through the SSL termination layer to the internal containerized services.
Sources: deployment/ARCHITECTURE.md:7-40, deployment/GATEWAY_SETUP.md:12-25
Environment Specifications
| Feature | Local Development | Staging Environment |
|---|---|---|
| Server | Localhost | gate.lexapp.co.ua |
| URL | https://localdev.legal.org.ua | https://stage.legal.org.ua |
| Backend Port | 3000 | 3004 |
| Frontend Port | 5173 (Vite Dev Server) | 8092 |
| PostgreSQL Port | 5432 | 5434 |
| Redis Port | 6379 | 6381 |
| Qdrant Port | 6333-6334 | 6337-6338 |
Sources: deployment/INDEX.md:58-62, deployment/GATEWAY_SETUP.md:12-25, deployment/ARCHITECTURE.md:44-60
Service Orchestration
Core Management Script
The manage-gateway.sh script serves as the primary interface for all infrastructure operations. It handles pre-flight checks, backup creation, smoke testing, and reporting.
Key Management Capabilities:
- Environment Control:
start,stop,restartfor local and staging profiles. - Deployment: Automated deployment via SSH to the gate server, including code pulling and image rebuilding.
- Gateway Operations: Management of the
legal-nginx-gatewaycontainer for routing. - Maintenance: Health checks and data cleaning (volume removal).
Sources: deployment/manage-gateway.sh:40-85, deployment/INDEX.md:40-52
Deployment Workflow
The deployment process for the staging environment involves a coordinated sequence of remote commands executed over SSH.
The sequence above shows the automated deployment lifecycle used to update the remote staging server.
Sources: deployment/manage-gateway.sh:315-450, DEPLOY_DEV_FIXES.md:55-85
Infrastructure Components
Database and Storage
The system employs a multi-tiered storage approach:
- PostgreSQL: Used for metadata and structured data (court cases, patterns, and user queries).
- Qdrant: Acts as the vector database for semantic search and similarity matching of legal embeddings.
- Redis: Serves as the caching layer for query results and session data.
- MinIO: Provides S3-compatible object storage for documents.
Sources: deployment/ARCHITECTURE.md:33-40, DEPLOY_DEV_FIXES.md:95-105
Configuration and Credentials
Credentials are managed through .env files (e.g., .env.local, .env.stage). The system includes an automated initialization process for PostgreSQL to prevent authentication failures.
PostgreSQL Auto-Init Logic:
- The script
check-credentials.shvalidates that superuser and application user passwords are set. - During the first container start,
init-postgres.shwaits for the engine to be ready. - It automatically creates the application user and database if they do not exist.
- Proper permissions are granted to the application user for the specific environment database.
Sources: deployment/QUICK_START.md:12-20, deployment/CREDENTIALS_SETUP.md:15-35, deployment/manage-gateway.sh:242-260
Infrastructure Monitoring
The platform includes a monitoring stack to ensure reliability and performance:
- Prometheus: Collects metrics from backend and infrastructure exporters.
- Grafana: Visualizes metrics and provides alerting dashboards.
- Health Endpoints: Services expose
/health,/health/live, and/health/readyfor automated status monitoring. - Exporters: Specific exporters for PostgreSQL, Redis, and system nodes provide granular telemetry.
Sources: deployment/ARCHITECTURE.md:75-80, deployment/manage-gateway.sh:410-425
Conclusion
The infrastructure of SecondLayer is built on a foundation of containerization and automated orchestration, allowing for rapid transitions between development and staging. By centralizing operations in manage-gateway.sh and utilizing standardized Docker environments, the platform maintains consistency and security through isolated networks and automated credential management. This architecture ensures that the complex requirements of legal data processing, semantic search, and multi-service integration are met with high availability and maintainability.