Directory Overview
A complete extension structure looks like this:Required Files
package.json
Every extension must have apackage.json file:
type: "module": Required for ES modules supportmain: Entry point (typically not used directly)scripts.tsc: For compiling TypeScript
tsconfig.json
TypeScript configuration for compilation:Directory Details
src/api/
Contains REST API endpoint definitions. Each endpoint is a folder with:methods: HTTP methods (GET, POST, PUT, DELETE)path: URL pathaccess:publicorprivate(requires authentication)
src/graphql/
Contains GraphQL schema extensions and resolvers:src/pages/
Contains React components for UI. Organized by area:src/subscribers/
Event subscribers organized by event name:src/crons/
Cron job handler functions:bootstrap.ts.
src/bootstrap.ts
Optional initialization script that runs during application startup:Naming Conventions
File Names
- Components: PascalCase (e.g.,
FreeShippingMessage.tsx) - Handlers: camelCase (e.g.,
handler.ts,bodyParser.ts) - Subscribers: camelCase (e.g.,
consoleLog.js,sendEmail.ts) - Crons: camelCase (e.g.,
everyMinute.ts,dailyReport.ts) - Config: kebab-case (e.g.,
route.json)
Middleware Prefix
Middleware functions use bracket notation:Directory Names
- Routes: kebab-case (e.g.,
create-foo/,my-custom-page/) - Events: snake_case (e.g.,
product_created/,order_placed/) - Page areas: camelCase (e.g.,
frontStore/,admin/)
Development vs Production
Development Mode
- Uses
src/directory - Hot reload enabled
- TypeScript compiled on-the-fly
- Detailed error messages
Production Mode
- Uses
dist/directory (required) - Compiled JavaScript only
- Optimized performance
- Must run
npm run tscbefore deployment
Best Practices
- Keep it Modular: Each feature should be self-contained
- Use TypeScript: Better type safety and IDE support
- Document Your Code: Add comments and README files
- Follow Conventions: Stick to naming and structure standards
- Test Thoroughly: Test in both development and production modes
- Version Control: Use semantic versioning for your extension
Next Steps
- Learn about Hooks and Events
- Check the Creating Extensions guide
- Explore the sample extension included with EverShop