Skip to content

Commit 8622778

Browse files
authored
Merge pull request #12 from nativeapptemplate/broadcasts_refreshes_to
init claude
2 parents 9b794d1 + 8d7ddaf commit 8622778

2 files changed

Lines changed: 121 additions & 0 deletions

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,6 @@ yarn-debug.log*
4848
.DS_Store
4949
.idea
5050
*~
51+
52+
# Claude
53+
.claude/

CLAUDE.md

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
# CLAUDE.md
2+
3+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4+
5+
## Project Overview
6+
7+
This is a Rails 7.1.5.1 API application that serves as the backend for NativeAppTemplate iOS/Android mobile applications. It's a multi-tenant SaaS application with token-based authentication, role-based authorization, and RESTful API endpoints.
8+
9+
## Development Commands
10+
11+
### Initial Setup
12+
```bash
13+
bin/setup # Installs all dependencies, prepares database, builds assets
14+
```
15+
16+
### Running the Application
17+
```bash
18+
bin/dev # Starts Rails server, CSS watcher, JS bundler, and Sidekiq workers
19+
```
20+
21+
### Testing
22+
```bash
23+
bin/rails test # Run all tests
24+
bin/rails test test/path/to/test.rb # Run specific test file
25+
bin/rails test test/path/to/test.rb:42 # Run specific test line
26+
```
27+
28+
### Linting & Security
29+
```bash
30+
bin/rubocop # Ruby code linting
31+
bundle exec erblint --lint-all # ERB template linting
32+
bin/brakeman # Security vulnerability scanning
33+
```
34+
35+
### Database Operations
36+
```bash
37+
bin/rails db:create db:migrate # Create and migrate database
38+
bin/rails db:seed_fu # Load seed data (uses seed-fu gem)
39+
bin/rails db:reset # Drop, create, migrate, and seed
40+
```
41+
42+
### Console & Debugging
43+
```bash
44+
bin/rails console # Rails console
45+
bin/rails dbconsole # Database console
46+
```
47+
48+
## Architecture & Key Concepts
49+
50+
### API Structure
51+
- All API endpoints are under `/api/v1/` namespace
52+
- Token-based authentication using `devise_token_auth`
53+
- Separate namespaces for different user types (e.g., `/api/v1/shopkeeper/`)
54+
- JSON API specification for responses using `jsonapi-serializer`
55+
- CORS enabled for cross-origin requests
56+
57+
### Authentication & Authorization
58+
- **Authentication**: Devise Token Auth with headers-based token management
59+
- **Authorization**: Pundit policies for resource-level permissions
60+
- **Multi-tenancy**: acts_as_tenant for complete data isolation between accounts
61+
- **RBAC**: Role and Permission models for fine-grained access control
62+
63+
### Key Models & Relationships
64+
- `Account` - Top-level tenant/organization
65+
- `Shopkeeper` - Main user type (belongs to Account)
66+
- `Shop` - Core business entity (belongs to Account)
67+
- `ItemTag` - Belongs to Shop with unique name constraint
68+
- `Role` & `Permission` - Authorization system
69+
- State machines implemented with AASM gem
70+
71+
### Background Processing
72+
- Sidekiq for background jobs with Redis backend
73+
- Queue priorities: critical (10), mailers (5), default (2), low (1)
74+
- Monitor at `/madmin/sidekiq` in development
75+
76+
### Testing Strategy
77+
- Minitest for all tests (models, controllers, integration)
78+
- WebMock for stubbing external HTTP requests
79+
- Parallel test execution supported
80+
- API integration tests for all endpoints
81+
82+
### Development Server Configuration
83+
- Server binds to specific IP: `192.168.1.21:3000` (not localhost)
84+
- Mailbin for email testing at `/mailbin`
85+
- Admin interface at `/madmin`
86+
- Hot reload for CSS/JS changes via yarn watchers
87+
88+
### Important Conventions
89+
- Use `seed-fu` for database seeding (not standard Rails seeds)
90+
- API responses follow JSON API specification
91+
- All API controllers inherit from `Api::V1::BaseController`
92+
- Tenant isolation handled automatically via `AccountMiddleware`
93+
- Image processing with Active Storage and `image_processing` gem
94+
95+
### Deployment
96+
- Configured for Render.com deployment
97+
- Build script: `bin/render-build.sh`
98+
- Web server: `bin/render-start.sh`
99+
- Background workers: `bin/render-start-sidekiq.sh`
100+
101+
## Common Development Tasks
102+
103+
### Creating New API Endpoints
104+
1. Add route in `config/routes.rb` under appropriate namespace
105+
2. Create controller inheriting from `Api::V1::BaseController`
106+
3. Add Pundit policy in `app/policies/`
107+
4. Create serializer in `app/serializers/`
108+
5. Write integration tests in `test/integration/`
109+
110+
### Working with Multi-tenancy
111+
- All models should include `acts_as_tenant :account`
112+
- Current account accessible via `current_account` in controllers
113+
- Tenant switching handled by `AccountMiddleware`
114+
115+
### Adding Background Jobs
116+
1. Create job class in `app/jobs/`
117+
2. Specify queue with `queue_as :default` (or :critical, :low, etc.)
118+
3. Call with `MyJob.perform_later(args)`

0 commit comments

Comments
 (0)