Skip to content

Commit 4ce7a5a

Browse files
authored
Merge pull request #561 from mikeschlottig/claude/claude-md-mic5efuhvcmm05yg-01JTs7sQBsDkHu6EtfYRd9YS
Add CLAUDE.md with comprehensive codebase guide for AI assistants
2 parents 59a5fa6 + 32a8e5f commit 4ce7a5a

File tree

1 file changed

+249
-0
lines changed

1 file changed

+249
-0
lines changed

CLAUDE.md

Lines changed: 249 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,249 @@
1+
# CLAUDE.md - AI Assistant Guide for BottleCRM
2+
3+
## Project Overview
4+
5+
BottleCRM (Django-CRM) is an open-source CRM system built with Django and Django REST Framework. It provides customer relationship management for startups and small businesses.
6+
7+
**Status**: Maintenance mode - active development has moved to [MicroPyramid/opensource-startup-crm](https://github.com/MicroPyramid/opensource-startup-crm) (SvelteKit version).
8+
9+
## Tech Stack
10+
11+
- **Backend**: Django 4.2.1, Django REST Framework 3.14.0
12+
- **Database**: PostgreSQL
13+
- **Authentication**: JWT (djangorestframework-simplejwt)
14+
- **Task Queue**: Celery 5.2.7 with Redis
15+
- **CMS**: Wagtail 5.0.1
16+
- **API Docs**: drf-spectacular (Swagger/OpenAPI)
17+
- **Deployment**: Docker, Gunicorn
18+
19+
## Project Structure
20+
21+
```
22+
crm/ # Django project settings
23+
common/ # Shared models, auth, utilities
24+
accounts/ # Account/Company management
25+
contacts/ # Contact management
26+
leads/ # Lead management
27+
opportunity/ # Sales pipeline
28+
tasks/ # Task management
29+
cases/ # Support/issue tracking
30+
events/ # Calendar/events
31+
teams/ # Team management
32+
invoices/ # Invoice management
33+
emails/ # Email management
34+
cms/ # Wagtail CMS
35+
templates/ # HTML templates
36+
static/ # Static assets
37+
docs/ # Sphinx documentation
38+
scripts/ # Deployment scripts
39+
```
40+
41+
## Key Files
42+
43+
| File | Purpose |
44+
|------|---------|
45+
| `manage.py` | Django CLI entry point |
46+
| `crm/settings.py` | Main configuration |
47+
| `crm/urls.py` | URL routing |
48+
| `crm/celery.py` | Celery task queue setup |
49+
| `common/models.py` | User, Org, Profile models |
50+
| `common/utils.py` | Shared utilities and constants |
51+
| `requirements.txt` | Python dependencies |
52+
53+
## Development Setup
54+
55+
### Prerequisites
56+
- Python 3.x
57+
- PostgreSQL 9.4+
58+
- Redis server
59+
60+
### Quick Start
61+
62+
```bash
63+
# Install dependencies
64+
pip install -r requirements.txt
65+
66+
# Configure environment
67+
cp ENV.md .env
68+
# Edit .env with your database credentials
69+
70+
# Run migrations
71+
python manage.py migrate
72+
73+
# Start server
74+
python manage.py runserver
75+
76+
# Start Celery worker (separate terminal)
77+
celery -A crm worker --loglevel=INFO
78+
```
79+
80+
### Docker Setup
81+
82+
```bash
83+
docker build -t djcrm:1 -f docker/dockerfile .
84+
docker-compose -f docker/docker-compose.yml up
85+
```
86+
87+
## Common Commands
88+
89+
```bash
90+
# Run development server
91+
python manage.py runserver
92+
93+
# Run migrations
94+
python manage.py migrate
95+
96+
# Create migrations
97+
python manage.py makemigrations
98+
99+
# Run tests
100+
pytest
101+
102+
# Run tests with coverage
103+
coverage run -m pytest
104+
coverage report
105+
106+
# Start Celery worker
107+
celery -A crm worker --loglevel=INFO
108+
109+
# Format code
110+
black .
111+
```
112+
113+
## Testing
114+
115+
- **Framework**: pytest with Django plugin
116+
- **Config**: `pytest.ini`
117+
- **Coverage**: `.coveragerc`
118+
119+
### Test Locations
120+
- `*/tests_celery_tasks.py` - Celery task tests (per app)
121+
- `*/tests.py` - Unit tests
122+
123+
### Run Tests
124+
```bash
125+
pytest # All tests
126+
pytest accounts/ # Single app
127+
pytest -x # Stop on first failure
128+
coverage run -m pytest # With coverage
129+
```
130+
131+
## API Structure
132+
133+
### Base URL Patterns
134+
- `/api/` - Common endpoints
135+
- `/api/accounts/` - Account management
136+
- `/api/contacts/` - Contact management
137+
- `/api/leads/` - Lead management
138+
- `/api/opportunities/` - Sales pipeline
139+
- `/api/teams/` - Team management
140+
- `/api/tasks/` - Task management
141+
- `/api/events/` - Events
142+
- `/api/cases/` - Case management
143+
144+
### API Documentation
145+
- `/swagger-ui/` - Swagger UI
146+
- `/api/schema/redoc/` - ReDoc
147+
- `/schema/` - OpenAPI schema
148+
149+
## Code Conventions
150+
151+
### Django App Pattern
152+
Each app follows this structure:
153+
- `models.py` - Database models
154+
- `views.py` - API views (class-based)
155+
- `serializer.py` - DRF serializers
156+
- `tasks.py` - Celery async tasks
157+
- `tests_celery_tasks.py` - Task tests
158+
159+
### Model Pattern
160+
Models inherit from `common.base.BaseModel` for timestamp fields:
161+
```python
162+
from common.base import BaseModel
163+
164+
class MyModel(BaseModel):
165+
# created_at and updated_at are automatic
166+
name = models.CharField(max_length=255)
167+
```
168+
169+
### View Pattern
170+
Views use DRF class-based views with permissions:
171+
```python
172+
from rest_framework.views import APIView
173+
from rest_framework.permissions import IsAuthenticated
174+
175+
class MyView(APIView):
176+
permission_classes = [IsAuthenticated]
177+
```
178+
179+
### Serializer Naming
180+
- Read serializers: `ModelSerializer`
181+
- Write serializers: `CreateModelSerializer`
182+
183+
### Code Quality
184+
- **Formatter**: Black (configured in `.pre-commit-config.yaml`)
185+
- **Pre-commit**: `pre-commit install`
186+
187+
## Environment Variables
188+
189+
Key variables (see `ENV.md` for full list):
190+
191+
```
192+
SECRET_KEY # Django secret key
193+
ENV_TYPE # dev/stage/live
194+
DBNAME # PostgreSQL database name
195+
DBUSER # Database user
196+
DBPASSWORD # Database password
197+
DBHOST # Database host
198+
CELERY_BROKER_URL # Redis URL for Celery
199+
```
200+
201+
## Multi-tenancy
202+
203+
The app supports multiple organizations via the `Org` model in `common/models.py`. Middleware in `common/middleware/get_company.py` handles organization context.
204+
205+
## Important Patterns
206+
207+
### Authentication
208+
JWT tokens via `djangorestframework-simplejwt`. Custom auth in `common/external_auth.py`.
209+
210+
### Async Tasks
211+
Celery tasks defined in `*/tasks.py` files. Example:
212+
```python
213+
from celery import shared_task
214+
215+
@shared_task
216+
def send_email_task(email_data):
217+
# Task implementation
218+
pass
219+
```
220+
221+
### Tags and Relationships
222+
Many-to-many relationships use through models. Tags are stored in `accounts/models.py`.
223+
224+
## CI/CD
225+
226+
- **GitHub Actions**: CodeQL security scanning
227+
- **Travis CI**: Test execution and coverage
228+
- **Jenkins**: Docker build and deployment
229+
230+
## External Documentation
231+
232+
- ReadTheDocs: http://django-crm.readthedocs.io
233+
- Demo: https://bottlecrm.io/
234+
- Sphinx docs: `docs/source/`
235+
236+
## When Making Changes
237+
238+
1. **Follow existing patterns** - Check similar files in the same app
239+
2. **Add tests** - Create tests in `tests_celery_tasks.py` or `tests.py`
240+
3. **Run formatter** - Use `black .` before committing
241+
4. **Update migrations** - Run `makemigrations` for model changes
242+
5. **Check API docs** - Ensure serializers are documented with drf-spectacular
243+
244+
## Common Issues
245+
246+
- **Database connection**: Ensure PostgreSQL is running and `.env` is configured
247+
- **Celery tasks not running**: Start Redis and Celery worker
248+
- **Static files 404**: Run `python manage.py collectstatic`
249+
- **Migration conflicts**: Check for unapplied migrations with `python manage.py showmigrations`

0 commit comments

Comments
 (0)