What are the Batteries?
The included-out-of-the-box services and what they save you.
Grit ships with five "batteries" ā pre-wired services that solve real production problems. Cache, file storage, email, background jobs, AI. You don't have to choose, install, or configure them from scratch ā they're there, ready, in the right shape. This chapter walks through each one in turn.
What is a "battery"?
A battery is an included service that:
- Is enabled in
docker-compose.ymlfor local dev. - Has a Go client / service initialized in
main.go. - Is exposed to your code via a clean interface (e.g.,
s.cache.Get(key),s.mail.Send(to, ...)). - Has an admin page in the dashboard so non-devs can poke at it (Jobs dashboard, Mail preview, etc.).
The five batteries
Where the batteries plug in
Why batteries-included matters
Without batteries, the "day-1" experience of a new API looks like this:
- Pick a Redis client library (3 choices, vibes-based decision).
- Wire connection pool, retry, env config.
- Decide on cache key naming convention.
- Wrap GET/SET in a service so you can test it.
- ⦠and you haven't written any product code yet.
Multiply that by five (S3, mail, jobs, AI). Grit makes the decisions for you ā opinionated, but the opinions are defensible. You can replace any battery later, but you don't have to choose to get started.
Where the batteries live in the code
apps/api/internal/ āāā cache/ ā Redis cache service + middleware āāā storage/ ā S3/MinIO/R2 client + upload handler āāā mail/ ā Resend client + 4 HTML templates āāā jobs/ ā asynq client + worker definitions āāā ai/ ā Claude + OpenAI clients
Same shape: one package per battery, exposing a thin Go interface. Tests can swap in a fake; production wires the real thing.
Enabling / disabling at scaffold time
When you run grit new, the CLI asks which batteries you want. You can include everything (default for triple kit) or skip some for a minimal API. You can also add a battery later by running grit add battery <name>.
The admin dashboard for each battery
Every battery gets a page in the admin panel under /admin/system:
- Jobs ā live queue depth, running jobs, retry attempts, failed jobs you can re-queue.
- Mail Preview ā render templates with sample data without sending.
- Files ā browse + delete uploads.
- Cron ā see scheduled jobs, last/next run.
- AI ā usage stats, token spend.
What this chapter covers, in order
- Redis cache ā speed up reads, throttle, store ephemeral state.
- S3 storage ā uploads, signed URLs, image processing.
- Mail (Resend) ā transactional + marketing email with editable templates.
- Jobs (asynq) ā background work, retries, cron.
- AI (Claude + OpenAI) ā chat, embeddings, provider swap.
Each lesson follows the same template: what it does, how it's implemented, where the file lives, how to modify it, and a small exercise.
Quick check
What's next
Next lesson ā Redis cache. Speed up reads, cache list endpoints, throttle expensive calls. The most common production performance win.
Spot a typo? Have an idea?
Help us improve this lesson. One click opens a GitHub issue with the lesson URL pre-filled ā suggest clearer wording, report a bug, or request more depth. The course keeps improving thanks to learners like you.
Suggest an improvement on GitHub