Coding Conventions
Coding Conventions
Section titled “Coding Conventions”This page documents all coding patterns enforced in the Juca codebase. Following these conventions ensures consistency and makes the codebase predictable for both human and AI contributors.
Naming Conventions
Section titled “Naming Conventions”| Context | Convention | Example |
|---|---|---|
| Components | PascalCase | WorkCanvas.tsx, PhaseRail.tsx |
| Hooks | camelCase with use prefix | useFeatureFlag, useSSEStream |
| Server Actions | camelCase | updateDiagnosis, evaluatePrecedent |
| API routes | kebab-case directories | document-metadata/, validate-processo/ |
| Block types | snake_case | risk_balance, exit_card, action_prompt |
| Feature flags | camelCase | unifiedHome, deepMode |
| CSS tokens | kebab-case with -- prefix | --color-primary, --radius-xl |
Authentication Patterns
Section titled “Authentication Patterns”The codebase uses two auth patterns. Never mix them:
Server Actions — Use requireActionAuth():
'use server';import { requireActionAuth } from '@/actions/utils';
export async function updateDiagnosis(sessionId: string, fields: object) { const user = await requireActionAuth(); // throws if unauthorized // ...}API Routes — Use auth() directly:
import { auth } from '@/lib/auth';
export async function GET() { const session = await auth(); if (!session?.user) return new Response('Unauthorized', { status: 401 }); // ...}Block Creation Pattern
Section titled “Block Creation Pattern”Always use factory helpers to create blocks:
import { createDiagnosisData } from '@/lib/blocks/types';import { getBlocksDB } from '@/lib/db/sessions';
const blockData = createDiagnosisData(analysis);await getBlocksDB().addBlock({ sessionId, type: 'diagnosis', data: blockData});Next.js 16 Route Params
Section titled “Next.js 16 Route Params”Route parameters in Next.js 16 are Promise-based:
export async function GET( request: Request, { params }: { params: Promise<{ id: string }> }) { const { id } = await params; // Must await! // ...}Commit Conventions
Section titled “Commit Conventions”feat(scope): description # New featurefix(scope): description # Bug fixdocs: description # Documentation onlychore: description # Maintenance, dependenciesScopes: rewrite, briefing, deploy, lint, test, auth, etc.
All commits include a co-author header:
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>CSS and Animations
Section titled “CSS and Animations”Tailwind v4 CSS-first approach — tokens in src/app/globals.css:
:root { --color-primary: #000000; --color-accent: #fff06d; --color-bg-primary: #ffffff;}Available animation utilities:
| Class | Effect |
|---|---|
animate-fade-in | 300ms fadeIn (translateY 10px→0, opacity 0→1) |
spring-transition | cubic-bezier(0.34, 1.56, 0.64, 1) for spring feel |
animate-pulse | Built-in Tailwind pulse |
scroll-smooth-block | Smooth scroll behavior |
For staggered animations:
<div style={{ animationDelay: `${index * 100}ms`, animationFillMode: 'backwards'}}>Import Organization
Section titled “Import Organization”All imports use the @/ alias. Order:
// 1. React / Next.jsimport React, { useState } from 'react';import { NextResponse } from 'next/server';
// 2. External librariesimport { jsPDF } from 'jspdf';
// 3. Internal librariesimport { auth } from '@/lib/auth';import { getBlocksDB } from '@/lib/db/sessions';
// 4. Componentsimport { WorkCanvas } from '@/components/canvas/WorkCanvas';
// 5. Typesimport type { Block, BlockType } from '@/types/blocks';Code Style
Section titled “Code Style”- TypeScript strict mode — all code must pass
tscwithout errors - ESLint with Next.js rules (flat config in
eslint.config.mjs) - No Prettier — ESLint handles formatting
- No console.log in production code — use the centralized logger at
src/lib/logger.ts