Imported from anilyagiz/autosecops-x (
frontend/AGENTS.md). Install upstream withnpx skills add anilyagiz/autosecops-x --skill frontend. Copyright stays with the author.
Frontend AGENTS.md
Overview
The AutoSecOps frontend is a single-page React/TypeScript application built from frontend/index.jsx and bundled with Webpack 5. It serves the analyst and admin UI for the AutoSecOps control plane.
- Stack: React 18.3.1, React DOM 18.3.1, TypeScript 5.8.2, React Router 3.2.6, react-query 3.39.3, axios 1.18.0, SCSS, Webpack 5.98.0.
- Runtime: served from
frontend/templates/react.ejs, built intoassets/. - State: React Context for global app/user state plus react-query for server state.
- Tooling: Jest 29.2.0, MSW 2.5.1, React Testing Library, Storybook 8.4.7, ESLint 7.32.0 (Airbnb + TypeScript + Prettier).
Build & Run
Use yarn from the repository root. Do not run npm install in the root (it creates a package-lock.json which is gitignored).
| Command | What it does |
|---|---|
make deps-js |
yarn install frontend dependencies. |
make serve |
Build the Go binary and start the dev server on localhost:8080. |
yarn test |
Run all Jest tests (frontend/test/jest.config.js). |
yarn test -- ComponentName.tests.tsx |
Run a single test file. |
yarn test:ci |
CI Jest run with coverage. |
yarn test:sharded |
CI sharded Jest run. |
yarn test:e2e |
Playwright end-to-end tests. |
yarn test:e2e:ui |
Playwright UI mode. |
yarn lint |
ESLint frontend/**/*.{js,jsx,ts,tsx}. |
yarn tsc --noEmit --project tsconfig.all_frontend.json |
TypeScript type check for frontend/. |
make verify-frontend |
Typecheck + lint + Webpack production build. |
yarn storybook |
Storybook dev server on http://localhost:6006. |
yarn build-storybook |
Build static Storybook. |
yarn prettier:check |
Prettier check over frontend/**/*.{jsx,js,tsx,ts}. |
Architecture
- Entry point:
frontend/index.jsx(Webpack entry:webpack.config.js:56). - Routing: React Router v3, declared in
frontend/router/index.tsxand split into route components infrontend/router/components/. Path constants live infrontend/router/paths.tsandfrontend/router/url_prefix.ts. - Layouts:
frontend/layouts/CoreLayout/CoreLayout.tsx,frontend/layouts/GatedLayout/GatedLayout.tsx,frontend/layouts/UnsupportedScreenSize/UnsupportedScreenSize.tsx. - State:
frontend/context/app.tsxmanages user, team, and config;frontend/context/notification.tsxfor flash messages;frontend/context/query.tsx,frontend/context/policy.tsx,frontend/context/table.tsx,frontend/context/routing.tsxfor focused cross-cutting state. - API:
frontend/services/index.tsexports the coreaxiossend helpers (sendRequest,sendRequestWithProgress,sendRequestWithHeaders,sendRequestWithProgressAndHeaders). Domain-specific endpoints live infrontend/services/entities/*.ts. - Styling: SCSS with global variables and helpers in
frontend/styles/var/,frontend/styles/global/, and per-component_styles.scssfiles.
Directory Structure
| Path | Purpose | Notes |
|---|---|---|
components/ |
150+ reusable UI components. | Co-located pattern: *.tsx, _styles.scss, *.tests.tsx, index.ts. |
pages/ |
Route-level page components. | Co-located with sub-components, cards, and helpers. |
services/ |
HTTP request helpers and entity CRUD. | services/index.ts (core axios helpers), services/entities/*.ts (70+ modules), services/mock_service/ (test mocks). |
interfaces/ |
Global TypeScript entity interfaces. | I-prefixed. 60+ files. |
context/ |
React Context providers. | app.tsx, notification.tsx, query.tsx, policy.tsx, table.tsx, routing.tsx. |
router/ |
React Router v3 setup and route guards. | index.tsx, paths.ts, url_prefix.ts, page_titles.ts, components/ (auth/premium/sandbox wrappers). |
layouts/ |
Top-level layout shell. | CoreLayout, GatedLayout, UnsupportedScreenSize. |
utilities/ |
Shared helpers and constants. | permissions/, sort/, theme.ts, endpoints.ts, format_api_errors/, local.ts, helpers.tsx, etc. |
hooks/ |
Reusable React hooks. | useQueryTargets.ts, useTeamIdParam.ts, useToggleSidePanel.ts, etc. |
styles/ |
SCSS variables, mixins, global styles, theme overrides. | var/, global/, helpers.scss, theme-overrides.scss. |
test/ |
Jest config, MSW handlers, mock server, test utilities. | jest.config.js, mock-server.ts, default-handlers.ts, handlers/, stubs.ts, test-utils.tsx, test-setup.ts. |
__mocks__/ |
Typed default mock entities and override helpers. | 30+ files (host, user, team, policy, software, MDM, etc.). |
templates/ |
HTML templates and theme data. | react.ejs, enroll-ota.html, theme-data.json. |
docs/patterns.md |
Extended UI patterns reference. | Keep in sync with this codemap. |
Key Components
Notable reusable component areas (co-located pattern: component + _styles.scss + *.tests.tsx + index.ts):
- Data tables:
components/TableContainer/DataTable/*(specialized cells, filters, action buttons, status cells, setup cells, performance cells). - Modals / banners:
components/Modal/,components/ModalFooter/,components/InfoBanner/,components/FlashMessage/,components/MainContent/,components/Sandbox/,components/GitOpsModeTooltipWrapper/. - Activity and feeds:
components/ActivityTimeline/,components/ActivityItem/,components/ActivityDetails/InstallDetails/,components/FeedListItem/. - Hosts / MDM / platform:
components/AddHostsModal/,components/HostIsolation/,components/MDM/*,components/PlatformSelector/,components/PlatformCompatibility/,components/LastUpdatedHostCount/. - Forms / editors:
components/SQLEditor/,components/Editor/,components/FileUploader/,components/Icon/,components/Spinner/,components/DataError/,components/EmptyTable/,components/StatusIndicator/. - Icons:
components/Icon/with icon definitions; add SVGs incomponents/icons/then register inICON_MAP.
Key Pages
Pages are co-located under frontend/pages/ and grouped by product surface:
- Dashboard:
pages/DashboardPage/with cards (activity feed, host counts, OS, MDM, Munki, software, missing hosts, predictive risk, etc.). - Hosts / Devices:
pages/hosts/ManageHostsPage/,pages/hosts/details/HostDetailsPage/,pages/hosts/details/DeviceUserPage/,pages/hosts/details/HostQueryReport/. - Queries / Live:
pages/queries/ManageQueriesPage/,pages/queries/details/QueryDetailsPage/,pages/queries/live/LiveQueryPage/,pages/queries/edit/EditQueryPage/,pages/packs/. - Policies / Controls:
pages/policies/,pages/ManageControlsPage/(OS updates, OS settings, scripts, secrets, setup experience). - Software:
pages/SoftwarePage/(titles, OS, vulnerabilities, add, custom package, app store, maintained apps, version/ title details). - Security Operations:
pages/SecurityOperationsPage/,pages/SecurityOperations/(incidents, cases),pages/EvidenceCenterPage/,pages/ThreatHuntingPage/,pages/SigmaRulesPage/,pages/PlaybookDesignerPage/,pages/MitreCoveragePage/,pages/case/. - Agentic / AI:
pages/AgentCommandCenterPage/,pages/DashboardPage/cards/ActivityFeed/components/ActivityAutomationDetailsModal/. - Admin:
pages/admin/OrgSettingsPage/,pages/admin/IntegrationsPage/,pages/admin/UserManagementPage/,pages/admin/TeamManagementPage/. - Auth / User:
pages/LoginPage/,pages/RegistrationPage/,pages/ForgotPasswordPage/,pages/ResetPasswordPage/,pages/ConfirmInvitePage/,pages/ConfirmSSOInvitePage/,pages/MfaPage/,pages/LogoutPage/,pages/AccountPage/,pages/ApiOnlyUser/. - Errors:
pages/errors/AutoSecOps403/,pages/errors/AutoSecOps404/.
Services and API Calling
- Core HTTP:
frontend/services/index.tsdefinessendRequest,sendRequestWithProgress,sendRequestWithHeaders, andsendRequestWithProgressAndHeaders. All attach theAuthorization: Bearer <token>header and prefix/api. - Entity modules:
frontend/services/entities/*.ts(e.g.hosts.ts,queries.ts,users.ts,software.ts,mdm.ts,incidents.ts,cases.ts,sigma_rules.ts,playbooks.ts,threat_hunting.ts,agentic_control_plane.ts, etc.). - Calling patterns:
- Use
useQuery/useMutationfrom react-query when loading on mount or caching is needed. - Use direct
async/awaitcalls for one-off user actions. - Keep
getErrorMessagehelpers in siblinghelpers.tsorhelpers.tsxfiles to keep components clean.
- Use
Type System
- Global interfaces:
frontend/interfaces/*.tsare shared I-prefixed types (IHost,IUser,IConfig,ITeam,IQuery, etc.). - Local interfaces: Define local prop/state interfaces inside the consuming component/page file.
- TypeScript config:
tsconfig.all_frontend.jsonextends@tsconfig/recommendedand setsbaseUrltofrontendso imports can be un-prefixed (e.g.import App from "components/App").
Patterns
- Co-located files:
ComponentName.tsx,_styles.scss,ComponentName.tests.tsx,index.tsin one directory. - Named exports for utilities:
export const helper = .... Do not export default utility objects. - I-prefixed global interfaces:
IHost,IUser,IConfig. - Functional components and hooks: use functional components, not classes.
- State: prefer
useState. Prop drill no more than ~2 levels; otherwise use Context. - API data: read config from Context; update config by re-fetching from the API.
- react-query: type generics as
useQuery<IResponse, Error, IData>and useselectwhen the rendered data shape differs. - Forms: wrap with native
<form>andonSubmit={handleSubmit}wherehandleSubmit(evt: React.FormEvent<HTMLFormElement>)callsevt.preventDefault()and returns early ifvalidate(formData)returns errors. - Validation: pure
validate(formData)functions returnRecord<string, string>mapping field names to error messages. Set new errors on blur and only update existing errors on change. - Page layout: top-level pages use
MainContentandSidePanelContent/SidePanelPage. - Handlers: prefer handler prop names like
onSubmitandonUpdateSomething. Avoid prop-spread syntax. - Navigation/flash: call
router.push(path)beforerenderFlashor the flash may auto-hide on the route change. UsepersistOnPageChange: trueinrenderFlashoptions when needed. - Errors: keep error message formatting in
helpers.ts/helpers.tsx(getErrorMessage). - Modals: wrap action buttons in
modal-cta-wrap. - Icons: add optimized SVG components in
components/icons/, then register the name inICON_MAP. - Security: avoid
dangerouslySetInnerHTML. If unavoidable, run user input throughDOMPurify.sanitize. - File size: aim for <500 lines per file; split larger components/pages.
Testing
- Unit / integration: Jest
29.2.0withjest-fixed-jsdom, config atfrontend/test/jest.config.js, setup atfrontend/test/test-setup.ts. - Test match:
frontend/**/*tests.[jt]s?(x). Tests are co-located with the component. - Mocking: MSW default handlers in
frontend/test/handlers/andfrontend/test/default-handlers.ts; mock server defined infrontend/test/mock-server.ts. - Stubs:
frontend/__mocks__/*Mock.tsfiles provide typed default mocks with override helpers. - E2E: Playwright via
yarn test:e2eandyarn test:e2e:ui.
Anti-Patterns
- Do not use class components.
- Do not use Redux.
- Do not use default exports for utility objects.
- Do not reach for
@ts-ignore,@ts-expect-error, oras anyto silence types. - Do not spread props onto components (
<Component {...props} />). - Do not use
dangerouslySetInnerHTMLwithout sanitizing first. - Do not run
npm installin the repository root (useyarn/make deps-js).
Boundaries and Critical Rules
- Work only inside
frontend/unless the task explicitly extends to other directories. ee/may be edited when relevant after readingee/AGENTS.md; do not editwebsite/orportal/unless explicitly authorized.- The root project uses
yarn. Never runnpm installin the repository root. - Do not make unsupported commercial claims in any docs or UI copy; see root
AGENTS.md/make verify-claims. - Prefer functional components + hooks. Keep global interfaces I-prefixed and in
frontend/interfaces/. - Use
react-queryfor server state, Context for cross-cutting UI/app state. - Respect the co-location pattern; tests and styles live next to the component/page they cover.
