Komennot, asetukset, tavoitearkkitehtuurin tiivistelmä sekä käyttöliittymä- ja saavutettavuussäännöt tuleville istunnoille. Co-Authored-By: Claude Opus 5.5 <[email protected]>
6.8 KiB
CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Project
Toiminnanohjaus is an ERP for a small (5–10 people) Finnish media and marketing company. It covers customers, customer jobs, tasks, time tracking, expenses, price lists, billing exports to Fennoa, quick sales and, later, inventory and machines.
- Stack: Django 5.2 LTS, Python 3.14, MariaDB 10.11 (XAMPP in development), HTMX, Alpine.js, Tailwind CSS 4 and daisyUI 5.
- Language: code (identifiers, tables, columns, enum keys) is in English. Specs, UI texts, docs and commit messages are in Finnish.
Current state: only the project skeleton exists (the config/ package, MariaDB settings, .env). Nothing under apps/ has been built yet, and the frontend build (package.json), pytest, ruff, mypy and import-linter are not set up. docs/architecture.md describes the target design. Follow it when you add code, and set up each tool the first time it is needed.
Source of truth
docs/maarittely.mdis the specification: roles and the permission matrix, data model (section 14), phases (sections 15–19) and open questions. References like (K12) point to question numbers indocs/määrittely.txt, which holds the original Q&A and is kept only as history. When requirements change, updatemaarittely.md.docs/architecture.mdholds the architecture rules, the testing strategy, the UI and accessibility rules, and the Laravel → Django mapping. The spec and architecture were ported from an earlier Laravel/Livewire project, so translate any Laravel idiom you find instead of copying it.
Commands (PowerShell, from the repo root)
.venv\Scripts\python manage.py runserver # dev server http://127.0.0.1:8000 (start MySQL in XAMPP Control Panel first)
.venv\Scripts\python manage.py check
.venv\Scripts\python manage.py makemigrations <app>
.venv\Scripts\python manage.py migrate
.venv\Scripts\python -m pip install -r requirements.txt
Planned tooling, per docs/architecture.md (not set up yet):
.venv\Scripts\pytest apps # all tests
.venv\Scripts\pytest apps/customers/tests/domain/test_x.py::test_name # single test
.venv\Scripts\pytest apps -m "not django_db" # fast tests that don't touch the DB
.venv\Scripts\lint-imports # layer/module dependency rules
.venv\Scripts\mypy apps
.venv\Scripts\ruff check . ; .venv\Scripts\ruff format .
npm run dev / npm run build # Tailwind + daisyUI -> static/dist/app.css
Configuration
config/settings.pyreads.envvia python-dotenv. Variables:DJANGO_SECRET_KEY(required),DJANGO_DEBUG,DJANGO_ALLOWED_HOSTS,DB_NAME(defaultdjango-toiminnanohjaus),DB_USER,DB_PASSWORD,DB_HOST,DB_PORT..envis gitignored;.env.exampleis the template.- The database engine is
django.db.backends.mysql(mysqlclient), with utf8mb4 andSTRICT_TRANS_TABLES. The database name contains a hyphen, so backtick-quote it in raw SQL. - Settings use
LANGUAGE_CODE = "fi"andTIME_ZONE = "Europe/Helsinki". Templates go intemplates/plus app templates, static files instatic/, andSTATIC_ROOTisstaticfiles/. - The custom user model
users.User(AUTH_USER_MODEL) does not exist yet. The database was already migrated with Django's defaultauth.User. Before creating the users app, drop and recreate the (still empty) database, then rerun migrations.
Architecture (target, see docs/architecture.md)
The project is a modular monolith. Each business area is a Django app under apps/<module>/ (planned: shared, users, customers, jobs, tasks, time_tracking, expenses, catalog, sales, billing, later inventory, machines). Each app has Clean Architecture layers:
domain/holds pure Python with nodjangoimports: dataclass entities (register()/reconstitute()), frozen value objects that validate themselves,StrEnumenums,DomainErrorsubclasses carrying a code, events, and repositoryProtocols.application/holds use cases (one class, oneexecute(), with dependencies injected through the constructor), frozen dataclass DTOs and queryProtocols. Query protocols are the module's public read API. This layer has nodjangoimports.infrastructure/holds the Django models (named…Model, inorm.pyand re-exported from the app'smodels.py; setMeta.db_tableto the table names in spec section 14), the repository implementations and the query implementations, which return DTOs straight from the ORM.presentation/holds thin views, Django Forms and templates. Forms validate input shape and build DTOs. Domain errors are turned into field errors withform.add_error(). HTMX requests get partial templates.container.pyis the composition root, with factory functions that wire the use cases. There is no DI framework.
Cross-cutting rules:
- Cross-module access: modules never touch another module's ORM models, infrastructure or presentation. They read through the other module's application query interface and react to its domain events. Foreign keys to another module's table are allowed, but queries across that relation are not.
- Shared role enum:
users.domain.enums.Roleis the one shared domain type that every module may use. - Transactions: the use case is the transaction boundary (
UnitOfWorkwrapstransaction.atomic;ATOMIC_REQUESTSis not used). Events are published withtransaction.on_commitand subscribed inAppConfig.ready(). Django signals are not used for domain events. - Background work: django-q2 runs background jobs. Scheduled jobs are management commands.
- Data conventions: money is stored as integer cents (
*_cents), VAT as basis points, hours asDecimal(6,2). Quantities in the inventory phase are stored as integer thousandths (*_milli).
UI and accessibility
WCAG 2.2 AA / EN 301 549 is the contract's acceptance criterion for the whole UI.
- Colour: colour never carries information alone. Priority, status and "late" are always also shown as text and an icon.
- Interaction and focus: everything must work from the keyboard, and drag and drop always has a button alternative.
- After an HTMX swap, move focus deliberately and announce the change in an
aria-live/role="status"region. - Dialogs use
<dialog>(the daisyUI modal).
- After an HTMX swap, move focus deliberately and announce the change in an
- Layout: no horizontal page scrolling from 320 px up to FullHD. The machine console needs touch targets of at least 44 × 44 px.
- Implementation: use daisyUI classes, with shared partials in
apps/shared/presentation/templates/components/. Alpine.js is for local UI state only, never for business logic. - Assets: no CDN in production; build the assets with npm.
- Texts: all UI text goes through
gettext/{% translate %}.