- This is a monorepo with two main folders:
frontend/→ Next.js (React + Vite can be used for smaller projects, but Next.js is chosen for scalability, SSR/SSG, routing, and SEO).backend/→ Node.js + Express + MongoDB, fully in TypeScript, with ES Modules ("type": "module").
- All code must be modular, maintainable, and scalable.
- Avoid single files longer than 300 lines; break them into smaller modules.
-
Use TypeScript everywhere (
.ts/.tsx). -
Enforce strict typing (
strict: trueintsconfig.json). -
Follow SOLID principles and separation of concerns.
-
Code must be linted with ESLint + Prettier + Husky pre-commit hooks.
-
Always prefer async/await over callbacks or
.then(). -
Follow RESTful API design and proper HTTP status codes.
-
Use environment variables (never hardcode secrets, keys, or DB URLs).
-
Every module must have clear responsibilities and no "god files".
-
Always write meaningful commit messages using Conventional Commits style:
feat: add idea submission featurefix: resolve MongoDB connection issuerefactor: split routes into separate files
-
Always implement loading states for user interactions (buttons, forms, page transitions).
-
Use comprehensive error handling with user-friendly error messages and toast notifications.
-
Implement proper validation on both client and server sides with clear error messages.
-
🗺️ CRITICAL: Always maintain the ROADMAP.md file - When implementing features, completing tasks, or making significant changes, update the roadmap to reflect current progress and adjust priorities as needed.
-
🤝 IMPLEMENTATION APPROVAL REQUIRED - Before implementing any new feature, service, or significant code change, ALWAYS:
- Explain the implementation approach and architecture
- Describe the technical decisions and trade-offs
- Get explicit user approval before proceeding with code changes
- Ask for feedback on the proposed solution
- Feature Completion: Mark items as completed with ✅ and brief description
- New Feature Implementation: Add new features to appropriate phases
- Priority Changes: Adjust immediate/medium/long-term priorities based on development needs
- Status Updates: Update "Current Development Status" section regularly
- Timeline Adjustments: Modify phase timelines when scope or complexity changes
- [x] **Feature Name** (Brief implementation details) ✅
- [ ] **In Progress Feature** (Current status/blockers) 🚧
- [ ] **Planned Feature** (Dependencies/requirements)- Current Development Status: Update monthly or after major milestones
- Implementation Timeline & Priorities: Adjust based on completed work
- Phase Progress: Mark completed items and update phase status
- Next Priority Items: Keep this aligned with current development focus
- After completing any major feature
- When starting a new development sprint/phase
- When dependencies or technical requirements change
- When adjusting project scope or timeline
- During monthly project reviews
-
Framework: Next.js (with App Router) for scalability.
-
Styling: TailwindCSS + shadcn/ui for components.
-
shadcn/ui Standards:
- Use "new-york" style with CSS variables
- Lucide icons for all iconography
- Components in
@/components/ui/directory - Always use provided variants and sizes
- Extend components by composition, not modification
- Use
cn()utility for conditional classes
-
NEVER use mock/dummy data - Always fetch real data from API endpoints using React Query hooks.
-
State Management: React Query (TanStack) for server data + Context API/Zustand for global UI state.
-
API requests via a typed Axios client with interceptors.
-
UI/UX Standards:
- Always implement loading states using our enhanced Button component with
loadingprop - Use toast notifications for user feedback (success/error messages)
- Implement proper form validation with real-time feedback
- Use skeleton loaders while content is loading
- Ensure all interactive elements provide immediate visual feedback
- Always implement loading states using our enhanced Button component with
-
Directory structure:
frontend/ src/ app/ # Next.js App Router (routes, pages, layouts) components/ # Reusable UI components features/ # Feature-specific components (e.g., ideas, users) hooks/ # Custom React hooks lib/ # API clients, utils, config store/ # State management (Zustand/Context) types/ # Global TypeScript interfaces -
Best Practices:
-
Use functional components only.
-
Each component ≤ 150 lines.
-
Always use
propsinterfaces with TypeScript. -
Write utility functions separately in
lib/instead of inside components. -
Favor composition over inheritance.
-
Use lazy loading / code splitting for heavy components.
-
Loading States: Always use the enhanced Button component for forms:
<Button loading={mutation.isPending} loadingText="Processing..." disabled={!isValid}> Submit </Button>
-
Error Handling: Use toast notifications for all user feedback:
toast({ title: 'Success!', description: 'Operation completed successfully', });
-
- Framework: Express with TypeScript + ES Modules.
- Database: MongoDB with Mongoose.
- Directory structure:
backend/ src/ config/ # Database config, environment setup models/ # Mongoose models controllers/ # Request handlers routes/ # Express routes services/ # Business logic (separate from controllers) middlewares/ # Auth, error handling, validation utils/ # Helper functions types/ # TypeScript interfaces/types app.ts # Express app setup server.ts # Server bootstrap - Best Practices:
-
Use DTOs (Data Transfer Objects) for request/response typing.
-
Always validate input with Zod schemas - follow existing patterns in
validation/folder. -
Use async error handling middleware (no
try/catchin every controller). -
Error handling: Use AppError class for operational errors:
throw new AppError('Resource not found', 404);
-
Separate:
- Controller → Handles req/res, delegates to services
- Service → Business logic, data processing
- Model → Database schema and validations
-
Use index.ts barrels in folders for cleaner imports.
-
Never mix DB queries directly in controllers.
-
Validation patterns: Always clean and validate data:
// Clean undefined arrays before sending const cleanData = { title: data.title.trim(), tags: data.tags?.length > 0 ? data.tags : undefined, };
-
- Use JWT authentication (with refresh tokens).
- Hash passwords with bcrypt.
- Sanitize inputs against NoSQL Injection and XSS.
- Use Helmet.js and CORS properly configured.
- Use plural collection names (
users,ideas,projects). - Keep schema definitions clean and modular.
- Example for
Idea:interface Idea { title: string; description: string; domain: string[]; createdBy: ObjectId; upvotes: number; createdAt: Date; updatedAt: Date; }
- Use Jest + Supertest for backend.
- Use React Testing Library for frontend.
- Always write unit tests for utils/services and integration tests for routes.
-
Package manager: pnpm (monorepo friendly).
-
Use Docker for containerization.
-
Add GitHub Actions CI/CD with lint + test on every PR.
-
Add commit hooks (Husky + lint-staged).
-
Development Scripts:
pnpm dev- Start both frontend and backend in developmentpnpm build- Build both packages for productionpnpm seed- Seed database with sample datapnpm db:migrate- Run database migrationspnpm lint- Run ESLint across all packagespnpm test- Run all tests
-
Workspace Structure:
- Root level scripts handle cross-package commands
- Use
--filterflag to target specific packages - Shared dependencies managed at workspace root
-
Prettier Configuration:
- Semi-colons:
true - Single quotes:
true - Print width:
100 - Tab width:
2spaces - Trailing commas:
es5
- Semi-colons:
-
ESLint Rules:
- Unused vars:
error(except args starting with_) anytype:warn(minimize usage)- No explicit return types required for functions
- Non-null assertions:
warn
- Unused vars:
-
Naming conventions:
- Variables & functions →
camelCase - Classes & types →
PascalCase - Constants →
UPPER_SNAKE_CASE
- Variables & functions →
-
File naming:
kebab-case.tsfor files. -
Folder naming: lowercase (e.g.,
controllers,models).
- Shared types in
shared/src/types/with.jsextension imports for compatibility - Barrel exports in
shared/src/index.tsfor clean imports - Consistent DTOs across frontend and backend
- API response types standardized with
ApiResponse<T>andPaginatedResponse<T>
- Backend: Use
AppErrorclass for operational errors with appropriate status codes - Frontend: Always use toast notifications for user feedback
- Validation: Client-side validation + server-side Zod schemas
- Loading states: Never leave users without feedback during async operations
- Form handling: Validate, show loading, handle errors, show success
-
Consistent Response Format:
// Success responses { "success": true, "data": { /* response data */ }, "message": "Operation successful" } // Error responses { "success": false, "error": "Error message", "message": "User-friendly message", "statusCode": 400 }
-
Pagination Standard:
{ "success": true, "data": [...], "pagination": { "page": 1, "limit": 10, "total": 100, "pages": 10, "hasNext": true, "hasPrev": false } }
-
API Client Configuration:
- Use axios with interceptors for auth and error handling
- Base URL from environment variables
- Credentials included for cookie-based auth
- Consistent error response handling
- Modular Monolith: Keep related features together, clear module boundaries
- Domain-Driven Design: Organize code by business domains (users, ideas, comments)
- API-First: Design APIs before implementation, maintain OpenAPI specs
- Database-First: Plan schema changes, use migrations, maintain data integrity
- Atomic Design: Atoms (Button) → Molecules (SearchForm) → Organisms (Header) → Templates → Pages
- Composition over Inheritance: Build complex components from simpler ones
- Props Interface Standards: Always define and export prop types
- Consistent Naming:
<FeatureName><ComponentType>(e.g.,IdeaCard,UserProfile)
- Feature Flags: Use environment-based feature toggles for gradual rollouts
- Progressive Enhancement: Core functionality first, enhancements second
- Mobile-First: Design for mobile, enhance for desktop
- Accessibility-First: WCAG 2.1 AA compliance from day one
- Code Splitting: Lazy load routes and heavy components
- Image Optimization: Use Next.js Image component, WebP format
- Bundle Analysis: Regular bundle size monitoring and optimization
- Database Indexing: Index frequently queried fields
- Caching Strategy: Redis for sessions, API response caching
- Input Validation: Client + Server validation on ALL inputs
- Rate Limiting: API endpoint protection against abuse
- CSRF Protection: Token-based protection for state-changing operations
- SQL/NoSQL Injection Prevention: Parameterized queries, input sanitization
- Dependency Updates: Regular security audit and updates
- Error Tracking: Structured error logging with context
- Performance Monitoring: API response times, database query performance
- User Analytics: Track feature usage for data-driven decisions
- Health Checks: Automated monitoring of critical services
- Branch Strategy:
feature/*,fix/*,release/*naming - PR Requirements: Tests passing, code review, documentation updates
- Deployment Pipeline: Staging → Production with automated testing
- Database Migrations: Reversible, tested migrations only
- Roadmap Maintenance: Update ROADMAP.md after every significant milestone
- API Documentation: Auto-generated from code (OpenAPI/Swagger)
- Component Documentation: Storybook for UI components
- Architecture Decision Records: Document major technical decisions
- Changelog: Semantic versioning with detailed change logs
- Roadmap Updates: Keep ROADMAP.md current with development progress
- Design Tokens: Centralized colors, typography, spacing
- Component Library: Maintain shadcn/ui customizations in dedicated files
- Responsive Breakpoints: Consistent across all components
- Dark/Light Mode: Built-in theme switching capability
- Internationalization: i18n ready architecture from start
-
When creating a new API route:
- First create a TypeScript interface in
types/. - Add a Mongoose model in
models/. - Add a service function in
services/. - Add a controller that uses the service.
- Register it in
routes/. - Write a test for it.
- Update ROADMAP.md if this completes a planned feature.
- First create a TypeScript interface in
-
For new frontend features:
- Create a
feature/folder with related components. - Add TypeScript types in
types/. - Connect API via React Query hook in
hooks/. - Build components with Tailwind + shadcn/ui.
- Ensure accessibility (a11y).
- Update ROADMAP.md to reflect feature completion and adjust priorities.
- Create a
-
When completing major milestones:
- Mark completed features in ROADMAP.md with ✅
- Update "Current Development Status" section
- Adjust next priorities based on completed work
- Update timeline estimates if needed
- Add new features or technical debt items as discovered