Skip to content

Commit a4c60bf

Browse files
committed
docs(api-gateway): Update the context.md to reflect new structure
1 parent 2db9a13 commit a4c60bf

1 file changed

Lines changed: 99 additions & 58 deletions

File tree

services/api-gateway/CONTEXT.md

Lines changed: 99 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,107 @@
1-
# Kubin Server - Context
1+
# API Gateway - Context
22

3-
## What is the Server?
3+
## What is the API Gateway?
44

5-
The Kubin Server is a web service that stores, manages, and serves Kubernetes cluster snapshots. It provides the backend infrastructure for the entire Kubin platform, handling snapshot storage, user authentication, and API access.
5+
The API Gateway is the single entry point for all external requests to the Kubin platform. It handles routing, authentication, rate limiting, and serves as the orchestration layer between the CLI, Web UI, and the underlying microservices.
66

77
## Core Responsibilities
88

9-
### 1. Snapshot Storage
10-
- Stores uploaded snapshots securely
11-
- Manages snapshot metadata and indexing
12-
- Handles snapshot compression and decompression
13-
- Provides snapshot retrieval and download
14-
15-
### 2. API Management
16-
- Exposes REST API for snapshot operations
17-
- Handles upload, download, and management requests
18-
- Provides search and filtering capabilities
19-
- Manages API rate limiting and security
20-
21-
### 3. User Management
22-
- Handles user authentication and authorization
23-
- Manages user accounts and permissions
24-
- Controls access to public and private snapshots
25-
- Provides API key management for CLI access
26-
27-
### 4. Data Management
28-
- Organizes snapshots by user and organization
29-
- Implements snapshot versioning and history
30-
- Manages snapshot retention and cleanup
31-
- Provides backup and recovery capabilities
9+
### 1. Request Routing
10+
11+
- Routes requests to appropriate backend services
12+
- Load balances traffic across service instances
13+
- Handles service discovery and health checking
14+
- Provides unified API versioning (`/api/v1`, `/internal/api/v1`)
15+
16+
### 2. Security & Authentication
17+
18+
- TLS termination and security headers
19+
- JWT-based authentication validation
20+
- API rate limiting (100 concurrent uploads, 1000 queries/min)
21+
- CORS handling for web UI integration
22+
23+
### 3. Traffic Management
24+
25+
- Request/response middleware stack
26+
- Error handling and recovery
27+
- Request logging and monitoring
28+
- Graceful shutdown coordination
29+
30+
## Architecture Role
31+
32+
The API Gateway serves as the orchestration layer in Kubin's microservices architecture:
33+
34+
**Upstream Services:**
35+
36+
- **Upload Orchestrator**: Handles snapshot upload coordination
37+
- **Metadata Service**: Manages PostgreSQL-backed snapshot metadata
38+
- **Storage Service**: Coordinates S3 file operations
39+
- **Query Service**: Orchestrates data retrieval from multiple services
40+
- **Analytics Service**: Provides ClickHouse-powered log analytics
41+
42+
**Client Interfaces:**
43+
44+
- **CLI Tool**: Direct API access for snapshot uploads
45+
- **Web UI**: Internal API endpoints for frontend functionality
46+
47+
## API Structure
48+
49+
### External API (`/api/v1`)
50+
51+
- `POST /api/v1/snapshots` - Initiate snapshot upload (→ Upload Orchestrator)
52+
- `GET /api/v1/snapshots` - List snapshots (→ Metadata Service)
53+
54+
### Internal API (`/internal/api/v1`)
55+
56+
- `GET /internal/api/v1/snapshots/{id}/resources` - Get snapshot resources
57+
- `GET /internal/api/v1/snapshots/{id}/pods` - Get pod information
58+
- `GET /internal/api/v1/snapshots/{id}/logs` - Get pod logs (→ Analytics Service)
59+
- `GET /internal/api/v1/snapshots/{id}/namespaces` - Get namespaces
60+
61+
## Communication Patterns
62+
63+
### Synchronous Routing
64+
65+
- CLI upload requests → Upload Orchestrator (immediate response)
66+
- Web UI queries → Query Service (real-time data)
67+
- File operations → Storage Service (direct S3 coordination)
68+
69+
### Middleware Stack
70+
71+
1. **Recovery**: Panic recovery and error handling
72+
2. **Logging**: Request/response logging
73+
3. **Security**: Headers, CORS, authentication
74+
4. **JSON**: Content-type management
75+
76+
## Integration with Microservices Architecture
77+
78+
The API Gateway is part of Kubin's distributed system that separates concerns:
79+
80+
- **Upload Path**: API Gateway → Upload Orchestrator → Storage Service → Kafka → Log Processor
81+
- **Query Path**: API Gateway → Query Service → (Metadata Service + Analytics Service + Storage Service)
82+
- **Caching**: Redis integration for performance optimization
3283

3384
## Key Features
3485

35-
- **RESTful API**: Standard HTTP/JSON API for all operations
36-
- **Authentication**: JWT-based user authentication
37-
- **Authorization**: Role-based access control
38-
- **Search**: Full-text search across snapshots
39-
- **Sharing**: Public and private snapshot sharing
40-
- **Versioning**: Track changes in snapshots over time
41-
42-
## Service Architecture
43-
44-
The server is designed as:
45-
- **Stateless**: Can be scaled horizontally
46-
- **Containerized**: Runs in Kubernetes or Docker
47-
- **Database-backed**: Persistent storage for metadata
48-
- **File storage**: Separate storage for snapshot files
49-
- **Load balanced**: Supports multiple instances
50-
51-
## API Endpoints
52-
53-
Core endpoints include:
54-
- `POST /snapshots` - Upload new snapshot
55-
- `GET /snapshots` - List snapshots
56-
- `GET /snapshots/{id}` - Get snapshot details
57-
- `GET /snapshots/{id}/download` - Download snapshot
58-
- `DELETE /snapshots/{id}` - Delete snapshot
59-
60-
## Integration Points
61-
62-
- **CLI Tool**: Receives uploaded snapshots
63-
- **Web UI**: Provides data for the frontend
64-
- **Database**: Stores metadata and user information
65-
- **File Storage**: Stores actual snapshot files
66-
- **Authentication**: Integrates with identity providers
86+
- **High Throughput**: Optimized for concurrent snapshot uploads
87+
- **Fault Tolerance**: Circuit breakers and graceful degradation
88+
- **Observability**: Comprehensive logging and health checks
89+
- **Scalability**: Stateless design for horizontal scaling
90+
91+
## Health & Monitoring
92+
93+
- `/healthz` - Basic health check
94+
- `/readyz` - Readiness check (validates downstream services)
95+
- Structured logging with request tracing
96+
- Error reporting and recovery patterns
97+
98+
## Configuration
99+
100+
Environment-based configuration supporting:
101+
102+
- Server timeouts and connection limits
103+
- Authentication providers and JWT settings
104+
- Rate limiting policies
105+
- Allowed origins for CORS
106+
- Service discovery endpoints
107+

0 commit comments

Comments
 (0)