Here's a comprehensive crewAI configuration for implementing your full-stack web application:
python
from crewai import Agent, Task, Crew, Process
from crewai_tools import FileReadTool, DirectoryReadTool, FileWriteTool
import os
# Initialize tools
file_reader = FileReadTool()
directory_reader = DirectoryReadTool()
file_writer = FileWriteTool()
# Define Agents
backend_architect = Agent(
role='Backend Architect',
goal='Design and implement the Node.js backend with GraphQL API',
backstory="""You are an experienced backend developer specializing in Node.js,
GraphQL, and PostgreSQL. You excel at creating scalable, well-structured APIs
and database integrations.""",
verbose=True,
allow_delegation=False,
tools=[file_reader, file_writer, directory_reader]
)
database_engineer = Agent(
role='Database Engineer',
goal='Implement and optimize the PostgreSQL database layer',
backstory="""You are a database expert who specializes in PostgreSQL.
You create efficient database schemas, migrations, and query optimizations.""",
verbose=True,
allow_delegation=False,
tools=[file_reader, file_writer]
)
graphql_specialist = Agent(
role='GraphQL API Specialist',
goal='Implement GraphQL resolvers, types, and schema',
backstory="""You are a GraphQL expert who creates efficient, well-documented
GraphQL APIs with proper error handling and performance optimization.""",
verbose=True,
allow_delegation=False,
tools=[file_reader, file_writer]
)
frontend_developer = Agent(
role='React Frontend Developer',
goal='Build the React frontend application with GraphQL integration',
backstory="""You are a senior React developer who creates clean, responsive,
and user-friendly interfaces. You excel at state management and GraphQL client integration.""",
verbose=True,
allow_delegation=False,
tools=[file_reader, file_writer, directory_reader]
)
devops_engineer = Agent(
role='DevOps Engineer',
goal='Set up project structure, dependencies, and deployment configurations',
backstory="""You are a DevOps specialist who ensures smooth development workflows,
proper project setup, and deployment readiness.""",
verbose=True,
allow_delegation=False,
tools=[file_reader, file_writer]
)
testing_engineer = Agent(
role='Testing Engineer',
goal='Implement comprehensive testing for both frontend and backend',
backstory="""You are a testing expert who writes unit tests, integration tests,
and e2e tests to ensure code quality and reliability.""",
verbose=True,
allow_delegation=False,
tools=[file_reader, file_writer]
)
# Define Tasks
analyze_requirements = Task(
description="""Analyze the project requirements document at {requirements_path}.
Extract and summarize:
1. Core features and functionality
2. User roles and permissions
3. Data models and relationships
4. API endpoints needed
5. UI/UX requirements
6. Performance and security requirements""",
expected_output="Detailed analysis document with all requirements categorized and prioritized",
agent=backend_architect
)
setup_project_structure = Task(
description="""Create the project structure with the following:
1. Backend folder structure (src/, config/, models/, resolvers/, etc.)
2. Frontend folder structure (src/, components/, pages/, hooks/, etc.)
3. Package.json files for both frontend and backend
4. Configuration files (.env.example, tsconfig.json, etc.)
5. Docker configuration files
6. Git ignore files""",
expected_output="Complete project structure with all necessary folders and configuration files",
agent=devops_engineer
)
implement_database = Task(
description="""Using the SQL schema at {sql_schema_path}:
1. Create database migration files
2. Implement Sequelize/Prisma models
3. Set up database connection configuration
4. Create seed data scripts
5. Implement database utilities and helpers""",
expected_output="Complete database layer implementation with migrations, models, and utilities",
agent=database_engineer
)
implement_graphql_server = Task(
description="""Using the GraphQL schema at {graphql_schema_path}:
1. Set up Apollo Server or similar GraphQL server
2. Implement type definitions
3. Create resolvers for all queries and mutations
4. Implement data loaders for optimization
5. Add authentication and authorization middleware
6. Set up GraphQL subscriptions if needed""",
expected_output="Fully functional GraphQL server with all resolvers and middleware",
agent=graphql_specialist
)
implement_backend_services = Task(
description="""Implement backend business logic:
1. Create service layer for business logic
2. Implement authentication system (JWT, sessions)
3. Add input validation and sanitization
4. Implement error handling middleware
5. Create utility functions and helpers
6. Set up logging and monitoring""",
expected_output="Complete backend implementation with all services and middleware",
agent=backend_architect
)
implement_react_frontend = Task(
description="""Build the React frontend:
1. Set up React with TypeScript
2. Configure Apollo Client for GraphQL
3. Implement routing with React Router
4. Create reusable components based on requirements
5. Implement pages and layouts
6. Set up state management (Context API/Redux/Zustand)
7. Add authentication flow
8. Implement responsive design""",
expected_output="Complete React frontend with all components and pages",
agent=frontend_developer
)
implement_graphql_queries = Task(
description="""Create GraphQL queries and mutations for the frontend:
1. Write all GraphQL queries needed by components
2. Create mutations for data modifications
3. Implement optimistic updates
4. Set up cache policies
5. Create custom hooks for GraphQL operations""",
expected_output="Complete set of GraphQL operations and React hooks",
agent=frontend_developer
)
implement_testing = Task(
description="""Implement comprehensive testing:
1. Unit tests for backend services and resolvers
2. Integration tests for GraphQL API
3. Unit tests for React components
4. Integration tests for frontend flows
5. Set up test configuration and scripts
6. Create test data factories""",
expected_output="Complete test suite with good coverage",
agent=testing_engineer
)
create_documentation = Task(
description="""Create project documentation:
1. API documentation with examples
2. Setup and installation guide
3. Development workflow documentation
4. Deployment instructions
5. Architecture diagrams
6. Code style guide""",
expected_output="Comprehensive project documentation",
agent=backend_architect
)
setup_deployment = Task(
description="""Prepare for deployment:
1. Create Dockerfile for backend
2. Create Dockerfile for frontend
3. Set up docker-compose for local development
4. Create CI/CD configuration (GitHub Actions/GitLab CI)
5. Create production environment variables template
6. Set up monitoring and logging configuration""",
expected_output="Complete deployment configuration and scripts",
agent=devops_engineer
)
# Create the Crew
web_app_crew = Crew(
agents=[
backend_architect,
database_engineer,
graphql_specialist,
frontend_developer,
devops_engineer,
testing_engineer
],
tasks=[
analyze_requirements,
setup_project_structure,
implement_database,
implement_graphql_server,
implement_backend_services,
implement_react_frontend,
implement_graphql_queries,
implement_testing,
create_documentation,
setup_deployment
],
process=Process.sequential,
verbose=True
)
# Function to run the crew
def build_web_app(requirements_path, sql_schema_path, graphql_schema_path, output_dir):
"""
Execute the web app development crew
Args:
requirements_path: Path to requirements document
sql_schema_path: Path to SQL schema file
graphql_schema_path: Path to GraphQL schema file
output_dir: Directory where the project will be created
"""
# Create output directory if it doesn't exist
os.makedirs(output_dir, exist_ok=True)
# Set up inputs for the crew
inputs = {
'requirements_path': requirements_path,
'sql_schema_path': sql_schema_path,
'graphql_schema_path': graphql_schema_path,
'output_dir': output_dir
}
# Run the crew
result = web_app_crew.kickoff(inputs=inputs)
return result
# Example usage
if __name__ == "__main__":
# Configure these paths according to your setup
result = build_web_app(
requirements_path="./requirements.md",
sql_schema_path="./schema.sql",
graphql_schema_path="./schema.graphql",
output_dir="./my-web-app"
)
print("\n=== Project Build Complete ===")
print(result)
To enhance this configuration, you might also want to add:
python
# Additional specialized agents
security_expert = Agent(
role='Security Expert',
goal='Implement security best practices and vulnerability prevention',
backstory="""You are a security specialist who ensures the application
follows OWASP guidelines and implements proper security measures.""",
verbose=True,
allow_delegation=False,
tools=[file_reader, file_writer]
)
performance_optimizer = Agent(
role='Performance Optimization Expert',
goal='Optimize application performance and implement caching strategies',
backstory="""You specialize in web application performance, implementing
caching, lazy loading, and optimization techniques.""",
verbose=True,
allow_delegation=False,
tools=[file_reader, file_writer]
)
# Additional tasks
implement_security = Task(
description="""Implement security measures:
1. Set up CORS properly
2. Implement rate limiting
3. Add input validation and sanitization
4. Set up HTTPS configuration
5. Implement proper authentication flows
6. Add security headers
7. Implement CSRF protection""",
expected_output="Secure application with all security measures implemented",
agent=security_expert
)
optimize_performance = Task(
description="""Optimize application performance:
1. Implement Redis caching for GraphQL
2. Set up database query optimization
3. Implement frontend code splitting
4. Add lazy loading for images and components
5. Set up CDN configuration
6. Implement service worker for offline support""",
expected_output="Optimized application with improved performance metrics",
agent=performance_optimizer
)
To use this configuration:
Install crewAI and dependencies:
bash
pip install crewai crewai-tools langchain-openai
Set up your environment variables:
bash
export OPENAI_API_KEY="your-api-key"
Prepare your input files:
requirements.md (project requirements)
schema.sql (PostgreSQL schema)
schema.graphql (GraphQL schema)
Run the crew to build your application:
python
python crew_config.py
The crew will work through each task sequentially, creating a complete web application based on your specifications. Each agent will handle their specialized area, ensuring a well-structured, professional implementation.