agentleFS
IgnazioDSIgnazioDS/langgraph-fastapi-starter/CLAUDE.md

langgraph-fastapi-starter

CLAUDE.md9 starsChanged 2 months agoMITView on GitHub

This file defines how Claude Code operates within this repository. Read it completely before touching any file. It governs every decision. A production-grade starting point for AI agent backends. Not a demo. Not a tutorial. A template that a technical founder can fork, configure, and extend into a real product in under 30 minutes. The constraint that shapes everything: minimum surface area for maximum production readiness. Every file that exists must earn its place. Every abstraction must be removable without…

The file

Show its rules and text

We split this CLAUDE.md into the rules it gives an agent

22 rules. About 0 are common, 19 are distinctive, and 3 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈19

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 3

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Read it completely before touching any file.

    line 4
  2. Distinctive:

    Every file that exists must earn its place.

    line 15
  3. Distinctive:

    When you are unsure whether to add something, ask: "Does a founder need to understand this to build their product?" If yes, it belongs.

    line 27
  4. Distinctive:

    No Redis. No Celery. No Kafka.

    line 37
  5. Distinctive:

    If something requires one of these to work, it does not belong in the starter.

    line 38
  6. Distinctive:

    No CREATE TABLE in application startup code.

    line 47
  7. Distinctive:

    All database structure lives in migrations/.

    line 48
  8. Very specific:

    Use psycopg2 (sync) for database operations inside a thread pool executor.

    line 52
  9. Distinctive:

    Do not introduce SQLAlchemy async.

    line 54
  10. Distinctive:

    Every log entry is JSON. Fields: timestamp, level, request_id, event, and any relevant context.

    line 58
  11. Distinctive:

    No OAuth. No JWT. No sessions.

    line 66
  12. Distinctive:

    No TypedDict for API boundaries.

    line 77
  13. Very specific:

    Every endpoint has a try/except with specific exception types.

    line 81
  14. Very specific:

    No test that only asserts response.status_code == 200 without also checking the body.

    line 93
  15. Distinctive:

    No FastAPI imports in services/.

    line 108
  16. Distinctive:

    No ORM. No query builder. Named parameters only.

    line 116
  17. Distinctive:

    No application logic in migrations.

    line 125
  18. Distinctive:

    If you find yourself building any of the following, stop:

    line 137
  19. Distinctive:

    Every operation a developer needs to do has a make target.

    line 155
  20. Distinctive:

    If it's not in the Makefile, it's not a supported operation.

    line 156
  21. Distinctive:

    When a migration is added, it is committed with the model change it enables.

    line 184
  22. Distinctive:

    Never commit a migration without the code that uses it.

    line 185

≈ “Common” is an estimate: at least 1 in 5 of the 12,729 CLAUDE.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
CLAUDE.md

CLAUDE.md — langgraph-fastapi-starter

This file defines how Claude Code operates within this repository. Read it completely before touching any file. It governs every decision.


What This Project Is

A production-grade starting point for AI agent backends. Not a demo. Not a tutorial. A template that a technical founder can fork, configure, and extend into a real product in under 30 minutes.

The constraint that shapes everything: minimum surface area for maximum production readiness. Every file that exists must earn its place. Every abstraction must be removable without breaking the system. Every decision must be documented so the person forking this can disagree with it and change it confidently.


The One Rule

This is a starter, not a framework.

A framework hides decisions. A starter exposes them.

When you are unsure whether to add something, ask: "Does a founder need to understand this to build their product?" If yes, it belongs. If it's infrastructure they'd never touch, it probably doesn't.


Architecture Principles

FastAPI + LangGraph + pgvector + Alembic. That is the stack. Do not extend it.

No Redis. No Celery. No Kafka. No additional databases. No service mesh. If something requires one of these to work, it does not belong in the starter. The founder can add them when they need them. The starter should not impose them.

One agent, one graph. The starter ships with a single example agent: a research assistant that uses web search and document retrieval. It exists to show how the graph is wired, not to be production-ready itself. It will be deleted and replaced by whoever forks this. Make it clear, not clever.

Alembic for all schema changes. No exceptions. No CREATE TABLE in application startup code. No schema changes in seed scripts. All database structure lives in migrations/. The startup sequence is: alembic upgrade head → seed (if needed) → run.

Sync database access, async FastAPI. Use psycopg2 (sync) for database operations inside a thread pool executor. FastAPI is async; database calls are sync and offloaded via run_in_executor. Do not introduce SQLAlchemy async. Do not introduce asyncpg. The complexity is not worth it at this stage. Document this decision in CLAUDE.md.

