Aller au contenu principal

EMTB Source Tree Organization

Overview​

The EMTB Tax Claim Management System follows a monorepo architecture with independent applications for API and frontend, organized for optimal development workflow and role-based access control implementation.

Root Directory Structure​

emtb/
β”œβ”€β”€ .bmad-core/ # AI agent configurations and templates
β”œβ”€β”€ .claude/ # Claude Code configurations
β”œβ”€β”€ .cursor/ # Cursor IDE configurations
β”œβ”€β”€ .github/ # GitHub Actions workflows and templates
β”‚ β”œβ”€β”€ workflows/ # CI/CD pipeline definitions
β”‚ └── ISSUE_TEMPLATE/ # Issue and PR templates
β”œβ”€β”€ .git/ # Git repository data
β”œβ”€β”€ apps/ # Application packages (main development)
β”‚ β”œβ”€β”€ api/ # NestJS backend application
β”‚ └── frontend/ # Next.js frontend application
β”œβ”€β”€ docs/ # Project documentation
β”‚ β”œβ”€β”€ architecture/ # Technical architecture documents
β”‚ β”œβ”€β”€ prd.md # Product Requirements Document
β”‚ └── architecture.md # Main architecture specification
β”œβ”€β”€ web-bundles/ # Generated bundle assets
β”œβ”€β”€ README.md # Project overview and setup
β”œβ”€β”€ RENDER_DEPLOYMENT.md # Render.com deployment guide
β”œβ”€β”€ RENDER_TROUBLESHOOTING.md # Infrastructure troubleshooting
└── render.yaml # Render.com service definitions

Backend Application Structure (apps/api/)​

Core Organization​

apps/api/
β”œβ”€β”€ src/
β”‚ β”œβ”€β”€ main.ts # Application entry point
β”‚ β”œβ”€β”€ app.module.ts # Root application module
β”‚ β”œβ”€β”€ app.controller.ts # Health check and root endpoints
β”‚ β”œβ”€β”€ app.service.ts # Root application services
β”‚ β”‚
β”‚ β”œβ”€β”€ prisma/ # Database connection and configuration
β”‚ β”‚ β”œβ”€β”€ prisma.module.ts # Prisma module definition
β”‚ β”‚ └── prisma.service.ts # Database service with connection pooling
β”‚ β”‚
β”‚ β”œβ”€β”€ client/ # Client management domain
β”‚ β”‚ β”œβ”€β”€ client.module.ts # Client module with dependencies
β”‚ β”‚ β”œβ”€β”€ client.controller.ts # REST endpoints for client operations
β”‚ β”‚ β”œβ”€β”€ client.service.ts # Business logic for client management
β”‚ β”‚ β”œβ”€β”€ client.service.spec.ts # Unit tests for client service
β”‚ β”‚ β”œβ”€β”€ client.controller.spec.ts # Controller unit tests
β”‚ β”‚ └── dto/ # Data Transfer Objects
β”‚ β”‚ β”œβ”€β”€ create-client.dto.ts
β”‚ β”‚ └── update-client.dto.ts
β”‚ β”‚
β”‚ β”œβ”€β”€ site/ # Site management domain
β”‚ β”‚ β”œβ”€β”€ site.module.ts # Site module definition
β”‚ β”‚ └── [similar structure to client/]
β”‚ β”‚
β”‚ β”œβ”€β”€ reclamation/ # Tax claim management domain
β”‚ β”‚ β”œβ”€β”€ reclamation.module.ts
β”‚ β”‚ └── [similar structure to client/]
β”‚ β”‚
β”‚ β”œβ”€β”€ facture/ # Invoice management domain
β”‚ β”‚ └── facture.module.ts
β”‚ β”‚
β”‚ β”œβ”€β”€ user/ # User management domain
β”‚ β”‚ └── user.module.ts
β”‚ β”‚
β”‚ β”œβ”€β”€ apporteur-affaire/ # Partner/referrer management
β”‚ β”‚ └── apporteur-affaire.module.ts
β”‚ β”‚
β”‚ β”œβ”€β”€ facture-partenaire/ # Partner invoice management
β”‚ β”‚ └── facture-partenaire.module.ts
β”‚ β”‚
β”‚ β”œβ”€β”€ cadastre/ # Property/cadastral data management
β”‚ β”‚ β”œβ”€β”€ cadastre.module.ts
β”‚ β”‚ β”œβ”€β”€ cadastre.controller.ts
β”‚ β”‚ β”œβ”€β”€ cadastre.service.ts
β”‚ β”‚ └── dto/
β”‚ β”‚ β”œβ”€β”€ create-cadastre.dto.ts
β”‚ β”‚ └── update-cadastre.dto.ts
β”‚ β”‚
β”‚ β”œβ”€β”€ import/ # Data import functionality
β”‚ β”‚ β”œβ”€β”€ import.module.ts # Import service module
β”‚ β”‚ β”œβ”€β”€ import.service.ts # Data import logic
β”‚ β”‚ └── import.service.spec.ts # Import testing
β”‚ β”‚
β”‚ β”œβ”€β”€ cli/ # Command-line interface
β”‚ β”‚ β”œβ”€β”€ cli.module.ts # CLI module definition
β”‚ β”‚ └── import.command.ts # Import command implementation
β”‚ β”‚
β”‚ β”œβ”€β”€ scripts/ # Utility and maintenance scripts
β”‚ β”‚ β”œβ”€β”€ fix-json-data.ts # Data cleanup scripts
β”‚ β”‚ β”œβ”€β”€ fix-json-data.spec.ts
β”‚ β”‚ β”œβ”€β”€ validate-import-data.ts # Data validation scripts
β”‚ β”‚ └── validate-import-data.spec.ts
β”‚ β”‚
β”‚ └── cli.ts # CLI entry point
β”‚
β”œβ”€β”€ test/ # End-to-end and integration tests
β”‚ └── jest-e2e.json # E2E testing configuration
β”‚
β”œβ”€β”€ prisma/ # Database schema and migrations
β”‚ β”œβ”€β”€ schema.prisma # Database schema definition
β”‚ └── migrations/ # Database migration files
β”‚
β”œβ”€β”€ package.json # Backend dependencies and scripts
└── tsconfig.json # TypeScript configuration

