Architecture Overview
Relevant source files
The following files were used as context for generating this wiki page:
Analog is a full-stack, open-source calendar application built on a modern JavaScript tech stack. The project is structured as a monorepo managed by Turborepo and Bun, containing a Next.js web application, a tRPC-based API, and several shared packages. This architecture facilitates code sharing, streamlined development, and efficient build processes.
The core components include a reactive frontend, a robust API layer that communicates with both a PostgreSQL database and external services like Google and Microsoft calendars, and a comprehensive authentication system. The system is designed to be run locally using Bun for the runtime and Docker for the database, ensuring a consistent development environment.
Monorepo Structure
The project utilizes a monorepo structure managed by Bun workspaces and optimized with Turborepo. The codebase is organized into apps for deployable applications and packages for shared libraries and utilities.
Sources: package.json:20-24, turbo.json
This diagram shows the workspace organization within the Analog monorepo.
Sources: package.json:20-24, apps/web/package.json:2, packages/api/package.json:2
Key Directories
apps/: Contains the main web application (@repo/web), which is a Next.js 15 application.packages/: Houses shared code, including:@repo/api: The backend API built with tRPC.@repo/db: Database schema and queries using Drizzle ORM.@repo/auth: Authentication logic using Better Auth.- Other utility packages for specific integrations (e.g.,
@repo/google-calendar,@repo/google-tasks).
tooling/: Contains shared tooling configurations like ESLint and TypeScript.
Sources: package.json:20-24, apps/web/package.json:2, packages/api/package.json:2
High-Level System Architecture
The application follows a client-server model where the Next.js frontend communicates with the backend API, which in turn interacts with the database and external calendar services.
This diagram illustrates the primary components and data flow within the Analog system.
Sources: README.md:94-97, packages/api/package.json:30-40, apps/web/package.json:48
Tech Stack
The project is built with a range of modern technologies for web development, database management, and authentication.
| Category | Technology |
|---|---|
| Web | Next.js (v15), TypeScript, Tailwind CSS (v4), tRPC, TanStack Query |
| UI | shadcn/ui, Radix UI, Framer Motion |
| Database | PostgreSQL with Drizzle ORM |
| Auth | Better Auth for Google & Microsoft OAuth |
| Runtime | Bun |
| Monorepo | Turborepo |
| Deployment | Vercel |
Sources: README.md:94-97, package.json:25, apps/web/package.json
Components
Frontend (@repo/web)
The frontend is a Next.js application using the App Router. It leverages Server Components and Client Components for rendering.
- Framework: Next.js 15 with Turbopack for development.
- API Communication: Uses
@trpc/clientand@tanstack/react-queryto make type-safe API calls to the@repo/apipackage. - State Management: Primarily uses TanStack Query for server state and Jotai for client state.
- UI Components: Built with
shadcn/ui, which is based on Radix UI primitives and styled with Tailwind CSS. - Routing: Utilizes Next.js App Router with route groups for organization (e.g.,
(auth),(legal),(marketing)).
Sources: apps/web/package.json:4, apps/web/package.json:50, apps/web/package.json:66, apps/web/src/app/(auth)/login/page.tsx
Backend (@repo/api)
The backend is a tRPC API designed to be consumed by the Next.js frontend. It acts as a gateway to the database and external services.
- API Framework:
tRPCfor creating end-to-end typesafe APIs. - Database Access: Interacts with the database via the
@repo/dbpackage (Drizzle ORM). - External Integrations: Contains clients and logic for interacting with:
- Google Calendar API (
@repo/google-calendar) - Google Tasks API (
@repo/google-tasks) - Microsoft Graph API (
@microsoft/microsoft-graph-client) - Google Maps/Places API (
@googlemaps/places)
- Google Calendar API (
- Rate Limiting: Uses
@upstash/ratelimitwith Redis for API rate limiting.
Sources: packages/api/package.json:18, packages/api/package.json:30-40
Authentication
Authentication is handled by better-auth, supporting OAuth with Google and Microsoft. The flow is initiated from the frontend and handled via API routes.
This diagram shows the sequence of events during the Google OAuth login process.
Sources: README.md:41-52, apps/web/src/app/(auth)/login/page.tsx:18-22, packages/api/package.json:19
Database (@repo/db)
The project uses PostgreSQL as its database, managed with Drizzle ORM.
- Database: PostgreSQL, run via Docker for local development.
- ORM: Drizzle ORM for type-safe database queries.
- Migrations: Drizzle Kit is used for generating and applying database schema changes. The
db:pushanddb:migratescripts are defined for this purpose.
Sources: README.md:73, package.json:13-14
Build & Development
The development workflow is managed by Bun scripts and orchestrated by Turborepo.
Key Scripts
| Script | Description |
|---|---|
bun run dev | Starts the development server for all workspaces using turbo run dev. |
bun run build | Builds all workspaces for production. |
bun run lint | Lints all workspaces. |
bun run docker:up | Starts the PostgreSQL Docker container. |
bun run db:push | Pushes the Drizzle schema to the database (for development). |
Sources: package.json:4-15
Turborepo Configuration
turbo.json defines the task pipeline, caching, and environment variable dependencies for the monorepo.
- Caching: The
buildtask is configured to cache outputs in.next/**anddist/**, speeding up subsequent builds. - Task Dependencies:
builddepends on^build, meaning it will build all dependencies of a workspace before building the workspace itself. - Environment Variables: Tasks like
buildanddevexplicitly declare their dependency on a long list of environment variables, ensuring that tasks are re-run when these variables change.
Sources: turbo.json:3-80
Environment Configuration
The application relies on a .env file for configuration. Key variables are required for authentication, database connection, and external API access.
| Variable | Purpose |
|---|---|
DATABASE_URL | Connection string for the PostgreSQL database. |
BETTER_AUTH_SECRET | Secret key for better-auth session signing. |
GOOGLE_CLIENT_ID | Google OAuth Client ID. |
GOOGLE_CLIENT_SECRET | Google OAuth Client Secret. |
GOOGLE_MAPS_API_KEY | API key for Google Maps/Places. |
MICROSOFT_CLIENT_ID | Microsoft OAuth Client ID. |
MICROSOFT_CLIENT_SECRET | Microsoft OAuth Client Secret. |
UPSTASH_REDIS_REST_URL | URL for Upstash Redis (used for rate limiting). |
UPSTASH_REDIS_REST_TOKEN | Token for Upstash Redis. |
Sources: README.md:29-69, turbo.json:8-35