Guidance for agents working in the 508.dev integrations monorepo.
This repo contains multiple services:
- Discord bot (
apps/discord_bot) - Backend API (
apps/api) - Worker consumer (
apps/worker) - Shared package (
packages/shared)
- Feature modularity in bot cogs
- Bot features live in
apps/discord_bot/src/five08/discord_bot/cogs/*.py. - Cogs auto-load from the
five08.discord_bot.cogspackage.
- Shared runtime code
- Cross-service settings/queue/job logic lives in
packages/shared/src/five08/. - Keep service-specific behavior in each app package.
- Service separation
apps/discord_bot: Discord gateway and bot commands/cogsapps/api: webhook ingest API and dashboard auth routesapps/worker: queue consumer and processing jobsdocker-compose.yml: full container stack for Coolify/local parity; day-to-day dev should prefer host-run app services with Docker-managed infra
- Human audit logging
- Human-triggered CRM actions from Discord should write to the worker audit ingest endpoint.
- Audit logging must be best effort: command flows should never fail if audit writes fail.
- Keep reusable audit-write logic outside individual cogs.
- Bot core:
apps/discord_bot/src/five08/discord_bot/bot.py - Bot config:
apps/discord_bot/src/five08/discord_bot/config.py - Bot audit helper:
apps/discord_bot/src/five08/discord_bot/utils/audit.py - Backend API:
apps/api/src/five08/backend/api.py - Worker consumer:
apps/worker/src/five08/worker/consumer.py - Shared settings:
packages/shared/src/five08/settings.py - Shared queue helpers:
packages/shared/src/five08/queue.py
uv sync
./scripts/test.sh
./scripts/lint.sh
./scripts/format.sh
./scripts/mypy.shRun services directly:
uv run --package discord_bot discord-bot
uv run --package api backend-api
uv run --package worker worker-consumerRun the local dev stack:
./scripts/dev.sh infra
./scripts/dev.sh discord-bot
./scripts/dev.sh api
./scripts/dev.sh worker
./scripts/dev.sh all./scripts/dev.sh is the primary local-dev entrypoint. Full container parity
remains available with:
./scripts/docker-compose.sh up --buildfrom discord.ext import commands
class MyCog(commands.Cog):
def __init__(self, bot: commands.Bot) -> None:
self.bot = bot
async def setup(bot: commands.Bot) -> None:
await bot.add_cog(MyCog(bot))- Keep ingest endpoints fast: validate input, persist jobs, enqueue, return 202.
- Run long processing in worker consumer jobs (Dramatiq actors), with Postgres as source-of-truth job state and Redis as delivery transport.
- Internal file movement is routed through MinIO (
internal-transfers) inside the stack; this is explicitly the internal transfer path, with external object store adapters kept separate for future needs. - Worker schema is managed with Alembic migrations in
apps/worker/src/five08/worker/migrationsand applied at backend-api startup.
- Protected API auth uses
API_SHARED_SECRETfor all protected API routes, including webhooks. - Worker queue configuration is now resolved to a single effective
worker_queue_name; startup fails whenWORKER_QUEUE_NAMEScontains multiple queue names. - Job handler lookup for rerun and worker execution is now centralized in
five08.worker.jobs.JOB_FUNCTIONS.
- Shared job state is persisted in Postgres table
jobswith job type, status (queued,running,succeeded,failed,dead,canceled), payload, idempotency key, attempt counters, scheduling, and lock metadata.
- Add shared env/config in
packages/shared/src/five08/settings.py. - Add service-specific settings in local service
config.pyby subclassing shared settings. - Keep secrets in env vars, not code.
- For Discord CRM audit writes, use
AUDIT_API_BASE_URLand sharedAPI_SHARED_SECRET.
- Prefer adding new bot features as isolated cogs.
- Prefer adding reusable helpers/clients to
packages/shared/src/five08/. - Update docs and
.env.examplewhen introducing new config. - Keep changes incremental and testable.