Skip to content

Commit 2c839f8

Browse files
JacobCoffeeclaude
andcommitted
refactor: centralize tool configuration in pyproject.toml
Simplified Makefile and CI workflow to use pyproject.toml configuration instead of specifying paths explicitly: - `make type-check`: now runs `ty check` (uses pyproject.toml) - `make test`: now runs `pytest` (uses testpaths from pyproject.toml) - CI workflow: updated to match Makefile behavior This ensures consistency between local and CI environments, makes the configuration maintainable from a single source, and includes all tests (1036 total, including byte-common smoke tests). Updated documentation to remove misleading performance comments about API exclusion. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 43081a7 commit 2c839f8

File tree

2 files changed

+302
-1
lines changed

2 files changed

+302
-1
lines changed

CLAUDE.md

Lines changed: 301 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,301 @@
1+
# Byte Bot - Development Guide
2+
3+
> **Version**: 0.3.0 (Phase 2 - Microservices) **Python**: 3.13 **Architecture**: Microservices (uv workspace)
4+
> **Updated**: 2025-11-23
5+
6+
---
7+
8+
## ⚡ Critical Rules
9+
10+
1. **NEVER work on main branch** - Always use feature branches via `git worktree` but using `make worktree` command from
11+
makefile!
12+
2. **ALWAYS ensure you write tests** for changes!
13+
3. **ALWAYS run `make ci`** before committing - Must pass (lint + type-check + fmt + test)
14+
4. **ALWAYS use `uv run`** for Python - Never call `python`/`python3` directly
15+
5. **ALWAYS update docs/** for user-facing changes - Sphinx RST format
16+
6. **ALWAYS create atomic commits** - Small, focused, reviewable
17+
7. **Use prek, not pre-commit** - Git hooks configured with prek
18+
8. **Dispatch subagents for complex tasks** - `ui-engineer`, `python-backend`, `software-architect`,
19+
`documentation-expert`
20+
21+
- Ready-to-use .env is at /Users/coffee/git/public/JacobCoffee/byte/ with loaded values.
22+
- `make worktree` automatically copies `.claude/settings.local.json` and `.env` to new worktrees.
23+
24+
---
25+
26+
## 🏗️ Architecture (Post-Phase 2)
27+
28+
**uv Workspace** with 3 members:
29+
30+
```
31+
workspace root (pyproject.toml)
32+
├── packages/byte-common # Shared models, schemas, utils
33+
├── services/api # Litestar REST API + web dashboard
34+
└── services/bot # discord.py bot
35+
```
36+
37+
**Runtime**:
38+
39+
- **Docker Compose** (recommended): All services + PostgreSQL in containers
40+
- **Local**: Services run separately, PostgreSQL in Docker via `make infra-up`
41+
42+
**Communication**:
43+
44+
- Bot → API via HTTP (`byte_bot/api_client.py`)
45+
- API → PostgreSQL (direct SQLAlchemy)
46+
- Shared code via `byte-common` package
47+
48+
---
49+
50+
## 🚀 Quick Start Commands
51+
52+
### Setup
53+
54+
```bash
55+
# Full install (backend + frontend + prek hooks)
56+
make install
57+
58+
# Docker development (PRIMARY workflow)
59+
make docker-up # Start all services
60+
make docker-logs # Follow logs
61+
make docker-down # Stop all services
62+
```
63+
64+
### Development
65+
66+
```bash
67+
# Local development (alternative)
68+
make infra-up # Start PostgreSQL only
69+
make run-dev-server # Terminal 1: Litestar API (hot-reload)
70+
make run-dev-bot # Terminal 2: Discord bot
71+
make run-dev-frontend # Terminal 3: TailwindCSS watcher
72+
73+
# Quality checks (MUST PASS before commit)
74+
make ci # Run all checks
75+
76+
# Individual checks
77+
make lint # prek hooks (ruff + codespell)
78+
make fmt # Ruff format
79+
make type-check # ty type checker
80+
make test # pytest with coverage
81+
```
82+
83+
### Database
84+
85+
```bash
86+
# Migrations (from services/api/)
87+
cd services/api
88+
uv run alembic revision --autogenerate -m "description"
89+
make migrate # Apply migrations
90+
91+
# Container management
92+
make refresh-container # Wipe DB, migrate, load test data
93+
```
94+
95+
### Docker Utilities
96+
97+
```bash
98+
make docker-rebuild # Force rebuild all services
99+
make docker-shell-api # Enter API container shell
100+
make docker-shell-bot # Enter bot container shell
101+
make docker-shell-postgres # PostgreSQL shell
102+
```
103+
104+
---
105+
106+
## 📁 Project Structure (Essential Paths)
107+
108+
```
109+
byte/
110+
├── pyproject.toml # Workspace root config
111+
├── Makefile # Primary automation (280 lines)
112+
├── docker-compose.yml # Development environment
113+
114+
├── packages/byte-common/ # Shared package
115+
│ ├── src/byte_common/
116+
│ │ ├── models/ # SQLAlchemy ORM models
117+
│ │ ├── schemas/ # Pydantic API schemas
118+
│ │ └── utils.py
119+
│ └── pyproject.toml
120+
121+
├── services/api/ # Litestar web service
122+
│ ├── src/byte_api/
123+
│ │ ├── app.py # create_app() factory
124+
│ │ ├── domain/ # Business logic (guilds, github, system, web)
125+
│ │ └── lib/ # Infrastructure (db, settings, openapi, etc.)
126+
│ │ └── db/migrations/ # Alembic migrations
127+
│ ├── Dockerfile
128+
│ └── pyproject.toml
129+
130+
├── services/bot/ # Discord bot service
131+
│ ├── src/byte_bot/
132+
│ │ ├── bot.py # Bot class, run_bot()
133+
│ │ ├── api_client.py # HTTP client to API service
134+
│ │ ├── plugins/ # Discord commands (auto-loaded)
135+
│ │ └── views/ # Discord UI components
136+
│ ├── Dockerfile
137+
│ └── pyproject.toml
138+
139+
├── tests/ # Integration + unit tests
140+
├── docs/ # Sphinx documentation (RST)
141+
│ └── conf.py
142+
└── worktrees/ # Git worktrees (keep in repo)
143+
```
144+
145+
---
146+
147+
## 🔧 Technology Stack
148+
149+
| Component | Tool | Notes |
150+
| ------------------- | --------------------------------- | ------------------------------------- |
151+
| **Package Manager** | uv | Fast, PEP 517 build backend |
152+
| **Linting** | ruff | Replaces black, flake8, isort |
153+
| **Type Checking** | ty | Type checks all services and packages |
154+
| **Testing** | pytest + pytest-asyncio | Coverage required |
155+
| **Git Hooks** | prek | NOT pre-commit |
156+
| **Web Framework** | Litestar 2.4.3+ | ASGI, OpenAPI, Jinja2 |
157+
| **Discord Bot** | discord.py 2.3.2+ | Slash commands, views |
158+
| **ORM** | SQLAlchemy 2.0 + Advanced Alchemy | Async, repository pattern |
159+
| **Database** | PostgreSQL 15+ | Via Docker or Railway |
160+
| **Frontend** | TailwindCSS + DaisyUI | Compiled via separate watcher |
161+
162+
**Documentation**: Sphinx, Context7 MCP, allowed WebFetch domains:
163+
164+
- `docs.astral.sh` (uv docs)
165+
- `docs.litestar.dev` (Litestar framework)
166+
- `discordpy.readthedocs.io` (discord.py)
167+
168+
---
169+
170+
## 🔄 Git Workflow
171+
172+
### Branching with Worktrees (REQUIRED for parallel work)
173+
174+
```bash
175+
# Create feature branch in worktree (automated)
176+
make worktree
177+
# OR manually:
178+
git checkout main && git pull
179+
git worktree add worktrees/feature-name -b feature/feature-name
180+
181+
# Work in worktree
182+
cd worktrees/feature-name
183+
# ... make atomic commits ...
184+
185+
# Cleanup after merge
186+
cd ../..
187+
git worktree remove worktrees/feature-name
188+
189+
# Clean up stale worktrees
190+
make worktree-prune
191+
# OR: git worktree prune -v
192+
```
193+
194+
### Commit Standards
195+
196+
- **Atomic commits**: One logical change per commit
197+
- **Conventional commits**: `feat:`, `fix:`, `docs:`, `refactor:`, etc.
198+
- **Examples**:
199+
-`feat: add guild caching to API client`
200+
-`fix: handle missing Discord token gracefully`
201+
-`feat: complete Phase 3 migration` (too large)
202+
203+
### PR Workflow
204+
205+
```bash
206+
# Ensure CI passes locally
207+
make ci
208+
209+
# Create PR via gh CLI
210+
gh pr create --title "feat: description" --body "..."
211+
212+
# Check PR status
213+
gh pr checks
214+
```
215+
216+
---
217+
218+
## 🐛 Common Issues
219+
220+
| Issue | Solution |
221+
| -------------------------------- | -------------------------------------------------------------- |
222+
| **Bot not responding** | Check `DISCORD_TOKEN`, `DISCORD_DEV_GUILD_ID` in `.env` |
223+
| **Import errors** | Run `uv sync` to install dependencies |
224+
| **Database connection errors** | Ensure PostgreSQL running: `make infra-up` or `make docker-up` |
225+
| **Migrations failing** | Check DB connection, try `make refresh-container` |
226+
| **Frontend styles not updating** | Restart `make run-dev-frontend` watcher |
227+
| **Docker build fails** | Try `make docker-rebuild` |
228+
229+
---
230+
231+
## 📝 Development Patterns
232+
233+
### Environment Variables
234+
235+
Key variables in `.env`:
236+
237+
- `DISCORD_TOKEN` - Bot token from Discord Developer Portal
238+
- `DB_URL` - PostgreSQL connection (format: `postgresql+asyncpg://user:pass@host:port/db`)
239+
- `SECRET_KEY` - API secret for JWT/sessions
240+
- `GITHUB_APP_*` - GitHub App credentials (ID, private key, client ID/secret)
241+
242+
### Code Style (Enforced by `make ci`)
243+
244+
- **Line length**: 120 characters
245+
- **Type hints**: Required (modern union syntax: `str | None`)
246+
- **Docstrings**: Google style (enforced by ruff)
247+
- **Async**: Use `async`/`await` (SQLAlchemy 2.0 async mode)
248+
249+
### Testing
250+
251+
```python
252+
# Tests in tests/ directory
253+
# Markers: @pytest.mark.unit, @pytest.mark.integration
254+
# Async tests: @pytest.mark.asyncio (auto-enabled)
255+
```
256+
257+
### Database Models
258+
259+
- **Location**: `packages/byte-common/src/byte_common/models/`
260+
- **Migrations**: `cd services/api && uv run alembic revision --autogenerate -m "msg"`
261+
- **Apply**: `make migrate`
262+
263+
### Bot Plugins
264+
265+
- **Location**: `services/bot/src/byte_bot/plugins/`
266+
- **Auto-loaded**: Place `*.py` files, add `def setup(bot)` function
267+
- **Example**: See `plugins/admin.py`, `plugins/github.py`
268+
269+
---
270+
271+
## 🤖 Subagent Coordination
272+
273+
When dispatching subagents:
274+
275+
1. **Create separate worktrees** for each agent
276+
2. **Assign clear boundaries** (files/modules)
277+
3. **Coordinate via git commits** (atomic, descriptive)
278+
4. **Merge incrementally** (review each commit)
279+
280+
**Available agents**:
281+
282+
- `ui-engineer` - Frontend, TailwindCSS, Jinja2 templates
283+
- `python-backend` - API, database, business logic
284+
- `software-architect` - System design, refactoring
285+
- `documentation-expert` - Sphinx docs, API references, tutorials
286+
287+
---
288+
289+
## 📚 Resources
290+
291+
- **Project Docs**: `docs/` (Sphinx RST format)
292+
- **Docker Guide**: `docs/docker-setup.md`
293+
- **API Docs**: http://localhost:8000/api/swagger (when running)
294+
- **External**:
295+
- discord.py: https://discordpy.readthedocs.io/
296+
- Litestar: https://docs.litestar.dev/
297+
- uv: https://docs.astral.sh/uv/
298+
299+
---
300+
301+
**Repository**: https://github.com/JacobCoffee/byte

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ ruff-noqa: ## Runs Ruff, adding noqa comments to disable warnings
115115
@$(UV) run --no-sync ruff check . --add-noqa
116116

117117
type-check: ## Run ty type checker
118-
@$(UV) run --no-sync ty check services/bot/src packages/byte-common/src
118+
@$(UV) run --no-sync ty check
119119

120120
test: ## Run the tests
121121
@$(UV) run --no-sync pytest

0 commit comments

Comments
 (0)