This document outlines the structure and organization of files and directories in the Formbricks codebase, providing guidelines for maintaining consistency and clarity across the project.
The Formbricks codebase follows a monorepo structure using pnpm workspaces, with two main directories:
apps/
- Contains full applications
packages/
- Contains shared libraries and utilities
The apps/
directory contains complete applications:
Main Formbricks web application (Next.js)
Primary application with full feature set
Uses App Router architecture
Contains environment-specific settings and configurations
Demo application (Next.js)
Showcases Formbricks in-product surveying functionality
Used for testing and demonstration purposes
React Native demo app (React Native)
Demonstrates mobile integration capabilities
Example implementation for React Native
Component documentation
Visual documentation of UI components
Testing environment for isolated components
The packages/
directory contains shared libraries and utilities:
Contains core functionality for in-product surveys
Shared logic between different SDK implementations
Base classes and utilities
JavaScript SDK for browser-based applications
Used for running surveys on websites and web apps (browser)
Public NPM package
React Native SDK
Used to run surveys in mobile apps built with React Native / Expo
Includes native platform adaptations
Shared business logic
Shared utilities and helpers
TypeScript type definitions
Zod schemas for validation
Database schemas and migrations
Prisma schema definitions
Migration management
Survey-specific functionality
Survey rendering logic and UI components
Survey state management
Each feature module follows a consistent structure:
When adding new features, follow these guidelines:
Determine Scope:
Complete application → apps/
Shared library → packages/
Feature for existing app → appropriate module in apps/web/modules/
Module Creation: Create a new module with the standard structure:
Component Organization:
Base UI components → modules/ui/components/
Feature-specific components → modules/[feature]/components/
Keep modules focused and single-purpose
Maintain clear separation between UI and business logic
Use proper TypeScript interfaces and types
Group related files in descriptive directories
Use consistent naming patterns
Keep files focused and modular
Minimize dependencies between modules
Share common utilities through appropriate packages
Maintain clear module boundaries
Document complex logic and APIs as laid out in the Documentation section
Keep documentation current with code changes
Test files should be located alongside the code they test
Use .test.ts
or .spec.ts
suffix for test files
Example: user-service.test.ts
for user-service.ts
.eslintrc.js
- ESLint configuration
tsconfig.json
- TypeScript configuration
package.json
- Package metadata and scripts
.env
- Environment variables
Each package maintains its own configuration files:
package.json
- Package-specific dependencies and scripts
tsconfig.json
- Package-specific TypeScript settings
.eslintrc.js
- Package-specific linting rules
.gitignore
- Specifies ignored files and directories
.github/
- GitHub specific configurations and workflows
CHANGELOG.md
- Documents version changes
LICENSE
- License information
Following these organizational patterns ensures:
Consistent code structure across the project
Easy navigation and maintenance
Clear separation of concerns
Scalable architecture for future growth
Remember to maintain these patterns when adding new code to keep the codebase organized and maintainable.