Technical Specification Agent for ANYON Platform - Automated TRD Generation
The Tech Spec Agent is an AI-powered system that automatically generates Technical Requirements Documents (TRDs), API specifications, database schemas, and architecture diagrams from Product Requirements Documents (PRDs) and design outputs.
- Automated TRD Generation: Generate comprehensive technical specifications from PRDs with Section 3: System Architecture
- Technology Research: AI-powered research and recommendations for open-source libraries
- Interactive Decision-Making: Real-time WebSocket communication for user technology selections
- Code Analysis: Parse Google AI Studio code to infer API specifications
- Document Generation:
- TRD with System Architecture section (textual description)
- API specifications (OpenAPI/Swagger YAML)
- Database schemas (SQL DDL + Mermaid ERD)
- Architecture diagrams (Mermaid system flowcharts)
- Technology stack documentation
- Quality Validation: 90% quality threshold with specialized architecture review agent
- Design Agent Integration: Seamless integration via shared PostgreSQL tables
- Production-Ready: Monitoring, error recovery, and high availability
- Architecture
- Architecture Documentation
- Prerequisites
- Installation
- Configuration
- Running the Application
- Development
- Testing
- Deployment
- API Documentation
- Monitoring
- Troubleshooting
- Contributing
┌─────────────────────────────────────────────────────────────┐
│ ANYON Platform │
│ (Frontend: TechSpecChat Component + Kanban Board) │
└────────┬─────────────────────────────┬────────────────────┘
│ REST API │ WebSocket
▼ ▼
┌────────────────────────────────────────────────────────────┐
│ Tech Spec Agent (FastAPI) │
│ ┌──────────────────────────────────────────────────┐ │
│ │ LangGraph Workflow (21 Nodes) │ │
│ └──────────────────────────────────────────────────┘ │
└────────┬──────────────────────────┬───────────────────────┘
│ │
▼ ▼
┌─────────────────────┐ ┌─────────────────────┐
│ PostgreSQL DB │ │ Redis Cache │
│ • shared.* tables │ │ • Tech research │
│ • tech_spec.* │ │ • Parsed code │
│ • agent_error_logs │ │ │
└─────────────────────┘ └─────────────────────┘
- Framework: FastAPI 0.121+
- Workflow Engine: LangGraph 1.0.3+
- LLM: Claude Sonnet 4 (via Anthropic API)
- Database: PostgreSQL 15+
- Cache: Redis 5.2+
- Monitoring: Prometheus + Grafana
- Deployment: Docker + docker-compose
Tech Spec Agent automatically generates THREE types of architecture documentation:
- Generated at 70% workflow completion
- Textual description within the TRD document
- Includes architecture pattern, components, data flow, scalability
- Generated at 85% workflow completion
- Mermaid Entity Relationship Diagram
- Shows tables, relationships, foreign keys
- Accompanies SQL DDL statements
- Generated at 90% workflow completion
- Validated at 92% workflow completion
- Standalone Mermaid flowchart showing complete system topology:
- Client Layer: Web and mobile applications
- API Gateway: Load balancer with SSL/TLS
- Application Layer: Multiple API server instances + business services
- Data Layer: Primary database + read replicas + caching
- External Services: OAuth, file storage, email, push notifications
- Monitoring: Prometheus, Grafana, Sentry
Example Architecture Diagram Output:
flowchart TB
subgraph Clients["Client Layer"]
WebApp["Next.js Web App"]
MobileApp["React Native App"]
end
subgraph Gateway["API Gateway"]
LB["NGINX Load Balancer"]
end
subgraph Application["Application Layer"]
API1["API Server 1"]
API2["API Server 2"]
end
subgraph DataLayer["Data Layer"]
DB["PostgreSQL Primary"]
DBRep["PostgreSQL Replica"]
Cache["Redis Cache"]
end
WebApp --> LB
MobileApp --> LB
LB --> API1
LB --> API2
API1 --> DB
API2 --> DBRep
DB -.-> DBRep
API1 --> Cache
All architecture documents are validated through:
- Structure checks: Minimum 300 characters for TRD Section 3
- Database ERD validation: All tables and relationships present
- Architecture quality review (92% progress): Specialized AI agent scores 0-100 on:
- Completeness (30 points): All layers present
- Consistency (25 points): Matches selected technologies
- Best Practices (25 points): Load balancing, caching, replication
- Scalability (15 points): Horizontal scaling capability
- Security (5 points): Authentication, encryption
- Pass threshold: >= 80/100 for architecture quality
- Overall TRD quality threshold: >= 90/100
See EXAMPLE_ARCHITECTURE_DIAGRAM.md for a complete example output.
- Python: 3.11 or higher
- PostgreSQL: 15 or higher
- Redis: 5.2 or higher
- Docker: 20.10+ (optional, for containerized development)
- API Keys:
- Anthropic API Key (Claude)
- OpenAI API Key (Google AI Studio integration)
- Tavily API Key (web search)
-
Clone the repository:
git clone https://github.com/anyon/tech-spec-agent.git cd tech-spec-agent -
Create virtual environment:
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install dependencies:
pip install --upgrade pip pip install -e . -
Install development dependencies (for testing):
pip install -e ".[dev]" -
Install PostgreSQL and Redis:
- PostgreSQL: Download from https://www.postgresql.org/download/
- Redis: Download from https://redis.io/download/ or use Docker:
docker run -d -p 6379:6379 redis:7-alpine
-
Clone the repository:
git clone https://github.com/anyon/tech-spec-agent.git cd tech-spec-agent -
Start all services:
docker-compose up -d
This will start:
- PostgreSQL (port 5432)
- Redis (port 6379)
- Tech Spec Agent API (port 8000)
- Prometheus (port 9090)
- Grafana (port 3001)
-
Copy the example environment file:
cp .env.example .env
-
Edit
.envand set your values:# Required - Database DATABASE_URL=postgresql+asyncpg://postgres:password@localhost:5432/anyon_db DATABASE_URL_SYNC=postgresql://postgres:password@localhost:5432/anyon_db # Required - LLM APIs ANTHROPIC_API_KEY=sk-ant-your-key-here OPENAI_API_KEY=sk-your-key-here TAVILY_API_KEY=tvly-your-key-here # Required - ANYON Integration ANYON_API_BASE_URL=https://anyon.platform/api ANYON_WEBHOOK_SECRET=your-webhook-secret ANYON_FRONTEND_URL=https://anyon.platform # Required - Security JWT_SECRET_KEY=your-super-secret-jwt-key-change-this-in-production # Optional - See .env.example for all options
-
Create database (if not using Docker):
createdb anyon_db
-
Run migrations:
alembic upgrade head
-
Verify database connection:
python -c "from src.database.connection import db_manager; import asyncio; asyncio.run(db_manager.check_connection())"
# Activate virtual environment
source venv/bin/activate # On Windows: venv\Scripts\activate
# Run the FastAPI server
uvicorn src.main:app --reload --host 0.0.0.0 --port 8000The API will be available at:
- API: http://localhost:8000
- API Docs: http://localhost:8000/docs
- Health Check: http://localhost:8000/health
# Start all services
docker-compose up -d
# View logs
docker-compose logs -f tech-spec-agent
# Stop services
docker-compose down# Build production image
docker build -t tech-spec-agent:latest .
# Run production container
docker run -d \
-p 8000:8000 \
--env-file .env \
tech-spec-agent:latestTech Agent/
├── src/
│ ├── main.py # FastAPI application entry point
│ ├── config.py # Configuration management
│ ├── database/
│ │ ├── connection.py # Database connection manager
│ │ └── models.py # SQLAlchemy models
│ ├── api/
│ │ └── endpoints.py # REST API endpoints
│ ├── langgraph/
│ │ ├── state.py # State schema
│ │ ├── workflow.py # Workflow definition
│ │ └── nodes/ # Individual node implementations
│ ├── integration/
│ │ └── design_agent_loader.py # Design Agent integration
│ └── websocket/
│ └── connection_manager.py # WebSocket manager
├── tests/
│ ├── conftest.py # Pytest fixtures
│ ├── unit/ # Unit tests
│ └── integration/ # Integration tests
├── alembic/ # Database migrations
├── monitoring/ # Prometheus & Grafana configs
├── .github/workflows/ # CI/CD pipelines
├── docker-compose.yml
├── Dockerfile
├── pyproject.toml
├── .env.example
└── README.md
We use several tools to maintain code quality:
# Format code with Black
black src/ tests/
# Sort imports with isort
isort src/ tests/
# Lint with Ruff
ruff check src/ tests/
# Type check with mypy
mypy src/Install pre-commit hooks to automatically run checks:
pip install pre-commit
pre-commit install# Run all tests with coverage
pytest --cov=src --cov-report=html --cov-report=term-missing -v# Unit tests only
pytest tests/unit/ -v
# Integration tests only
pytest tests/integration/ -v
# Run specific test file
pytest tests/unit/test_config.py -v
# Run with specific marker
pytest -m "slow" -v# Generate HTML coverage report
pytest --cov=src --cov-report=html
# Open coverage report
# Linux/Mac: open htmlcov/index.html
# Windows: start htmlcov/index.htmlCoverage Target: 80%+
-
Build image:
docker build -t anyon/tech-spec-agent:1.0.0 . -
Push to registry:
docker push anyon/tech-spec-agent:1.0.0
-
Deploy to server:
docker pull anyon/tech-spec-agent:1.0.0 docker run -d \ -p 8000:8000 \ --env-file .env \ --name tech-spec-agent \ anyon/tech-spec-agent:1.0.0
- Development:
ENVIRONMENT=development(enables debug, docs, reload) - Staging:
ENVIRONMENT=staging(limited debug, full logging) - Production:
ENVIRONMENT=production(no debug, no docs, optimized)
| Method | Endpoint | Description |
|---|---|---|
| GET | /health |
Health check endpoint |
| GET | / |
API information |
| POST | /api/projects/{project_id}/start-tech-spec |
Start Tech Spec session |
| GET | /api/tech-spec/sessions/{session_id}/status |
Get session status |
| POST | /api/tech-spec/sessions/{session_id}/decisions |
Submit user decision |
| GET | /api/tech-spec/sessions/{session_id}/trd |
Download TRD |
- URL:
wss://api.anyon.platform/ws/tech-spec/{session_id}?token={jwt_token} - Protocol: Bidirectional JSON messages
- Use Case: Real-time progress updates and user interaction
Full API documentation: http://localhost:8000/docs (when running locally)
Access Prometheus at http://localhost:9090
Key Metrics:
tech_spec_sessions_total- Total sessions createdtech_spec_session_duration_seconds- Session duration histogramtech_spec_trd_quality_score- TRD quality score gaugetech_spec_errors_total- Total errors by type
Access Grafana at http://localhost:3001 (default login: admin/admin)
Pre-configured Dashboards:
- Session Overview - Active, paused, completed sessions
- Performance Metrics - Response times, throughput
- Error Rates - Error trends by node
- Technology Popularity - Most selected technologies
# Check PostgreSQL is running
psql -U postgres -c "SELECT 1"
# Test connection from Python
python -c "from src.database.connection import db_manager; import asyncio; asyncio.run(db_manager.check_connection())"# Check Redis is running
redis-cli ping
# Test from Python
python -c "import redis; r = redis.from_url('redis://localhost:6379/0'); print(r.ping())"# Check logs
docker-compose logs tech-spec-agent
# Check environment variables
env | grep DATABASE_URL
# Verify port is free
lsof -i :8000 # Linux/Mac
netstat -ano | findstr :8000 # Windows- "Database connection failed": Check DATABASE_URL is correct and PostgreSQL is running
- "Redis connection failed": Check REDIS_URL and Redis service status
- "Invalid API key": Verify ANTHROPIC_API_KEY and OPENAI_API_KEY are set correctly
- "Health check failing": Check all services (PostgreSQL, Redis) are healthy
We welcome contributions! Please follow these guidelines:
- Fork the repository
- Create a feature branch:
git checkout -b feature/amazing-feature - Make your changes and add tests
- Run tests:
pytest - Check code quality:
black src/ && ruff check src/ && mypy src/ - Commit your changes:
git commit -m "Add amazing feature" - Push to branch:
git push origin feature/amazing-feature - Open a Pull Request
- Python Version: 3.11+
- Code Style: Black (line length 100)
- Type Hints: Required for all functions
- Test Coverage: Minimum 80%
- Documentation: Docstrings for all public functions
This project is licensed under the MIT License - see the LICENSE file for details.
- Documentation: https://docs.anyon.platform/tech-spec-agent
- Issues: https://github.com/anyon/tech-spec-agent/issues
- Email: support@anyon.platform
- Design Agent - For providing the architectural patterns
- LangChain/LangGraph - For workflow orchestration
- Anthropic - For Claude Sonnet 4 LLM
- FastAPI - For the excellent web framework
Built with ❤️ by the ANYON Team