Architecture Analyzer
This skill provides a systematic workflow for conducting comprehensive architectural analysis of codebases.
Purpose
This skill enables deep analysis of codebase architecture by examining:
- Project structure and organization
- Technology stack and dependencies
- Database design and relationships
- Design patterns and architectural decisions
- Authentication, authorization, and security systems
- API structure and endpoints
- Frontend architecture and state management
- Backend architecture and business logic
- Code quality and maintainability
When to Use This Skill
Use this skill when:
- A user requests an architectural overview or deep analysis of a codebase
- Documentation of existing architecture is needed
- Understanding system design decisions is required
- Onboarding new developers to a complex codebase
- Planning major refactoring or feature additions
- Auditing code quality and architectural patterns
- A user asks for suggestions to improve a codebase
Scripts
suggest_improvements.py
Analyzes a Python codebase and suggests improvements based on cyclomatic complexity and maintainability index.
Usage:
python suggest_improvements.py <path_to_codebase>
AI Agent Analysis Workflow
This workflow is designed for an AI agent to perform architectural analysis using its available tools.
Step 1: High-Level Exploration
List Files Recursively:
- Use
ls -Rto get a complete, recursive listing of all files and directories in the repository. - Save this output to a file (e.g.,
file_listing.txt) for reference. - From this listing, identify key files such as
package.json,requirements.txt,pom.xml,Dockerfile,docker-compose.yml, and any files in directories namedconfig,database, ormigrations.
- Use
Read Key Configuration Files:
- Read the contents of the dependency management files (
package.json,requirements.txt, etc.) to identify the primary frameworks and libraries. - Read any database configuration files to determine the database system and connection details.
- Read Docker-related files to understand the containerization setup.
- Read the contents of the dependency management files (
Step 2: Source Code Analysis
Identify Application Entry Points:
- For a web application, search for files that listen on a port (e.g.,
grep -r "app.listen" .). - For a standalone application, look for a
mainfunction or script (grep -r "if __name__ == '__main__':" .for Python).
- For a web application, search for files that listen on a port (e.g.,
Trace Code Paths:
- Starting from an entry point, use
grepto follow function calls and class instantiations to understand the high-level control flow. - For example, if you find a route definition like
app.get('/users', UserController.getUsers), you would then search for theUserControllerclass and itsgetUsersmethod.
- Starting from an entry point, use
Investigate Key Architectural Components:
- Models/Entities: Use
grepto find class definitions that appear to be data models (e.g.,grep -r "class User" .). - Controllers/Views: Look for files that handle incoming requests and outgoing responses.
- Services/Business Logic: Search for files that contain the core application logic, often found in directories named
services,lib, orapp. - Database Interactions: Search for common database query methods (e.g.,
grep -r ".find(" .,grep -r ".query(" .,grep -r "SELECT .* FROM" .).
- Models/Entities: Use
Step 3: Synthesize and Document
Create a Markdown Document:
- Start a new Markdown file (e.g.,
ARCHITECTURE.md).
- Start a new Markdown file (e.g.,
Document Findings:
- Technology Stack: Based on the configuration files, list the primary languages, frameworks, and libraries.
- Directory Structure: Use the file listing to create a summary of the important directories and their purposes.
- Data Model: Describe the main data entities and their relationships.
- Control Flow: Explain how a typical request flows through the application.
- Architectural Patterns: Based on your analysis, identify any architectural patterns in use (e.g., MVC, RESTful API, Microservices).
Suggest Improvements:
- Run the
suggest_improvements.pyscript on the codebase. - Incorporate the script's output into a "Recommendations" section of your
ARCHITECTURE.mdfile.
- Run the
Conceptual Analysis Workflow
Phase 1: Project Discovery
Identify the root directory structure
- List top-level directories to understand project organization
- Identify frontend, backend, database, and configuration directories
- Note any monorepo or multi-service architecture
Analyze dependency files
- Backend: Check for
package.json,requirements.txt,composer.json,pom.xml,Gemfile, etc. - Frontend: Check for
package.json,yarn.lock,pnpm-lock.yaml - Document all major dependencies and frameworks
- Backend: Check for
Identify configuration files
- Environment configuration (
.env.example, config files) - Build tools (
vite.config.js,webpack.config.js,tsconfig.json) - Database configuration
- Deployment configuration
- Environment configuration (
Phase 2: Backend Analysis
Framework and architecture
- Identify the backend framework (Express, Laravel, Django, etc.)
- Determine architectural pattern (MVC, Clean Architecture, Layered, etc.)
- Map out the directory structure (controllers, models, services, routes)
Database layer
- Locate migration files and analyze table structures
- Identify relationships between entities
- Document seeder files and initial data
- Map out the data model and ER relationships
API and routing
- Analyze route definitions
- Document API endpoints and their purposes
- Identify middleware and request processing flow
- Note authentication/authorization mechanisms
Business logic
- Identify service layers and business rules
- Document validation schemas
- Map out data transformation and processing
Phase 3: Frontend Analysis
Framework and structure
- Identify frontend framework (React, Vue, Angular, etc.)
- Analyze component hierarchy and organization
- Document page/route structure
State management
- Identify state management solution (Redux, Zustand, Pinia, Context API)
- Analyze store structure and state flow
- Document data fetching patterns
UI components
- Identify component library (shadcn/ui, Material UI, custom)
- Document reusable component patterns
- Note styling approach (Tailwind, CSS modules, styled-components)
Client-side routing
- Map out route definitions
- Document navigation patterns
- Identify protected routes and auth guards
Phase 4: Cross-Cutting Concerns
Authentication and Authorization
- Document authentication strategy (JWT, sessions, OAuth)
- Analyze role-based access control (RBAC) implementation
- Map permission checking throughout the application
Security
- Identify CORS configuration
- Document input validation and sanitization
- Note security middleware and practices
Error handling
- Analyze error handling patterns
- Document logging and monitoring
Testing
- Identify test frameworks and structure
- Document test coverage approach
- Note integration and E2E test patterns
Phase 5: Documentation Generation
Create a comprehensive architecture document including:
Executive Summary
- Technology stack overview
- High-level architecture description
- Key architectural decisions
Project Structure
- Directory tree with explanations
- Module organization
Technology Stack
- Backend frameworks and libraries
- Frontend frameworks and libraries
- Database and ORM
- Build tools and deployment
Database Architecture
- Entity-relationship diagram (textual or Mermaid)
- Table descriptions
- Key relationships and constraints
API Documentation
- Endpoint listing with purposes
- Authentication requirements
- Request/response patterns
Frontend Architecture
- Component hierarchy
- State management patterns
- Routing structure
Authentication & Authorization
- Auth flow description
- Role and permission system
- Protected resource patterns
Key Patterns and Conventions
- Code organization patterns
- Naming conventions
- Common utilities and helpers
Workflows and Business Logic
- Major user flows
- Complex business processes
- Data transformation pipelines
Recommendations
- Architectural strengths
- Areas for improvement
- Technical debt observations
- (Automated) Code Quality Suggestions from
suggest_improvements.py
Best Practices
- Start broad, then narrow: Begin with high-level structure before diving into details
- Follow the data: Trace data flow from database through backend to frontend
- Use grep strategically: Search for patterns like
export class,router.,CREATE TABLE - Read key files fully: Don't skip important configuration and entry point files
- Document as you go: Build the analysis document incrementally
- Note inconsistencies: Highlight areas where patterns deviate
- Consider the user's goal: Tailor depth and focus to what the user needs to understand
- Leverage automation: Use the
suggest_improvements.pyscript to get a quick overview of code quality.