Documentation

Complete guide to integrating Lattice into your microservices architecture

Introduction

Lattice is a service discovery platform that automatically maps your microservices architecture. Drop-in plugins analyze your applications at runtime, discovering routes, dependencies, and service relationships.

No manual configuration required. Lattice plugins integrate with your existing framework in minutes, providing real-time visibility into your entire service ecosystem.

Quick Start

1. Create Account

Sign up for a Lattice account and get your API key:

Visit https://lattice.black/signup

2. Install Plugin

Choose your framework and install the appropriate plugin:

yarn add @lattice.black/plugin-express
yarn add @lattice.black/plugin-nextjs

3. Configure

Set your API key from the dashboard:

LATTICE_API_KEY=your_api_key_here

4. Start Discovery

Your services will begin appearing in the Lattice dashboard within minutes.

Express.js Plugin

Installation

yarn add @lattice.black/plugin-express

Basic Usage

import express from 'express';
import { LatticePlugin } from '@lattice.black/plugin-express';

const app = express();

// Initialize Lattice plugin
const lattice = new LatticePlugin({
  serviceName: 'my-api',
  apiKey: process.env.LATTICE_API_KEY,
});

// Define your routes
app.get('/api/users', (req, res) => {
  res.json({ users: [] });
});

app.post('/api/users', (req, res) => {
  res.json({ created: true });
});

// Analyze and start discovery
await lattice.analyze(app);

// Optional: Add metrics tracking middleware
app.use(lattice.createMetricsMiddleware());

app.listen(3000, () => {
  console.log('Server running on port 3000');
});

Configuration Options

OptionTypeDefault
serviceNamestringAuto-detected
apiKeystringprocess.env.LATTICE_API_KEY
enabledbooleantrue
autoSubmitbooleantrue
submitIntervalnumber300000 (5 min)
discoverRoutesbooleantrue
discoverDependenciesbooleantrue

Next.js Plugin

Installation

yarn add @lattice.black/plugin-nextjs

Basic Usage

Create a discovery script and run it during your build or startup:

// scripts/discover.ts
import { LatticeNextPlugin } from '@lattice.black/plugin-nextjs';

const lattice = new LatticeNextPlugin({
  serviceName: 'my-nextjs-app',
  apiKey: process.env.LATTICE_API_KEY,
  appDir: './src/app', // Path to your Next.js app directory
});

await lattice.analyze();

Package.json Script

{
  "scripts": {
    "discover": "tsx scripts/discover.ts",
    "build": "yarn discover && next build"
  }
}

Configuration Options

OptionTypeDefault
serviceNamestringRequired
appDirstring./src/app
enabledbooleantrue
autoSubmitbooleantrue

Configuration

Environment Variables

Configure the plugin with your API key:

LATTICE_API_KEY=your_api_key_from_dashboard
LATTICE_ENABLED=true
LATTICE_AUTO_SUBMIT=true
LATTICE_SUBMIT_INTERVAL=300000

Callbacks

Hook into the discovery lifecycle with callbacks:

const lattice = new LatticePlugin({
  serviceName: 'my-api',
  onAnalyzed: (metadata) => {
    console.log(`Discovered ${metadata.routes.length} routes`);
  },
  onSubmitted: (response) => {
    console.log(`Submitted: ${response.serviceId}`);
  },
  onError: (error) => {
    console.error('Discovery error:', error);
  },
});

Disabling in Production

Control discovery behavior per environment:

const lattice = new LatticePlugin({
  serviceName: 'my-api',
  enabled: process.env.NODE_ENV !== 'production',
});

API Reference

Collector API Endpoints

POST/api/v1/ingest/metadata

Submit service metadata, routes, and dependencies

GET/api/v1/services

List all discovered services

GET/api/v1/services/:id

Get service details including routes and dependencies

Authentication

All API requests require an API key in the Authorization header:

Authorization: Bearer YOUR_API_KEY

Ready to Start?

Get your API key and start discovering services in minutes

Create Free Account