Skip to content

Commit 4743b5c

Browse files
authored
feat: add Mermaid diagrams and enhanced validation (#3)
* feat: add Mermaid diagrams and enhanced validation Add 5 Mermaid diagrams replacing ASCII art: - Layered Architecture (docs/architecture.md) - Data Flow sequence diagram (docs/architecture.md) - Test Pyramid (docs/architecture.md) - Getting Started Flow (docs/quickstart.md) - CBA Workflow (codebase-agent.md) Also: - Fix malformed code block endings in architecture.md - Enhance validate-mermaid.sh to extract and validate inline diagrams from markdown files (not just standalone .mmd) * fix: use portable arithmetic in validate-mermaid.sh Replace ((var++)) with var=$((var + 1)) to avoid exit code 1 when incrementing from 0 with set -e enabled. * fix: configure puppeteer for CI sandbox restrictions Add puppeteer-config.json with --no-sandbox for GitHub Actions. Update validate-mermaid.sh to use config when available.
1 parent 1d7e5fc commit 4743b5c

File tree

6 files changed

+251
-76
lines changed

6 files changed

+251
-76
lines changed

.claude/agents/codebase-agent.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,29 @@ color: blue
2121

2222
You are the Codebase Agent for the Ambient Code Reference Repository. You assist with autonomous codebase operations while maintaining safety, quality, and adherence to project standards.
2323

24+
## CBA Workflow
25+
26+
```mermaid
27+
flowchart TB
28+
A[Issue Received] --> B{Clear Requirements?}
29+
B -->|No| C[Ask for Clarification]
30+
C --> A
31+
B -->|Yes| D[Analyze Codebase]
32+
D --> E[Create Implementation Plan]
33+
E --> F[Show Plan to User]
34+
F --> G{Approved?}
35+
G -->|No| E
36+
G -->|Yes| H[Implement Changes]
37+
H --> I[Run Linters & Tests]
38+
I --> J{All Pass?}
39+
J -->|No| H
40+
J -->|Yes| K[Create PR]
41+
K --> L[Wait for Human Review]
42+
L --> M{Approved?}
43+
M -->|Changes Requested| H
44+
M -->|Yes| N[Merge]
45+
```
46+
2447
## Core Capabilities
2548

2649
### 1. Issue-to-PR Automation

.github/workflows/docs-validation.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ jobs:
3030
else
3131
echo "No Mermaid diagrams to validate"
3232
fi
33+
env:
34+
PUPPETEER_CONFIG: ${{ github.workspace }}/scripts/puppeteer-config.json
3335

3436
lint-markdown:
3537
runs-on: ubuntu-latest

docs/architecture.md

Lines changed: 77 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,37 @@ The Ambient Code Reference Repository demonstrates a **layered architecture** wi
66

77
## Layered Architecture
88

9-
```text
10-
┌─────────────────────────────────────┐
11-
│ API Layer (FastAPI) │ HTTP, routes, serialization
12-
├─────────────────────────────────────┤
13-
│ Service Layer (Logic) │ Business rules, orchestration
14-
├─────────────────────────────────────┤
15-
│ Model Layer (Pydantic) │ Validation, types
16-
├─────────────────────────────────────┤
17-
│ Core Layer (Utilities) │ Config, security, logging
18-
└─────────────────────────────────────┘
19-
```text
9+
```mermaid
10+
flowchart TB
11+
subgraph API["API Layer (FastAPI)"]
12+
direction LR
13+
Routes[Routes]
14+
Handlers[Handlers]
15+
Serialization[Serialization]
16+
end
17+
subgraph Service["Service Layer (Logic)"]
18+
direction LR
19+
Business[Business Rules]
20+
Orchestration[Orchestration]
21+
end
22+
subgraph Model["Model Layer (Pydantic)"]
23+
direction LR
24+
Validation[Validation]
25+
Types[Types]
26+
end
27+
subgraph Core["Core Layer (Utilities)"]
28+
direction LR
29+
Config[Config]
30+
Security[Security]
31+
Logging[Logging]
32+
end
33+
34+
API --> Service
35+
Service --> Model
36+
Model --> Core
37+
API --> Core
38+
Service --> Core
39+
```
2040

2141
### API Layer
2242

@@ -39,7 +59,7 @@ def create_item(data: ItemCreate) -> Item:
3959
return item_service.create_item(data)
4060
except ValueError as e:
4161
raise HTTPException(status_code=409, detail=str(e))
42-
```text
62+
```
4363

4464
### Service Layer
4565

@@ -73,7 +93,7 @@ def create_item(self, data: ItemCreate) -> Item:
7393
self._next_id += 1
7494

7595
return item
76-
```text
96+
```
7797

7898
### Model Layer
7999

@@ -97,7 +117,7 @@ class ItemCreate(ItemBase):
97117
@classmethod
98118
def sanitize_name(cls, v: str) -> str:
99119
return sanitize_string(v, max_length=200)
100-
```text
120+
```
101121

102122
### Core Layer
103123

@@ -121,32 +141,32 @@ class Settings(BaseSettings):
121141
env_file = ".env"
122142

123143
settings = Settings()
124-
```text
144+
```
125145

126146
## Data Flow
127147

128148
### Creating an Item
129149

130-
```text
131-
1. Client sends POST /api/v1/items
132-
133-
2. API Layer (items.py)
134-
- Pydantic validates request body
135-
- create_item() called
136-
137-
3. Service Layer (item_service.py)
138-
- Check business rules (duplicate slug)
139-
- Create Item model
140-
- Store in memory
141-
142-
4. Model Layer (item.py)
143-
- Sanitize fields
144-
- Validate types
145-
146-
5. API Layer returns 201 Created
147-
- Serialize Item to JSON
148-
- Return to client
149-
```text
150+
```mermaid
151+
sequenceDiagram
152+
participant Client
153+
participant API as API Layer
154+
participant Svc as Service Layer
155+
participant Model as Model Layer
156+
157+
Client->>+API: POST /api/v1/items
158+
API->>API: Pydantic validates request
159+
API->>+Svc: create_item(data)
160+
Svc->>Svc: Check business rules
161+
Svc->>+Model: Create Item model
162+
Model->>Model: Sanitize fields
163+
Model->>Model: Validate types
164+
Model-->>-Svc: Item instance
165+
Svc->>Svc: Store in memory
166+
Svc-->>-API: Item object
167+
API->>API: Serialize to JSON
168+
API-->>-Client: 201 Created + Item
169+
```
150170

151171
## Design Patterns
152172

@@ -164,7 +184,7 @@ item_service = ItemService()
164184

165185
# app/api/v1/items.py
166186
from app.services.item_service import item_service
167-
```text
187+
```
168188

169189
### Dependency Injection (Implicit)
170190

@@ -180,7 +200,7 @@ def create_item(
180200
service: ItemService = Depends(get_item_service)
181201
):
182202
return service.create_item(data)
183-
```text
203+
```
184204

185205
### Validation Pipeline
186206

@@ -197,7 +217,7 @@ class ItemCreate(ItemBase):
197217
@classmethod
198218
def validate_slug_field(cls, v: str) -> str:
199219
return validate_slug(v)
200-
```text
220+
```
201221

202222
## Security Architecture
203223

@@ -232,21 +252,27 @@ class Settings(BaseSettings):
232252

233253
class Config:
234254
env_file = ".env"
235-
```text
255+
```
236256

237257
## Testing Architecture
238258

239259
### Test Pyramid
240260

241-
```text
242-
┌──────────┐
243-
│ E2E │ Few, slow (workflow tests)
244-
├──────────┤
245-
│Integration│ Some, medium (API tests)
246-
├──────────┤
247-
│ Unit │ Many, fast (service tests)
248-
└──────────┘
249-
```text
261+
```mermaid
262+
flowchart TB
263+
subgraph E2E["E2E Tests"]
264+
E[Few, Slow - Workflow Tests]
265+
end
266+
subgraph Integration["Integration Tests"]
267+
I[Some, Medium - API Tests]
268+
end
269+
subgraph Unit["Unit Tests"]
270+
U[Many, Fast - Service Tests]
271+
end
272+
273+
E2E --> Integration
274+
Integration --> Unit
275+
```
250276

251277
**Unit**: Test service layer in isolation
252278
**Integration**: Test API with TestClient
@@ -266,7 +292,7 @@ JSON format for log aggregation:
266292
"message": "Item created",
267293
"request_id": "abc123"
268294
}
269-
```text
295+
```
270296

