|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Project Overview |
| 6 | + |
| 7 | +**CodeHelp** is a Gatsby v4-based static site generator serving as a community-driven resource portal (codehelp.io). It aggregates curated links for developers, designers, and marketers across learning materials and development tools. |
| 8 | + |
| 9 | +- **Framework**: Gatsby v4.5.2 |
| 10 | +- **Language**: JavaScript/React v17 |
| 11 | +- **Styling**: styled-components (CSS-in-JS) |
| 12 | +- **Deployment**: Netlify (automatic on git push) |
| 13 | +- **State Management**: React Context API (theme/dark mode) |
| 14 | + |
| 15 | +## Common Development Commands |
| 16 | + |
| 17 | +| Command | Purpose | |
| 18 | +|---------|---------| |
| 19 | +| `npm start` or `npm run develop` | Start dev server on localhost:8000 with hot reload | |
| 20 | +| `npm run build` | Build production-optimized site to `/public` | |
| 21 | +| `npm run serve` | Serve the built site locally for testing | |
| 22 | +| `npm run clean` | Clear Gatsby cache and build artifacts | |
| 23 | +| `npm run format` | Format all code with Prettier (2-space, single quotes) | |
| 24 | +| `npm run test` | Currently not implemented—echo stub only | |
| 25 | + |
| 26 | +## Architecture & Code Structure |
| 27 | + |
| 28 | +### Directory Layout |
| 29 | + |
| 30 | +``` |
| 31 | +src/ |
| 32 | +├── pages/ # File-based routing (auto-creates routes) |
| 33 | +│ ├── index.js # Homepage (/) |
| 34 | +│ ├── learning.js # /learning resources page |
| 35 | +│ ├── resources.js # /resources development tools page |
| 36 | +│ └── 404.js # Not found page |
| 37 | +│ |
| 38 | +├── components/ # Reusable React components |
| 39 | +│ ├── Layout.js # Main wrapper (contains globalContext Provider via gatsby-browser.js) |
| 40 | +│ ├── Header/ # Logo and navigation |
| 41 | +│ ├── Nav/ # Main nav links + Discord popup modal |
| 42 | +│ ├── Footer/ # Footer with links |
| 43 | +│ ├── Sidebar/ # Category navigation with anchor links |
| 44 | +│ ├── DataList/ # Maps data array → Resource cards |
| 45 | +│ ├── Resource/ # Individual resource card component |
| 46 | +│ ├── ThemeToggle/ # Dark/light mode switcher |
| 47 | +│ └── Seo.js # react-helmet wrapper for head management |
| 48 | +│ |
| 49 | +├── context/ # React Context for state |
| 50 | +│ └── globalContext.js # Theme state (dark/light), persists to localStorage |
| 51 | +│ |
| 52 | +├── hooks/ |
| 53 | +│ └── useWindowSize.js # Track window dimensions for responsive design |
| 54 | +│ |
| 55 | +├── data/ # Static JSON data (no database) |
| 56 | +│ ├── resources.json # Development tools/frameworks organized by category |
| 57 | +│ └── learning.json # Learning materials organized by category |
| 58 | +│ |
| 59 | +├── assets/ # Static files |
| 60 | +│ ├── styles/ # Global + component-level styles |
| 61 | +│ ├── fonts/ # Custom fonts (Apercu-Mono-Pro) |
| 62 | +│ └── images/ # PNG, SVG assets |
| 63 | +│ |
| 64 | +└── pages/ + components/ → Rendered via Layout wrapper → Theme provider |
| 65 | +``` |
| 66 | + |
| 67 | +### Data Flow & Structure |
| 68 | + |
| 69 | +**Page rendering**: |
| 70 | +1. Pages (`resources.js`, `learning.js`) import static JSON from `src/data/` |
| 71 | +2. Pass data to `Sidebar` (category filters) and `DataList` (resource cards) |
| 72 | +3. Sidebar renders anchor links for category navigation |
| 73 | +4. DataList maps array → Resource components (individual cards) |
| 74 | +5. All styled with styled-components, theme-aware via Context |
| 75 | + |
| 76 | +**Data shape** (JSON structure): |
| 77 | +```javascript |
| 78 | +{ |
| 79 | + "resources": [ |
| 80 | + { |
| 81 | + "label": { |
| 82 | + "id": "guides-info", |
| 83 | + "name": "General Guides & Information", |
| 84 | + "categories": [ |
| 85 | + { |
| 86 | + "category": { |
| 87 | + "id": "web-development", |
| 88 | + "name": "Web Development", |
| 89 | + "resources": [ |
| 90 | + { |
| 91 | + "name": "MDN Web Docs", |
| 92 | + "description": "...", |
| 93 | + "url": "https://..." |
| 94 | + } |
| 95 | + ] |
| 96 | + } |
| 97 | + } |
| 98 | + ] |
| 99 | + } |
| 100 | + } |
| 101 | + ] |
| 102 | +} |
| 103 | +``` |
| 104 | + |
| 105 | +### Styling Architecture |
| 106 | + |
| 107 | +- **CSS-in-JS** via styled-components |
| 108 | +- **Theme variables** defined in `src/assets/styles/` (e.g., `--color__background`, `--color__text`) |
| 109 | +- **Global styles** wrap all components with theme-aware colors |
| 110 | +- **Component styles**: Each component has a `.styles.js` file (e.g., `Header.styles.js`) |
| 111 | +- **Responsive design**: CSS media queries in component styles |
| 112 | + |
| 113 | +### State Management |
| 114 | + |
| 115 | +**Global Theme**: |
| 116 | +- Stored in `src/context/globalContext.js` (React Context) |
| 117 | +- Wrapped around entire app in `gatsby-browser.js` |
| 118 | +- Persists theme choice to localStorage |
| 119 | +- Switch via ThemeToggle component |
| 120 | + |
| 121 | +### Key Plugins & Features |
| 122 | + |
| 123 | +| Plugin | Purpose | |
| 124 | +|--------|---------| |
| 125 | +| gatsby-plugin-google-analytics | Google Analytics tracking (trackEvent on Discord clicks) | |
| 126 | +| gatsby-plugin-image/sharp | Optimized image handling and processing | |
| 127 | +| gatsby-plugin-styled-components | styled-components integration | |
| 128 | +| gatsby-plugin-anchor-links | Smooth anchor navigation for sidebar categories | |
| 129 | +| gatsby-plugin-manifest | PWA manifest for installability | |
| 130 | +| gatsby-plugin-offline | Service worker for offline PWA support | |
| 131 | +| gatsby-plugin-react-helmet | Head tag management via react-helmet | |
| 132 | + |
| 133 | +## Important Config Files |
| 134 | + |
| 135 | +| File | Notes | |
| 136 | +|------|-------| |
| 137 | +| `gatsby-config.js` | Plugin setup, site metadata, Google Analytics ID, PWA manifest | |
| 138 | +| `gatsby-browser.js` | Wraps app with globalContext Provider for theme state | |
| 139 | +| `.prettierrc` | Enforce 2-space indentation, single quotes, no semicolons, trailing commas | |
| 140 | +| `.eslintrc` | Airbnb config + React/JSX/a11y plugins | |
| 141 | +| `netlify.toml` | Netlify deployment (auto-builds on git push) | |
| 142 | +| `.env.development/.env.production` | Google Analytics ID (GOOGLE_ANALYTICS_ID) | |
| 143 | + |
| 144 | +## Code Patterns & Conventions |
| 145 | + |
| 146 | +### Component Structure |
| 147 | +- Functional components with hooks |
| 148 | +- styled-components for component styles |
| 149 | +- PropTypes for prop validation |
| 150 | +- File structure: `ComponentName.js` + `ComponentName.styles.js` |
| 151 | + |
| 152 | +### Comments |
| 153 | + |
| 154 | +- Always use **lowercase** unless referencing case-sensitive items (component names, file paths, variable names, etc.) |
| 155 | +- Write comments declaratively and directly, like a commit message |
| 156 | +- Focus on the "why" rather than obvious "what" |
| 157 | +- Examples: |
| 158 | + - ✓ `// toggle dark mode theme in localStorage` |
| 159 | + - ✗ `// This toggles the dark mode theme in localStorage` |
| 160 | + - ✓ `// map categories to sidebar navigation links` |
| 161 | + - ✗ `// Map categories to sidebar navigation links` |
| 162 | + |
| 163 | +### Adding a New Resource/Learning Item |
| 164 | +1. Edit `src/data/resources.json` or `src/data/learning.json` |
| 165 | +2. Follow existing category/resource structure |
| 166 | +3. Run `npm start` to see changes (hot reload works) |
| 167 | +4. No build or deployment needed for local testing |
| 168 | + |
| 169 | +### Adding a New Page |
| 170 | +1. Create `.js` file in `src/pages/` (Gatsby auto-routes) |
| 171 | +2. Export React component with Layout wrapper |
| 172 | +3. Use Seo component for head metadata |
| 173 | +4. Styling via styled-components |
| 174 | + |
| 175 | +### Theme-Aware Styling |
| 176 | +```javascript |
| 177 | +import { useContext } from 'react' |
| 178 | +import { GlobalContext } from '../context/globalContext' |
| 179 | + |
| 180 | +const MyComponent = () => { |
| 181 | + const { theme } = useContext(GlobalContext) |
| 182 | + |
| 183 | + return styled.div` |
| 184 | + background: var(--color__background); |
| 185 | + color: var(--color__text); |
| 186 | + ` |
| 187 | +} |
| 188 | +``` |
| 189 | + |
| 190 | +## Deployment & Build Process |
| 191 | + |
| 192 | +- **Dev**: `npm start` → localhost:8000 |
| 193 | +- **Production**: `npm run build` → outputs `/public/` with optimized assets |
| 194 | +- **Netlify**: Auto-detects gatsby-config.js, builds and deploys on git push to master |
| 195 | +- **Live site**: https://codehelp.io |
| 196 | + |
| 197 | +## Linting & Formatting |
| 198 | + |
| 199 | +- **ESLint**: Airbnb config enforces style rules |
| 200 | +- **Prettier**: Auto-format with `npm run format` |
| 201 | +- Pre-commit hooks: None currently configured (consider adding) |
| 202 | + |
| 203 | +## Notes for Future Development |
| 204 | + |
| 205 | +- Data is static JSON—no database or API backend |
| 206 | +- Theme switching is client-side only (Context + localStorage) |
| 207 | +- Analytics tracked on Discord link clicks (see Nav component) |
| 208 | +- Accessibility plugins enabled (jsx-a11y, manifest) |
| 209 | +- PWA support enabled (installable, offline fallback) |
| 210 | +- No automated tests currently—test suite commented in package.json |
0 commit comments