How It Works
This guide explains the architecture and core concepts of Sourcetool to help you understand how the system works behind the scenes.
Architecture Overview
Sourcetool follows a unique architecture that allows you to build full-featured web applications using only backend code. Here's how it works:
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
│ │ │ │ │ │
│ Your Go Code │◄────►│ Sourcetool SDK │◄────►│ Sourcetool Cloud│
│ │ │ │ │ │
└─────────────────┘ └─────────────────┘ └─────────────────┘
▲
│
▼
┌─────────────────┐
│ │
│ End Users │
│ │
└─────────────────┘
- Your Go Code: You write business logic and UI definitions in Go
- Sourcetool SDK: Translates your UI definitions into frontend components
- Sourcetool Cloud: Hosts the frontend application and manages user sessions
- End Users: Access your application through a web browser
Backend to Frontend Bridge
Sourcetool eliminates the need to write frontend code by providing a bridge between your Go backend and the frontend UI:
- UI Builder API: You use the
UIBuilder
interface to define UI components - State Serialization: The SDK serializes the UI state and sends it to Sourcetool Cloud
- Component Rendering: Sourcetool Cloud renders the components in the user's browser
- Event Handling: User interactions are sent back to your Go code for processing
Page Lifecycle
When a user accesses a page in your application, the following sequence occurs:
- Request: The user requests a page (e.g.,
/users
) - Handler Execution: Sourcetool calls your page handler function
- UI Building: Your handler builds the UI using the
UIBuilder
interface - Rendering: The UI is rendered in the user's browser
- Interaction: When the user interacts with the UI, your handler is called again with the updated state
func userListPage(ui sourcetool.UIBuilder) error {
// 1. Define UI components
ui.Markdown("# Users")
// 2. Handle user input
searchTerm := ui.TextInput("Search", textinput.Placeholder("Search users..."))
// 3. Process data based on input
users, err := fetchUsers(searchTerm)
if err != nil {
return err
}
// 4. Display results
ui.Table(users)
return nil
}
Session Management
Sourcetool manages user sessions automatically:
- Session Creation: When a user accesses your application, a new session is created
- State Persistence: The state of UI components is persisted across page reloads
- Session Expiry: Sessions expire after a period of inactivity
Real-time Updates
Sourcetool supports real-time updates through WebSockets:
- WebSocket Connection: A WebSocket connection is established between the user's browser and Sourcetool Cloud
- Event Streaming: Events are streamed in real-time between the frontend and backend
- UI Updates: The UI is updated automatically when the underlying data changes
Component Rendering
When you define a UI component in your Go code, Sourcetool:
- Creates a Component Definition: Converts your Go code into a component definition
- Assigns a Unique ID: Each component gets a unique identifier
- Tracks State: Maintains the state of the component across requests
- Renders the Component: Renders the component in the user's browser
Data Flow
Data flows through your application as follows:
┌─────────────┐ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐
│ │ │ │ │ │ │ │
│ User Input │────►│ Go Handler │────►│ Data Store │────►│ UI Rendering│
│ │ │ │ │ │ │ │
└─────────────┘ └─────────────┘ └─────────────┘ └─────────────┘
▲ │
│ │
└────────────────────────────────────────────────────────────┘
- User Input: The user interacts with the UI
- Go Handler: Your handler function processes the input
- Data Store: Your code interacts with your data store (database, API, etc.)
- UI Rendering: The updated UI is rendered based on the new data
- Feedback Loop: The user sees the updated UI and can provide new input
Environments and Deployment
Sourcetool supports multiple environments for your applications:
- Development: For local development and testing
- Staging: For pre-production testing
- Production: For live applications
Each environment can have its own:
- API keys
- Configuration settings
- Access controls
- Domain names
Organizations and Access Control
Sourcetool provides organization-level access control:
- Organizations: Group users and applications
- User Roles: Assign different roles to users (admin, developer, member)
- Groups: Create groups of users for fine-grained access control
- Pages: Control which groups can access which pages
API Keys
API keys are used to authenticate your application with Sourcetool Cloud:
- Development Keys: For local development
- Production Keys: For production environments
- Custom Keys: Create custom keys for specific use cases or services
Next Steps
Now that you understand how Sourcetool works, you can:
- Learn more about Pages and how they structure your application
- Explore Environments for deploying your application
- Understand Organizations for managing users and access control