OpenAgent System Architecture & Development Guidelines
Defines a strict React component hierarchy, a 4-step CSS/JS asset pipeline, and a TDD workflow for a Go-powered transpilation server.
What this file does
Defines a strict React component hierarchy, a 4-step CSS/JS asset pipeline, and a TDD workflow for a Go-powered transpilation server.
When to use it
- You need to enforce a Layout → App component pattern across all pages
- You are building a custom transpiler that generates per-page CSS and JS files
- You want to mandate test-driven development and a pre-deployment checklist
- You are setting up caching headers and ETags for static assets
Assumes this stack
OpenAgent System Architecture & Development Guidelines
🏗️ Core Architecture Principles
1. Component Structure (CRITICAL - DO NOT BREAK)
The application follows a strict architectural pattern that MUST be maintained:
Top-Level Page Components (e.g., test.tsx)
- MUST be named
{PageName}Page(e.g.,TestPage,LoginPage,DashboardPage) - MUST import and use a
Layoutcomponent from../layouts/layout_pagesorlayour_adminetc. - MUST import an
Appcomponent from./{pagename}.component - MUST pass props to the Layout component, not render layout HTML directly, via CustomLayout if required.
// CORRECT structure for test.tsx
import Layout from '../layouts/layout_pages';
import App from './test.component';
export default function TestPage({page}: {page: Page}) {
return (
<Layout page={page} linkPaths={linkPaths} scriptPaths={scriptPaths}>
<App page={page} />
</Layout>
);
}
Component Files (e.g., test.component.tsx)
- Contains the actual page content and logic
- Receives
pageprops from the parentTestPage
Layout Components (e.g., layout_pages.tsx)
- Handles the overall page structure (header, footer, navigation)
- Receives
page,linkPaths,scriptPathsas props - Renders meta tags, CSS links, and JavaScript includes
2. Meta Tag Architecture
Meta tags are handled through a structured approach:
- Extraction: Meta tags are extracted from page HTML using
extractMetaTagsStructured() - Conversion: Converted to JavaScript arrays (
contentMetaandpropMeta) - Injection: Passed to Layout component via props
- Rendering: Layout component maps over arrays to render actual
<meta>tags
// In layout_pages.html
{page.contentMeta && page.contentMeta.map((meta: any) => (
<meta name={meta.name} content={meta.content} />
))}
{page.propMeta && page.propMeta.map((meta: any) => (
<meta property={meta.property} content={meta.content} />
))}
3. CSS/JS Asset Architecture (CRITICAL)
The application uses a 4-step generation process for page-specific assets:
CSS Extraction & Naming Convention
- NO CONSOLIDATION - Each page gets its own CSS file
- Naming Convention:
pages_{pagename}.css(e.g.,pages_test.css,pages_login.css) - Path Structure:
/tsx/css/pages_{pagename}.css - Extraction: CSS is extracted from page HTML and saved as separate files
- Injection: CSS paths are passed to Layout via
linkPathsprop
JavaScript Generation (4-Step Process)
- Main JS:
pages_{pagename}.js- Page-specific JavaScript - Component JS:
{pagename}.component.js- Component-specific JavaScript - Common JS:
_common.js- Shared JavaScript across all pages - Hydration Code: React hydration code for component initialization
Asset Path Structure
/tsx/css/pages_test.css # Page-specific CSS
/tsx/js/pages_test.js # Page-specific JS
/tsx/js/test.component.js # Component-specific JS
/tsx/js/_common.js # Common/shared JS
Integration with Layout
// CSS injection in layout
{linkPaths && linkPaths.split(',').map((link: string) => (
<link rel="stylesheet" href={link} />
))}
// JS injection in layout
{scriptPaths && scriptPaths.split(',').map((script: string) => (
<script type="text/javascript" src={script} />
))}
🚫 Common Mistakes to AVOID
Architecture Violations
- ❌ NEVER name top-level components
{PageName}Layout - ❌ NEVER render layout HTML directly in page components
- ❌ NEVER break the Layout → App component hierarchy
- ❌ NEVER use
dangerouslySetInnerHTMLfor meta tags (causes HTML encoding issues), instead of loops over structured extractions.
Meta Tag Issues
- ❌ NEVER pass meta tags as raw HTML strings
- ❌ NEVER use
keyattributes for one-time rendered meta tags - ❌ NEVER place meta tags in the body section
CSS/JS Asset Issues
- ❌ NEVER consolidate CSS files - each page needs its own CSS
- ❌ NEVER break the 4-step JS generation process
- ❌ NEVER use incorrect naming conventions for assets
- ❌ NEVER forget to include
_common.jsin script paths
TSX Generation Issues (CRITICAL - Causes Internal Server Errors)
- ❌ NEVER leave HTML comments in generated TSX files
- ❌ NEVER generate invalid JSX syntax
- ❌ NEVER break the Go wax engine rendering process
- ❌ ALWAYS validate generated TSX files for syntax errors
Deployment Issues
- ❌ NEVER deploy without explicit user permission
- ❌ NEVER assume deployment is needed after changes
- ❌ ALWAYS test locally first
- ❌ NEVER deploy without git commit
🔄 Development Workflow
1. Local Development
# Start development server
go run . server
# Run tests
make test
# Build for production
go build -ldflags="-s -w" .
2. File Watching
- The server automatically watches
tpl/directory for changes - Templates are transpiled on file changes
- Generated files go to
tpl/generated/
3. Testing Process
- Make changes to templates or Go code
- Test locally using
go run . server - Verify changes work as expected
- Run
make testfor comprehensive testing - WAIT for user approval before deployment
4. Deployment Process
- ONLY deploy when explicitly requested by user
- Uses Docker Compose for containerized deployment
- SCP-based deployment copies files and runs
docker compose up -d --build - Backup existing deployments before overwriting
- Test on remote server after deployment
📁 File Structure
openagent/
├── tpl/
│ ├── pages/ # Source HTML pages
│ ├── layouts/ # Layout templates
│ ├── components/ # Reusable components
│ └── generated/ # Transpiled TSX files
├── server/
│ └── transpile/ # Transpilation logic
├── static/ # Static assets
├── data/sql/ # Database queries
└── migrations/ # Database migrations
🛠️ Key Functions & Files
Transpilation (server/transpile/)
templates.go: Main transpilation logicmisc.go: Utility functions for meta tag extractionjsx.go: JSX-specific transpilation
Meta Tag Functions (misc.go)
extractMetaTagsStructured(): Extracts meta tags into structured dataconvertMetaTagsToJS(): Converts to JavaScript arraysremoveMetaTags(): Removes meta tags from HTML content
Layout Templates
layout_pages.html: Main application layoutlayout_admin.html: Admin panel layoutlayout_marketing.html: Marketing pages layout
🧪 Testing Guidelines (TDD MANDATORY)
Test-Driven Development (TDD) Requirements
- MANDATORY: Write tests BEFORE implementing features
- MANDATORY: All tests must pass before deployment
- MANDATORY: Test coverage report must be generated
- MANDATORY: Integration tests must confirm no internal server errors
Test Coverage Requirements
- Component Tests: Test all components up to depth 5
- Inner Component Tests: Test nested component interactions
- Integration Tests: End-to-end functionality testing
- TSX Generation Tests: Validate generated TSX syntax
- Asset Generation Tests: Verify CSS/JS file generation
Before Making Changes
- Understand the current architecture
- Read existing code patterns
- Write tests first (TDD)
- Test changes locally first
- Verify no regressions
After Making Changes
- Run test coverage report
- Run
make testto ensure all tests pass - Check for internal server errors
- Test the specific functionality manually
- Check generated files for correctness
- Verify meta tags render properly
- Validate generated TSX files for syntax errors
Critical Test Commands
# Run all tests with coverage
make test
go test -cover ./...
# Test specific functionality
curl -s http://localhost:8800/test | grep -A 3 -B 3 "meta name"
# Check transpiled output for syntax errors
cat tpl/generated/pages/test.tsx
# Test for internal server errors
curl -v http://localhost:8800/test
# Component depth testing (up to depth 5)
go test -v ./server/transpile -run "TestComponentDepth"
# Integration tests for TSX generation
go test -v ./server/transpile -run "TestTranspileIntegration"
Internal Server Error Debugging
If internal server errors occur:
- Check generated TSX files for syntax errors
- Validate JSX syntax in transpiled files
- Remove HTML comments from generated TSX
- Check Go wax engine rendering process
- Verify asset paths are correct
- Test component hydration code
🚀 Deployment Guidelines
Pre-Deployment Checklist
- TDD: Tests written and passing
- Test Coverage: Coverage report generated and reviewed
- Internal Server Errors: Integration tests confirm no 500 errors
- TSX Validation: Generated TSX files have valid syntax
- Asset Generation: CSS/JS files generated correctly
- Git Commit: All changes committed to git
- Local Testing: Changes work as expected locally
- No Regressions: Existing functionality not broken
- User Approval: User has explicitly approved deployment
Deployment Commands
# Deploy to remote server
make deploy
# Check deployment status (Docker Compose)
ssh root@in.msheriff.com "cd /var/www/openagent && docker compose ps"
# View container logs
ssh root@in.msheriff.com "cd /var/www/openagent && docker compose logs -f app"
# Restart services
ssh root@in.msheriff.com "cd /var/www/openagent && docker compose restart"
📝 Code Style & Best Practices
Go Code
- Use descriptive function names
- Add comments for complex logic
- Handle errors properly
- Follow Go naming conventions
HTML/JSX Templates
- Use semantic HTML
- Maintain consistent indentation
- Use React fragments (
<>) instead of divs when appropriate - Avoid unnecessary attributes (like
keyfor static content)
Meta Tags
- Use structured data approach
- Separate
nameandpropertymeta tags - Keep meta tags in the
<head>section - Use proper content values
SEO & Performance Optimization
- Cache Headers: Implement proper caching for static assets
- ETags: Use ETags for efficient cache validation
- Expires Headers: Set appropriate expiration times for different asset types
- Compression: Enable gzip compression for text-based assets
- Minification: Minify CSS, JS, and HTML for production
🚀 Caching & Performance Architecture
Cache Header Strategy
Implement different caching strategies for different asset types:
Static Assets (CSS, JS, Images)
// Long-term caching for versioned assets
w.Header().Set("Cache-Control", "public, max-age=31536000, immutable")
w.Header().Set("Expires", "Thu, 31 Dec 2025 23:59:59 GMT")
w.Header().Set("ETag", `"${fileHash}"`)
HTML Pages
// Short-term caching for dynamic content
w.Header().Set("Cache-Control", "public, max-age=300") // 5 minutes
w.Header().Set("ETag", `"${pageHash}"`)
API Responses
// Conditional caching for API data
w.Header().Set("Cache-Control", "private, max-age=60")
w.Header().Set("ETag", `"${dataHash}"`)
Asset Caching Implementation
- File Hashing: Generate content-based hashes for assets
- Versioned URLs: Use hashes in asset URLs for cache busting
- Conditional Requests: Implement If-None-Match for ETags
- Compression: Enable gzip for text-based assets
Cache Header Types
- Cache-Control: Modern caching directive
- Expires: Legacy expiration header
- ETag: Entity tag for conditional requests
- Last-Modified: File modification time
- Vary: Cache variation headers
Performance Monitoring
- PageSpeed Insights: Monitor Core Web Vitals
- GTmetrix: Analyze loading performance
- WebPageTest: Detailed performance analysis
- Lighthouse: SEO and performance auditing
🔧 Troubleshooting
Common Issues
- Port already in use: Kill existing processes with
lsof -ti:8800 | xargs kill -9 - Meta tags in body: Check transpilation logic and layout structure
- HTML encoding: Use structured approach instead of raw HTML strings
- Architecture broken: Revert to proper Layout → App component structure
- Internal Server Error: Check generated TSX files for syntax errors
- HTML comments in TSX: Remove all HTML comments from generated files
- CSS/JS not loading: Verify asset generation and path structure
- Component hydration fails: Check React hydration code generation
- Go wax engine errors: Validate TSX syntax before rendering
Debug Commands
# Check running processes
lsof -i :8800
# View server logs
tail -f /var/log/openagent.log
# Test specific routes
curl -v http://localhost:8800/test
🎯 Success Criteria
A successful implementation should:
- ✅ Maintain the established architecture
- ✅ Render meta tags correctly in the head section
- ✅ Pass all tests
- ✅ Work locally before deployment
- ✅ Not break existing functionality
- ✅ Follow the user's explicit requirements
📞 Communication Guidelines
- ALWAYS ask for clarification if requirements are unclear
- NEVER assume deployment is needed
- ALWAYS test changes locally first
- RESPECT the user's architectural decisions
- DOCUMENT any changes that affect the architecture
Remember: The user has invested significant time in designing this architecture. Respect it, maintain it, and don't break it without explicit permission.
What's inside
14 sections covering architecture, asset generation, TDD, deployment, caching, and troubleshooting with 8 code examples and 2 checklists
Change this for your project
- Replace
openagent/with your own project root directory - Replace
in.msheriff.comwith your own remote server hostname - Replace
/var/www/openagentwith your own deployment path on the remote server - Replace
8800with your own development server port
Where it goes
Save in docs/ or the repository root. Gives agents and new contributors a map of the codebase.
Worth borrowing
- Separate meta tag extraction, conversion, and injection into distinct steps to avoid raw HTML strings
- Use a 4-step JS generation process (page JS, component JS, common JS, hydration code) to keep concerns isolated
Related Documents
PCB Design Sources for Industry-Scale Testing
Lists GitHub repos and communities where you can download real PCB designs for testing optimization at scale.
Design Document: BharatSeva AI
Describes a 10-agent AWS system that helps India's informal workers access government schemes via voice-first, serverless architecture.
Qwen Image and Edit: Open-sourcing and Local GGUF Generations with Lightning
Documents the Qwen-Image and Qwen-Image-Edit models, covering architecture, training, benchmarks, ComfyUI setup, and prompting techniques for local GGUF deployment.
OpenClaw Enterprise Transformation Plan
Transforms a single-user AI agent into a dual-mode platform supporting both viral open-source and Fortune 500 enterprise deployments through phased security, IAM, audit, multi-tenancy, and Kubernetes features.