Analyze system architecture, component relationships, data flow, and architectural patterns.
Analyzes system architecture, component relationships, data flow, and architectural patterns.
/plugin marketplace add adelabdelgawad/fullstack-agents/plugin install adelabdelgawad-fullstack-agents-plugins-fullstack-agents@adelabdelgawad/fullstack-agentsAnalyze system architecture including component relationships, data flow, and architectural decisions.
/analyze architectureIdentify architectural layers:
# Backend layers
echo "=== Backend Layers ==="
[ -d "api/v1" ] && echo "Presentation: api/v1/ (Routers)"
[ -d "api/services" ] && echo "Business: api/services/"
[ -d "api/repositories" ] && echo "Data Access: api/repositories/"
[ -d "db" ] && echo "Database: db/"
# Frontend layers
echo "=== Frontend Layers ==="
[ -d "app/(pages)" ] && echo "Pages: app/(pages)/"
[ -d "components" ] && echo "Components: components/"
[ -d "lib" ] && echo "Libraries: lib/"
[ -d "app/api" ] && echo "API Routes: app/api/"
Analyze import relationships:
# Router dependencies
echo "=== Router → Service Dependencies ==="
grep -rh "from.*service import\|import.*service" api/v1/*.py 2>/dev/null
# Service dependencies
echo "=== Service → Repository Dependencies ==="
grep -rh "from.*repository import\|import.*repository" api/services/*.py 2>/dev/null
Document API endpoints:
# FastAPI endpoints
echo "=== Backend API Endpoints ==="
grep -rh "@router\.\(get\|post\|put\|delete\|patch\)" api/v1/*.py 2>/dev/null
# Next.js API routes
echo "=== Frontend API Routes ==="
find app/api -name "route.ts" 2>/dev/null
Entity relationships:
# Find relationships in models
echo "=== Model Relationships ==="
grep -n "relationship\|ForeignKey" db/models.py 2>/dev/null
## Architecture Analysis Report
**Generated:** {timestamp}
### System Overview
┌─────────────────────────────────────────────────────────────────┐ │ Client (Browser) │ └─────────────────────────────┬───────────────────────────────────┘ │ ▼ ┌─────────────────────────────────────────────────────────────────┐ │ Next.js Frontend (SSR) │ │ ┌─────────────┐ ┌─────────────┐ ┌─────────────────────────┐ │ │ │ Pages │ │ Components │ │ Context Providers │ │ │ │ (SSR+SWR) │ │ (Client) │ │ (State Management) │ │ │ └──────┬──────┘ └──────┬──────┘ └───────────┬─────────────┘ │ │ │ │ │ │ │ └────────────────┴──────────────────────┘ │ │ │ │ │ API Routes │ │ (Proxy to Backend) │ └─────────────────────────────┬───────────────────────────────────┘ │ ▼ ┌─────────────────────────────────────────────────────────────────┐ │ FastAPI Backend │ │ ┌─────────────┐ ┌─────────────┐ ┌─────────────────────────┐ │ │ │ Routers │→ │ Services │→ │ Repositories │ │ │ │ (v1/) │ │ (Business) │ │ (Data Access) │ │ │ └─────────────┘ └─────────────┘ └───────────┬─────────────┘ │ │ │ │ └─────────────────────────────────────────────────┬───────────────┘ │ │ ▼ ▼ ┌────────────────────┐ ┌─────────────────────────────────────────┐ │ Redis │ │ PostgreSQL │ │ (Cache/Queue) │ │ (Database) │ └────────────────────┘ └─────────────────────────────────────────┘ │ ▼ ┌─────────────────────────────────────────────────────────────────┐ │ Celery Workers │ │ ┌─────────────┐ ┌─────────────┐ ┌─────────────────────────┐ │ │ │ Worker │ │ Beat │ │ Flower │ │ │ │ (Tasks) │ │ (Scheduler) │ │ (Monitoring) │ │ │ └─────────────┘ └─────────────┘ └─────────────────────────┘ │ └─────────────────────────────────────────────────────────────────┘
### Layer Architecture
#### Backend (FastAPI)
| Layer | Purpose | Location | Dependencies |
|-------|---------|----------|--------------|
| **Router** | HTTP handling, validation | `api/v1/` | Service |
| **Service** | Business logic | `api/services/` | Repository |
| **Repository** | Data access | `api/repositories/` | Database |
| **Schema** | Data transfer objects | `api/schemas/` | None |
| **Model** | Database entities | `db/models.py` | SQLAlchemy |
**Dependency Rule:** Router → Service → Repository (never reverse)
#### Frontend (Next.js)
| Layer | Purpose | Location | Type |
|-------|---------|----------|------|
| **Page** | Route + SSR data | `app/(pages)/` | Server |
| **Table** | Data display + SWR | `_components/table/` | Client |
| **Context** | CRUD operations | `context/` | Client |
| **API Routes** | Backend proxy | `app/api/` | Server |
### Data Flow
#### Request Flow (List Products)
#### Mutation Flow (Create Product)
### Entity Relationships
┌──────────────────┐ │ User │ │──────────────────│ │ id │ │ email │ │ role │ └────────┬─────────┘ │ │ 1:N ▼ ┌──────────────────┐ ┌──────────────────┐ │ Order │──────→│ Product │ │──────────────────│ N:M │──────────────────│ │ id │ │ id │ │ user_id (FK) │ │ name │ │ status │ │ price │ │ total │ │ category_id (FK) │ └──────────────────┘ └────────┬─────────┘ │ │ N:1 ▼ ┌──────────────────┐ │ Category │ │──────────────────│ │ id │ │ name │ └──────────────────┘
### Architectural Patterns
| Pattern | Implementation | Location |
|---------|----------------|----------|
| Repository Pattern | Data access abstraction | `api/repositories/` |
| Service Layer | Business logic isolation | `api/services/` |
| Single Session Per Request | Session passed through layers | Router → Service → Repo |
| SSR + SWR Hybrid | Server render + client updates | Next.js pages |
| API Proxy | Frontend doesn't call backend directly | `app/api/` routes |
| Context Pattern | State management for CRUD | `context/*.tsx` |
### Architectural Decisions
1. **Why Repository Pattern?**
- Isolates data access logic
- Makes services testable with mocks
- Single place for query optimization
2. **Why Single Session Per Request?**
- Ensures transaction consistency
- Avoids connection pool exhaustion
- Simplifies error handling
3. **Why SSR + SWR?**
- SEO-friendly initial render
- Fast client-side updates
- Automatic background revalidation
4. **Why API Proxy?**
- Hides backend from client
- Handles auth token refresh
- Enables request transformation
### Recommendations
1. **Consider adding API versioning**
- Current: `/api/v1/`
- Allows breaking changes in future versions
2. **Add circuit breaker for external services**
- Prevents cascade failures
- Graceful degradation
3. **Consider event-driven architecture**
- For cross-service communication
- Async processing with Celery
Designs feature architectures by analyzing existing codebase patterns and conventions, then providing comprehensive implementation blueprints with specific files to create/modify, component designs, data flows, and build sequences