Here's an updated prompt to request a fully functional and professional portfolio…
- User
Here's an updated prompt to request a fully functional and professional portfolio website setup:
Prompt for Language Model:
"I am building a professional portfolio website and need a complete, fully functional project setup with code. Please provide a detailed folder structure using the latest industry standards and libraries in frontend development, with a focus on a modern React-based setup.
Code Requirements: Write all code to be fully functional, including sample pages (e.g., Home, About, Portfolio, Contact), components (e.g., Navbar, Footer, Project Card, Contact Form), and a routing setup. Libraries and Features: Use the latest libraries and tools to enhance performance, animations, and responsive design. Feel free to include recommended libraries for optimized styling, such as styled-components, and other features like framer-motion for animations and react-router-dom for navigation. Scalability and Maintainability: Organize the project with best practices in mind, including modular and reusable components. Consider scalability for future growth by structuring files efficiently. Additional Best Practices: If there are additional improvements or advanced practices you recommend, please include them."
- Assistant
Absolutely, I'd be happy to help you set up a professional portfolio website with a modern React-based architecture. Here's a comprehensive guide that includes a detailed folder structure, sample code for pages and components, and best practices to ensure scalability and maintainability.
Project Setup
Prerequisites:
- Node.js (v14 or above)
- npm or yarn package manager installed
Setting up the Project:
# Using create-react-app with TypeScript template npx create-react-app my-portfolio --template typescript cd my-portfolio
Folder Structure
my-portfolio/ ├── public/ │ └── index.html ├── src/ │ ├── assets/ │ │ ├── images/ │ │ └── fonts/ │ ├── components/ │ │ ├── common/ │ │ │ ├── Navbar/ │ │ │ ├── Footer/ │ │ │ └── Loader/ │ │ └── specific/ │ │ ├── ProjectCard/ │ │ └── ContactForm/ │ ├── contexts/ │ ├── hooks/ │ ├── pages/ │ │ ├── Home/ │ │ ├── About/ │ │ ├── Portfolio/ │ │ └── Contact/ │ ├── routes/ │ │ └── AppRoutes.tsx │ ├── styles/ │ │ └── GlobalStyles.ts │ ├── types/ │ ├── utils/ │ ├── App.tsx │ ├── index.tsx │ └── react-app-env.d.ts ├── package.json ├── tsconfig.json ├── README.md └── yarn.lock / package-lock.json
Key Dependencies
Install the following libraries to enhance your project:
# For routing npm install react-router-dom # For styling npm install styled-components # For animations npm install framer-motion # For typing with styled-components npm install --save-dev @types/styled-components # For form handling (optional but recommended) npm install react-hook-form # For validation (optional but recommended) npm install yup @hookform/resolvers # TypeScript types (if needed) npm install --save-dev @types/react-router-dom
Detailed Implementation
1. Global Styles
Create
GlobalStyles.tsin thestylesfolder to define global CSS styles usingstyled-components.// src/styles/GlobalStyles.ts import { createGlobalStyle } from 'styled-components'; export const GlobalStyles = createGlobalStyle` /* Reset and global styles */ *, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; } body { font-family: 'Open Sans', sans-serif; background-color: ${({ theme }) => theme.colors.background}; color: ${({ theme }) => theme.colors.text}; } /* Scrollbar styling */ ::-webkit-scrollbar { width: 8px; } ::-webkit-scrollbar-thumb { background: ${({ theme }) => theme.colors.primary}; border-radius: 4px; } `;2. Theme Configuration
Create a
themeobject for theme-based styling.// src/styles/theme.ts export const theme = { colors: { primary: '#556cd6', secondary: '#19857b', background: '#f0f2f5', text: '#333333', }, // Add more theming properties as needed };3. Entry Point
Modify
App.tsxto includeGlobalStyles,ThemeProvider, and routes.// src/App.tsx import React from 'react'; import { ThemeProvider } from 'styled-components'; import { GlobalStyles } from './styles/GlobalStyles'; import { theme } from './styles/theme'; import AppRoutes from './routes/AppRoutes'; const App: React.FC = () => { return ( <ThemeProvider theme={theme}> <GlobalStyles /> <AppRoutes /> </ThemeProvider> ); }; export default App;4. Routing Setup
Create
AppRoutes.tsxin theroutesfolder.// src/routes/AppRoutes.tsx import React from 'react'; import { BrowserRouter as Router, Routes, Route } from 'react-router-dom'; import Home from '../pages/Home/Home'; import About from '../pages/About/About'; import Portfolio from '../pages/Portfolio/Portfolio'; import Contact from '../pages/Contact/Contact'; const AppRoutes: React.FC = () => ( <Router> {/* Common components like Navbar can be placed here */} <Routes> <Route path="/" element={<Home />} /> <Route path="/about" element={<About />} /> <Route path="/portfolio" element={<Portfolio />} /> <Route path="/contact" element={<Contact />} /> </Routes> {/* Common components like Footer can be placed here */} </Router> ); export default AppRoutes;5. Common Components
Navbar
// src/components/common/Navbar/Navbar.tsx import React from 'react'; import { NavLink } from 'react-router-dom'; import styled from 'styled-components'; const NavbarContainer = styled.nav` /* Styling for Navbar */ `; const Navbar: React.FC = () => ( <NavbarContainer> <NavLink to="/">Home</NavLink> <NavLink to="/about">About</NavLink> <NavLink to="/portfolio">Portfolio</NavLink> <NavLink to="/contact">Contact</NavLink> </NavbarContainer> ); export default Navbar;Footer
// src/components/common/Footer/Footer.tsx import React from 'react'; import styled from 'styled-components'; const FooterContainer = styled.footer` /* Styling for Footer */ `; const Footer: React.FC = () => ( <FooterContainer> <p>© {new Date().getFullYear()} My Portfolio</p> </FooterContainer> ); export default Footer;6. Specific Components
ProjectCard
// src/components/specific/ProjectCard/ProjectCard.tsx import React from 'react'; import styled from 'styled-components'; import { motion } from 'framer-motion'; const Card = styled(motion.div)` /* Styling for Project Card */ `; interface ProjectCardProps { title: string; description: string; imageUrl: string; projectUrl: string; } const ProjectCard: React.FC<ProjectCardProps> = ({ title, description, imageUrl, projectUrl }) => ( <Card whileHover={{ scale: 1.05 }}> <img src={imageUrl} alt={title} /> <h3>{title}</h3> <p>{description}</p> <a href={projectUrl} target="_blank" rel="noopener noreferrer"> View Project </a> </Card> ); export default ProjectCard;ContactForm
// src/components/specific/ContactForm/ContactForm.tsx import React from 'react'; import styled from 'styled-components'; import { useForm } from 'react-hook-form'; import { yupResolver } from '@hookform/resolvers/yup'; import * as yup from 'yup'; const Form = styled.form` /* Styling for Contact Form */ `; interface ContactFormInputs { name: string; email: string; message: string; } const schema = yup.object().shape({ name: yup.string().required('Name is required'), email: yup.string().email('Invalid email').required('Email is required'), message: yup.string().required('Message is required'), }); const ContactForm: React.FC = () => { const { register, handleSubmit, formState: { errors } } = useForm<ContactFormInputs>({ resolver: yupResolver(schema), }); const onSubmit = (data: ContactFormInputs) => { // Handle form submission console.log(data); }; return ( <Form onSubmit={handleSubmit(onSubmit)}> <input type="text" placeholder="Name" {...register('name')} /> <p>{errors.name?.message}</p> <input type="email" placeholder="Email" {...register('email')} /> <p>{errors.email?.message}</p> <textarea placeholder="Message" {...register('message')} /> <p>{errors.message?.message}</p> <button type="submit">Send Message</button> </Form> ); }; export default ContactForm;7. Pages
Home Page
// src/pages/Home/Home.tsx import React from 'react'; import styled from 'styled-components'; import { motion } from 'framer-motion'; const HomeContainer = styled(motion.div)` /* Styling for Home Page */ `; const Home: React.FC = () => ( <HomeContainer initial={{ opacity: 0 }} animate={{ opacity: 1 }} exit={{ opacity: 0 }} > <h1>Welcome to My Portfolio</h1> {/* Additional content */} </HomeContainer> ); export default Home;About Page
// src/pages/About/About.tsx import React from 'react'; import styled from 'styled-components'; const AboutContainer = styled.div` /* Styling for About Page */ `; const About: React.FC = () => ( <AboutContainer> <h1>About Me</h1> <p>/* Your bio */</p> </AboutContainer> ); export default About;Portfolio Page
// src/pages/Portfolio/Portfolio.tsx import React from 'react'; import styled from 'styled-components'; import ProjectCard from '../../components/specific/ProjectCard/ProjectCard'; const PortfolioContainer = styled.div` /* Styling for Portfolio Page */ `; const Portfolio: React.FC = () => { const projects = [ // Sample project data { title: 'Project One', description: 'Description for project one.', imageUrl: '/path/to/image1.jpg', projectUrl: 'http://example.com/project-one', }, // Add more projects ]; return ( <PortfolioContainer> <h1>My Projects</h1> {projects.map((project) => ( <ProjectCard key={project.title} {...project} /> ))} </PortfolioContainer> ); }; export default Portfolio;Contact Page
// src/pages/Contact/Contact.tsx import React from 'react'; import styled from 'styled-components'; import ContactForm from '../../components/specific/ContactForm/ContactForm'; const ContactContainer = styled.div` /* Styling for Contact Page */ `; const Contact: React.FC = () => ( <ContactContainer> <h1>Contact Me</h1> <ContactForm /> </ContactContainer> ); export default Contact;8. Additional Configurations
TypeScript Path Aliases
To simplify imports, configure path aliases in
tsconfig.json:// tsconfig.json { "compilerOptions": { // ... other options "baseUrl": "src", "paths": { "@components/*": ["components/*"], "@pages/*": ["pages/*"], "@styles/*": ["styles/*"], "@assets/*": ["assets/*"], "@utils/*": ["utils/*"], "@hooks/*": ["hooks/*"] } } }Example usage:
import Navbar from '@components/common/Navbar/Navbar';9. Hooks and Utilities
Create custom hooks and utility functions as needed.
Example:
// src/hooks/useWindowSize.ts import { useState, useEffect } from 'react'; const useWindowSize = () => { const [size, setSize] = useState<[number, number]>([window.innerWidth, window.innerHeight]); useEffect(() => { const handleResize = () => setSize([window.innerWidth, window.innerHeight]); window.addEventListener('resize', handleResize); return () => window.removeEventListener('resize', handleResize); }, []); return size; }; export default useWindowSize;10. Assets Management
Store images, fonts, and other assets in the
assetsfolder.Example:
- Images:
src/assets/images/ - Fonts:
src/assets/fonts/
Best Practices and Advanced Tips
Code Splitting and Lazy Loading
Use React's
lazyandSuspensefor code splitting to improve performance.// src/routes/AppRoutes.tsx import React, { Suspense, lazy } from 'react'; // ... other imports const Home = lazy(() => import('../pages/Home/Home')); const About = lazy(() => import('../pages/About/About')); // ... const AppRoutes: React.FC = () => ( <Router> {/* Navbar */} <Suspense fallback={<Loader />}> <Routes> {/* Routes */} </Routes> </Suspense> {/* Footer */} </Router> );Responsive Design
Utilize CSS media queries or libraries like
styled-systemto create responsive components.// Example with styled-components const ResponsiveDiv = styled.div` width: 100%; @media (min-width: 768px) { width: 50%; } `;Accessibility
Ensure your website is accessible:
- Use semantic HTML elements.
- Add
arialabels where necessary. - Ensure color contrast meets WCAG standards.
SEO Optimization
Even though it's a single-page application, you can improve SEO by:
- Using
react-helmetto manage meta tags.
// src/pages/Home/Home.tsx import { Helmet } from 'react-helmet'; const Home: React.FC = () => ( <> <Helmet> <title>Home | My Portfolio</title> <meta name="description" content="Welcome to my professional portfolio." /> </Helmet> {/* Rest of the component */} </> );State Management
For global state, consider using Context API or libraries like Redux or Zustand if the project scales.
Error Handling
Implement error boundaries to catch exceptions in the component tree.
// src/components/common/ErrorBoundary/ErrorBoundary.tsx import React, { Component, ErrorInfo, ReactNode } from 'react'; interface ErrorBoundaryProps { children: ReactNode; } interface ErrorBoundaryState { hasError: boolean; } class ErrorBoundary extends Component<ErrorBoundaryProps, ErrorBoundaryState> { state: ErrorBoundaryState = { hasError: false }; static getDerivedStateFromError(_: Error): ErrorBoundaryState { return { hasError: true }; } componentDidCatch(error: Error, info: ErrorInfo) { // Log error console.error('ErrorBoundary caught an error', error, info); } render() { if (this.state.hasError) { return <h2>Something went wrong.</h2>; } return this.props.children; } } export default ErrorBoundary;Testing
Write unit and integration tests using tools like Jest and React Testing Library.
Conclusion
This setup provides a robust foundation for your professional portfolio website. By adhering to modern best practices, utilizing powerful libraries, and structuring your project efficiently, you ensure that your website is performant, scalable, and maintainable.
Feel free to customize and expand upon this foundation to suit your specific needs. If you have any questions or need further assistance with any part of the setup, don't hesitate to ask!
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.