Skip to content

Commit cfb601e

Browse files
authored
Init ARCHITECTURE.md and AGENTS.md (knative#3296)
* ai agents init * add AGENTS.local.md override * contributing file ref * AI use when contributing * suggestions * more suggestions
1 parent ba53524 commit cfb601e

File tree

7 files changed

+273
-10
lines changed

7 files changed

+273
-10
lines changed

.claude/CLAUDE.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Read AGENTS.md for instructions

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ __pycache__
3131
/templates/python/cloudevents/.venv
3232
/templates/python/http/.venv
3333

34+
# AI
35+
AGENTS.override.md
36+
.claude/*.local.*
37+
3438
# E2E Tests
3539
/e2e/testdata/default_home/go
3640
/e2e/testdata/default_home/.cache

AGENTS.md

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# AGENTS.md
2+
3+
## OVERRIDE
4+
5+
Use `AGENTS.override.md` file WITH HIGHEST PRECEDENCE if it exists. Do NOT mix
6+
instructions from both files together. The `AGENTS.override.md` is a complete
7+
override for `AGENTS.md`. Otherwise, continue.
8+
9+
## ALWAYS keep in mind
10+
11+
Don't sugar coat anything. Act like a professional software developer and
12+
engineer. If working autonomously, adhere to architecture, naming
13+
conventions and coding standards in this codebase. If unsure, read similar
14+
files and get some inspiration from the rest of this codebase. If introducing
15+
new features, make sure to cover them via unit tests and don't forget to take
16+
edge cases into account.
17+
18+
## Commands
19+
20+
### Build & Development
21+
- `make all` - Build binary and regenerate docs
22+
- `make build` - Build for current OS
23+
24+
### Testing strategy reference
25+
Before committing, test locally following the table below:
26+
27+
| If changed | Target | Description |
28+
|------------|--------|-------------|
29+
| `*.go` files | `make test` | Core unit tests |
30+
| Any files | `make check` | Linting, formatting, spelling |
31+
| `templates/` files | `make test-templates` | All language template tests |
32+
| Significant architectural changes | `make test-full` | e2e tests (cluster required - read `CONTRIBUTING.md`) |
33+
34+
### Generated Files
35+
- `./hack/update-codegen.sh` - update embedded filesystem & regenerate docs
36+
- `make check-embedded-fs` - check embedded FS is up to date with templates
37+
38+
39+
## Boundaries
40+
41+
### Always Do
42+
- Run `make test` before considering any change complete
43+
- Run `make check` before commits
44+
- Run `make check-embedded-fs` after modifying `templates/`
45+
- Ask before deleting ANY file or significant code block
46+
47+
### Ask First
48+
- Security-related code changes (authentication, credentials, secrets handling)
49+
- API changes
50+
- Adding new dependencies
51+
- Modifying CI/GitHub Actions workflows
52+
- Architectural decisions
53+
54+
### Never Do
55+
- Edit generated files directly:
56+
- `generate/zz_filesystem_generated.go`
57+
- `schema/func_yaml-schema.json`
58+
- Commit secrets, API keys, or credentials
59+
- Delete files without explicit user approval
60+
- Force push to main/master branch
61+
- Skip tests or linting
62+
63+
## Common Pitfalls
64+
65+
### Codegen Sync
66+
After modifying `templates/` or making documentation changes, you MUST run:
67+
```bash
68+
./hack/update-codegen.sh
69+
```
70+
71+
72+
## Contributing
73+
74+
If creating a contribution to this project on GitHub suggest to user reading
75+
CONTRIBUTING.md.

ARCHITECTURE.md

Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
# Architecture
2+
3+
## High level overview
4+
5+
Knative Func is a CLI that simplifies building and deploying serverless functions
6+
on Kubernetes. Instead of writing Dockerfiles and Kubernetes manifests,
7+
developers run `func create`, `func build`, and `func deploy`. The CLI handles
8+
image building (via Buildpacks, S2I, or direct OCI), registry pushing, and
9+
Knative Service creation or newly available bare K8s deployment.
10+
11+
## Code Map
12+
13+
```
14+
cmd/ # CLI commands (Cobra) - START HERE
15+
func/main.go # Entry point
16+
build.go, deploy.go # Individual commands
17+
18+
pkg/
19+
functions/ # Core library - the "brain"
20+
client.go # Central orchestrator, defines all interfaces
21+
function.go # Function type representing a project
22+
23+
buildpacks/ # Pack/Cloud Native Buildpacks builder (in container)
24+
s2i/ # Source-to-Image builder (in container)
25+
oci/ # Direct OCI image builder (on host)
26+
27+
knative/ # Knative Serving deployer
28+
k8s/ # Kubernetes utilities
29+
30+
pipelines/tekton/ # Remote builds via Tekton
31+
mcp/ # AI agent integration (MCP server)
32+
33+
templates/ # Function scaffolding (go, node, python, etc.)
34+
generate/ # Embedded filesystem (generated)
35+
schema/ # JSON schemas
36+
```
37+
38+
## Entry Point
39+
40+
```
41+
cmd/func/main.go
42+
└── pkg/app.Main()
43+
└── cmd.NewRootCmd()
44+
└── Individual commands (build, deploy, create, ...)
45+
```
46+
47+
The CLI in `cmd/` servers as a terminal frontend and a reference implementation
48+
for using `pkg/functions`. Commands parse flags, create a `Client` and
49+
delegate to `pkg/functions/client.go`:
50+
51+
```go
52+
// Typical command pattern
53+
client, _ := fn.New(fn.WithBuilder(buildpacks.NewBuilder()))
54+
client.Build(ctx, f)
55+
```
56+
57+
## Key Search Terms
58+
59+
When exploring the codebase, search for these:
60+
61+
| Term | Where | What it does |
62+
|------|-------|--------------|
63+
| `fn.Client` | `pkg/functions/client.go` | Main client type for all operations |
64+
| `NewClient` | `cmd/client.go` | Creates fully-configured client |
65+
| `ClientFactory` | `cmd/root.go` | Function type for client creation |
66+
| `Builder` | `pkg/functions/client.go` | Interface for function builders |
67+
| `Deployer` | `pkg/functions/client.go` | Interface for function deployers |
68+
| `Function` | `pkg/functions/function.go` | Type representing a function |
69+
70+
## Layer Architecture
71+
72+
```mermaid
73+
flowchart TB
74+
CLI[CLI Layer<br/>cmd/] --> Client[Client Layer<br/>pkg/functions/]
75+
Client --> Builders[Builders]
76+
Client --> Deployers[Deployers<br/>pkg/k8s/, pkg/knative/]
77+
Client --> Pipelines[Pipelines<br/>pkg/pipelines/]
78+
Client --> Other[Other Providers]
79+
80+
Builders --> Buildpack[Buildpacks<br/>pkg/buildpacks/]
81+
Builders --> S2I[S2I<br/>pkg/s2i/]
82+
Builders --> OCI[OCI<br/>pkg/oci/]
83+
```
84+
85+
### CLI Layer (`cmd/`)
86+
87+
- Cobra commands: build.go, deploy.go, create.go, run.go, delete.go, etc.
88+
- Handles flags, user prompts, output formatting
89+
- Delegates all business logic to Client
90+
91+
### Client Layer (`pkg/functions/`)
92+
93+
- `client.go`: Central orchestrator for all function operations
94+
- Defines core interfaces: Builder, Pusher, Deployer, Runner, Remover, Lister, Describer
95+
- `function.go`: Function type representing a function project
96+
97+
### Builders
98+
99+
Implement the `Builder` interface (source → OCI image):
100+
- `pkg/buildpacks/`: Cloud Native Buildpacks via Pack
101+
- `pkg/s2i/`: Red Hat Source-to-Image
102+
- `pkg/oci/`: Direct OCI image building on host
103+
104+
### Deployers
105+
106+
- `pkg/knative/`: Creates/updates Knative Services
107+
- `pkg/k8s/`: Kubernetes utilities & Services
108+
109+
## Function Lifecycle
110+
111+
```mermaid
112+
flowchart LR
113+
Create[func create] --> Build[func build]
114+
Create[func create] --> Deploy[func Deploy]
115+
Create[func create] --> Run[func Run]
116+
Deploy --> Invoke[func invoke]
117+
Run --> Invoke[func invoke]
118+
119+
Build --> Deploy[func deploy]
120+
Build --> Run[func run]
121+
122+
subgraph "Optional"
123+
Build[func build]
124+
end
125+
126+
subgraph "Local Dev"
127+
Run[func run]
128+
end
129+
```
130+
131+
| Stage | Client Method | Description |
132+
|-------|---------------|-------------|
133+
| Create | `Init()` | Create boilerplate project from template |
134+
| Scaffold | `Scaffold()` | Scaffold project as a service|
135+
| Build | `Build()` | Produce OCI image via Builder |
136+
| Deploy | `Deploy()` | Push image, create K8s/Knative Service |
137+
| Run | `Run()` | Local execution for development |
138+
| Invoke | `Invoke()` | Send request to deployed function |
139+
140+
## Key Interfaces
141+
142+
Defined in `pkg/functions/client.go`:
143+
144+
| Interface | Purpose |
145+
|-----------|---------|
146+
| `Builder` | Source → OCI image |
147+
| `Pusher` | Image → Registry |
148+
| `Deployer` | Image → Service on K8s |
149+
| `Runner` | Local execution |
150+
| `Remover` | Delete deployed function |
151+
| `Lister` | List deployed functions |
152+
| `Describer` | Describe function instances |
153+
| `PipelinesProvider` | Remote build orchestration |
154+
155+
## Subsystems
156+
157+
### Pipelines (Remote Builds)
158+
159+
Located in `pkg/pipelines/tekton/`. Enables `func deploy --remote` to build on-cluster via Tekton instead of locally. Supports Pipelines-as-Code (PAC) for GitOps workflows.
160+
161+
### MCP Server
162+
163+
Located in `pkg/mcp/`. Started via `func mcp start` (Agents should run this). Allows AI agents (Claude Code, Cursor) to create/build/deploy functions programmatically. Read-only by default; set `FUNC_ENABLE_MCP_WRITE=true` for full access.
164+
165+
### Configuration
166+
167+
- `func.yaml`: Function metadata, build/deploy options, environment variables. Schema: `schema/func_yaml-schema.json`
168+
- Templates in `templates/` embedded at build time into `generate/zz_filesystem_generated.go`
169+
- Runtimes: go, node, python, rust, quarkus, springboot, typescript
170+
- Invocation styles: http, cloudevents
171+
172+
## AI
173+
174+
### Custom instructions file
175+
176+
Currently the `AGENTS.md` file is read by many agents by default. The very top
177+
of that file defines an optional custom override `AGENTS.override.md` and instructs
178+
agents to read it with highest precedence. You can create that file and add it at
179+
root of the repository if you so desire. It won't be source controlled (see `.gitignore`)

CLAUDE.md

Lines changed: 0 additions & 4 deletions
This file was deleted.

CONTRIBUTING.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ This document details how to get started contributing to the project. This incl
55
**Tip**:
66
Install git hooks that do basic pre-commit checks.
77

8+
**Tip**:
9+
Read through our (architecture)[ARCHITECTURE.md] file for how we structure this project (Or have AI do it!)
10+
811
```sh
912
make setup-githooks
1013
```
@@ -81,7 +84,12 @@ To run integration tests, use `make test-integration`.
8184

8285
The cluster and registry can be deleted by running `hack/delete.sh`
8386

87+
## Using AI
8488

89+
General instruction are available for AI agents in `AGENTS.md`.
90+
If you prefer your own instructions, you can instead create `AGENTS.override.md`.
8591

86-
87-
92+
Usually AI agents read the `AGENTS.md` file by default. At the top of this file
93+
there is an override directive which points the AI agent to instead read this
94+
`AGENTS.override.md` and follow it. It is preemptively part of `.gitignore` so
95+
that it is not source controlled.

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
[Try the QuickStart](https://knative.dev/docs/getting-started/about-knative-functions/)
1313
[Read the Documentation](https://knative.dev/docs/functions/)
1414

15+
## Architecture
16+
17+
For more information about how this project is structured please read our [architecture documentation](ARCHITECTURE.md)
18+
1519
## Command Reference
1620

1721
For detailed documentation on all available `func` commands, including usage examples and options, see the [Command Reference Documentation](docs/reference/). This reference covers all commands from creating and deploying functions to managing configurations and repositories.
@@ -29,7 +33,3 @@ We are always looking for contributions from the Function Developer community.
2933
For a list of all help wanted issues in Knative, take a look at [CLOTRIBUTOR](https://clotributor.dev/search?project=knative&page=1).
3034

3135
The `func` Working Group meets @ 10:00 US Eastern every Tuesday, we'd love to have you! For more information, see the invitation on the [Knative Team Calendar](https://calendar.google.com/calendar/u/0/embed?src=knative.team_9q83bg07qs5b9rrslp5jor4l6s@group.calendar.google.com).
32-
33-
## Roadmap
34-
35-
Our project roadmap can be found: https://github.com/orgs/knative/projects/49

0 commit comments

Comments
 (0)