Frontend Architecture
Relevant source files
The following files were used as context for generating this wiki page:
The Analog frontend is a modern, full-stack web application built with Next.js and the App Router. It leverages a robust, type-safe technology stack to deliver a feature-rich user experience. The architecture emphasizes developer productivity through a monorepo setup, a comprehensive UI component system, and a streamlined data-fetching strategy.
This document outlines the core architectural components, technology stack, project structure, and key configurations of the apps/web application within the Analog monorepo.
Core Technologies
The frontend is built upon a curated set of modern web development tools. The primary technologies are defined in the project's README.md and apps/web/package.json.
Sources: README.md, apps/web/package.json
Technology Stack Overview
The following diagram illustrates the main technologies used in the frontend and their roles.
This diagram shows the high-level technology stack of the apps/web frontend.
Sources: README.md, apps/web/package.json
Key Dependencies
The following table summarizes the key libraries and their purpose in the application.
| Library | Version | Description |
|---|---|---|
next | 15.5.2 | The core React framework, using the App Router. |
react | 19.1.1 | The UI library for building components. |
typescript | 5.9.2 | Provides static typing for the entire codebase. |
tailwindcss | 4.1.12 | A utility-first CSS framework for styling. |
shadcn/ui | N/A | A collection of re-usable UI components built on Radix UI and Tailwind CSS. |
@trpc/client | 11.5.0 | Enables type-safe API communication between the client and server. |
@tanstack/react-query | 5.85.6 | Manages server state, including data fetching, caching, and synchronization. |
jotai | 2.13.1 | An atomic state management library for client-side state. |
better-auth | 1.3.7 | Handles user authentication, primarily via Google OAuth. |
bun | 1.2.18 | Used as the JavaScript runtime, package manager, and bundler. |
Sources: apps/web/package.json, package.json:16, README.md:12-15
Project Structure and Configuration
The frontend application resides in a Turborepo monorepo, which optimizes build and development workflows.
Sources: turbo.json, package.json:17-21
Monorepo Setup
The project uses Turborepo to manage the apps and packages workspaces. The turbo.json file defines tasks like build, dev, and lint, orchestrating them across the monorepo. This setup allows for shared packages (e.g., @repo/api, @repo/auth) and efficient caching of build outputs.
Sources: turbo.json, package.json:17-21
Path Aliases
To simplify import paths and improve code organization, the project uses path aliases configured in components.json.
| Alias | Path | Description |
|---|---|---|
@/components | src/components | Directory for general React components. |
@/utils | src/lib/utils | Utility functions, including cn for merging Tailwind classes. |
@/hooks | src/hooks | Custom React hooks. |
@/lib | src/lib | Core library code, utilities, and configurations. |
@/ui | src/components/ui | Location for shadcn/ui components. |
{
"aliases": {
"components": "@/components",
"utils": "@/lib/utils",
"hooks": "@/hooks",
"lib": "@/lib",
"ui": "@/components/ui"
}
}
Source: apps/web/components.json:11-17
Next.js Configuration
The next.config.ts file contains important configurations for the web application.
API Headers
The application configures custom CORS headers for specific API routes to allow external access, likely for mobile clients or third-party integrations.
// apps/web/next.config.ts:14-26
async headers() {
// For routes that are public
const headers = [
{ key: "Access-Control-Allow-Credentials", value: "true" },
{ key: "Access-Control-Allow-Origin", value: "*" },
{
key: "Access-Control-Allow-Methods",
value: "GET, POST, PUT, PATCH, DELETE, OPTIONS",
},
{
key: "Access-Control-Allow-Headers",
value: "Authorization, Content-Type, X-CSRF-Token, X-API-Key",
},
];
return [
{
source: "/api/mcp/:path*",
headers,
},
// ... other routes
];
},
The routes /api/mcp/:path*, /api/auth/mcp/:path*, /api/v1/:path*, and /api/openapi.json are configured with open CORS policies.
Sources: apps/web/next.config.ts:14-44
Build Customizations
The Webpack and Turbopack configurations are customized to handle SVG files. It allows importing SVGs as React components by default, while also supporting URL imports via a ?url query string.
Sources: apps/web/next.config.ts:46-77
Image Optimization
next/image is configured to optimize images from specific remote hostnames, including Google User Content and Marble CMS.
Sources: apps/web/next.config.ts:78-94
Third-Party Integrations
The Next.js configuration is wrapped with higher-order functions from Sentry (withSentryConfig) and Simple Analytics (withSimpleAnalytics) to integrate monitoring and analytics services.
Sources: apps/web/next.config.ts:97-126
UI and Component Architecture
The UI is built with React and styled with Tailwind CSS. The component architecture is heavily influenced by shadcn/ui.
Component System
The project uses shadcn/ui for its base component library. This is not a traditional component library but a collection of copy-pasteable components that can be customized. The components.json file defines the configuration for shadcn/ui, including the style, color scheme, and file paths.
Sources: apps/web/components.json, README.md:82
Custom Components
The application includes custom client components for specific functionalities. An example is the Response component, which is designed to render markdown content, potentially streamed from an AI service.
Key features of the Response component:
- It is a memoized client component (
"use client"). - It uses
react-markdownwith plugins likeremark-gfm,remark-math, andrehype-katexto render rich markdown. - It includes a custom parser (
parseIncompleteMarkdown) to handle and fix incomplete markdown syntax during streaming, preventing rendering errors. - It uses a hardened version of
ReactMarkdownfor security. - It provides custom styling for HTML elements like headings, lists, and code blocks.
Sources: apps/web/src/components/ai-elements/response.tsx
Routing and Layouts
The application uses the Next.js App Router, which is evident from the apps/web/src/app directory structure.
Root Layout
The main entry point for the UI is the RootLayout component in apps/web/src/app/layout.tsx.
This diagram shows the structure of the root layout.
This diagram shows the component hierarchy within RootLayout.
Sources: apps/web/src/app/layout.tsx:75-87
The RootLayout is responsible for:
- Setting the base HTML structure (
<html>,<body>). - Loading global fonts: Geist Sans, Geist Mono, and Satoshi.
- Wrapping all pages in a
Providerscomponent, which likely sets up context for themes, data fetching (TanStack Query), and state management (Jotai). - Including a global
Toastercomponent for displaying notifications. - Integrating
SimpleAnalyticsfor analytics tracking.
Sources: apps/web/src/app/layout.tsx
Route Groups
The project uses route groups, such as (legal), (marketing), and (auth), to organize routes without affecting the URL structure. For example, the login page is located at apps/web/src/app/(auth)/login/page.tsx but is accessible at the /login URL.
Sources: apps/web/src/app/(auth)/login/page.tsx, apps/web/src/app/(legal)/terms/page.tsx
Authentication Flow
Authentication is managed by better-auth. The login page at /login demonstrates the client-side authentication flow.
The following sequence diagram illustrates the login process.
This diagram shows the sequence of events during user login.
Sources: apps/web/src/app/(auth)/login/page.tsx:18-22, README.md:41-47
If a user has an active session, they are redirected from /login to /calendar. The page can also display an alert if re-authentication is required due to missing scopes.
Sources: apps/web/src/app/(auth)/login/page.tsx:18-25
Summary
The Analog frontend architecture is a well-structured system built on a modern technology stack. Key architectural decisions include:
- Next.js App Router: For a hybrid server/client rendering model.
- Turborepo Monorepo: For efficient code sharing and development workflows.
- Type-Safety: End-to-end type safety with TypeScript and tRPC.
- Component-Based UI: A robust UI system using
shadcn/uiand Tailwind CSS. - Decoupled State Management: Using TanStack Query for server state and Jotai for client state.
- Integrated Tooling: Built-in support for analytics (Simple Analytics) and error monitoring (Sentry).
This architecture provides a scalable and maintainable foundation for the Analog application.