Domain Module Pattern​

Each domain (client, site, reclamation, etc.) follows a consistent structure:

domain/
β”œβ”€β”€ domain.module.ts # NestJS module with providers and exports
β”œβ”€β”€ domain.controller.ts # HTTP endpoints with Swagger documentation
β”œβ”€β”€ domain.service.ts # Business logic and Prisma integration
β”œβ”€β”€ domain.controller.spec.ts # Controller unit tests
β”œβ”€β”€ domain.service.spec.ts # Service unit tests
└── dto/ # Data Transfer Objects
β”œβ”€β”€ create-domain.dto.ts # Creation DTOs with validation
└── update-domain.dto.ts # Update DTOs (usually extends CreateDto)

Frontend Application Structure (apps/frontend/)​

Core Organization​

apps/frontend/
β”œβ”€β”€ app/ # Next.js 14 App Router structure
β”‚ β”œβ”€β”€ layout.tsx # Root layout with providers
β”‚ β”œβ”€β”€ page.tsx # Home page component
β”‚ β”œβ”€β”€ loading.tsx # Loading UI component
β”‚ β”œβ”€β”€ error.tsx # Error boundary component
β”‚ β”œβ”€β”€ not-found.tsx # 404 page component
β”‚ β”‚
β”‚ β”œβ”€β”€ api/ # API routes (Next.js API routes)
β”‚ β”‚ └── auth/ # Auth0 API routes
β”‚ β”‚
β”‚ β”œβ”€β”€ protected/ # Authenticated routes
β”‚ β”‚ β”œβ”€β”€ layout.tsx # Protected area layout
β”‚ β”‚ β”œβ”€β”€ dashboard/ # Dashboard pages
β”‚ β”‚ β”œβ”€β”€ clients/ # Client management pages
β”‚ β”‚ β”œβ”€β”€ reclamations/ # Tax claim pages
β”‚ β”‚ └── reports/ # Reporting pages
β”‚ β”‚
β”‚ └── auth/ # Authentication pages
β”‚ β”œβ”€β”€ login/
β”‚ β”œβ”€β”€ logout/
β”‚ └── callback/
β”‚
β”œβ”€β”€ components/ # Reusable UI components
β”‚ β”œβ”€β”€ shared/ # Generic shared components
β”‚ β”‚ β”œβ”€β”€ List.tsx # Generic data list component
β”‚ β”‚ β”œβ”€β”€ ConfirmationDialog.tsx # Confirmation modals
β”‚ β”‚ └── LoadingSpinner.tsx # Loading indicators
β”‚ β”‚
β”‚ β”œβ”€β”€ layout/ # Layout-specific components
β”‚ β”‚ β”œβ”€β”€ Header.tsx # Application header
β”‚ β”‚ β”œβ”€β”€ Sidebar.tsx # Navigation sidebar
β”‚ β”‚ └── Footer.tsx # Application footer
β”‚ β”‚
β”‚ └── forms/ # Form components
β”‚ β”œβ”€β”€ FormField.tsx # Generic form field wrapper
β”‚ └── ValidationMessage.tsx # Form validation display
β”‚
β”œβ”€β”€ domains/ # Domain-specific components and logic
β”‚ β”œβ”€β”€ clients/ # Client management domain
β”‚ β”‚ β”œβ”€β”€ components/ # Client-specific components
β”‚ β”‚ β”‚ β”œβ”€β”€ ClientsList.tsx # Client listing component
β”‚ β”‚ β”‚ β”œβ”€β”€ ClientShortDetails.tsx # Client summary
β”‚ β”‚ β”‚ └── forms/ # Client form components
β”‚ β”‚ β”‚ β”œβ”€β”€ ClientForm.tsx
β”‚ β”‚ β”‚ β”œβ”€β”€ ContactForm.tsx
β”‚ β”‚ β”‚ β”œβ”€β”€ PartnerForm.tsx
β”‚ β”‚ β”‚ β”œβ”€β”€ PartnerSelectList.tsx
β”‚ β”‚ β”‚ β”œβ”€β”€ MandatForm.tsx
β”‚ β”‚ β”‚ β”œβ”€β”€ ConventionForm.tsx
β”‚ β”‚ β”‚ └── GeneralInformationForm.tsx
β”‚ β”‚ β”‚
β”‚ β”‚ └── hooks/ # Client-specific hooks
β”‚ β”‚ └── queries/ # React Query hooks
β”‚ β”‚ └── clients.ts # Client data fetching hooks
β”‚ β”‚
β”‚ β”œβ”€β”€ reclamations/ # Tax claim management domain
β”‚ β”œβ”€β”€ sites/ # Site management domain
β”‚ └── reports/ # Reporting domain
β”‚
β”œβ”€β”€ contexts/ # React Context providers
β”‚ β”œβ”€β”€ AuthProvider.tsx # Auth0 context wrapper
β”‚ β”œβ”€β”€ ThemeProvider.tsx # MUI theme context
β”‚ └── SnackbarProvider.tsx # Global notification context
β”‚
β”œβ”€β”€ hooks/ # Shared custom hooks
β”‚ β”œβ”€β”€ useAuth.ts # Authentication state hook
β”‚ β”œβ”€β”€ useLocalStorage.ts # Local storage utilities
β”‚ └── useDebounce.ts # Debouncing utilities
β”‚
β”œβ”€β”€ shared/ # Shared utilities and services
β”‚ β”œβ”€β”€ services/ # API service layer
β”‚ β”‚ β”œβ”€β”€ client.ts # Client API service
β”‚ β”‚ β”œβ”€β”€ reclamation.ts # Tax claim API service
β”‚ β”‚ └── api.ts # Base API client
β”‚ β”‚
β”‚ β”œβ”€β”€ query-keys.ts # React Query key definitions
β”‚ β”œβ”€β”€ constants.ts # Application constants
β”‚ └── utils.ts # Utility functions
β”‚
β”œβ”€β”€ types/ # TypeScript type definitions
β”‚ β”œβ”€β”€ next-auth.d.ts # Next-auth type extensions
β”‚ β”œβ”€β”€ strapi.dts.ts # Generated API types
β”‚ β”œβ”€β”€ shared.ts # Shared type definitions
β”‚ β”œβ”€β”€ theme.ts # MUI theme types
β”‚ β”œβ”€β”€ sidebar.ts # Navigation types
β”‚ β”œβ”€β”€ autocomplete-option.ts # Form component types
β”‚ β”œβ”€β”€ images.d.ts # Image asset types
β”‚ └── emotion.d.ts # Emotion CSS types
β”‚
β”œβ”€β”€ theme/ # MUI theme configuration
β”‚ β”œβ”€β”€ index.ts # Theme provider and configuration
β”‚ └── components/ # Component-specific theme overrides
β”‚
β”œβ”€β”€ utils/ # Utility functions and helpers
β”‚ β”œβ”€β”€ constants.ts # Global constants
β”‚ β”œβ”€β”€ formatters.ts # Data formatting utilities
β”‚ └── validators.ts # Form validation utilities
β”‚
β”œβ”€β”€ vendor/ # Third-party assets and configurations
β”‚ └── mui/ # Material-UI specific customizations
β”‚
β”œβ”€β”€ middleware.ts # Next.js middleware (authentication)
β”œβ”€β”€ constants.js # Legacy constants (to be migrated)
β”œβ”€β”€ next.config.js # Next.js configuration
β”œβ”€β”€ tailwind.config.js # Tailwind CSS configuration
β”œβ”€β”€ postcss.config.js # PostCSS configuration
β”œβ”€β”€ tsconfig.json # TypeScript configuration
β”œβ”€β”€ jest.config.ts # Jest testing configuration
β”œβ”€β”€ jest.setup.ts # Jest setup and global mocks
└── package.json # Frontend dependencies and scripts

