MachineAuth
AGENTS.md61 starsChanged 9 months agoMITView on GitHub
MachineAuth is a self-hosted AI Agent Authentication SaaS platform (v2.12.61) providing OAuth 2.0-based authentication for AI agents and machine-to-machine communication. Imports: stdlib → external → internal (use goimports) Naming: Packages lowercase, exported PascalCase, unexported camelCase, constants PascalCase. Error Handling: Wrap with context using fmt.Errorf with %w: HTTP Handlers: Return structured JSON, proper status codes: Types: Use precise types, pointers for optional values, embed uuid.UUID directly: Logging: Use log.Printf with context. Imports: Use absolute imports with @/ alias. Naming: Components PascalCase,…
- Reads credentials
- Installs packages
Where files are headingNew AGENTS.md files have more rules about keeping secrets out of the code, and fewer about code style.
Of the AGENTS.md files we read, the 33,398 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.
In this repositoryOne other file it gives its agents.
- .github/copilot-instructions.mdCopilot instructions
The file
We split this AGENTS.md into the rules it gives an agent
4 rules. About 0 are common, 0 are distinctive, and 4 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈0
Distinctive · estimate
This author's own choices. Worth a look.
4
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 73
Types: Use precise types, pointers for optional values, embed uuid.UUID directly:
- Very specific: line 82
Logging: Use log.Printf with context.
- Very specific: line 86
Imports: Use absolute imports with @/ alias.
- Very specific: line 223
Use @/ for absolute imports (maps to ./src/)
≈ “Common” is an estimate: at least 1 in 5 of the 43,423 AGENTS.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
AGENTS.md - MachineAuth Development Guide
Project Overview
MachineAuth is a self-hosted AI Agent Authentication SaaS platform (v2.12.61) providing OAuth 2.0-based authentication for AI agents and machine-to-machine communication.
Tech Stack
- Backend: Go 1.21+ (module:
machineauth) - Frontend: React 18 + TypeScript + Vite + Tailwind CSS
- Database: PostgreSQL 15+ (or JSON file for development)
- SDKs:
sdk/typescript(@machineauth/sdk) andsdk/python(machineauth)
Build, Lint, and Test Commands
Backend (Go)
go mod download # Install dependencies
go build -o bin/server ./cmd/server # Build server
go run ./cmd/server # Run server
go test -v ./... # Run all tests
go test -v -run TestName ./path/... # Run single test
go test -v -coverprofile=cov.out ./... # Tests with coverage
golangci-lint run # Lint (requires golangci-lint)
go fmt ./... && go vet ./... # FormatFrontend (React)
cd web && npm install # Install dependencies
cd web && npm run dev # Development (port 3000)
cd web && npm run build # Production build
cd web && npm run lint # Lint
cd web && npx tsc --noEmit # TypeScript checkCode Style Guidelines
Go (Backend)
Imports: stdlib → external → internal (use goimports)
import (
"context"
"encoding/json"
"github.com/golang-jwt/jwt/v5"
"github.com/google/uuid"
"machineauth/internal/config"
"machineauth/internal/models"
)Naming: Packages lowercase, exported PascalCase, unexported camelCase, constants PascalCase.
Error Handling: Wrap with context using fmt.Errorf with %w:
if err != nil {
return nil, fmt.Errorf("failed to create agent: %w", err)
}HTTP Handlers: Return structured JSON, proper status codes:
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(models.AgentResponse{Agent: *agent})Types: Use precise types, pointers for optional values, embed uuid.UUID directly:
type Agent struct {
ID uuid.UUID `json:"id"`
Name string `json:"name"`
ExpiresAt *time.Time `json:"expires_at,omitempty"`
}Logging: Use log.Printf with context.
React/TypeScript (Frontend)
Imports: Use absolute imports with @/ alias.
import { useState } from 'react';
import { AgentService } from '@/services/api';
import { Agent } from '@/types';Naming: Components PascalCase, functions camelCase, files kebab-case.
Types: Define explicit types, avoid any.
Styling: Tailwind CSS with HSL color variables.
Project Structure
machineauth/
├── cmd/server/main.go # Entry point
├── internal/
│ ├── config/ # Configuration
│ ├── db/ # Database layer
│ ├── handlers/ # HTTP handlers
│ ├── middleware/ # HTTP middleware
│ ├── models/ # Data models
│ └── services/ # Business logic
├── web/ # React frontend
│ └── src/
│ ├── components/ # React components
│ ├── pages/ # Page components
│ ├── services/ # API services
│ ├── types/ # TypeScript types
│ └── App.tsx
└── docker-compose.ymlAPI Endpoints
| Method | Path | Description |
| POST | /oauth/token | Get access token |
| POST | /oauth/introspect | Validate token |
| POST | /oauth/revoke | Revoke token |
| GET | /.well-known/jwks.json | Public keys |
| GET | /health | Health check |
| GET | /health/ready | Readiness check |
| GET | /metrics | Service metrics |
| GET | /api/agents | List agents |
| POST | /api/agents | Create agent |
| GET | /api/agents/:id | Get agent |
| DELETE | /api/agents/:id | Delete agent |
| POST | /api/agents/:id/rotate | Rotate credentials |
| POST | /api/webhooks | Create webhook |
| GET | /api/webhooks | List webhooks |
| GET | /api/webhooks/:id | Get webhook |
| PUT | /api/webhooks/:id | Update webhook |
| DELETE | /api/webhooks/:id | Delete webhook |
| POST | /api/webhooks/:id/test | Test webhook |
| GET | /api/webhooks/:id/deliveries | Delivery history |
| GET | /api/webhook-events | List event types |
Database Schema
agents table
idUUID PRIMARY KEYnameVARCHAR(255) NOT NULLclient_idVARCHAR(255) UNIQUE NOT NULLclient_secret_hashVARCHAR(255) NOT NULLscopesTEXT[] DEFAULT '{}'public_keyTEXT (for DPoP/mTLS)is_activeBOOLEAN DEFAULT truecreated_atTIMESTAMPupdated_atTIMESTAMPexpires_atTIMESTAMP (optional)
audit_logs table
idUUID PRIMARY KEYagent_idUUID REFERENCES agents(id)actionVARCHAR(100)ip_addressVARCHAR(45)user_agentTEXTcreated_atTIMESTAMP
webhook_configs table
idUUID PRIMARY KEYorganization_idVARCHAR(255)team_idVARCHAR(255)nameVARCHAR(255) NOT NULLurlTEXT NOT NULLsecretVARCHAR(255) NOT NULLeventsTEXT[] NOT NULLis_activeBOOLEAN DEFAULT truemax_retriesINTEGER DEFAULT 10retry_backoff_baseINTEGER DEFAULT 2created_atTIMESTAMPupdated_atTIMESTAMPlast_tested_atTIMESTAMP (optional)consecutive_failsINTEGER DEFAULT 0
webhook_deliveries table
idUUID PRIMARY KEYwebhook_config_idUUID REFERENCES webhook_configs(id)eventVARCHAR(100)payloadTEXTheadersTEXTstatusVARCHAR(50) (pending, delivered, failed, retrying, dead)attemptsINTEGER DEFAULT 0last_attempt_atTIMESTAMP (optional)last_errorTEXTnext_retry_atTIMESTAMP (optional)created_atTIMESTAMP
Environment Variables
PORT=8080
ENV=development
DATABASE_URL=postgresql://user:pass@localhost:5432/agentauth
# Dev fallback: DATABASE_URL=json:machineauth.json
JWT_SIGNING_ALGORITHM=RS256
JWT_KEY_ID=key-1
JWT_ACCESS_TOKEN_EXPIRY=3600
ALLOWED_ORIGINS=http://localhost:3000
# Admin
ADMIN_EMAIL=admin@example.com
ADMIN_PASSWORD=changeme
# Webhooks
WEBHOOK_WORKER_COUNT=3
WEBHOOK_MAX_RETRIES=10
WEBHOOK_TIMEOUT_SECS=10Development Notes
- Frontend proxies
/api,/oauth,/.well-known,/health,/metricstolocalhost:8081 - Use
@/for absolute imports (maps to./src/) - Admin credentials:
admin@example.com/changeme(change before deployment) - Primary Go entry:
go run ./cmd/server(port 8080)
Key Conventions
- Handlers: HTTP request/response handling, validation (see
internal/handlers/agents.go) - Services: Business logic, orchestration (see
internal/services/) - Models: API request/response types, JSON serialization (see
internal/models/models.go) - DB: Storage abstraction;
db.Connectreturns either PostgreSQL orJSONDBbased onDATABASE_URLprefix (seeinternal/db/db.go) - Backend uses
snake_caseJSON (e.g.,client_id,expires_at);ClientSecretHashtaggedjson:"-"(never serialized) - Frontend: React hooks for state,
react-hook-formfor forms,sonnerfor toasts,axiosfor API calls - Frontend API base URL from
VITE_API_URLenv var; falls back to production URL — set it tohttp://localhost:8081locally - Router registration:
cmd/server/main.gowires all routes manually ontohttp.NewServeMux; middleware (JWTAuth,AdminAuth) wraps handlers via closures middleware.AgentIDKeycontext key carriesuuid.UUID; retrieve withmiddleware.GetAgentIDFromContext(ctx)- Webhook system:
services.DeliveryWorkergoroutine pool dispatches deliveries;AuditService.SetWebhookServiceinjects webhook triggering into audit events - Version string lives in
cmd/server/main.goroot handler response ("version":"2.12.61")
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

