tmi

package module
v0.0.0-...-548cdc5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 22, 2026 License: Apache-2.0 Imports: 1 Imported by: 0

README ¶

TMI - Threat Modeling Improved

A collaborative threat modeling server built with Go.

Try it yourself at https://www.tmi.dev
API server online at https://api.tmi.dev
API clients available at https://github.com/ericfitz/tmi-clients

Overview

TMI (Threat Modeling Improved) is a collaborative platform for managing an organization's security review process, including threat modeling. Our mission is to reduce the toil of security reviewing, and to make threat modeling accessible, efficient, and integrated into the software development lifecycle.

The platform features security review organization and state management, interactive data flow diagram creation with real-time collaboration, and comprehensive threat documentation capabilities. Built with modern web technologies, TMI helps teams manage the security review process and identify, analyze, and mitigate security threats through collaborative modeling.

This project is the TMI server back-end, a Go service that implements the TMI REST API.

The associated Angular/Typescript front-end web application is called TMI-UX.

Quick Start

For detailed setup instructions, see Development Setup Guide.

Prerequisites
  • Go 1.25+
  • Docker Desktop (for database & Redis containers)
  • Make (for build automation)
Installation
git clone https://github.com/ericfitz/tmi.git
cd tmi
make dev-up

The complete development environment (a local kind cluster running the server, plus database and Redis) will start automatically, with the server reachable on port 8080.

Project Structure

  • api/ - API types and handlers
  • cmd/server/ - Server entry point and configuration
  • api-schema/tmi-openapi.json - OpenAPI specification

Architecture

Data Storage Pattern

The project uses strongly-typed concurrent maps for in-memory storage:

// Store provides thread-safe storage for a specific entity type
type Store[T any] struct {
    data  map[string]T
    mutex sync.RWMutex
}

// DiagramStore stores diagrams by UUID
var DiagramStore = NewStore[api.Diagram]()

// ThreatModelStore stores threat models by UUID
var ThreatModelStore = NewStore[api.ThreatModel]()

Benefits of this approach:

  • Type safety with generics
  • Concurrency protection with mutexes
  • Clear separation between different entity stores
  • Easy to replace with a database implementation later

This pattern is used for all entity types (diagrams, threat models, threats) and provides:

  • CRUD operations
  • Atomic updates
  • Support for filtering and queries

Documentation

Comprehensive documentation is organized by audience:

📖 For Developers
🚀 For Operations Teams
📋 Complete Documentation Index

See TMI Wiki for the complete documentation catalog organized by role and topic.

Development Commands

make dev-up             # Start complete dev environment (kind cluster)
make dev-status         # Show dev environment status
make dev-down           # Tear down dev environment (keep db data)
make build-server       # Build production binary
make test-unit                # Run unit tests
make test-integration-new     # Run integration tests (server must be running)
make cats-fuzz               # Run security fuzzing
make lint               # Run code linting

Configuration

Server configuration can be set via environment variables or using a .env file:

  1. Copy the .env.example file to .env
  2. Modify the values as needed
  3. Start the server, which will automatically load the .env file

You can also specify a custom .env file with:

./bin/tmiserver --env=/path/to/custom.env

Available configuration options:

Variable Default Description
SERVER_PORT 8080 HTTP/HTTPS server port
SERVER_INTERFACE 0.0.0.0 Network interface to listen on
SERVER_READ_TIMEOUT 5s HTTP read timeout
SERVER_WRITE_TIMEOUT 10s HTTP write timeout
SERVER_IDLE_TIMEOUT 60s HTTP idle timeout
LOG_LEVEL info Logging level (debug, info, warn, error)
TLS_ENABLED false Enable HTTPS/TLS
TLS_CERT_FILE Path to TLS certificate file
TLS_KEY_FILE Path to TLS private key file
TLS_SUBJECT_NAME [hostname] Subject name for certificate validation
TLS_HTTP_REDIRECT true Redirect HTTP to HTTPS when TLS is enabled
JWT_SECRET secret JWT signing secret (change for production!)
JWT_EXPIRES_IN 24h JWT expiration
OAUTH_URL https://oauth-provider.com/oauth2 OAuth provider URL
OAUTH_SECRET OAuth client secret
DB_URL localhost Database URL
DB_USERNAME Database username
DB_PASSWORD Database password
DB_NAME tmi Database name
ENV development Environment (development or production)
WebSocket URLs

When TLS is enabled (TLS_ENABLED=true), clients should connect using secure WebSocket URLs:

  • Use wss:// instead of ws:// for WebSocket connections
  • Example: wss://your-server.com:8080/ws/diagrams/123

When TLS is disabled, use standard WebSocket URLs:

  • Example: ws://your-server.com:8080/ws/diagrams/123

You can use the /api/server-info endpoint to get the correct WebSocket base URL automatically.

License

See license.txt

Documentation ¶

Overview ¶

Package tmi embeds static assets that the TMI server serves under /static.