Key Architectural Patterns​

Backend Patterns​

  1. Module-based Organization: Each business domain has its own NestJS module
  2. Controller-Service Pattern: Clear separation between HTTP handling and business logic
  3. DTO Pattern: Validation and type safety with class-validator decorators
  4. Repository Pattern: Prisma service acts as repository layer
  5. CLI Integration: Command pattern for data management operations

Frontend Patterns​

  1. Domain-driven Organization: Components organized by business domain
  2. Atomic Design: Shared components, domain-specific components, page layouts
  3. Custom Hook Pattern: React Query integration with domain-specific hooks
  4. Service Layer Pattern: Centralized API communication layer
  5. Provider Pattern: Context-based state management

RBAC Implementation Structure (Planned)​

Backend RBAC Structure​

src/
β”œβ”€β”€ auth/ # RBAC authentication and authorization
β”‚ β”œβ”€β”€ guards/ # Role-based route guards
β”‚ β”œβ”€β”€ decorators/ # Role requirement decorators
β”‚ β”œβ”€β”€ services/ # Authentication services
β”‚ └── middleware/ # Tenant context middleware
β”‚
β”œβ”€β”€ tenant/ # Multi-tenant data isolation
β”‚ β”œβ”€β”€ services/ # Tenant context management
β”‚ └── middleware/ # Prisma middleware for filtering
β”‚
└── audit/ # Security audit logging
β”œβ”€β”€ services/ # Audit log services
└── models/ # Audit data models

