## ๐ง 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*