Structured logging, not print statements. Every log entry is JSON. Fields: timestamp, level, request_id, event, and any relevant context. Use Python's logging module with a JSON formatter. No third-party logging libraries. The founder will replace this with their preferred stack (Datadog, Plex, whatever) — keep it swappable.

API key auth, nothing more. Bearer token in Authorization header. Keys stored as bcrypt hashes in postgres. One table: api_keys (id, key_hash, name, tenant_id, role, created_at, last_used_at, revoked_at). No OAuth. No JWT. No sessions. If a founder needs OAuth, they will add it. The starter gives them the hook (a middleware function) but not the complexity.


Code Standards

Type hints are required on every function. Return types included. Any is banned. If you need Any, the data model is wrong.

Pydantic v2 for all request/response models. No TypedDict for API boundaries. No raw dicts. Every endpoint has a typed request model and a typed response model, even if trivial.

Error handling is explicit. Every endpoint has a try/except with specific exception types. HTTP errors use FastAPI's HTTPException with a code and a message that a developer can act on. No except Exception as e: return 500.

No global state outside of config. The database connection pool, the LangGraph graph instance, and the embedder are initialized at startup via FastAPI lifespan events and passed via dependency injection. Nothing is instantiated at module import time except the config singleton.

Tests are real assertions. Integration tests hit the actual FastAPI app via httpx.AsyncClient. Unit tests assert exact values, not just type or length. No test that only asserts response.status_code == 200 without also checking the body.


File Conventions

app/main.py — FastAPI app factory only. Lifespan events, middleware registration, router inclusion. No business logic. No database queries. No LangGraph calls.

app/routers/ — One file per resource: agents.py, api_keys.py, health.py. Routers contain endpoint definitions only. No SQL. No graph calls directly. Delegate to services/.

app/services/ — Business logic. agent_service.py calls the graph. api_key_service.py manages key lifecycle. These are plain Python classes. No FastAPI imports in services/.

app/graph/ — LangGraph definitions. graph.py builds and compiles the graph. nodes.py contains individual node implementations. state.py defines the TypedDict state. tools.py defines tools. Nothing in graph/ should import from routers/ or services/.

app/db/ — Database layer. connection.py manages the psycopg2 pool. queries.py contains raw SQL as module-level constants (not f-strings — parameterized). No ORM. No query builder. Named parameters only.

app/middleware/ — auth.py for API key validation. logging.py for request logging. Both are FastAPI middleware, not dependencies (they run on every request).

app/models/ — Pydantic models. requests.py and responses.py. Separate from database schema. The API shape and the database shape are allowed to differ.

migrations/ — Alembic migrations only. env.py, alembic.ini, versions/. No application logic in migrations.

scripts/ — Operational scripts: create_api_key.py, revoke_api_key.py, health_check.py. Runnable directly. Return exit code 0 on success, 1 on failure.

tests/ — Mirror of app/. test_routers/, test_services/, test_graph/. conftest.py provides fixtures: test database, test client, sample api key.


What Does Not Belong Here

If you find yourself building any of the following, stop:

  • A multi-tenant RBAC system (one role field is enough)
  • A webhook delivery system
  • A job queue or background task infrastructure
  • A file upload and storage system
  • An admin UI or dashboard
  • Any frontend code
  • Email or notification sending
  • Billing or subscription logic
  • Feature flags

These are real product needs. They are not starter needs. The founder builds them.


The Makefile Is the Interface

Every operation a developer needs to do has a make target. If it's not in the Makefile, it's not a supported operation. Targets must work with no arguments via sensible defaults. Targets must print what they're doing before they do it.


The README Is the Product

A founder evaluating this starter reads the README before looking at a single file. The README must answer exactly one question per section:

  • What is this? (one paragraph)
  • What does it ship with? (inventory table)
  • How do I run it? (six commands maximum)
  • What do I change first? (explicit list of extension points)
  • What did you decide and why? (design decisions)
  • What does the project structure mean? (annotated tree)

The README must not explain LangGraph. It must not explain pgvector. It must not explain FastAPI. Those projects have documentation. Link to them. The README explains this template.


Commit Discipline

One logical change per commit. Commit messages are imperative: "Add API key revocation endpoint" not "Added revocation" and not "misc fixes".

When a migration is added, it is committed with the model change it enables. Never commit a migration without the code that uses it.


Extension Points — Document These Explicitly

The starter must make it obvious where to add:

  1. New agent graphs (graph/): comment block pointing here
  2. New tools (graph/tools.py): comment block pointing here
  3. New API endpoints (routers/): comment block pointing here
  4. New database tables (migrations/): instructions for alembic revision
  5. New authentication methods (middleware/auth.py): comment block pointing here
  6. Environment-specific config (app/config.py): all values, documented defaults

These are not just documented in README. They are comment blocks in the code at the exact locations where a founder would add their code.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.