A third party ATProto appview
1# Local Development Guide
2
3This guide explains how to run AppView locally for development and testing.
4
5## Prerequisites
6
7- Docker and Docker Compose installed
8- At least 4GB RAM available for Docker
9- Git for version control
10
11## Quick Start
12
131. **Copy the local environment file:**
14 ```bash
15 cp .env.local .env
16 ```
17
182. **Start all services in development mode:**
19 ```bash
20 docker-compose -f docker-compose.yml -f docker-compose.dev.yml up
21 ```
22
23 Or run in background:
24 ```bash
25 docker-compose -f docker-compose.yml -f docker-compose.dev.yml up -d
26 ```
27
283. **View logs:**
29 ```bash
30 docker-compose -f docker-compose.yml -f docker-compose.dev.yml logs -f
31 ```
32
334. **Access the application:**
34 - AppView: http://localhost:5000
35 - PostgreSQL: localhost:5432
36 - Redis: localhost:6379
37
38## Development Features
39
40### Hot Reload
41Code changes are automatically reflected in running containers:
42- **Python services**: Changes to `python-firehose/*.py` apply immediately
43- **Node.js app**: Changes to `src/**` require restart (working on hot-reload)
44
45### Lower Resource Usage
46Development mode uses much lower resource limits:
47- Database: 2GB RAM (vs 20GB+ in production)
48- Redis: 512MB RAM (vs 8GB in production)
49- Python workers: 512MB-1GB each
50
51### Debug Logging
52All services run with `LOG_LEVEL=DEBUG` for detailed output.
53
54## Common Commands
55
56### Restart a specific service (after code changes)
57```bash
58docker-compose -f docker-compose.yml -f docker-compose.dev.yml restart python-backfill-worker
59```
60
61### Rebuild after dependency changes
62```bash
63docker-compose -f docker-compose.yml -f docker-compose.dev.yml build python-backfill-worker
64docker-compose -f docker-compose.yml -f docker-compose.dev.yml up -d python-backfill-worker
65```
66
67### Stop all services
68```bash
69docker-compose -f docker-compose.yml -f docker-compose.dev.yml down
70```
71
72### Reset database (WARNING: deletes all data)
73```bash
74docker-compose -f docker-compose.yml -f docker-compose.dev.yml down -v
75docker-compose -f docker-compose.yml -f docker-compose.dev.yml up -d
76```
77
78### Access database directly
79```bash
80docker-compose exec db psql -U postgres -d atproto
81```
82
83### Access Redis CLI
84```bash
85docker-compose exec redis redis-cli
86```
87
88## Service Architecture
89
90- **db**: PostgreSQL database for storing posts, users, etc.
91- **redis**: In-memory cache and message broker
92- **python-firehose**: Connects to AT Protocol firehose, pushes to Redis
93- **python-worker**: Consumes from Redis, writes to database
94- **python-backfill-worker**: Direct firehose → database (with optional backfill)
95- **app**: Node.js AppView API server
96- **constellation-bridge**: Optional enhanced stats service
97
98## Debugging Tips
99
100### Watch Python worker logs in real-time
101```bash
102docker-compose -f docker-compose.yml -f docker-compose.dev.yml logs -f python-backfill-worker
103```
104
105### Check if services are healthy
106```bash
107docker-compose -f docker-compose.yml -f docker-compose.dev.yml ps
108```
109
110### Execute commands in a running container
111```bash
112docker-compose exec python-backfill-worker bash
113```
114
115### Check database connection
116```bash
117docker-compose exec python-backfill-worker python -c "import asyncpg; import asyncio; asyncio.run(asyncpg.connect('postgresql://postgres:password@db:5432/atproto'))"
118```
119
120## Testing the SQL Fix
121
122After fixing the `post_viewer_states` SQL error:
123
1241. Restart the affected service:
125 ```bash
126 docker-compose -f docker-compose.yml -f docker-compose.dev.yml restart python-backfill-worker
127 ```
128
1292. Watch for errors:
130 ```bash
131 docker-compose -f docker-compose.yml -f docker-compose.dev.yml logs -f python-backfill-worker | grep -i error
132 ```
133
1343. Should see no more `$NULL` or `$false` syntax errors!
135
136## Production vs Development
137
138Key differences between `.env.local` and production:
139
140| Setting | Local Dev | Production |
141|---------|-----------|------------|
142| Database RAM | 2GB | 20GB+ |
143| Redis RAM | 512MB | 8GB |
144| Worker pool size | 10 | 20 |
145| Logging | DEBUG | INFO |
146| Backfill | Disabled | Optional |
147| Constellation | Disabled | Optional |
148
149## Troubleshooting
150
151### Port already in use
152If you see "port already in use" errors, check what's using the ports:
153```bash
154netstat -ano | findstr :5432
155netstat -ano | findstr :5000
156```
157
158### Out of memory
159Increase Docker's memory limit in Docker Desktop settings (Minimum 4GB recommended).
160
161### Database connection refused
162Wait for the database to be healthy:
163```bash
164docker-compose -f docker-compose.yml -f docker-compose.dev.yml logs db
165```
166
167## Next Steps
168
1691. Make code changes in your editor (VSCode)
1702. Changes to Python files apply immediately (no restart needed)
1713. For dependency changes, rebuild the container
1724. Test your changes locally before deploying to VPS
173
174## Useful VSCode Extensions
175
176- Docker (by Microsoft) - Manage containers from VSCode
177- PostgreSQL (by Chris Kolkman) - Query database directly
178- Python (by Microsoft) - Python development support
179- GitLens - Enhanced git integration