How devbrains-com/swisstaxcalculator works
Main Components
• Frontend/UI Layer: Represented by Nuxt 3 with Vue components (e.g., app.vue, pages/index.vue, and other components in the components folder). Note the use of assets (CSS files) and form-related components (e.g., those inside components/formkit and components/global).
• Server/API Layer: The server folder (server/api) hosts API routes such as inputdata.get.ts, locations.get.ts, and taxes.post.ts. These endpoints receive client requests and forward them to the business logic for processing.
• Business Logic / Tax Calculation Layer: The core tax logic lives in the lib/taxes directory. This layer includes modules for different tax aspects – deductions, factors, income, pension capital, personnel, tariffs, and more. Each sub-folder deals with specific tax rules and calculations.
• Data Layer: This project uses file-based data storage. The data folder is split into raw (initial JSON files from external sources) and parsed directories (organized per year, canton and tax category). Data is imported at build time (via the yarn importdata script) and held in memory during execution.
• Utility and Support Modules: Other directories such as inputs, lib/utils, modules, and utils support both the UI components and tax logic with common functions and configurations (e.g., formkit.config.ts, tsconfig.json).
• Data Flow from the Client to the Server:
• Client (Nuxt pages and Vue components) sends user input (e.g., tax-related values) through the UI.
• These inputs trigger API requests (server/api/taxes.post.ts for tax calculations, server/api/locations.get.ts for retrieving location data, etc.).
• Server API and Business Logic Interaction:
• API endpoints receive the requests, validate input data, and forward them to the tax calculation modules found in lib/taxes.
• The tax logic uses various data helpers, constants, and data importers to calculate results based on the loaded raw/parsed data.
• Data Handling:
• Data is initially brought in by the import process (using yarn importdata) from the data/raw folder and organized into the data/parsed folder. Once imported, the file-based data is loaded into memory.
• Integration of Utility Modules:
• Shared utilities (in lib/utils, utils, and inputs) assist both the frontend and business logic layers with additional data operations (e.g., formatting, currency calculations with DineroJS, array formatting).
Architectural Patterns and Design Principles
• Separation of Concerns: Components and pages handle presentation; server/api routes manage the HTTP layer; business logic is strictly isolated in the lib/taxes module; and raw data is handled separately.
• Modular Design: The tax calculations are broken into submodules (deduction, factor, income, etc.), promoting reusability and easier maintenance.
• Static Deployment & In-Memory Data Optimization: The design emphasizes static deployment where tax data is pre-parsed and efficiently loaded into memory for quick calculations.
Essential Elements
• UI Components and API endpoints.
• API endpoints and the tax business logic.
• Business logic and the file-based data layer.
• Notes for any significant design practices such as the in-memory loading for speed and the modular separation within lib/taxes.