Frontend Architecture & State Management
Relevant source files
The following files were used as context for generating this wiki page:
The GoGovSG frontend is a React-based Single Page Application (SPA) that manages the creation, management, and analytics of shortened government links. It uses Redux for centralized state management and Webpack for module bundling and environment-specific asset resolution.
The application serves three distinct branded environments—Go.gov.sg, for.edu.sg, and for.sg—using a single codebase. It leverages redux-thunk for asynchronous actions and Material-UI for component styling.
Sources: README.md:14-16, README.md:231-235, package.json:96-107
Core Technologies & Tooling
The frontend stack relies on modern JavaScript/TypeScript tools to ensure cross-browser compatibility and maintainable state transitions.
| Component | Technology | Purpose |
|---|---|---|
| Framework | React 17 | Component-based UI rendering |
| State Management | Redux | Centralized store for application state |
| Middleware | Redux Thunk | Handling asynchronous API calls |
| Bundler | Webpack 5 | Module bundling and asset management |
| Transpiler | Babel & SWC | Converting TSX/JSX to browser-compatible JS |
| Styling | Material-UI (v4) | UI component library and theme management |
Sources: package.json:96-121, webpack.config.ts:89-106, README.md:237-248
Application Architecture
The frontend architecture follows a modular structure where specific features (home, user, apiintegration) contain their own components and Redux logic.
Module Structure
All frontend code resides in src/client. The app directory contains core layouts and global utility functions, while feature-specific directories handle user-facing modules.
Build and Asset Variants
The system uses Webpack aliasing to inject environment-specific assets (gov, edu, or health) at build time based on the ASSET_VARIANT environment variable. This allows the same component logic to render different logos, favicons, and copy.
Sources: webpack.config.ts:74-77, README.md:231-235
State Management Flow
GoGovSG utilizes Redux to coordinate data between the UI and backend APIs. Components dispatch actions, which are processed by thunks for API calls or sent directly to reducers to update the GoGovReduxState.
Data Fetching and Synchronization
The following sequence illustrates how a user page initializes state by fetching links and validation rules upon login.
Global State Structure
The GoGovReduxState interface consolidates multiple slices of state. Key state slices include:
- login: Tracks authentication status (
isLoggedIn) and email validation patterns. - user: Manages the link list, link creation state (
isUploading), and modal visibility. - home: Stores public statistics for the landing page.
- api: Manages API key presence and modal state.
Sources: src/client/user/index.tsx:18-28, src/client/apiintegration/index.tsx:39-44, src/client/user/components/CreateUrlModal/CreateLinkForm.tsx:55-66
Component Layout & Navigation
The BaseLayout component serves as the primary wrapper for all pages, providing consistent headers, footers, and global banners.
Layout Hierarchy
BaseLayout coordinates several top-level UI elements:
- Masthead: Official government banner (displayed if
assetVariantis 'gov'). - Banner: Displays system-wide messages or IE warnings.
- Header: Contains navigation buttons and branding.
- Children: The specific page content (e.g.,
UserPage,HomePage). - Footer: Government-specific site links.
Sources: src/client/app/components/BaseLayout/index.tsx:69-95
Page Components
- UserPage: Requires authentication. It manages the
UserLinkTableand various modals (CreateUrlModal,AnnouncementModal). - HomePage: Public-facing. It fetches public link statistics and displays feature slivers.
- ApiIntegrationPage: Provides UI for managing external API keys.
Sources: src/client/user/index.tsx:49-62, src/client/home/index.tsx:55-78, src/client/apiintegration/index.tsx:55-70
Link Creation Workflow
The link creation process is managed through CreateLinkForm, which handles three types of targets: URLs, Files, and Bulk CSV uploads.
Form Validation Rules
The frontend enforces strict validation before allowing submission to the backend:
- Short URL: Must consist of lowercase letters, numbers, and hyphens.
- Long URL: Must be a valid URL format.
- File Size: Maximum 20MB for single files; 10MB for Bulk CSVs.
- Tags: Maximum of 3 tags per link.
Sources: src/client/user/components/CreateUrlModal/CreateLinkForm.tsx:112-126, src/client/user/components/CreateUrlModal/CreateLinkForm.tsx:380-385
Conclusion
The GoGovSG frontend architecture prioritizes environmental flexibility and strict state synchronization. By combining Redux with a modular React structure, the application ensures that link management and analytics are delivered reliably across three different government branding variants. Implementation details like Webpack aliasing and centralized thunk-based API interactions allow developers to maintain a single core logic while serving diverse institutional needs.