Ruletypescript
Project Structure Rule
Secret-Zero is a Next.js application with TypeScript, implementing a secure secret sharing portal using Stytch B2B authentication and Infisical for secret management.
Secret-Zero Project Structure
Overview
Secret-Zero is a Next.js application with TypeScript, implementing a secure secret sharing portal using Stytch B2B authentication and Infisical for secret management.
Directory Structure
Root Level Configuration
package.json- Dependencies and scriptsnext.config.ts- Next.js configurationtsconfig.json- TypeScript configurationeslint.config.mjs- ESLint configurationpostcss.config.mjs- PostCSS configurationtailwind.config.js- Tailwind CSS configurationcomponents.json- shadcn/ui component configurationenv.ts- Environment variable validation (Zod schemas)instrumentation.ts- Next.js instrumentation for logging/monitoringdevelopment_log.md- Development activity log (mandatory protocol)
Source Code Structure
actions/ - Server Actions
auth.ts- Authentication-related server actionsdeposit.ts- Secret deposit operations
app/ - Next.js App Router
(auth)/- Authentication routes (route groups)login/page.tsx- Login pageauthenticate/page.tsx- Authentication flowlayout.tsx- Auth layout
(portal)/- Protected portal routes (route groups)dashboard/page.tsx- User dashboarddeposit/[orgSlug]/page.tsx- Organization-specific deposit pagelayout.tsx- Portal layout
api/webhooks/stytch/route.ts- Stytch webhook handlerlayout.tsx- Root layoutpage.tsx- Home pageglobals.css- Global styles
components/ - React Components
ui/- shadcn/ui components (reusable UI primitives)forms/- Form components (secret-form.tsx)component-example.tsx,example.tsx- Example components
lib/ - Utility Libraries
crypto.ts- Cryptographic utilitiesinfisical.ts- Infisical integrationstytch.ts- Stytch authentication clientutils.ts- General utility functions
Configuration & Documentation
docs/ - Documentation
prd.md- Product Requirements DocumentSTYTCH_SETUP.md- Stytch integration guideINFISICAL_SETUP.md- Infisical setup instructionsVERCEL_DEPLOYMENT.md- Deployment configurationSECURITY_TESTS.md- Security testing procedures
public/ - Static Assets
- SVG icons and assets for the application
.claude/ - Claude Code Integration
CLAUDE.md- Project memory and instructions for Claude Coderules/- Modular project rules organized by topictech-stack.md- Technology stack guidelinesproject-structure.md- Project structure conventionslanguage-policy.md- Language policy (English requirement)self-improve.md- Rule improvement guidelines
Important Conventions
File Organization
- Use TypeScript for all source files (.ts/.tsx)
- Server components in
app/directory - Server actions in
actions/directory - Reusable components in
components/directory - Utility functions in
lib/directory
Route Organization
- Authentication routes grouped under
(auth)/ - Protected routes grouped under
(portal)/ - Dynamic routes use
[param]syntax - API routes under
api/
Component Architecture
- UI primitives in
components/ui/(shadcn/ui) - Feature-specific components in appropriate directories
- Form components in
components/forms/
Security Considerations
- All sensitive operations use server actions
- Environment variables validated with Zod schemas
- Cryptographic operations centralized in
lib/crypto.ts - Authentication handled through Stytch B2B
- Client-side encryption for secrets before transmission
Development Workflow
- All changes logged in
development_log.mdwith timestamp formatYYYYMMDDTHHMMZ - Follow Claude Code rules for consistent code style
- Use English for all code comments and documentation
- Maintain security-first approach in all implementations
Critical Security Configurations
next.config.ts
- Logging disabled:
logging.incomingRequests: false- prevents request body logging - Taint API enabled:
experimental.taint: true- marks secrets as untransmittable to client - Payload size limit:
experimental.serverActions.bodySizeLimit: "100kb" - Security headers: X-Frame-Options, X-Content-Type-Options, Referrer-Policy, X-XSS-Protection
env.ts (Zod Validation)
All environment variables are validated at startup. Critical secrets:
SERVER_PRIVATE_KEY- RSA private key for decrypting client payloads (Infisical-managed)INFISICAL_CLIENT_ID/SECRET- Machine Identity credentials (Universal Auth)STYTCH_PROJECT_ID/SECRET- B2B authentication credentials
middleware.ts
Validates Stytch JWT for all /dashboard/* and /deposit/* routes. Redirects to /login if session invalid.