## ๐Ÿง  Development Philosophy At ego.cx, code isn't just code. It's the invisible structure that supports the digital identity of brands and professionals. Every line should be **clear, maintainable, and creative**. **Our principles are:** - **KISS** โ€” Keep It Simple, Stupid. The simplest solution is almost always the best. - **DRY** โ€” Don't Repeat Yourself. Reuse is sacred. - **YAGNI** โ€” You Aren't Gonna Need It. Don't build for the future; build for now. - **Disruption with purpose** โ€” Innovating isn't doing weird things. It's doing what works in a way no one else is doing. --- ## ๐Ÿ“‹ Golden Rules of Development ### 1. Code is read more than it's written. Write code as if the person maintaining it is a new colleague. Or your future self in 6 months. โœ… *"Clear and consistent names."* โŒ *"Cryptic abbreviations and convoluted logic."* ### 2. Each component has one responsibility. One file, one function, one task. Separate to master. โœ… *"button.js โ†’ buttons only."* โŒ *"ui-components.js โ†’ buttons, modals, tooltips, and forms."* ### 3. Performance isn't a luxury; it's a requirement. Code should be fast by default. Don't optimize at the end; optimize from the start. โœ… *"Lazy loading by default."* โŒ *"Load everything upfront and fix it later."* ### 4. Document as you write. Code that needs explanation should be better code. But if it needs to be explained, do it. โœ… *"// This hook handles OAuth2 authentication"* โŒ *"// Does things"* ### 5. CSS isn't an accident. Use semantic classes. Don't use `!important`. Use CSS variables. Make design part of the system. โœ… *"class="button-primary""* โŒ *"style="color: red; font-size: 16px;""* --- ## ๐Ÿ› ๏ธ File and Project Structure ``` project/ โ”œโ”€โ”€ src/ โ”‚ โ”œโ”€โ”€ components/ # Reusable components โ”‚ โ”‚ โ”œโ”€โ”€ Button/ โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ Button.jsx โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ Button.css โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ Button.test.js โ”‚ โ”‚ โ””โ”€โ”€ Card/ โ”‚ โ”‚ โ”œโ”€โ”€ Card.jsx โ”‚ โ”‚ โ”œโ”€โ”€ Card.css โ”‚ โ”‚ โ””โ”€โ”€ Card.test.js โ”‚ โ”œโ”€โ”€ pages/ # Specific pages โ”‚ โ”‚ โ”œโ”€โ”€ Home/ โ”‚ โ”‚ โ”œโ”€โ”€ Product/ โ”‚ โ”‚ โ””โ”€โ”€ About/ โ”‚ โ”œโ”€โ”€ hooks/ # Custom hooks โ”‚ โ”‚ โ”œโ”€โ”€ useAuth.js โ”‚ โ”‚ โ””โ”€โ”€ useTheme.js โ”‚ โ”œโ”€โ”€ utils/ # Utility functions โ”‚ โ”‚ โ”œโ”€โ”€ formatDate.js โ”‚ โ”‚ โ””โ”€โ”€ validateEmail.js โ”‚ โ”œโ”€โ”€ styles/ # Global styles and variables โ”‚ โ”‚ โ”œโ”€โ”€ variables.css โ”‚ โ”‚ โ””โ”€โ”€ global.css โ”‚ โ””โ”€โ”€ config/ # Configurations โ”‚ โ””โ”€โ”€ constants.js โ”œโ”€โ”€ public/ # Static files โ”‚ โ”œโ”€โ”€ images/ โ”‚ โ””โ”€โ”€ fonts/ โ”œโ”€โ”€ tests/ # Integration tests โ”œโ”€โ”€ README.md โ”œโ”€โ”€ LICENSE โ””โ”€โ”€ package.json ``` --- ## ๐ŸŽจ Code Style Guide ### JavaScript / TypeScript โœ… **Variable names in camelCase** ```javascript const userName = 'Carlos'; const isAuthenticated = true; ``` โœ… **Function names: verbs + nouns** ```javascript function getUserData() { ... } function validateEmail() { ... } ``` โœ… **Components in PascalCase** ```javascript function ButtonPrimary({ children, onClick }) { ... } function CardFeature({ title, description }) { ... } ``` โœ… **Constants in UPPER_SNAKE_CASE** ```javascript const API_URL = 'https://api.ego.cx/v1'; const MAX_RETRIES = 3; ``` โœ… **Use arrow functions for pure functions** ```javascript const sum = (a, b) => a + b; ``` โœ… **Use async/await for promises** ```javascript const fetchData = async (url) => { const response = await fetch(url); return response.json(); }; ``` ### CSS / SCSS โœ… **CSS variables first** ```css :root { --color-primary: #DC0000; --spacing-base: 4px; --font-family-base: 'Inter', sans-serif; } ``` โœ… **Semantic and utility classes** ```css .button-primary { background: var(--color-primary); padding: 12px 24px; border-radius: 4px; } ``` โœ… **Use the base spacing system** ```css .card { padding: calc(var(--spacing-base) * 4); /* 16px */ margin-bottom: calc(var(--spacing-base) * 6); /* 24px */ } ``` --- ## ๐Ÿค– AI and Copilots: How to Use Them Well ### Principles for Programming with AI 1. **Context is power.** Give the copilot full context: the file, dependencies, and purpose. 2. **Review before trusting.** AI writes code fast; you know if it's correct. 3. **Ask for explanations.** Not just code; ask *why* it chose that solution. 4. **Iterate.** The first attempt is rarely the best. Ask for alternatives. 5. **Maintain consistency.** AI can jump between styles. Guide it with examples. ### Sample Copilot Prompts #### ๐Ÿงฉ Generate a Component ``` Create a Button component in React with TypeScript. It must have: - Props: variant (primary | secondary), size (sm | md | lg), onClick, children - Use CSS Modules for styles - Include comments for each prop - Follow the ego.cx design system (colors #DC0000, #181716, #FCFCFC) ``` #### ๐Ÿ› ๏ธ Optimize a Function ``` This function processes a list of users: [insert code] Optimize it to: 1. Reduce O(nยฒ) complexity to O(n) 2. Use modern array methods (map, filter, reduce) 3. Maintain readability 4. Add comments about the optimization ``` #### ๐Ÿ“„ Refactor CSS ``` Refactor this CSS to use CSS variables and a 4px spacing system: [insert code] It must maintain exactly the same visual appearance. ``` --- ## ๐Ÿงช Testing and Quality ### Principles 1. **Write tests before or during, not after.** 2. **Each component has its own test.** 3. **Tests must be fast and deterministic.** 4. **Mock external dependencies, test internal logic.** ### Test Structure ```javascript // Button.test.js import { render, fireEvent } from '@testing-library/react'; import { ButtonPrimary } from './Button'; describe('ButtonPrimary', () => { it('renders with the correct text', () => { const { getByText } = render(Click me); expect(getByText('Click me')).toBeInTheDocument(); }); it('executes onClick when clicked', () => { const handleClick = jest.fn(); const { getByText } = render( Click me ); fireEvent.click(getByText('Click me')); expect(handleClick).toHaveBeenCalled(); }); }); ``` --- ## ๐Ÿš€ Deployment and Monitoring ### Deployment Checklist - [ ] All tests pass - [ ] Linter has no errors - [ ] Bundle optimized (code splitting, tree shaking) - [ ] Assets compressed (WebP, AVIF, minified) - [ ] Environment variables configured - [ ] Error logging configured - [ ] Performance metrics (Core Web Vitals) ### Monitoring - **Errors:** Sentry / LogRocket - **Performance:** Lighthouse / Web Vitals - **Analytics:** Google Analytics / Plausible / Umami --- ## ๐Ÿ“š Resources and References - [React Documentation](https://react.dev) - [TypeScript Handbook](https://www.typescriptlang.org/docs/) - [CSS Variables Guide](https://developer.mozilla.org/en-US/docs/Web/CSS/Using_CSS_custom_properties) - [KISS Principle](https://en.wikipedia.org/wiki/KISS_principle) - [DRY Principle](https://en.wikipedia.org/wiki/Don%27t_repeat_yourself) --- *โ€” Fernando Josรฉ Caicedo Albarello* *Founder, EgoCX*