You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -4,132 +4,175 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co
4
4
5
5
## Project Overview
6
6
7
-
BottleCRM is a SaaS CRM platform built with SvelteKit, designed for startups and enterprises with role-based access control (RBAC). The application features multi-tenancy through organizations, with strict data isolation enforced at the database level.
7
+
BottleCRM is a multi-tenant SaaS CRM platform built as a monorepo with SvelteKit, designed for startups and enterprises with role-based access control (RBAC). The application features organization-based multi-tenancy with strict data isolation enforced at the database level.
8
8
9
9
## Technology Stack
10
10
11
-
-**Frontend**: SvelteKit 2.x with Svelte 5.x
11
+
-**Frontend**: SvelteKit 2.x with Svelte 5.x (TypeScript)
12
12
-**Styling**: TailwindCSS 4.x
13
-
-**Database**: PostgreSQL with Prisma ORM
13
+
-**Database**: PostgreSQL with Drizzle ORM
14
+
-**Authentication**: Better Auth with organization plugin
14
15
-**Icons**: Lucide Svelte
15
16
-**Validation**: Zod
16
-
-**Package Manager**: pnpm
17
-
-**Type Checking**: JSDoc style type annotations (no TypeScript)
17
+
-**Package Manager**: pnpm (v10.0.0)
18
+
-**Build Tool**: Turbo (monorepo management)
19
+
-**Deployment**: Cloudflare Workers/Pages
20
+
21
+
## Monorepo Structure
22
+
23
+
```
24
+
├── apps/
25
+
│ ├── web/ # SvelteKit frontend application
26
+
│ └── api/ # Node.js API service (optional)
27
+
├── shared/
28
+
│ ├── database/ # Drizzle ORM schema and migrations
29
+
│ └── constants/ # Shared constants across apps
30
+
└── supabase/ # Supabase configuration (if used)
31
+
```
18
32
19
33
## Development Commands
20
34
35
+
### Monorepo Root Commands
21
36
```bash
22
-
# Development server
37
+
# Install dependencies
38
+
pnpm install
39
+
40
+
# Development (all apps)
23
41
pnpm run dev
24
42
25
-
# Build for production
43
+
# Build (all apps)
26
44
pnpm run build
27
45
28
-
# Preview production build
29
-
pnpm run preview
46
+
# Web app specific
47
+
pnpm run web:dev
48
+
pnpm run web:build
49
+
pnpm run web:preview
50
+
51
+
# API app specific
52
+
pnpm run api:dev
53
+
pnpm run api:build
54
+
```
30
55
56
+
### Database Commands
57
+
```bash
58
+
# Generate SQL and types
59
+
pnpm run db:generate
60
+
61
+
# Run migrations (local)
62
+
pnpm run db:migrate:local
63
+
64
+
# Run migrations (production)
65
+
pnpm run db:migrate:prod
66
+
67
+
# Generate, migrate, build in one command (local)
68
+
pnpm run db:gmb:local
69
+
70
+
# Database studio UI
71
+
pnpm run db:studio
72
+
```
73
+
74
+
### Web App Commands (from apps/web/)
75
+
```bash
31
76
# Type checking
32
77
pnpm run check
33
-
34
-
# Type checking with watch mode
35
78
pnpm run check:watch
36
79
37
-
# Linting and formatting (both required to pass)
80
+
# Linting and formatting
38
81
pnpm run lint
39
-
40
-
# Format code
41
82
pnpm run format
42
-
43
-
# Database operations
44
-
npx prisma migrate dev
45
-
npx prisma generate
46
-
npx prisma studio
47
83
```
48
84
49
85
## Architecture Overview
50
86
51
87
### Multi-Tenant Structure
52
-
-**Organizations**: Top-level tenant containers with strict data isolation
53
-
-**Users**: Can belong to multiple organizations with different roles (ADMIN/USER)
54
-
-**Super Admin**: Users with @micropyramid.com email domain have platform-wide access
88
+
-**Organizations**: Top-level tenant containers with complete data isolation
89
+
-**Members**: Users belong to organizations with specific roles (member/admin)
90
+
-**Sessions**: Track active organization via `activeOrganizationId`
91
+
-**Super Admin**: Platform-wide access (determined by business logic, not email domain)
55
92
56
93
### Core CRM Entities
57
94
-**Leads**: Initial prospects that can be converted to Accounts/Contacts/Opportunities
58
-
-**Accounts**: Company/organization records
95
+
-**Accounts** (`crm_account`): Company/organization records
59
96
-**Contacts**: Individual people associated with accounts
60
-
-**Opportunities**: Sales deals with pipeline stages
61
-
-**Tasks/Events**: Activity management
62
-
-**Cases**: Customer support tickets
63
-
-**Products/Quotes**: Sales catalog and quotation system
97
+
-**Opportunities**: Sales deals with pipeline stages and forecast categories
98
+
-**Tasks/Events**: Activity management linked to various entities
99
+
-**Cases**: Customer support tickets with priority and status tracking
100
+
-**Products/Quotes**: Product catalog and professional quotation system
64
101
65
102
### Authentication & Authorization
66
-
- Session-based authentication using cookies (`session`, `org`, `org_name`)
67
-
- Organization selection required after login via `/org` route
68
-
- Route protection in `src/hooks.server.js`:
103
+
-**Better Auth**: Session-based authentication with JWT plugin support
104
+
-**Organization Context**: Active organization stored in session (`activeOrganizationId`)
105
+
-**Route Protection** in `apps/web/src/hooks.server.ts`:
69
106
-`/app/*` routes require authentication and organization membership
70
-
-`/admin/*` routes restricted to @micropyramid.com domain users
71
-
-`/org` route for organization selection
107
+
-`/admin/*` routes require authentication (additional checks in route logic)
108
+
-`/org` route for organization selection post-login
109
+
-**Database Integration**: Drizzle adapter for Better Auth tables
72
110
73
111
### Data Access Control
74
-
- All database queries must include organization filtering
75
-
- User can only access data from organizations they belong to
76
-
- Prisma schema enforces relationships with `organizationId` foreign keys
112
+
- All CRM queries must filter by `organizationId`
113
+
- Organization membership verified through `member` table
114
+
- Strict foreign key constraints enforce data integrity
115
+
- Audit logging tracks all data modifications
77
116
78
117
### Route Structure
79
118
-`(site)`: Public marketing pages
80
-
-`(no-layout)`: Auth pages (login, org selection)
81
-
-`(app)`: Main CRM application (requires auth + org membership)
0 commit comments