Frontend RBAC Structure​

src/
β”œβ”€β”€ contexts/
β”‚ └── RoleContext.tsx # Role-based state management
β”‚
β”œβ”€β”€ components/
β”‚ └── rbac/ # Role-aware UI components
β”‚ β”œβ”€β”€ ProtectedRoute.tsx # Route protection
β”‚ └── RoleBasedRender.tsx # Conditional rendering
β”‚
└── hooks/
β”œβ”€β”€ useRole.ts # Role state management
└── usePermissions.ts # Permission checking

File Naming Conventions​

Backend (NestJS/TypeScript)​

  • Modules: domain.module.ts (kebab-case for domain, PascalCase for class)
  • Controllers: domain.controller.ts (REST endpoint handlers)
  • Services: domain.service.ts (business logic)
  • DTOs: create-domain.dto.ts, update-domain.dto.ts (kebab-case files)
  • Tests: *.spec.ts (same name as tested file)

Frontend (Next.js/React/TypeScript)​

  • Components: ComponentName.tsx (PascalCase)
  • Pages: page.tsx, layout.tsx (Next.js App Router convention)
  • Hooks: useHookName.ts (camelCase with 'use' prefix)
  • Services: serviceName.ts (camelCase)
  • Types: typeName.ts or domain.types.ts (camelCase)

Import Path Conventions​

Backend Imports​

// Relative imports within same module
import { CreateClientDto } from './dto/create-client.dto';

// Absolute imports for cross-module
import { PrismaService } from '../prisma/prisma.service';

Frontend Imports​

// Absolute imports using path mapping (tsconfig.json)
import { ClientService } from '$shared/services/client';
import { useAuth } from '$hooks/useAuth';
import FormField from '$components/forms/FormField';

// Domain-specific imports
import { ClientForm } from '$domains/clients/components/forms/ClientForm';

Build and Development Organization​

Package Scripts​

  • Development: npm run dev (both apps), npm run dev:api, npm run dev:frontend
  • Building: npm run build (both apps), npm run build:api, npm run build:frontend
  • Testing: npm run test, npm run test:unit, npm run test:e2e
  • Linting: npm run lint (both apps with --fix)
  • Type Checking: npm run type:check (TypeScript validation)

Deployment Structure​

  • Production Build: Separate Docker containers for API and frontend
  • Environment Variables: App-specific .env files
  • Database Migrations: Handled via Prisma migrate in deployment pipeline

This source tree organization supports the RBAC enhancement by providing clear separation of concerns, consistent patterns, and scalable architecture for multi-tenant security implementation.