How maxence-charriere/go-app works
Project Components
• Library Core (pkg/app):
– Contains the main engine, component definitions, event handling, state management, HTML generation, and HTTP support.
– Holds modules for actions, attributes, cache, context, notifications, routing, etc.
• UI Layer (pkg/ui):
• Auxiliary Services:
– Cache (pkg/cache): Implements caching strategies (LRU, expirations).
– CLI (pkg/cli): Provides command-line interfaces and commands for the framework.
– Errors (pkg/errors) and Logs (pkg/logs): Responsible for error management and logging respectively.
– Analytics (pkg/analytics): Integrates analytics information (e.g., Google Analytics) into the app.
• Documentation and Developer Resources (docs):
– Complete docs including architectural overviews, component guides, and integration instructions.
– Source files (docs/src) and generated web resources (docs/web) for the documentation site.
• WebAssembly (Wasm) Integration:
– Files for generating and handling Wasm (e.g., pkg/app/wasm.go, pkg/app/wasmexec.go, docs/web/app.wasm) which allow apps built with go-app to run in browsers.
• HTTP Server Integration:
– Demonstrated in the README “Standard HTTP” sample, showing how the library integrates with the net/http package.
Relationships and Interactions
• The User Code (application components written by developers using go-app) calls the declarative API provided by pkg/app.
• The UI components (defined in pkg/app and supported by pkg/ui) are rendered as HTML/CSS/JS – this rendering mechanism is connected to autogenerated resources (see pkg/app/gen for scripts and styling).
• The library integrates with the HTTP server model:
– Developers set up routing (app.Route) to point to their components.
– An HTTP handler (app.Handler) is available for integration with the Go net/http package.
• WebAssembly acts as a bridge to enable Go code to run in the browser and manage client-side interactions.
• Internal modules (cache, errors, logs, analytics) function as supporting services for performance, debugging, and additional integrations.
Architectural Patterns/Design Principles
• Modular design: Each major functionality (UI rendering, caching, CLI, logging) is isolated in its own package.
• Declarative UI: The library leverages a declarative syntax to compose UI elements solely in Go.
• Integration with existing standards: Uses Go’s http package for server-side routing and WebAssembly for client-side execution.
• Separation of concerns: Distinct responsibilities are assigned to packages—UI layout (pkg/app, pkg/ui), state and logic (pkg/app), caching (pkg/cache), etc.
• UI Engine (pkg/app)
• UI Components/Helpers (pkg/ui)
• WebAssembly Bridge (Wasm components & generated files)
• HTTP Integration (Handler, routing via app.Route and net/http)