Enterprise-Grade gRPC API Contracts with Multi-Language Client Generation
Single Source of Truth for GeniusTechSpace Platform
Features β’ Quick Start β’ Architecture β’ Documentation β’ Contributing
This repository is the single source of truth for all API contracts across the GeniusTechSpace platform. It provides:
- Protocol Buffer Definitions: Complete API specifications using proto3
- Multi-Language Clients: Auto-generated clients for Rust, Go, Python, TypeScript, and Java
- Enterprise Features: Multitenancy, compliance, audit logging, and security
- Developer Experience: Strong typing, validation, comprehensive documentation
- CI/CD Integration: Automated testing, breaking change detection, and publishing
This project prioritizes Rust for high-performance, type-safe service development while supporting multiple languages for diverse use cases.
- π’ Enterprise Multitenancy - Tenant/Organization/Workspace isolation
- π Security First - TLS, authentication, authorization, encryption
- π Comprehensive Audit Logging - Compliance-ready audit trails
- π Data Residency - Geographic data storage controls
- β‘ High Performance - gRPC binary protocol, streaming support
- π Backward Compatibility - Breaking change detection
- π Self-Documenting - Auto-generated documentation
- β Input Validation - Request/response validation rules
- GDPR - General Data Protection Regulation
- HIPAA - Health Insurance Portability and Accountability Act
- SOC 2 - Service Organization Control 2
- PCI DSS - Payment Card Industry Data Security Standard
- ISO 27001 - Information Security Management
- Buf >= 1.28.0 (required)
- Rust >= 1.75 (primary language)
- Go >= 1.21 (optional)
- Python >= 3.8 (optional)
- Node.js >= 18 (optional)
- Java >= 17 (optional)
# Clone the repository
git clone https://github.com/geniustechspace/api-contracts.git
cd api-contracts
# Install dependencies
make install
# Set up enterprise structure
make setup
# Generate clients
make generate
# Build Rust client (primary)
make build-rust# Check setup
make help
# Lint proto files
make lint
# Run tests
make testapi-contracts/
βββ proto/ # Protocol Buffer definitions
β βββ core/v1/ # Core infrastructure types
β β βββ tenant.proto # Multitenancy primitives β
β β βββ context.proto # Request/response context
β β βββ errors.proto # Standard error handling
β β βββ audit.proto # Audit logging
β β βββ metadata.proto # Standard metadata
β β βββ health.proto # Health checks
β β βββ pagination.proto # Pagination patterns
β β βββ types.proto # Common data types (email, phone, address)
β βββ idp/v1/ # Identity Provider
β β βββ auth/ # Authentication
β β βββ user/ # User management
β β βββ organization/ # Organization management
β β βββ role/ # RBAC
β β βββ permission/ # Permissions
β β βββ session/ # Session management
β βββ services/ # Business services
βββ clients/ # Generated clients
β βββ rust/ # Rust (PRIMARY)
β βββ go/ # Go
β βββ python/ # Python
β βββ typescript/ # TypeScript/JavaScript
β βββ java/ # Java
βββ docs/ # Documentation
β βββ api/ # Generated API docs
β βββ standards/ # Design standards
β βββ compliance/ # Compliance guides
β βββ architecture/ # Architecture docs
β βββ guides/ # How-to guides
βββ scripts/ # Automation scripts
βββ tests/ # Integration tests
βββ buf.yaml # Buf configuration
βββ buf.gen.yaml # Code generation config
βββ Makefile # Build automation
βββ README.md # This file
Tenant (Required)
βββ Organization (Optional)
βββ Workspace (Optional)
Every request MUST include tenant context:
gRPC Metadata:
x-tenant-id: tenant-123
x-organization-id: org-456
x-workspace-id: workspace-789
HTTP Headers:
X-Tenant-ID: tenant-123
X-Organization-ID: org-456
X-Workspace-ID: workspace-789
Client β API Gateway β Service β Database
β
Metadata:
- x-tenant-id (required)
- x-request-id (required)
- x-correlation-id (for tracing)
- x-user-id (if authenticated)
- Authorization: Bearer <token>
All services return standardized errors:
message ErrorResponse {
string code = 1; // Application error code
string message = 2; // Human-readable message
ErrorCategory category = 3; // Classification
ErrorSeverity severity = 4; // Severity level
repeated FieldViolation fields = 5; // Field-level errors
RetryInfo retry_info = 6; // Retry guidance
}use geniustechspace_api_contracts::idp::auth::v1::*;
use tonic::Request;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Connect to auth service
let mut client = AuthServiceClient::connect("http://[::1]:50051").await?;
// Create request with tenant context
let mut request = Request::new(SignInRequest {
tenant_id: "tenant-123".into(),
email: "user@example.com".into(),
password: "secure-password".into(),
});
// Add metadata
request.metadata_mut().insert(
"x-request-id",
"req-123".parse().unwrap()
);
// Make request
let response = client.sign_in(request).await?;
let token = response.into_inner().access_token;
println!("β
Authenticated: {}", token);
Ok(())
}package main
import (
"context"
"log"
"google.golang.org/grpc"
authv1 "github.com/geniustechspace/api-contracts/gen/go/idp/v1/auth"
)
func main() {
conn, err := grpc.Dial("localhost:50051", grpc.WithInsecure())
if err != nil {
log.Fatalf("Failed to connect: %v", err)
}
defer conn.Close()
client := authv1.NewAuthServiceClient(conn)
resp, err := client.SignIn(context.Background(), &authv1.SignInRequest{
TenantId: "tenant-123",
Email: "user@example.com",
Password: "secure-password",
})
if err != nil {
log.Fatalf("SignIn failed: %v", err)
}
log.Printf("β
Authenticated: %s", resp.AccessToken)
}import grpc
from proto.idp.v1.auth import auth_service_pb2, auth_service_pb2_grpc
# Connect to service
channel = grpc.insecure_channel('localhost:50051')
stub = auth_service_pb2_grpc.AuthServiceStub(channel)
# Make request
request = auth_service_pb2.SignInRequest(
tenant_id="tenant-123",
email="user@example.com",
password="secure-password"
)
response = stub.SignIn(request)
print(f"β
Authenticated: {response.access_token}")import * as grpc from '@grpc/grpc-js';
import { AuthServiceClient } from '@geniustechspace/api-contracts/idp/v1/auth';
const client = new AuthServiceClient(
'localhost:50051',
grpc.credentials.createInsecure()
);
client.signIn({
tenantId: 'tenant-123',
email: 'user@example.com',
password: 'secure-password'
}, (err, response) => {
if (err) {
console.error('β Error:', err);
return;
}
console.log('β
Authenticated:', response.accessToken);
});Use the interactive service generator for fast setup:
make add-serviceThis will prompt you for:
- Service name (e.g.,
user-management,billing) - Service description
- API version (default:
v1) - Main entity name
The tool automatically:
- Creates directory structure (
proto/<service-name>/v1/) - Generates proto files from templates
- Sets up README documentation
- Includes multitenancy, validation, and error handling
- Integrates with existing build scripts
Alternatively, create services manually:
-
Create proto directory:
mkdir -p proto/services/myservice/v1
-
Define service (
proto/services/myservice/v1/service.proto):syntax = "proto3"; package geniustechspace.services.myservice.v1; import "core/v1/tenant.proto"; import "core/v1/errors.proto"; import "google/api/annotations.proto"; import "validate/validate.proto"; option rust_package = "geniustechspace::services::myservice::v1"; // MyService provides example functionality. service MyService { // GetResource retrieves a resource by ID. rpc GetResource(GetResourceRequest) returns (GetResourceResponse) { option (google.api.http) = { get: "/v1/resources/{id}" }; } } // GetResourceRequest requests a resource by ID. message GetResourceRequest { // Resource identifier. string id = 1 [(validate.rules).string.uuid = true]; } // GetResourceResponse returns the requested resource. message GetResourceResponse { // Resource identifier. string id = 1; // Resource name. string name = 2; }
-
Generate clients:
make generate
-
Build and test:
make build make test
π‘ Tip: For a complete service template with validation, multitenancy, and CRUD operations, use
make add-serviceinstead. See templates/README.md for details.
# Lint proto files
make lint
# Format proto files
make format
# Check for breaking changes
make breaking
# Run all checks
make check- API Reference:
docs/api/index.html(after generation) - OpenAPI Spec:
docs/openapi/api.yaml(after generation)
- TLS Required: All connections must use TLS 1.3+
- Token Validation: JWT tokens validated on every request
- Rate Limiting: Per-tenant rate limits enforced
- Audit Logging: All security events logged
- Encryption: Data encrypted at rest and in transit
Email security concerns to: security@geniustechspace.com
We welcome contributions! Please see CONTRIBUTING.md for guidelines.
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Add/modify proto files
- Generate clients (
make generate) - Run tests (
make test) - Commit changes (
git commit -m 'Add amazing feature') - Push to branch (
git push origin feature/amazing-feature) - Open a Pull Request
All changes require:
- β Passing CI checks
- β No breaking changes (or properly versioned)
- β Complete documentation
- β Code review approval
This project supports the following compliance frameworks:
| Framework | Status | Documentation |
|---|---|---|
| GDPR | β Supported | docs/compliance/gdpr.md |
| HIPAA | β Supported | docs/compliance/hipaa.md |
| SOC 2 | β Supported | docs/compliance/soc2.md |
| PCI DSS | β Supported | docs/compliance/pci-dss.md |
We use a dual versioning strategy that combines directory-based API versioning with Buf's module versioning:
-
Proto API Versioning: Directory-based (
v1/,v2/, etc.) for API evolution- Enables multiple API versions to coexist
- Allows smooth client migration without breaking changes
- Industry standard (used by Google, Kubernetes, etc.)
-
Module Versioning: Semantic versioning (SemVer) via Buf for releases
- Tags: Format
v<major>.<minor>.<patch>(e.g.,v1.0.0) - Breaking changes in API require new directory (v2) AND new major version (v2.0.0)
- Buf tracks module dependencies and ensures reproducible builds
- Tags: Format
Why both? They solve different problems:
- Directory versioning = API contract evolution (runtime coexistence)
- Buf versioning = Module release management (dependency tracking)
See Versioning Strategy for detailed explanation.
This project uses a modular, multi-package architecture where each API module is independently installable. See MULTI_PACKAGE_ARCHITECTURE.md for details.
[dependencies]
# Install only what you need
geniustechspace-core = "0.1.0"
geniustechspace-idp = "0.1.0"
geniustechspace-notification = "0.1.0"# Install only what you need
go get github.com/geniustechspace/api-contracts/gen/go/core
go get github.com/geniustechspace/api-contracts/gen/go/idp
go get github.com/geniustechspace/api-contracts/gen/go/notification# Install only what you need
pip install geniustechspace-core
pip install geniustechspace-idp
pip install geniustechspace-notification# Install only what you need
npm install @geniustechspace/core
npm install @geniustechspace/idp
npm install @geniustechspace/notification<dependencies>
<!-- Install only what you need -->
<dependency>
<groupId>com.geniustechspace</groupId>
<artifactId>api-contracts-core</artifactId>
<version>0.1.0</version>
</dependency>
<dependency>
<groupId>com.geniustechspace</groupId>
<artifactId>api-contracts-idp</artifactId>
<version>0.1.0</version>
</dependency>
<dependency>
<groupId>com.geniustechspace</groupId>
<artifactId>api-contracts-notification</artifactId>
<version>0.1.0</version>
</dependency>
</dependencies>- Core infrastructure types (tenant, context, errors)
- Multi-language client generation
- Rust as primary language
- Complete IDP service definitions
- Common business types
- Service templates and generators
- Advanced streaming patterns
- GraphQL gateway support
- Automated SDK publishing
- Latency: p95 < 100ms, p99 < 500ms
- Throughput: 10,000+ RPS per service
- Availability: 99.95% uptime SLA
- Scalability: Horizontal scaling supported
Run benchmarks:
cd clients/rust
cargo bench- Issues: GitHub Issues
- Discussions: GitHub Discussions
- Email: dev@geniustechspace.com
This project is licensed under the BSD-3-Clause License - see the LICENSE file for details.
- Buf - Protocol Buffer tooling
- gRPC - High-performance RPC framework
- Tonic - Rust gRPC implementation
- Prost - Rust Protocol Buffer implementation