Web App Architecture (Next.js)
Relevant source files
The following files were used as context for generating this wiki page:
- README.md
- apps/web/README.md
- apps/web/core/components/README.md
- apps/web/core/stores/README.md
- apps/web/core/types/schemas/README.md
- apps/web/project.json
- apps/web/app/[locale]/(main)/task/[id]/page.tsx
- docker-compose.yml
- package.json
- packages/ui/package.json
- apps/web/core/components/features/projects/add-or-edit-project/steps/review-summary.tsx
The Ever Teams web application, located in apps/web, is a modern frontend built with Next.js and React. It serves as the primary user interface for the Ever Teams platform, providing features for work and project management. The application is part of a larger monorepo managed by Nx and Turbo, which facilitates code sharing and streamlined builds across different parts of the platform, including mobile and desktop applications.
The architecture emphasizes a strong separation of concerns, type safety, and scalability. It leverages a domain-driven structure for state management and components, relies on a shared UI library for primitive elements, and ensures data integrity through runtime validation against a backend API. The technology stack includes TypeScript, Tailwind CSS, and Jotai for state management.
Sources: README.md, apps/web/README.md, package.json:34-44
Monorepo and Project Structure
The ever-teams repository is a monorepo that uses Nx and turbo to manage multiple applications and shared packages. The main web application resides in apps/web. This structure promotes code reuse and consistency.
Key directories in the monorepo include:
apps/web: The Next.js web application.apps/mobile: An Expo (React Native) mobile application.apps/desktop: An Electron-based desktop application.apps/server-web: An Electron-based server that wraps and serves the Next.js frontend.packages/ui: A shared library of "dumb" UI primitives.packages/hooks: Shared React hooks.packages/types: Shared TypeScript types and interfaces.
Sources: README.md:231-237, package.json:141-151
The following diagram illustrates the dependency relationship between the main web application and the shared packages.
This diagram shows that the apps/web application consumes several shared packages for UI, hooks, types, and utilities.
Sources: package.json:141-151, packages/ui/package.json:11-14
Nx Project Configuration
The apps/web project is defined and configured in apps/web/project.json. This file specifies targets for building, serving, linting, and testing the application using Nx executors.
build: Uses@nx/next:buildto compile the Next.js application for production.serve: Uses@nx/next:serverto run a development server, typically onlocalhost:3030.lint: Uses@nx/linter:eslintto enforce code quality.
Sources: apps/web/project.json:5-40
Frontend Framework: Next.js
The web application is a Next.js project, bootstrapped with create-next-app. It utilizes the App Router, which is evident from the directory structure apps/web/app. This enables modern React features like Server Components and layouts.
Routing and Layouts
The routing is file-system based. For example, the page for a specific task is located at apps/web/app/[locale]/(main)/task/[id]/page.tsx. This file defines the component for the /task/:id route. The [locale] segment in the path indicates that the application supports internationalization (i18n).
The main layout for the application is defined in apps/web/core/components/layouts/default-layout.tsx and used within page components to provide a consistent structure, including a header, timer, and main content area.
Sources: apps/web/README.md:1-3, apps/web/app/[locale]/(main)/task/[id]/page.tsx, apps/web/core/components/common/skeleton/app-urls-dashboard-page-skeleton.tsx:16-20
Component Architecture
The component architecture is strictly organized to promote scalability and maintainability. It distinguishes between "smart" business-aware components and "dumb" reusable UI primitives.
Sources: apps/web/core/components/README.md
Core Components (apps/web/core/components/)
This directory contains smart UI components with internal logic, conditions, and hooks. They are organized by scope:
| Folder | Responsibility | Examples |
|---|---|---|
common/ | Shared, reusable components not tied to a specific business domain. | modal-wrapper.tsx, file-upload-block.tsx |
pages/ | Components strictly limited to a specific page or route. | pages/dashboard/productivity-chart.tsx |
Feature Folders (auth/, projects/) | Components tied to a specific product feature or entity. | projects/project-card.tsx, tasks/task-card.tsx |
Sources: apps/web/core/components/README.md:6-61
The following diagram shows the component folder structure.
This diagram illustrates how pages compose smart components from common, pages, and feature folders, which in turn use dumb primitives from packages/ui.
Sources: apps/web/core/components/README.md:100-104
UI Primitives (packages/ui)
The @ever-teams/ui package, located at packages/ui, contains pure, "dumb" UI primitives like buttons, inputs, and cards. These components are built using shadcn/ui, Radix UI, and HeadlessUI and are styled with Tailwind CSS. They are designed to be stateless and visually consistent, serving as the foundational building blocks for the smart components in apps/web/core/components.
Sources: README.md:38-39, packages/ui/package.json:2-3, apps/web/core/components/README.md:100-104
State Management: Jotai
Global state management is handled by Jotai. The stores are organized by feature domain within apps/web/core/stores/, ensuring a clean separation of concerns.
Key principles of the state management architecture include:
- Domain-Driven Structure: Each subfolder in
core/storescorresponds to a feature likeauth,tasks, orprojects. - Explicit Naming Conventions: Atoms follow strict naming rules to improve clarity and avoid collisions.
- Atom Granularity: Preferring small, focused atoms over large, monolithic state objects.
Sources: apps/web/core/stores/README.md:1-10
Atom Naming Conventions
| Type | Prefix | Example |
|---|---|---|
| Atom for primitives | xxxAtom | userAtom, menuOpenAtom |
| Derived atoms (get-only) | xxxDerived | activeProjectDerived |
| Selector atoms (filters) | xxxFilterAtom | taskFilterAtom |
| State with getter logic | getXxxAtom | getActiveTeamAtom |
Sources: apps/web/core/stores/README.md:28-36
Components consume this state using the useAtomValue or useAtom hooks from Jotai, as seen in various parts of the application. For example, review-summary.tsx uses useAtomValue(activeTeamState) to get the currently active team.
Sources: apps/web/core/components/features/projects/add-or-edit-project/steps/review-summary.tsx:26
Data Fetching and Validation
The web application communicates with a backend API (Ever Gauzy) to fetch and persist data. The API endpoint is configurable via the NEXT_PUBLIC_GAUZY_API_SERVER_URL environment variable.
Sources: README.md:118-120, docker-compose.yml:92-93
Zod Schema Validation
To ensure type safety and data integrity at the boundary between the client and server, the application uses Zod for runtime validation of API responses.
- Schemas: Zod schemas are defined in
apps/web/core/types/schemas/and are structured by domain (e.g.,role/,tag/). - Validation Utilities: Helper functions like
validateApiResponseandvalidatePaginationResponseare used to parse and validate incoming data. - Error Handling: A custom
ValidationErrorclass provides detailed error messages when validation fails. - Validated Services: The application provides "validated" service layers (e.g.,
role-validated.service.ts) that automatically wrap API calls with Zod validation.
Sources: apps/web/core/types/schemas/README.md:3-12, 45-51
The data fetching and validation flow is as follows:
This diagram shows how an API response is intercepted and validated by Zod before being passed to the application's state and UI.
Sources: apps/web/core/types/schemas/README.md:60-69, apps/web/app/[locale]/(main)/task/[id]/page.tsx:37-45
Deployment and Environment
The web application is designed to be deployed in various environments, with Docker being a primary method.
Docker Configuration
The docker-compose.yml file defines the webapp service for running the Next.js application in a container. It specifies the Docker image ghcr.io/ever-co/ever-teams-webapp:latest and a comprehensive list of environment variables used for configuration.
Sources: docker-compose.yml:89-91
Environment Variables
The application is configured at runtime using environment variables. Key variables include:
| Variable | Description | Example |
|---|---|---|
NEXT_PUBLIC_GAUZY_API_SERVER_URL | The base URL for the backend API. | https://api.ever.team |
APP_NAME | The name of the application for branding. | Ever Teams |
NEXT_PUBLIC_SITE_TITLE | The title used in site metadata. | Open Work and Project Management Platform |
GITHUB_CLIENT_ID / SECRET | Credentials for GitHub OAuth integration. | |
NEXT_PUBLIC_CAPTCHA_SITE_KEY | Site key for CAPTCHA services. |
Sources: docker-compose.yml:92-167
The project also supports one-click deployments to various platforms like Vercel, Render, and DigitalOcean.
Sources: README.md:162-189
Conclusion
The Ever Teams web application architecture is a robust and scalable system built on Next.js. Its foundation in a monorepo structure, combined with a clear separation of concerns in component design, state management, and data validation, creates a maintainable and developer-friendly codebase. The use of modern tools like Nx, Turbo, Jotai, and Zod ensures a high degree of type safety, code quality, and performance, making it well-suited for a complex project management platform.