The assets (favicons, web manifest icons, logos, and OAuth/SAML provider sign-in icons) are embedded into the binary rather than read from a relative ./static directory at runtime. The server runs from a Chainguard "static" container that contains only the binary (see Dockerfile.server), so a relative ./static path resolves to nothing and every static route 404s in production — including the provider sign-in icons (#498). Embedding keeps the image binary-only while making the assets available in every deployment topology regardless of the working directory.

Index ¶

Constants ¶

This section is empty.

Variables ¶

View Source
var StaticFS embed.FS

StaticFS holds the contents of the static/ directory, embedded at build time. Serve it under /static via fs.Sub(StaticFS, "static").

Functions ¶

This section is empty.

Types ¶

This section is empty.

Directories ¶

Path Synopsis
api
Package api provides storage and HTTP handlers for the TMI service.
Package api provides storage and HTTP handlers for the TMI service.
models
Package models - hooks.go contains GORM lifecycle hooks for validation.
Package models - hooks.go contains GORM lifecycle hooks for validation.
notifications
Package notifications provides database notification services that work across different database backends (PostgreSQL and Oracle).
Package notifications provides database notification services that work across different database backends (PostgreSQL and Oracle).
platform/v1alpha1
Package v1alpha1 contains the TMIComponent custom resource API for the TMI Component Platform.
Package v1alpha1 contains the TMIComponent custom resource API for the TMI Component Platform.
seed
Package seed provides database seeding for required initial data.
Package seed provides database seeding for required initial data.
validation
Package validation provides cross-database validation for TMI models.
Package validation provides cross-database validation for TMI models.
Package auth — /me/identities/link/* handlers (#383).
Package auth — /me/identities/link/* handlers (#383).
db
repository
Package repository provides database repository interfaces and implementations for the auth service.
Package repository provides database repository interfaces and implementations for the auth service.
cmd
chunkembed command
Command tmi-chunk-embed is the chunk-and-embed worker of the TMI Component Platform (issue #347).
Command tmi-chunk-embed is the chunk-and-embed worker of the TMI Component Platform (issue #347).
component-controller command
Command component-controller runs the TMI Component Platform controller.
Command component-controller runs the TMI Component Platform controller.
dbtool command
cmd/dbtool/health.go
cmd/dbtool/health.go
dedup-group-members command
Package main implements a one-off utility to remove duplicate rows from the group_members table.
Package main implements a one-off utility to remove duplicate rows from the group_members table.
extractor command
Command tmi-extractor is the sandboxed document-parse worker of the TMI Component Platform (issue #347).
Command tmi-extractor is the sandboxed document-parse worker of the TMI Component Platform (issue #347).
genconfig command
Command genconfig writes config-example.yml from the classification registry.
Command genconfig writes config-example.yml from the classification registry.
genconfigdocs command
Command genconfigdocs writes config-reference.md from the classification registry.
Command genconfigdocs writes config-reference.md from the classification registry.
migrate command
Package main implements the migrate CLI tool for TMI database schema management.
Package main implements the migrate CLI tool for TMI database schema management.
server command
worker-probe command
Command worker-probe is a stub TMI worker.
Command worker-probe is a stub TMI worker.
internal
config/bootstrap
Package bootstrap provides the minimal, environment-only configuration a TMI worker component needs to start and reach the point where it can accept a job.
Package bootstrap provides the minimal, environment-only configuration a TMI worker component needs to start and reach the point where it can accept a job.
configsecrets
Package configsecrets bridges internal/config and internal/secrets.
Package configsecrets bridges internal/config and internal/secrets.
crypto
Package crypto provides encryption utilities for TMI.
Package crypto provides encryption utilities for TMI.
dbcheck
Package dbcheck provides utilities for classifying database errors.
Package dbcheck provides utilities for classifying database errors.
dberrors
Package dberrors provides typed database error classification.
Package dberrors provides typed database error classification.
dbschema
Package dbschema: global ThreatModel alias sequence (#452).
Package dbschema: global ThreatModel alias sequence (#452).
periodic
Package periodic provides a small helper for ticker-driven background maintenance loops (e.g.
Package periodic provides a small helper for ticker-driven background maintenance loops (e.g.
platform/controller
Package controller implements the TMIComponent reconciler for the TMI Component Platform.
Package controller implements the TMIComponent reconciler for the TMI Component Platform.
safehttp
Package safehttp provides the shared SSRF-validation and dial-time IP-pinning core for server-originated outbound HTTP.
Package safehttp provides the shared SSRF-validation and dial-time IP-pinning core for server-originated outbound HTTP.
secrets
Package secrets provides a unified interface for retrieving secrets from various providers.
Package secrets provides a unified interface for retrieving secrets from various providers.
unicodecheck
Package unicodecheck provides consolidated Unicode validation for security-sensitive input.
Package unicodecheck provides consolidated Unicode validation for security-sensitive input.
worker
Package worker is the shared runtime for TMI Component Platform worker binaries (tmi-extractor, tmi-chunk-embed).
Package worker is the shared runtime for TMI Component Platform worker binaries (tmi-extractor, tmi-chunk-embed).
wwwauth
Package wwwauth builds RFC 6750 (OAuth 2.0 Bearer Token) WWW-Authenticate response headers.
Package wwwauth builds RFC 6750 (OAuth 2.0 Bearer Token) WWW-Authenticate response headers.
pkg
extract
Package extract is the framework-free document/content extraction library.
Package extract is the framework-free document/content extraction library.
jobenvelope
Package jobenvelope defines the single job-envelope schema used by every stage of the TMI Component Platform extraction pipeline.
Package jobenvelope defines the single job-envelope schema used by every stage of the TMI Component Platform extraction pipeline.
test
testdb
Package testdb provides direct database access for integration tests.
Package testdb provides direct database access for integration tests.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL