Production-Ready Agile Management for Modern Teams
Enterprise project management with organizations, workspaces, spaces, custom workflows, AI assistance, usage-based billing, and GitHub integration.
π Documentation | π Quick Start | π‘ Contributing | ποΈ Architecture
- Overview
- Documentation
- Key Features
- Tech Stack
- Quick Start Guide
- Architecture & Data Flow
- Project Structure
- Environment Configuration
- Feature Modules
- Permission & RBAC System
- Billing & Usage Tracking
- AI Features
- Development Workflow
- Testing
- Deployment
- Contributing
- Security
Fairlx is a production-ready enterprise project management platform built with Next.js 15, TypeScript, and Appwrite. It combines modern agile methodologies with powerful features for teams of any size.
- Dual Account System: Personal accounts for solo developers; Organization accounts with shared billing and multi-user management
- Hierarchical Organization: Organiz ations β Workspaces β Spaces β Projects β Tasks (flexible 5-level structure)
- Custom Workflows + AI: Build custom status flows and transitions with AI-powered suggestions and validation
- Production Billing: Usage-based metering (traffic, storage, compute) with Razorpay integration, grace periods, and automated suspension
- Enterprise RBAC: Multi-level role-based access control with granular permissions at org, workspace, space, project, and team levels
- AI-First Features: Google Gemini integration for workflow assistance, code analysis, documentation generation
- GitHub Native: Repository linking with automatic documentation generation and commit synchronization
| Capability | Implementation |
|---|---|
| Account Types | Personal (individual use) and Organization (team collaboration with shared billing) |
| Organization | Multi-tenant with departments, audit logs, role hierarchy (Owner/Admin/Moderator/Member) |
| Workspaces | Multiple workspaces per account with Simple/Advanced UI modes and feature toggles |
| Spaces | Logical containers (departments, products, clients) with unique keys for work item prefixing |
| Projects | Scrum/Kanban/Hybrid boards with WIP limits, sprint management, GitHub integration |
| Work Items | Tasks, Stories, Bugs, Epics with custom fields, labels, assignments, dependencies |
| Workflows | Custom statuses and transitions with team-based rules and AI assistance |
| Time Tracking | Estimates vs actuals, timesheets, variance analysis, capacity planning |
| Billing | Usage metering, invoicing, Razorpay e-mandate, grace periods, account suspension |
| AI Integration | Workflow suggestions, code Q&A, documentation generation via Gemini API |
| Document | Purpose |
|---|---|
| README.md | Complete setup, architecture, and feature reference (this file) |
| CONTRIBUTING.md | Development guidelines, branching strategy, PR workflow |
| CODE_OF_CONDUCT.md | Community standards and enforcement policies |
| changelog.md | Detailed version history and implementation updates |
| DATABASE_UPDATES.md | Schema changes, migrations, and workflow redesign notes |
| PROGRAMS_IMPLEMENTATION_GUIDE.md | Complete guide to Programs feature architecture |
| md/APPWRITE_SETUP.md | Step-by-step Appwrite database configuration |
| md/APPWRITE_GUIDE.md | Complete collection schemas, attributes, and indexes |
| md/MIGRATION_SETUP.md | Migration scripts for project RBAC and teams |
| docs/FEATURES_COMPLETE.md | Implementation summary with performance improvements |
| docs/SPACES_GUIDE.md | Visual guide to Spaces feature with use cases |
| docs/SPACES_TESTING_GUIDE.md | Testing procedures for Spaces functionality |
| docs/APPWRITE_ORGANIZATIONS_SETUP.md | Organization-level Appwrite configuration |
| src/features/billing/VALIDATION_CHECKLIST.md | Pre-production billing system validation |
- Personal Accounts: For individual developers and freelancers
- Organization Accounts: Team collaboration with shared billing and member management
- Multi-Workspace: Create unlimited workspaces per account
- UI Modes: Simple mode (small teams) or Advanced mode (enterprise features)
- Feature Toggles: Enable/disable Spaces, Programs, Teams, Advanced Permissions per workspace
- Departments: Organize organization members into departments with permissions
- Work Items: Tasks, Stories, Bugs, Epics, Ideas, Improvements with rich metadata
- Subtasks: Hierarchical task breakdown with progress tracking
- Custom Fields: Text, number, date, select, multi-select, user, checkbox, URL, currency, percentage, labels
- Work Item Links: Blocks, relates-to, duplicates, split-from, cloned-from, parent/child, causes relationships
- Personal Backlog: Individual work queues independent of projects
- Saved Views: Custom filters and sorting for Kanban, List, Calendar, Timeline views
- Board Types: Scrum, Kanban, or Hybrid workflows
- Sprint States: Planned, Active, Completed, Cancelled with velocity tracking
- WIP Limits: Configure work-in-progress limits per column
- Burndown Charts: Sprint progress visualization
- Velocity Tracking: Team capacity and historical velocity analysis
- Custom Columns: Configurable kanban columns with icons and colors
- Custom Workflows: Define status flows per workspace, space, or project
- Status Types: Open, In Progress, Closed for analytics
- Transitions: Controlled state changes with conditions
- Team-Based Rules: Restrict transitions by team or role
- Approval Workflows: Require approvals for specific transitions
- Auto-Transitions: Automatic state changes based on conditions
- AI Assistant: Generate workflows, suggest statuses/transitions, identify issues
- Time Logs: Track actual time spent on tasks
- Estimates: Story points and time estimates
- Variance Analysis: Compare estimates vs actuals
- Timesheets: Export time logs for reporting
- Capacity Planning: Team capacity vs workload analysis
- Timeline View: Gantt-style project timelines with epic grouping
- Project Teams: Teams scoped to specific projects
- Team Roles: Lead, Member, Custom roles with granular permissions
- Project Members: Project-specific membership and roles
- Custom Roles: Define custom role permissions per project
- Organization Roles: Owner, Admin, Moderator, Member hierarchy
- Workspace Roles: Admin, Editor, Viewer permissions
- Space Roles: Admin/Master, Member, Viewer access levels
- Comments: Threaded conversations with @mentions
- Attachments: File uploads (20MB limit) with preview support
- Project Documents: PRDs, FRDs, Technical Specs, API Docs (5GB storage)
- AI Documentation: Auto-generate documentation from project context
- Notifications: Real-time updates for assignments, status changes, comments
- Audit Logs: Organization-level activity tracking
- Repository Linking: Connect GitHub repos to projects
- Commit Sync: Track commits and link to work items
- AI Code Documentation: Auto-generate code documentation from repositories
- Code Q&A: Ask questions about codebase with AI assistance
- File References: Deep linking to specific files and lines
- Usage Metering: Track traffic (GB), storage (GB/month), compute units
- Automated Billing: Monthly billing cycles with Razorpay integration
- E-Mandate: Automatic payment collection via Razorpay e-mandate
- Grace Periods: 14-day grace period before account suspension
- Account Suspension: Automatic suspension for non-payment
- Invoicing: Generated invoices with detailed usage breakdown
- Wallet System: Prepaid wallet for billing (optional)
- Multi-Currency: Support for different currencies
- Workflow AI: Analyze workflows, suggest improvements, generate templates
- Code Analysis: Ask questions about linked GitHub repositories
- Documentation Generation: Auto-create PRDs, technical specs, API docs
- Duplicate Detection: Identify potentially duplicate work items
- Risk Prediction: Proactive alerts for scope creep and deadline risks
- Sprint Planning: AI recommendations for capacity and prioritization
- Email Verification: Required for account access
- OAuth Support: Google and GitHub authentication
- Password Management: Reset, change password functionality
- Session Management: Secure session handling with Appwrite
- Server-Side Validation: Never trust client-provided organization IDs
- Billing Enforcement: Middleware blocks writes for suspended accounts
- Webhook Verification: Razorpay webhook signature validation
- Idempotency: Prevent duplicate billing operations
- Route Guards: Validate IDs before navigation
| Technology | Purpose | Version |
|---|---|---|
| Next.js | React framework with App Router and Server Components | 15.5.7 |
| TypeScript | Type-safe JavaScript | 5.x |
| React | UI library | 18.x |
| Tailwind CSS | Utility-first CSS framework | 3.4.1 |
| shadcn/ui | Re-usable component library built on Radix UI | Latest |
| Radix UI | Unstyled, accessible UI primitives | Various |
| Lucide React | Icon library | 0.454.0 |
| TanStack Query | Data fetching and caching (React Query) | 5.59.19 |
| TanStack Table | Headless table library | 8.20.5 |
| React Hook Form | Form state management | 7.53.1 |
| Zod | Schema validation | 3.23.8 |
| nuqs | Type-safe URL search params | 2.7.1 |
| Sonner | Toast notifications | 1.7.0 |
| Technology | Purpose | Version |
|---|---|---|
| Appwrite | Backend-as-a-Service (Auth, Database, Storage, Realtime) | 21.5.0 (client), 14.0.0 (server) |
| Hono | Lightweight web framework for API routes | 4.6.9 |
| node-appwrite | Server-side Appwrite SDK | 14.0.0 |
| Technology | Purpose | Version |
|---|---|---|
| Google Gemini API | AI assistance (workflow, code analysis, docs) | gemini-2.5-flash-lite |
| Razorpay | Payment gateway and e-mandate | 2.9.4 |
| GitHub API | Repository integration | Via fetch |
| Technology | Purpose | Version |
|---|---|---|
| Tiptap | Rich text editor | 2.11.5 |
| React Big Calendar | Calendar view | 1.14.1 |
| Recharts | Charting library | 2.13.3 |
| @xyflow/react | Flow diagram library | 12.10.0 |
| @visx/ | D3-based visualization primitives | 3.12.0 |
| @hello-pangea/dnd | Drag and drop | 17.0.0 |
| React Day Picker | Date picker | 8.10.1 |
| React Markdown | Markdown rendering | 10.1.0 |
| React Syntax Highlighter | Code syntax highlighting | 16.1.0 |
| Technology | Purpose | Version |
|---|---|---|
| jsPDF | PDF generation | 3.0.3 |
| docx | Word document generation | 9.5.1 |
| html-to-docx | HTML to Word conversion | 1.8.0 |
| marked | Markdown parsing | 17.0.0 |
| Technology | Purpose | Version |
|---|---|---|
| Vitest | Unit testing framework | 4.0.16 |
| Playwright | End-to-end testing | 1.57.0 |
| ESLint | Code linting | 8.x |
| tsx | TypeScript execution | 4.21.0 |
| Technology | Purpose | Version |
|---|---|---|
| date-fns | Date manipulation | 3.0.0 |
| clsx | Conditional className utility | 2.1.1 |
| tailwind-merge | Tailwind class merging | 2.5.4 |
| class-variance-authority | Variant-based styling | 0.7.0 |
| idb | IndexedDB wrapper | 8.0.3 |
| dotenv | Environment variable loading | 17.2.3 |
Before you begin, ensure you have:
- Node.js 18.17 or later
- Package Manager: npm, yarn, pnpm, or bun
- Appwrite Instance: Cloud account or self-hosted Appwrite server
- Gemini API Key: For AI features (get from Google AI Studio)
- (Optional) Razorpay Account: For billing features
git clone https://github.com/Happyesss/Fairlx.git
cd Fairlxnpm install
# or
yarn install
# or
pnpm install
# or
bun install-
Create an Appwrite Project
- Go to Appwrite Cloud or your self-hosted instance
- Create a new project
- Copy the Project ID and API Endpoint
-
Generate API Key
- Navigate to Project Settings β API Keys
- Create a new API key with all scopes
- Copy the API Key (keep it secure)
-
Create Database and Collections
- Follow the complete setup guide: md/APPWRITE_SETUP.md
- Or use the detailed schema reference: md/APPWRITE_GUIDE.md
- Required Collections: 35+ collections (workspaces, members, projects, tasks, spaces, workflows, etc.)
- Required Buckets: 3 buckets (images, attachments_bucket, project-docs)
Create a .env.local file in the project root:
# App Configuration
NEXT_PUBLIC_APP_URL=http://localhost:3000
# Appwrite Configuration
NEXT_PUBLIC_APPWRITE_ENDPOINT=https://cloud.appwrite.io/v1
NEXT_PUBLIC_APPWRITE_PROJECT=your_project_id_here
NEXT_APPWRITE_KEY=your_api_key_here
NEXT_PUBLIC_APPWRITE_DATABASE_ID=your_database_id
# AI Configuration (Gemini)
GEMINI_API_KEY=your_gemini_api_key_here
# ===============================
# Core Collections
# ===============================
NEXT_PUBLIC_APPWRITE_WORKSPACES_ID=workspaces
NEXT_PUBLIC_APPWRITE_MEMBERS_ID=members
NEXT_PUBLIC_APPWRITE_PROJECTS_ID=projects
NEXT_PUBLIC_APPWRITE_TASKS_ID=tasks
NEXT_PUBLIC_APPWRITE_TIME_LOGS_ID=time_logs
NEXT_PUBLIC_APPWRITE_SPRINTS_ID=sprints
NEXT_PUBLIC_APPWRITE_WORK_ITEMS_ID=work_items
NEXT_PUBLIC_APPWRITE_PERSONAL_BACKLOG_ID=personal_backlog
NEXT_PUBLIC_APPWRITE_SUBTASKS_ID=subtasks
# Custom Columns & Settings
NEXT_PUBLIC_APPWRITE_CUSTOM_COLUMNS_ID=custom_columns
NEXT_PUBLIC_APPWRITE_DEFAULT_COLUMN_SETTINGS_ID=default_column_settings
# Notifications
NEXT_PUBLIC_APPWRITE_NOTIFICATIONS_ID=notifications
# Storage Buckets
NEXT_PUBLIC_APPWRITE_IMAGES_BUCKET_ID=images
NEXT_PUBLIC_APPWRITE_ATTACHMENTS_BUCKET_ID=attachments_bucket
NEXT_PUBLIC_APPWRITE_PROJECT_DOCS_BUCKET_ID=project-docs
# Attachments & Comments
NEXT_PUBLIC_APPWRITE_ATTACHMENTS_ID=attachments
NEXT_PUBLIC_APPWRITE_COMMENTS_ID=comments
# ===============================
# Spaces & Workflows
# ===============================
NEXT_PUBLIC_APPWRITE_SPACES_ID=spaces
NEXT_PUBLIC_APPWRITE_SPACE_MEMBERS_ID=space_members
NEXT_PUBLIC_APPWRITE_WORKFLOWS_ID=workflows
NEXT_PUBLIC_APPWRITE_WORKFLOW_STATUSES_ID=workflow_statuses
NEXT_PUBLIC_APPWRITE_WORKFLOW_TRANSITIONS_ID=workflow_transitions
# Custom Fields
NEXT_PUBLIC_APPWRITE_CUSTOM_FIELDS_ID=custom_fields
NEXT_PUBLIC_APPWRITE_CUSTOM_WORK_ITEM_TYPES_ID=custom_work_item_types
# Work Item Links
NEXT_PUBLIC_APPWRITE_WORK_ITEM_LINKS_ID=work_item_links
# Saved Views
NEXT_PUBLIC_APPWRITE_SAVED_VIEWS_ID=saved_views
# ===============================
# Teams & Programs
# ===============================
NEXT_PUBLIC_APPWRITE_PROGRAMS_ID=programs
NEXT_PUBLIC_APPWRITE_PROGRAM_MEMBERS_ID=program_members
NEXT_PUBLIC_APPWRITE_PROGRAM_MILESTONES_ID=program_milestones
# Project Teams
NEXT_PUBLIC_APPWRITE_PROJECT_TEAMS_ID=project_teams
NEXT_PUBLIC_APPWRITE_PROJECT_TEAM_MEMBERS_ID=project_team_members
NEXT_PUBLIC_APPWRITE_PROJECT_MEMBERS_ID=project_members
NEXT_PUBLIC_APPWRITE_PROJECT_ROLES_ID=project_roles
NEXT_PUBLIC_APPWRITE_PROJECT_PERMISSIONS_ID=project_permissions
NEXT_PUBLIC_APPWRITE_CUSTOM_ROLES_ID=custom_roles
# ===============================
# Organizations & Account Management
# ===============================
NEXT_PUBLIC_APPWRITE_ORGANIZATIONS_ID=organizations
NEXT_PUBLIC_APPWRITE_ORGANIZATION_MEMBERS_ID=organization_members
NEXT_PUBLIC_APPWRITE_ORGANIZATION_AUDIT_LOGS_ID=organization_audit_logs
NEXT_PUBLIC_APPWRITE_LOGIN_TOKENS_ID=login_tokens
# Departments
NEXT_PUBLIC_APPWRITE_DEPARTMENTS_ID=departments
NEXT_PUBLIC_APPWRITE_ORG_MEMBER_DEPARTMENTS_ID=org_member_departments
NEXT_PUBLIC_APPWRITE_DEPARTMENT_PERMISSIONS_ID=department_permissions
NEXT_PUBLIC_APPWRITE_ORG_MEMBER_PERMISSIONS_ID=org_member_permissions
# ===============================
# GitHub Integration
# ===============================
NEXT_PUBLIC_APPWRITE_GITHUB_REPOS_ID=github_repos
NEXT_PUBLIC_APPWRITE_CODE_DOCS_ID=code_docs
# GitHub Personal Access Token (optional, for higher rate limits)
GH_PERSONAL_TOKEN=your_github_token_here
# ===============================
# Project Documents
# ===============================
NEXT_PUBLIC_APPWRITE_PROJECT_DOCS_ID=project_docs
# ===============================
# Billing & Usage Tracking
# ===============================
NEXT_PUBLIC_APPWRITE_USAGE_EVENTS_ID=usage_events
NEXT_PUBLIC_APPWRITE_USAGE_AGGREGATIONS_ID=usage_aggregations
NEXT_PUBLIC_APPWRITE_USAGE_ALERTS_ID=usage_alerts
NEXT_PUBLIC_APPWRITE_STORAGE_SNAPSHOTS_ID=storage_snapshots
NEXT_PUBLIC_APPWRITE_INVOICES_ID=invoices
NEXT_PUBLIC_APPWRITE_BILLING_ACCOUNTS_ID=billing_accounts
NEXT_PUBLIC_APPWRITE_BILLING_AUDIT_LOGS_ID=billing_audit_logs
NEXT_PUBLIC_APPWRITE_PROCESSED_EVENTS_ID=processed_events
# Wallet (optional)
NEXT_PUBLIC_APPWRITE_WALLETS_ID=wallets
NEXT_PUBLIC_APPWRITE_WALLET_TRANSACTIONS_ID=wallet_transactions
NEXT_PUBLIC_APPWRITE_BILLING_SETTINGS_ID=billing_settings
# ===============================
# Razorpay Configuration (Optional)
# ===============================
RAZORPAY_KEY_ID=your_razorpay_key_id
RAZORPAY_KEY_SECRET=your_razorpay_key_secret
RAZORPAY_WEBHOOK_SECRET=your_webhook_secret
RAZORPAY_BASE_PLAN_ID=your_plan_id
# Exchange Rate API (optional)
EXCHANGE_RATE_API_KEY=your_exchange_rate_api_key
# ===============================
# Billing Configuration
# ===============================
BILLING_GRACE_PERIOD_DAYS=14
BILLING_CURRENCY=INR
USAGE_RATE_TRAFFIC_GB=0.10
USAGE_RATE_STORAGE_GB_MONTH=0.05
USAGE_RATE_COMPUTE_UNIT=0.001
# eMandate Feature Flag
ENABLE_EMANDATE=false
# Cron Secret (for automated billing)
CRON_SECRET=your_secure_cron_secret
# ===============================
# Email/Messaging (Optional)
# ===============================
NEXT_PUBLIC_APPWRITE_SMTP_PROVIDER_ID=smtp_provider
NEXT_PUBLIC_APPWRITE_EMAIL_TOPIC_ID=email_topicNote: See
.env.examplefor the complete template with all environment variables.
npm run dev
# or
yarn dev
# or
pnpm dev
# or
bun devOpen http://localhost:3000 in your browser.
- Navigate to http://localhost:3000
- Click "Sign Up" and create an account
- Verify your email (check Appwrite email settings)
- Choose account type: Personal or Organization
- Complete the onboarding flow
- Create your first workspace
For real-time WebSocket notifications (alternative to Appwrite Realtime):
npm run dev # Uses tsx server.ts automaticallyThe custom server (server.ts) runs both Next.js and Socket.IO on port 3000.
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β CLIENT (Browser) β
β β
β ββββββββββββββββ ββββββββββββββββ ββββββββββββββββ β
β β Next.js 15 β β React 18 β β TailwindCSS β β
β β App Router β β Components β β shadcn/ui β β
β ββββββββββββββββ ββββββββββββββββ ββββββββββββββββ β
β β β β β
β ββββββββββΌβββββββββββββββββββΌβββββββββββββββββββΌβββββββββ β
β β TanStack Query (State Management) β β
β ββββββββββ¬βββββββββββββββββββ¬ββββββββββββββββββββββββββββ β
βββββββββββββΌβββββββββββββββββββΌββββββββββββββββββββββββββββββββ
β β
ββββββββββΌβββββββ ββββββββββΌβββββββββ
β Hono API β β Server Actions β
β Routes β β (RSC) β
ββββββββββ¬βββββββ ββββββββββ¬βββββββββ
β β
ββββββββββΌβββββββββββββββββββΌβββββββββββββ
β Appwrite Backend β
β ββββββββββββ ββββββββββββ ββββββββ β
β β Auth β β Database β β Storeβ β
β ββββββββββββ ββββββββββββ ββββββββ β
ββββββββββββββββββββββββββββββββββββββββββ
β β
ββββββββββΌββββββ ββββββββββΌβββββββ
β Gemini API β β Razorpay API β
β (AI Features)β β (Billing) β
ββββββββββββββββ βββββββββββββββββ
-
User Authentication
User β Next.js Auth Pages β Appwrite Auth API β Session Cookie β AccountLifecycleProvider β Context Available -
Account Lifecycle
Login β Check Verification β Check Onboarding β Check Billing Status β Route to Appropriate Page (Verify/Onboard/Dashboard/Billing) -
Data Fetching
Component β TanStack Query Hook β Hono API Route β Appwrite SDK β Database β Response Cache β UI Update -
Data Mutation
Form Submit β Zod Validation β Mutation Hook β Hono API Route β Billing Enforcement Check β Appwrite SDK β Database Write β Optimistic Update β Query Invalidation β UI Refresh -
Usage Tracking
User Action β Track Usage Utility β Create Usage Event β Daily Aggregation (Cron) β Monthly Invoice Generation β Razorpay Payment β Webhook β Update Billing Status -
AI Workflow
User Prompt β AI Assistant Component β Hono API Route β Gemini API Request β Parse Response β Validate Schema β Apply Changes β Database Update β UI Refresh
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β USER ACCOUNT β
β βββββββββββββββββββ ββββββββββββββββββββ β
β β PERSONAL β OR β ORGANIZATION β β
β β Single user β β Multi-user β β
β β No billing β β Shared billing β β
β ββββββββββ¬βββββββββ ββββββββββ¬ββββββββββ β
βββββββββββββΌβββββββββββββββββββββββββββββββΌβββββββββββββ
β β
ββββββββββββββββ¬ββββββββββββββββ
β
ββββββββββββββββΌβββββββββββββββ
β WORKSPACES β
β Multiple per account β
β UI Mode: Simple/Advanced β
ββββββββββββββββ¬βββββββββββββββ
β
ββββββββββββββββΌβββββββββββββββ
β SPACES β
β (Optional intermediate) β
β Department/Product/Client β
ββββββββββββββββ¬βββββββββββββββ
β
ββββββββββββββββΌβββββββββββββββ
β PROJECTS β
β Scrum/Kanban/Hybrid β
β Custom workflows β
β Teams, Sprints, GitHub β
ββββββββββββββββ¬βββββββββββββββ
β
ββββββββββββββββββββΌβββββββββββββββββββ
β β β
βββββββββΌβββββββββ ββββββββΌββββββββ ββββββββΌββββββββ
β WORK ITEMS β β SPRINTS β β TEAMS β
β Tasks, Stories β β Planning β β Members β
β Bugs, Epics β β Active β β Roles β
β Custom Fields β β Completed β β Permissions β
ββββββββββ¬ββββββββ ββββββββββββββββ ββββββββββββββββ
β
ββββββΌβββββ
βSUBTASKS β
β Details β
βββββββββββ
ORGANIZATION (Org accounts only)
βββ Owner β Full control, billing, delete org
βββ Admin β Manage members, settings
βββ Moderator β Content management
βββ Member β Basic access
β
ββ WORKSPACE
βββ Admin β Full workspace control
βββ Editor β Create/edit content
βββ Viewer β Read-only
β
ββ SPACE
βββ Admin/Master β Full space control
βββ Member β Standard access
βββ Viewer β Read-only
β
ββ PROJECT
βββ Admin β Full project control
βββ Manager β Manage sprints, assign
βββ Developer β Work on tasks
βββ Viewer β Read-only
β
ββ TEAM
βββ Lead β Team leadership
βββ Member β Team participation
βββ Custom β Custom role
Fairlx/
βββ public/ # Static assets
β βββ Logo.png # Application logo
β βββ favicon.png # Favicon
β βββ apple-touch-icon.png # iOS icon
β
βββ docs/ # Additional documentation
β βββ APPWRITE_ORGANIZATIONS_SETUP.md
β βββ DATABASE_UPDATES.md
β βββ FEATURES_COMPLETE.md
β βββ SPACES_GUIDE.md
β βββ SPACES_TESTING_GUIDE.md
β
βββ md/ # Setup and migration guides
β βββ APPWRITE_GUIDE.md # Complete schema reference
β βββ APPWRITE_SETUP.md # Setup instructions
β βββ MIGRATION_SETUP.md # Migration procedures
β
βββ src/
β βββ app/ # Next.js App Router
β β βββ (auth)/ # Authentication routes
β β β βββ sign-in/ # Sign-in page
β β β βββ sign-up/ # Sign-up page
β β β βββ verify-email/ # Email verification
β β β βββ forgot-password/ # Password reset request
β β β βββ reset-password/ # Password reset form
β β β βββ onboarding/ # Onboarding flow
β β β
β β βββ (dashboard)/ # Main application routes
β β β βββ organization/ # Organization management
β β β β βββ settings/ # Org settings
β β β β βββ members/ # Member management
β β β β βββ billing/ # Billing dashboard
β β β β βββ usage/ # Usage analytics
β β β βββ profile/ # User profile
β β β βββ welcome/ # Welcome page
β β β βββ workspaces/ # Workspace routes
β β β βββ [workspaceId]/
β β β βββ settings/ # Workspace settings
β β β βββ members/ # Workspace members
β β β βββ spaces/ # Spaces management
β β β β βββ [spaceId]/
β β β β βββ settings/
β β β β βββ projects/
β β β βββ programs/ # Programs management
β β β βββ projects/ # Projects
β β β βββ [projectId]/
β β β βββ tasks/
β β β βββ board/
β β β βββ list/
β β β βββ calendar/
β β β βββ timeline/
β β β βββ sprints/
β β β βββ workflows/
β β β βββ teams/
β β β βββ settings/
β β β βββ github/
β β β
β β βββ (standalone)/ # Standalone pages
β β β βββ account-suspended/ # Suspension notice
β β β
β β βββ 403/ # Forbidden page
β β βββ api/ # API routes (Hono)
β β β βββ [[...route]]/ # Catch-all API router
β β βββ auth/ # Auth callbacks
β β β βββ callback/ # OAuth callback
β β βββ oauth/ # OAuth handlers
β β βββ fonts/ # Custom fonts
β β βββ globals.css # Global styles
β β βββ layout.tsx # Root layout
β β βββ page.tsx # Home/redirect page
β β βββ loading.tsx # Global loading state
β β βββ error.tsx # Global error boundary
β β βββ not-found.tsx # 404 page
β β βββ apple-icon.tsx # Dynamic iOS icon
β β βββ icon.tsx # Dynamic favicon
β β
β βββ components/ # Shared React components
β β βββ ui/ # shadcn/ui primitives
β β β βββ accordion.tsx
β β β βββ alert-dialog.tsx
β β β βββ avatar.tsx
β β β βββ badge.tsx
β β β βββ button.tsx
β β β βββ calendar.tsx
β β β βββ card.tsx
β β β βββ checkbox.tsx
β β β βββ collapsible.tsx
β β β βββ dialog.tsx
β β β βββ dropdown-menu.tsx
β β β βββ form.tsx
β β β βββ input.tsx
β β β βββ label.tsx
β β β βββ popover.tsx
β β β βββ progress.tsx
β β β βββ radio-group.tsx
β β β βββ scroll-area.tsx
β β β βββ select.tsx
β β β βββ separator.tsx
β β β βββ sheet.tsx
β β β βββ switch.tsx
β β β βββ table.tsx
β β β βββ tabs.tsx
β β β βββ textarea.tsx
β β β βββ toast.tsx
β β β βββ toaster.tsx
β β β βββ tooltip.tsx
β β β
β β βββ skeletons/ # Loading skeleton components
β β β βββ card-skeleton.tsx
β β β βββ list-skeleton.tsx
β β β βββ table-skeleton.tsx
β β β
β β βββ editor/ # Rich text editor components
β β β βββ tiptap-editor.tsx
β β β
β β βββ account-lifecycle-provider.tsx # Account state management
β β βββ analytics-card.tsx # Analytics display
β β βββ analytics.tsx # Analytics dashboard
β β βββ app-readiness-provider.tsx # App initialization
β β βββ billing-entity-badge.tsx # Billing status badge
β β βββ breadcrumb.tsx # Navigation breadcrumbs
β β βββ date-picker.tsx # Date selection
β β βββ dotted-separator.tsx # Visual separator
β β βββ draft-cleanup.tsx # Draft management
β β βββ empty-state-with-guide.tsx # Empty state with help
β β βββ global-app-loader.tsx # Global loading state
β β βββ help-tooltip.tsx # Contextual help
β β βββ hierarchy-diagram.tsx # Org structure diagram
β β βββ icon-help.tsx # Icon with help text
β β βββ lifecycle-guard.tsx # Lifecycle routing
β β βββ mobile-sidebar.tsx # Mobile navigation
β β βββ mode-toggle.tsx # Dark mode toggle
β β βββ navbar.tsx # Top navigation bar
β β βββ navigation.tsx # Main navigation
β β βββ onboarding-stepper.tsx # Onboarding wizard
β β βββ page-error.tsx # Page-level error
β β βββ page-loader.tsx # Page loading state
β β βββ permission-guard.tsx # Permission checking
β β βββ ProfileSidebar.tsx # Profile menu
β β βββ project-permission-guard.tsx # Project permissions
β β βββ project-permissions-editor.tsx # Permission editor
β β βββ project-rbac-test.tsx # RBAC testing
β β βββ project-tools.tsx # Project utilities
β β βββ projects.tsx # Projects list
β β βββ query-provider.tsx # TanStack Query setup
β β βββ responsive-modal.tsx # Responsive modal
β β βββ Separator.tsx # Visual separator
β β βββ setting-navigation.tsx # Settings nav
β β βββ sidebar.tsx # Main sidebar
β β βββ spaces.tsx # Spaces navigation
β β βββ task-details-modal.tsx # Task details
β β βββ theme-provider.tsx # Theme management
β β βββ tools.tsx # Utility tools
β β βββ workspace-switcher.tsx # Workspace selector
β β
β βββ features/ # Feature modules (modular by domain)
β β βββ attachments/ # File attachment management
β β βββ audit-logs/ # Activity logging
β β βββ auth/ # Authentication & authorization
β β βββ billing/ # Billing and invoicing
β β βββ comments/ # Comments and discussions
β β βββ currency/ # Currency handling
β β βββ custom-columns/ # Custom kanban columns
β β βββ custom-fields/ # Custom field definitions
β β βββ default-column-settings/ # Default column configs
β β βββ departments/ # Organization departments
β β βββ github-integration/ # GitHub repo integration
β β βββ members/ # Workspace membership
β β βββ notifications/ # Notification system
β β βββ onboarding/ # User onboarding
β β βββ org-permissions/ # Organization permissions
β β βββ organizations/ # Organization management
β β βββ personal-backlog/ # Personal work items
β β βββ programs/ # Program management
β β βββ project-docs/ # Project documentation
β β βββ project-members/ # Project membership
β β βββ project-teams/ # Project teams
β β βββ projects/ # Project management
β β βββ roles/ # Custom roles
β β βββ saved-views/ # Saved filters/views
β β βββ spaces/ # Spaces management
β β βββ sprints/ # Sprint management
β β βββ subtasks/ # Subtask management
β β βββ tasks/ # Task/work item management
β β βββ time-tracking/ # Time logging
β β βββ timeline/ # Timeline/Gantt view
β β βββ usage/ # Usage tracking
β β βββ user-access/ # User access control
β β βββ wallet/ # Wallet system
β β βββ work-item-links/ # Work item relationships
β β βββ workflows/ # Custom workflows + AI
β β βββ workspaces/ # Workspace management
β β
β β # Each feature module typically contains:
β β # βββ api/ # TanStack Query hooks
β β # βββ components/ # Feature-specific components
β β # βββ hooks/ # Feature-specific hooks
β β # βββ server/ # Hono API routes
β β # βββ types.ts # TypeScript types
β β # βββ schemas.ts # Zod validation schemas
β β
β βββ hooks/ # Shared custom hooks
β β βββ use-confirm.tsx # Confirmation dialog hook
β β βββ use-debounce.ts # Debounce utility hook
β β βββ use-permission.ts # Permission checking hook
β β
β βββ lib/ # Core utility libraries
β β βββ appwrite.ts # Appwrite client initialization
β β βββ billing-enforcement.ts # Billing middleware
β β βββ billing-utils.ts # Billing utilities
β β βββ organization-utils.ts # Organization helpers
β β βββ permission-matrix.ts # Permission definitions
β β βββ permissions.ts # Permission constants
β β βββ project-rbac.ts # Project-level RBAC
β β βββ query-config.ts # Query cache configuration
β β βββ rbac.ts # RBAC implementation
β β βββ route-utils.ts # Safe navigation utilities
β β βββ session-middleware.ts # Session validation
β β βββ track-usage.ts # Usage tracking
β β βββ usage-aggregation.ts # Usage aggregation logic
β β βββ usage-billing.ts # Usage billing logic
β β βββ utils.ts # General utilities
β β
β βββ types/ # Shared TypeScript types
β β βββ *.d.ts # Global type definitions
β β
β βββ config.ts # Environment configuration
β
βββ middleware.ts # Next.js middleware (auth)
βββ server.ts # Custom server (Socket.IO)
βββ components.json # shadcn/ui configuration
βββ tailwind.config.ts # Tailwind CSS config
βββ next.config.mjs # Next.js configuration
βββ next-env.d.ts # Next.js types
βββ tsconfig.json # TypeScript config
βββ tsconfig.server.json # Server TypeScript config
βββ vitest.config.ts # Vitest configuration
βββ playwright.config.ts # Playwright configuration
βββ postcss.config.mjs # PostCSS configuration
βββ package.json # Dependencies and scripts
βββ .env.example # Environment template
βββ .gitignore # Git ignore rules
βββ README.md # This file
βββ CONTRIBUTING.md # Contribution guidelines
βββ CODE_OF_CONDUCT.md # Code of conduct
βββ changelog.md # Changelog
βββ DATABASE_UPDATES.md # Database updates log
βββ PROGRAMS_IMPLEMENTATION_GUIDE.md # Programs guide
| Variable | Purpose | Example |
|---|---|---|
NEXT_PUBLIC_APP_URL |
Application base URL | http://localhost:3000 |
NEXT_PUBLIC_APPWRITE_ENDPOINT |
Appwrite API endpoint | https://cloud.appwrite.io/v1 |
NEXT_PUBLIC_APPWRITE_PROJECT |
Appwrite project ID | my-project-id |
NEXT_APPWRITE_KEY |
Appwrite server API key | secret-api-key |
NEXT_PUBLIC_APPWRITE_DATABASE_ID |
Main database ID | main-database |
GEMINI_API_KEY |
Google Gemini API key for AI features | AIza... |
All collection IDs must be configured. See .env.example for the complete list including:
- Core Collections: workspaces, members, projects, tasks, sprints, etc.
- Spaces & Workflows: spaces, workflows, workflow_statuses, workflow_transitions
- Custom Features: custom_fields, custom_columns, saved_views
- Teams & Programs: programs, project_teams, project_members, roles
- Organizations: organizations, organization_members, departments
- Billing & Usage: usage_events, invoices, billing_accounts
- Collaboration: comments, attachments, notifications
- Integration: github_repos, code_docs, project_docs
| Variable | Purpose | Max Size |
|---|---|---|
NEXT_PUBLIC_APPWRITE_IMAGES_BUCKET_ID |
User avatars, workspace images | N/A |
NEXT_PUBLIC_APPWRITE_ATTACHMENTS_BUCKET_ID |
Task attachments | 20MB per file |
NEXT_PUBLIC_APPWRITE_PROJECT_DOCS_BUCKET_ID |
Project documentation files | 5GB total |
| Variable | Purpose | Default |
|---|---|---|
RAZORPAY_KEY_ID |
Razorpay public key | - |
RAZORPAY_KEY_SECRET |
Razorpay secret key | - |
RAZORPAY_WEBHOOK_SECRET |
Razorpay webhook verification | - |
BILLING_GRACE_PERIOD_DAYS |
Days before suspension | 14 |
BILLING_CURRENCY |
Default currency | INR |
USAGE_RATE_TRAFFIC_GB |
Cost per GB traffic (cents) | 0.10 |
USAGE_RATE_STORAGE_GB_MONTH |
Cost per GB/month storage (cents) | 0.05 |
USAGE_RATE_COMPUTE_UNIT |
Cost per compute unit (cents) | 0.001 |
ENABLE_EMANDATE |
Enable Razorpay e-mandate | false |
CRON_SECRET |
Secret for cron endpoints | - |
| Variable | Purpose | Default |
|---|---|---|
GH_PERSONAL_TOKEN |
GitHub personal access token for higher rate limits | - |
| Variable | Purpose | Default |
|---|---|---|
NEXT_PUBLIC_APPWRITE_SMTP_PROVIDER_ID |
SMTP provider ID in Appwrite | - |
NEXT_PUBLIC_APPWRITE_EMAIL_TOPIC_ID |
Email notification topic ID | - |
Fairlx is built with a modular feature architecture. Each feature is self-contained with its own API, components, hooks, server routes, types, and schemas.
src/features/{feature-name}/
βββ api/ # TanStack Query hooks
β βββ use-get-*.ts # Query hooks (data fetching)
β βββ use-create-*.ts # Mutation hooks (create)
β βββ use-update-*.ts # Mutation hooks (update)
β βββ use-delete-*.ts # Mutation hooks (delete)
βββ components/ # React components
β βββ *-form.tsx # Form components
β βββ *-list.tsx # List views
β βββ *-card.tsx # Card views
β βββ *-modal.tsx # Modal dialogs
βββ hooks/ # Custom hooks
β βββ use-*.ts # Feature-specific hooks
β βββ use-*-modal.ts # Modal state hooks
βββ server/ # API routes (Hono)
β βββ route.ts # Hono route definitions
βββ types.ts # TypeScript type definitions
βββ schemas.ts # Zod validation schemas
βββ constants.ts # Constants (optional)
βββ utils.ts # Utility functions (optional)
βββ queries.ts # Server-side queries (optional)
| Feature | Description | Key Files |
|---|---|---|
| auth | Authentication, OAuth, email verification, password management | api/use-login.ts, api/use-register.ts, components/sign-in-card.tsx |
| organizations | Multi-tenant organization management with billing | api/use-get-organization.ts, server/route.ts, types.ts |
| workspaces | Workspace CRUD with UI modes and feature toggles | api/use-get-workspaces.ts, components/create-workspace-form.tsx |
| spaces | Logical containers with unique keys for work item prefixing | api/use-get-spaces.ts, components/create-space-form.tsx |
| projects | Project management with board types and GitHub integration | api/use-get-project.ts, components/edit-project-form.tsx |
| tasks | Work items (Tasks, Stories, Bugs, Epics) with custom fields | api/use-get-task.ts, components/task-view-switcher.tsx |
| members | Workspace membership and role management | api/use-get-members.ts, components/members-list.tsx |
| programs | Cross-team program management with status tracking | api/use-get-programs.ts, components/create-program-form.tsx |
| onboarding | User onboarding flow with account type selection | hooks/use-onboarding-state.ts, components/onboarding-stepper.tsx |
| user-access | User access control and permission management | api/use-get-user-access.ts |
| Feature | Description | Key Files |
|---|---|---|
| sprints | Sprint planning with velocity and burndown tracking | api/use-get-sprint.ts, components/sprint-board.tsx |
| subtasks | Hierarchical subtask management | api/use-get-subtasks.ts, components/subtask-list.tsx |
| work-item-links | 8 relationship types (blocks, relates, duplicates, etc.) | api/use-get-links.ts, types.ts |
| personal-backlog | Personal work queue independent of projects | api/use-get-backlog.ts |
| saved-views | Custom filters for Kanban/List/Calendar/Timeline | api/use-get-views.ts, components/view-selector.tsx |
| timeline | Gantt-style project timelines | components/timeline-view.tsx |
| Feature | Description | Key Files |
|---|---|---|
| workflows | Custom status flows with AI assistance | api/use-get-workflow.ts, components/workflow-builder.tsx |
| custom-fields | 10+ field types (text, number, date, select, etc.) | api/use-get-fields.ts, types.ts |
| custom-columns | Kanban column customization | api/use-get-columns.ts |
| default-column-settings | Default column configurations | api/use-get-default-columns.ts |
| roles | Custom role definitions with permission sets | api/use-get-roles.ts, components/role-editor.tsx |
| Feature | Description | Key Files |
|---|---|---|
| project-teams | Project-scoped team management | api/use-get-teams.ts, components/create-team-form.tsx |
| project-members | Project membership and roles | api/use-get-project-members.ts |
| departments | Organization-level department grouping | api/use-get-departments.ts |
| org-permissions | Organization permission management | api/use-get-org-permissions.ts |
| Feature | Description | Key Files |
|---|---|---|
| comments | Threaded comments with @mentions | api/use-get-comments.ts, components/comment-list.tsx |
| attachments | File uploads (20MB limit) | api/use-upload-attachment.ts |
| project-docs | Rich documentation with AI chat | api/use-get-docs.ts, components/doc-editor.tsx |
| notifications | Real-time notification system | api/use-get-notifications.ts, components/notification-panel.tsx |
| Feature | Description | Key Files |
|---|---|---|
| github-integration | GitHub repo linking with AI docs | api/use-get-repos.ts, lib/gemini-api.ts |
| audit-logs | Organization activity logging | api/use-get-audit-logs.ts |
| usage | Usage metering for billing | api/use-get-usage.ts, lib/track-usage.ts |
| time-tracking | Time logging and variance analysis | api/use-create-time-log.ts |
| Feature | Description | Key Files |
|---|---|---|
| billing | Billing accounts and invoice management | api/use-get-billing-account.ts, server/route.ts |
| wallet | Prepaid wallet system | api/use-get-wallet.ts |
| currency | Multi-currency support | api/use-get-currency.ts |
Fairlx implements a hierarchical role-based access control (RBAC) system with permissions cascading down from organization to workspace to space to project to team.
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β LEVEL 1: ORGANIZATION (Org Accounts Only) β
β βββ OWNER β Full control, billing, delete org β
β βββ ADMIN β Manage members, settings, workspaces β
β βββ MODERATOR β Content management, limited admin β
β βββ MEMBER β Basic access to resources β
βββββββββββββββββββββββββ¬ββββββββββββββββββββββββββββββββββ
β
βββββββββββββββββββββββββΌββββββββββββββββββββββββββββββββββ
β LEVEL 2: WORKSPACE β
β βββ WS_ADMIN β Full workspace control β
β βββ WS_EDITOR β Create/edit projects, spaces, tasks β
β βββ WS_VIEWER β Read-only workspace access β
βββββββββββββββββββββββββ¬ββββββββββββββββββββββββββββββββββ
β
βββββββββββββββββββββββββΌββββββββββββββββββββββββββββββββββ
β LEVEL 3: SPACE (Optional) β
β βββ ADMIN/MASTER β Full space control β
β βββ MEMBER β Standard space access β
β βββ VIEWER β Read-only space access β
βββββββββββββββββββββββββ¬ββββββββββββββββββββββββββββββββββ
β
βββββββββββββββββββββββββΌββββββββββββββββββββββββββββββββββ
β LEVEL 4: PROJECT β
β βββ PROJECT_ADMIN β Full project control β
β βββ MANAGER β Manage sprints, assign tasks β
β βββ DEVELOPER β Work on assigned tasks β
β βββ VIEWER β Read-only project access β
βββββββββββββββββββββββββ¬ββββββββββββββββββββββββββββββββββ
β
βββββββββββββββββββββββββΌββββββββββββββββββββββββββββββββββ
β LEVEL 5: TEAM (Project-Scoped) β
β βββ LEAD β Team leadership and oversight β
β βββ MEMBER β Team participation β
β βββ CUSTOM β Custom role with specific perms β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
| Action | Owner | Admin | Moderator | Member |
|---|---|---|---|---|
| Delete organization | β | β | β | β |
| Manage billing | β | β | β | β |
| Add/remove admins | β | β | β | β |
| Add/remove members | β | β | β | β |
| Create workspaces | β | β | β | β |
| View audit logs | β | β | β | β |
| Manage departments | β | β | β | β |
| Action | WS_ADMIN | WS_EDITOR | WS_VIEWER |
|---|---|---|---|
| Delete workspace | β | β | β |
| Edit workspace settings | β | β | β |
| Add/remove members | β | β | β |
| Create spaces | β | β | β |
| Create projects | β | β | β |
| Create tasks | β | β | β |
| View all content | β | β | β |
| Action | PROJECT_ADMIN | MANAGER | DEVELOPER | VIEWER |
|---|---|---|---|---|
| Delete project | β | β | β | β |
| Edit project settings | β | β | β | β |
| Manage teams | β | β | β | β |
| Create sprints | β | β | β | β |
| Assign tasks | β | β | β | β |
| Update task status | β | β | β | β |
| Comment on tasks | β | β | β | β |
| View tasks | β | β | β | β |
| File | Purpose |
|---|---|
| src/lib/permissions.ts | Permission constant definitions |
| src/lib/permission-matrix.ts | Full permission matrix |
| src/lib/rbac.ts | RBAC utility functions |
| src/lib/project-rbac.ts | Project-level RBAC |
| src/components/permission-guard.tsx | React permission guard component |
| src/components/project-permission-guard.tsx | Project permission guard |
| src/lib/organization-utils.ts | Organization permission utilities |
All Hono API routes enforce permissions server-side:
// Example from src/features/projects/server/route.ts
app.delete("/:projectId", sessionMiddleware, async (c) => {
const user = c.get("user");
const { projectId } = c.req.param();
// Check project admin permission
const hasPermission = await checkProjectPermission(
user.$id,
projectId,
"DELETE_PROJECT"
);
if (!hasPermission) {
return c.json({ error: "Forbidden" }, 403);
}
// Proceed with deletion
// ...
});Fairlx implements a production-ready usage-based billing system with automated metering, invoicing, and account lifecycle management.
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β USER ACTIONS β
β File Upload β API Call β Storage β Database Query β
ββββββββββ¬ββββββββββββββ¬βββββββββββ¬βββββββββββββββββββββββ
β β β
βΌ βΌ βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β USAGE TRACKING (track-usage.ts) β
β Records events: traffic, storage, compute β
ββββββββββ¬βββββββββββββββββββββββββββββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β USAGE_EVENTS Collection (Appwrite) β
β { organizationId, type, amount, timestamp } β
ββββββββββ¬βββββββββββββββββββββββββββββββββββββββββββββββββ
β
βΌ (Daily Cron)
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β USAGE AGGREGATION (usage-aggregation.ts) β
β Daily rollup of events per organization β
ββββββββββ¬βββββββββββββββββββββββββββββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β USAGE_AGGREGATIONS Collection (Appwrite) β
β { date, organizationId, traffic, storage, compute } β
ββββββββββ¬βββββββββββββββββββββββββββββββββββββββββββββββββ
β
βΌ (Monthly Cron - 1st of month)
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β BILLING CYCLE (usage-billing.ts) β
β 1. Calculate costs from aggregations β
β 2. Create invoice β
β 3. Attempt payment via Razorpay β
ββββββββββ¬βββββββββββββββββββββββββββββββββββββββββββββββββ
β
ββ SUCCESS βββββββββββββββββββββββββββββββββββββββ
β β
βΌ βΌ
βββββββββββββββββββββββ ββββββββββββββββββββββββββββββ
β Invoice: PAID β β Account Status: ACTIVE β
β Billing Account: β β Full access granted β
β Status = ACTIVE β ββββββββββββββββββββββββββββββ
βββββββββββββββββββββββ
β
ββ FAILURE βββββββββββββββββββββββββββββββββββββββ
β
βΌ
ββββββββββββββββββββββββββββββ
β Invoice: FAILED β
β Account Status: DUE β
β Grace period starts (14d) β
βββββββββββ¬βββββββββββββββββββ
β
βΌ (Grace period expired)
ββββββββββββββββββββββββββββββ
β Account Status: SUSPENDED β
β Writes blocked β
β Reads allowed β
ββββββββββββββββββββββββββββββ
Three types of usage are tracked:
| Type | Measurement | Rate (Default) |
|---|---|---|
| Traffic | Data transfer (GB) | βΉ0.10 per GB |
| Storage | Storage used (GB/month) | βΉ0.05 per GB/month |
| Compute | Compute units (API calls, operations) | βΉ0.001 per unit |
-
Usage Tracking (Continuous)
- Every user action creates a usage event
- Events stored in
usage_eventscollection - Tracked: organizationId, type, amount, timestamp
-
Daily Aggregation (Cron - 1 AM UTC)
- Rollup events into daily totals
- Store in
usage_aggregationscollection - Cleanup old events (retention policy)
-
Monthly Billing Cycle (Cron - 1st of month)
- Calculate total usage from aggregations
- Generate invoice with breakdown
- Attempt Razorpay payment (e-mandate)
- Update account status
-
Grace Period (14 days default)
- Day 1: Payment failed, status β DUE
- Day 1: Send email notification
- Day 7: Send reminder email
- Day 13: Send final warning
- Day 14: Account suspended
-
Account Suspension
- Status β SUSPENDED
- Writes blocked (middleware enforcement)
- Reads allowed
- Billing page accessible for payment
-
Recovery
- User completes payment
- Status β ACTIVE
- Access restored immediately
Middleware prevents mutations for suspended accounts:
// src/lib/billing-enforcement.ts
export const mutationGuard = async (c: Context, next: () => Promise<void>) => {
const user = c.get("user");
// Check if organization account
if (user.prefs.accountType === "ORG") {
const billingAccount = await getBillingAccount(
user.prefs.primaryOrganizationId
);
if (billingAccount.status === "SUSPENDED") {
return c.json({ error: "Account suspended. Please update billing." }, 402);
}
}
await next();
};- E-Mandate: Automated monthly debit from customer's account
- Webhooks:
payment.captured,payment.failed,refund.processed - Signature Verification: All webhooks validated before processing
- Idempotency: Processed events registry prevents duplicate operations
| Variable | Purpose | Default |
|---|---|---|
BILLING_GRACE_PERIOD_DAYS |
Days before suspension | 14 |
BILLING_CURRENCY |
Invoice currency | INR |
USAGE_RATE_TRAFFIC_GB |
Cost per GB traffic (cents) | 0.10 |
USAGE_RATE_STORAGE_GB_MONTH |
Cost per GB/month storage (cents) | 0.05 |
USAGE_RATE_COMPUTE_UNIT |
Cost per compute unit (cents) | 0.001 |
ENABLE_EMANDATE |
Enable e-mandate | false |
| Collection | Purpose |
|---|---|
billing_accounts |
Organization billing accounts |
invoices |
Generated invoices with usage breakdown |
usage_events |
Raw usage events |
usage_aggregations |
Daily usage rollups |
storage_snapshots |
Storage usage snapshots |
billing_audit_logs |
Billing activity audit trail |
processed_events |
Idempotency registry |
usage_alerts |
Usage threshold alerts |
Fairlx integrates Google Gemini AI (gemini-2.5-flash-lite) for intelligent workflow assistance, code analysis, and documentation generation.
The Workflow AI Assistant helps build and optimize custom workflows:
-
Analyze Workflow
- Identifies orphaned statuses (no incoming transitions)
- Detects unreachable statuses (no path from initial status)
- Finds dead-end statuses (no outgoing transitions)
- Suggests improvements
-
Suggest New Statuses
- Analyzes current workflow context
- Recommends additional statuses based on project type
- Suggests icons and colors
- Provides justification
-
Suggest Transitions
- Recommends logical state transitions
- Suggests conditions and rules
- Proposes team-based restrictions
- Identifies approval requirements
-
Generate Workflow Templates
- Natural language workflow creation
- Example: "Create a software development workflow with code review"
- Generates complete workflow with statuses and transitions
-
Workflow Q&A
- Ask questions about workflow structure
- Get explanations for transitions
- Understand workflow logic
// src/features/workflows/server/route.ts
app.post("/:workflowId/ai/suggest-statuses", async (c) => {
const { workflowId } = c.req.param();
const workflow = await getWorkflow(workflowId);
const statuses = await getWorkflowStatuses(workflowId);
// Call Gemini API
const suggestions = await geminiSuggestStatuses({
workflowName: workflow.name,
existingStatuses: statuses,
projectContext: workflow.projectContext
});
return c.json({ suggestions });
});-
Auto-Generated Code Documentation
- Analyzes repository structure
- Generates comprehensive documentation
- Explains code architecture
- Documents key functions and classes
-
Code Q&A
- Ask questions about codebase
- Get explanations with file references
- Understand complex code patterns
- Deep link to specific files and lines
-
Commit Summarization
- Analyzes commit diffs
- Generates meaningful summaries
- Identifies breaking changes
- Categorizes changes (feat/fix/docs)
// src/features/github-integration/lib/gemini-api.ts
export async function analyzeRepository(repoContent: string) {
const response = await fetch(
`https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash-lite:generateContent?key=${GEMINI_API_KEY}`,
{
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
contents: [{
parts: [{
text: `Analyze this repository and generate documentation: ${repoContent}`
}]
}]
})
}
);
return await response.json();
}-
Auto-Generate PRDs
- Product Requirements Documents from project context
- Includes goals, features, user stories
- Technical requirements and constraints
-
Technical Specifications
- Architecture diagrams (text-based)
- Data models and schemas
- API documentation
- Integration details
-
API Documentation
- Endpoint documentation from code
- Request/response examples
- Authentication details
- Error handling
// Generate PRD
const prd = await generateDocument({
type: "PRD",
projectName: "Mobile App",
context: {
goals: ["User authentication", "Real-time chat"],
stakeholders: ["Product Manager", "Engineering Team"]
}
});| Variable | Purpose |
|---|---|
GEMINI_API_KEY |
Google Gemini API key (required for AI features) |
AI operations count as compute units for billing:
- Workflow analysis: 1 compute unit
- Status suggestion: 2 compute units
- Code documentation: 5-10 compute units (depends on repo size)
- Q&A query: 1 compute unit
| Command | Description |
|---|---|
npm run dev |
Start development server with custom server (port 3000) |
npm run dev:next-only |
Start Next.js only (without Socket.IO) |
npm run build |
Create production build |
npm run start |
Start production Next.js server |
npm run start:socket |
Start production custom server with Socket.IO |
npm run lint |
Run ESLint |
npm run test |
Run Vitest in watch mode |
npm run test:run |
Run Vitest once |
- Strict mode enabled: All code must satisfy TypeScript strict checks
- Explicit types: Prefer explicit type annotations over inference
- No
any: Use specific types orunknownif type is truly unknown - Type imports: Use
import typefor type-only imports
// Good
import type { User } from "@/types";
const user: User = await getUser(id);
// Bad
import { User } from "@/types";
const user = await getUser(id); // Relies on inference- Default to Server Components: Use unless client interactivity required
- Client Components: Only for interactivity, browser APIs, React hooks
- Mark with
"use client": At the top of client component files
// Client component (interactive)
"use client";
import { useState } from "react";
export function Counter() {
const [count, setCount] = useState(0);
return <button onClick={() => setCount(count + 1)}>{count}</button>;
}
// Server component (default)
export async function UserList() {
const users = await getUsers(); // Server-side data fetch
return <div>{users.map(u => <UserCard key={u.id} user={u} />)}</div>;
}- Utility-first: Use Tailwind utilities instead of custom CSS
- Responsive: Mobile-first responsive design
- Dark mode: Support light, dark, and pitch-dark themes
- Component composition: Compose utilities with
cn()helper
import { cn } from "@/lib/utils";
<div className={cn(
"px-4 py-2 rounded-lg",
"bg-white dark:bg-slate-800",
isActive && "border-2 border-blue-500"
)} />- Use existing components: Don't recreate primitives
- Extend with variants: Use
class-variance-authorityfor variations - Composition over props: Compose primitives instead of complex props
import { Button } from "@/components/ui/button";
// Good - composition
<Button variant="outline" size="sm">Click</Button>
// Bad - custom styling
<button className="...custom classes...">Click</button>- Session middleware: Always use for protected routes
- Zod validation: Validate all inputs
- Error handling: Return appropriate HTTP status codes
- Type safety: Use Hono's type inference
import { Hono } from "hono";
import { zValidator } from "@hono/zod-validator";
import { sessionMiddleware } from "@/lib/session-middleware";
import { createFeatureSchema } from "./schemas";
const app = new Hono()
.post(
"/",
sessionMiddleware,
zValidator("json", createFeatureSchema),
async (c) => {
const user = c.get("user");
const data = c.req.valid("json");
// Implementation
return c.json({ data: result });
}
);- Query hooks: For data fetching (GET operations)
- Mutation hooks: For data modification (POST/PATCH/DELETE)
- Query keys: Use consistent key structure
- Cache invalidation: Invalidate related queries after mutations
// Query hook
export const useGetFeatures = (workspaceId: string) => {
return useQuery({
queryKey: ["features", workspaceId],
queryFn: async () => {
const response = await client.api.features.$get({
query: { workspaceId }
});
return await response.json();
},
staleTime: 5 * 60 * 1000, // 5 minutes
});
};
// Mutation hook
export const useCreateFeature = () => {
const queryClient = useQueryClient();
return useMutation({
mutationFn: async (data: CreateFeatureData) => {
const response = await client.api.features.$post({ json: data });
return await response.json();
},
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ["features"] });
},
});
};- Safe navigation: Always use route utilities for navigation
- Validate IDs: Never navigate with undefined/invalid IDs
- Type safety: Route utilities provide compile-time type checking
import { buildWorkspaceRoute } from "@/lib/route-utils";
import { useRouter } from "next/navigation";
const router = useRouter();
// Good
const route = buildWorkspaceRoute(workspaceId, "/settings");
router.push(route);
// Bad
router.push(`/workspaces/${workspaceId}/settings`); // No validation- Validate size: Check file size before upload
- Validate type: Check MIME type
- Use buckets: Upload to appropriate Appwrite bucket
- Show progress: Display upload progress to user
const file = event.target.files[0];
// Validate
if (file.size > 20 * 1024 * 1024) {
toast.error("File too large (max 20MB)");
return;
}
// Upload
const result = await storage.createFile(
ATTACHMENTS_BUCKET_ID,
ID.unique(),
file
);- Formatting: Use Prettier defaults (enforced by ESLint)
- Naming:
- Components: PascalCase (
UserCard.tsx) - Hooks: camelCase with
useprefix (usePermission.ts) - Utilities: camelCase (
formatDate.ts) - Constants: UPPER_SNAKE_CASE (
MAX_FILE_SIZE)
- Components: PascalCase (
- Imports: Order by external β internal β relative
- Comments: Explain "why", not "what"
- Unit & Integration: Vitest
- End-to-End: Playwright
# Unit tests (watch mode)
npm run test
# Unit tests (single run)
npm run test:run
# E2E tests
npx playwright test
# E2E tests (headed mode)
npx playwright test --headed
# E2E tests (UI mode)
npx playwright test --uisrc/
βββ features/
β βββ {feature}/
β βββ __tests__/ # Feature tests
β β βββ api.test.ts # API tests
β β βββ utils.test.ts # Utility tests
β βββ ...
tests/
βββ e2e/ # Playwright tests
βββ auth.spec.ts
βββ workspace.spec.ts
βββ project.spec.ts
import { describe, it, expect } from "vitest";
import { formatDate } from "../utils";
describe("formatDate", () => {
it("formats date correctly", () => {
const date = new Date("2024-01-01");
expect(formatDate(date)).toBe("January 1, 2024");
});
});import { test, expect } from "@playwright/test";
test("user can create workspace", async ({ page }) => {
await page.goto("/");
await page.click("text=Create Workspace");
await page.fill("input[name='name']", "Test Workspace");
await page.click("button:has-text('Create')");
await expect(page.locator("text=Test Workspace")).toBeVisible();
});-
Import Repository
- Go to vercel.com/new
- Import your GitHub repository
-
Configure Environment
- Add all environment variables from
.env.example - Set
NEXT_PUBLIC_APP_URLto your Vercel domain
- Add all environment variables from
-
Deploy
- Vercel automatically builds and deploys
- Subsequent pushes to
maintrigger automatic deployments
FROM node:18-alpine AS base
# Install dependencies only when needed
FROM base AS deps
RUN apk add --no-cache libc6-compat
WORKDIR /app
COPY package.json package-lock.json ./
RUN npm ci
# Rebuild the source code only when needed
FROM base AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .
ENV NEXT_TELEMETRY_DISABLED 1
RUN npm run build
# Production image, copy all the files and run next
FROM base AS runner
WORKDIR /app
ENV NODE_ENV production
ENV NEXT_TELEMETRY_DISABLED 1
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs
COPY --from=builder /app/public ./public
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
USER nextjs
EXPOSE 3000
ENV PORT 3000
CMD ["node", "server.js"]# Build image
docker build -t fairlx .
# Run container
docker run -p 3000:3000 \
--env-file .env.local \
fairlxversion: "3.8"
services:
app:
build: .
ports:
- "3000:3000"
env_file:
- .env.local
restart: unless-stopped
# Optional: Appwrite (self-hosted)
appwrite:
image: appwrite/appwrite:1.4
ports:
- "80:80"
- "443:443"
volumes:
- appwrite-config:/storage/config
- appwrite-certificates:/storage/certificates
- appwrite-functions:/storage/functions
- appwrite-uploads:/storage/uploads
- appwrite-cache:/storage/cache
environment:
- _APP_ENV=production
- _APP_OPENSSL_KEY_V1=your-secret-key
- _APP_DOMAIN=your-domain.com
- _APP_DOMAIN_TARGET=your-domain.com
restart: unless-stopped
volumes:
appwrite-config:
appwrite-certificates:
appwrite-functions:
appwrite-uploads:
appwrite-cache:Ensure all required variables are set:
# Critical
NEXT_PUBLIC_APP_URL=https://your-domain.com
NEXT_PUBLIC_APPWRITE_ENDPOINT=https://cloud.appwrite.io/v1
NEXT_PUBLIC_APPWRITE_PROJECT=prod-project-id
NEXT_APPWRITE_KEY=prod-api-key
GEMINI_API_KEY=prod-gemini-key
# Billing (if enabled)
RAZORPAY_KEY_ID=prod-key
RAZORPAY_KEY_SECRET=prod-secret
RAZORPAY_WEBHOOK_SECRET=webhook-secret
CRON_SECRET=secure-cron-secret
# All collection and bucket IDs
# ... (see .env.example)We welcome contributions! Please read CONTRIBUTING.md for details on our code of conduct and development process.
- Fork the repository
- Create a feature branch:
git checkout -b feature/amazing-feature - Make your changes following the development guidelines
- Run tests:
npm run test && npm run lint - Commit:
git commit -m 'Add amazing feature' - Push:
git push origin feature/amazing-feature - Open a Pull Request
- π Bug fixes: Fix issues and edge cases
- β¨ Features: Add new capabilities
- π Documentation: Improve docs, add examples
- π¨ UI/UX: Enhance design and user experience
- β‘ Performance: Optimize speed and efficiency
- βΏ Accessibility: Improve a11y compliance
- π Internationalization: Add translations
| Feature | Implementation |
|---|---|
| Authentication | Appwrite Auth with email verification required |
| OAuth | Secure Google and GitHub OAuth integration |
| Password Security | Bcrypt hashing, reset via secure tokens |
| Session Management | HTTP-only cookies, automatic expiration |
| RBAC | Multi-level role-based access control |
| Billing Enforcement | Middleware blocks writes for suspended accounts |
| Server-side Validation | Never trust client-provided IDs or data |
| Webhook Verification | Razorpay signature validation |
| Idempotency | Prevent duplicate operations with event registry |
| Data Encryption | At rest (Appwrite) and in transit (HTTPS) |
| File Upload Validation | Size limits, type checking, antivirus scanning |
| Route Guards | Prevent navigation with invalid IDs |
| Environment Secrets | All secrets in .env.local, never committed |
Do not report security vulnerabilities via public GitHub issues.
To report a vulnerability:
- Email: security@fairlx.com (if available)
- Use GitHub's private vulnerability reporting
- Provide detailed information:
- Description of the vulnerability
- Steps to reproduce
- Potential impact
- Suggested fix (if any)
We will respond within 48 hours and work with you to address the issue.
This project is licensed under the MIT License - see the LICENSE file for details.
Fairlx is built with amazing open-source technologies:
- Next.js - React framework
- Appwrite - Backend-as-a-Service
- Radix UI - Unstyled, accessible UI primitives
- shadcn/ui - Re-usable component library
- Tailwind CSS - Utility-first CSS framework
- TanStack Query - Data fetching and caching
- Hono - Lightweight web framework
- Google Gemini - AI assistance
- Razorpay - Payment processing
- Vercel - Deployment platform
Special thanks to all contributors and the open-source community.
- Documentation: You're reading it!
- Issues: GitHub Issues
- Discussions: GitHub Discussions