2.1 KiB
2.1 KiB
TFM aInventory - Coding Standards
Status: ACTIVE | Last Updated: 2026-04-26
1. General Principles
- Language: All code, variables, and documentation MUST be in English.
- Modularity: Files should be under 300 lines. Extract logic into hooks (frontend) or services (backend).
- Simplicity: Strict Single Responsibility Principle (SRP). Complexity score < 10.
2. Backend (FastAPI / Python)
- Framework: FastAPI (Async/Await)
- Validation: Pydantic v2
- Database: SQLAlchemy 2.0 (Async) + Alembic migrations.
- Testing: Pytest. Target Coverage: 85%+.
- Naming:
snake_casefor variables/functions,PascalCasefor classes.
3. Frontend (Next.js / TypeScript)
- Framework: Next.js 15+ (App Router, Strict TypeScript).
- Styling: Tailwind CSS (refer to
DESIGN_SYSTEM.md). - State Management: React Hooks + Dexie.js (Offline IndexDB).
- Testing: Vitest for unit, Playwright for E2E. Target Coverage: 80%+.
- Naming:
camelCasefor variables/functions,PascalCasefor components.
4. Testing Strategy (MANDATORY)
- Test-First: Write and pass tests BEFORE refactoring or adding features.
- Zero Regression: 100% of existing tests must pass post-change.
- Gating:
- Backend:
pytest backend/tests/ - Frontend:
npm run test - E2E:
npx playwright test
- Backend:
5. Security & Data Integrity
- Restricted Actions: DELETE requires Admin role.
- Audit Immortality: Deleting an item MUST NOT delete its
AuditLoghistory. - Authentication: Never bypassed, even in development. PBKDF2 for local, LDAP for enterprise.
- Credentials: Use
.envor YAML config. NEVER hardcode or log secrets. - Confirmations: Destructive actions require triple confirmation or native
window.confirm.
6. Versioning & Workflow
- Git: Use
devbranch for active work. Never push tomasterdirectly. - Versioning: Run
python3 scripts/save_version.pyon every commit. - Documentation: Every feature change MUST update:
README.md,USER_GUIDE.md,ARCHITECTURE.md,DEPLOYMENT.md, andROADMAP.md.