Scans repository structure and generates comprehensive architecture documentation including system overview, entry points, module relationships, data flow diagrams, and "edit here for X" guides. Creates ARCHITECTURE.md for onboarding and navigation. Use when users request "document the codebase", "explain the architecture", "create onboarding docs", or "map the system".
Generate comprehensive architecture documentation from repository analysis.
# Architecture Overview
## System Summary
[Project Name] is a [type] application built with [stack]. It follows [architecture pattern] and handles [primary use cases].
**Tech Stack:**
- Frontend: [framework + key libraries]
- Backend: [framework + key libraries]
- Database: [database + ORM]
- Infrastructure: [hosting + CI/CD]
## High-Level Architecture
```mermaid
graph TB
Client[Client/Browser] --> API[API Layer]
API --> Services[Business Logic]
Services --> DB[(Database)]
Services --> Cache[(Redis Cache)]
API --> Queue[Message Queue]
```
src/
├── app/ # Application entry point and routing
├── components/ # Reusable UI components
├── lib/ # Utility functions and helpers
├── services/ # Business logic layer
├── models/ # Data models and schemas
└── types/ # TypeScript type definitions
Main Application: src/app/page.tsx
API Routes: src/app/api/
Authentication (src/services/auth/)
User Management (src/services/users/)
Data Layer (src/models/)
sequenceDiagram
Client->>API: POST /api/auth/register
API->>Validation: Validate input
Validation->>Services: UserService.create()
Services->>Database: Insert user
Database-->>Services: User created
Services->>Email: Send welcome email
Services-->>API: Return JWT
API-->>Client: 201 Created
src/app/api/[endpoint]/route.ts)src/services/)src/models/)// src/services/users/user.service.ts
export class UserService {
async findById(id: string) {
return prisma.user.findUnique({ where: { id } });
}
async create(data: CreateUserDto) {
// Validation, business logic, database operations
}
}
// src/repositories/user.repository.ts
export class UserRepository {
async findAll() {
/* DB queries only */
}
async findById(id: string) {
/* DB queries only */
}
}
Create route file: src/app/api/[name]/route.ts
export async function GET(req: Request) {
// Implementation
}
Add service logic: src/services/[name].service.ts
Define types: src/types/[name].ts
Add tests: src/app/api/[name]/route.test.ts
Update API docs: Document in OpenAPI/Swagger
Update schema: prisma/schema.prisma
model NewModel {
id String @id @default(cuid())
// fields
}
Run migration: npx prisma migrate dev --name add-new-model
Generate types: npx prisma generate
Create service: src/services/new-model.service.ts
Add CRUD routes: src/app/api/new-model/
src/components/NewComponent/NewComponent.tsxNewComponent.module.css or inline TailwindNewComponent.test.tsxNewComponent.stories.tsx (if using Storybook)src/components/index.tssrc/services/auth/auth.service.tssrc/middleware/auth.middleware.tssrc/app/api/auth/| File | Purpose | Modify For |
| ---------------------- | ---------------------- | --------------------- |
| src/app/layout.tsx | Root layout, providers | Global layout changes |
| src/lib/db.ts | Database connection | Connection config |
| src/lib/api.ts | API client setup | Request interceptors |
| src/middleware.ts | Next.js middleware | Auth, redirects |
| prisma/schema.prisma | Database schema | Data model changes |
| .env.example | Environment vars | Adding config values |
next - React frameworkprisma - ORM and database toolkitreact - UI librarytypescript - Type safetyzod - Schema validationbcrypt - Password hashingjsonwebtoken - JWT handlingdate-fns - Date utilitiespnpm testDatabase connection errors
npx prisma generateType errors after schema changes
npx prisma generateBuild fails
.next folder: rm -rf .nextrm -rf node_modules && pnpm install
## Analysis Techniques
### Identify Framework
Look for telltale files:
- `next.config.js` → Next.js
- `vite.config.ts` → Vite
- `nest-cli.json` → NestJS
- `manage.py` → Django
- `Cargo.toml` → Rust
### Map Entry Points
- Frontend: `index.html`, `main.tsx`, `app.tsx`, `_app.tsx`
- Backend: `main.ts`, `server.ts`, `app.py`, `index.js`
- CLI: `cli.ts`, `__main__.py`, `main.go`
### Trace Request Flow
Follow typical paths:
1. Route/endpoint definition
2. Middleware/guards
3. Controller/handler
4. Service/business logic
5. Repository/model
6. Database query
### Module Categories
- **Core**: Essential business logic
- **Infrastructure**: Database, cache, queue
- **Utilities**: Helpers, formatters, validators
- **Features**: User-facing functionality
- **Config**: Environment, settings
## Mermaid Diagrams
### Architecture Diagram
```mermaid
graph LR
Client --> NextJS
NextJS --> API
API --> Services
Services --> Prisma
Prisma --> PostgreSQL
sequenceDiagram
participant Client
participant API
participant Service
participant DB
Client->>API: Request
API->>Service: Process
Service->>DB: Query
DB-->>Service: Data
Service-->>API: Result
API-->>Client: Response
graph TB
API[API Layer] --> Auth[Auth Service]
API --> Users[User Service]
Auth --> DB[(Database)]
Users --> DB
Users --> Cache[(Cache)]
Every codebase summary should include:
npx skills add patricio0312rev/codebase-summarizer下载完整 Skill 目录,包含 SKILL.md 及所有相关文件
Search for places (restaurants, cafes, etc.) via Google Places API proxy on localhost.
Interact with GitHub using the `gh` CLI. Use `gh issue`, `gh pr`, `gh run`, and `gh api` for issues, PRs, CI runs, and advanced queries.
Create or update AgentSkills. Use when designing, structuring, or packaging skills with scripts, references, and assets.
Start voice calls via the OpenClaw voice-call plugin.
Notion API for creating and managing pages, databases, and blocks.
Gemini CLI for one-shot Q&A, summaries, and generation.
Category:developer