271297
### Health Endpoints
272298

@@ -321,7 +347,7 @@ async def add_request_id(request: Request, call_next):
321347
request.state.request_id = generate_id()
322348
response = await call_next(request)
323349
return response
324-
```text
350+
```
325351

326352
### Adding Database
327353

@@ -330,7 +356,7 @@ async def add_request_id(request: Request, call_next):
330356
from sqlalchemy.ext.asyncio import create_async_engine
331357

332358
engine = create_async_engine(settings.database_url)
333-
```text
359+
```
334360

335361
## Best Practices
336362

docs/quickstart.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,23 @@ This is a **documentation-only reference** for AI-assisted development patterns.
1212

1313
**Looking for a working application?** See [demo-fastapi](https://github.com/jeremyeder/demo-fastapi)
1414

15+
### Getting Started Flow
16+
17+
```mermaid
18+
flowchart LR
19+
A[Clone Repo] --> B[Explore Docs]
20+
B --> C{What do you need?}
21+
C -->|CBA Setup| D[Copy .claude/]
22+
C -->|Architecture| E[Read docs/architecture.md]
23+
C -->|Testing| F[Read testing-patterns.md]
24+
C -->|CI/CD| G[Copy .github/workflows/]
25+
D --> H[Customize for your project]
26+
E --> H
27+
F --> H
28+
G --> H
29+
H --> I[Ship It]
30+
```
31+
1532
## Prerequisites
1633

1734
- Python 3.11 or 3.12 (for documentation tooling)

scripts/puppeteer-config.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"args": ["--no-sandbox", "--disable-setuid-sandbox"]
3+
}

0 commit comments

Comments
 (0)