Skip to content

Repository files navigation

grumpy_context

grumpy_context analyzes a Dart or Flutter project and returns typed context data that bricks and custom lints can consume.

What it returns

  • Project name from pubspec.yaml
  • Direct dependency declarations grouped by scope
  • Discovered modules and their layer inventories
  • Diagnostics for missing, partial, or ambiguous structure
  • The resolved discovery config that was applied

Usage

import 'package:grumpy_context/grumpy_context.dart';

Future<void> main() async {
  final context = await analyzeProject('/path/to/project');

  print(context.name);
  print(context.modules.map((module) => module.name).toList());
}

grumpy.yaml

The analyzer looks for an optional root-level grumpy.yaml. If it is missing, built-in defaults are used.

# yaml-language-server: $schema=https://raw.githubusercontent.com/necodeIT/grumpy_context/refs/heads/main/grumpy.schema.json
module_roots:
  - lib
  - lib/src

barrel_file_patterns:
  - "{folder}.dart"
  - "*.exports.dart"

layers:
  utils:
    - utils
  domain:
    models:
      - domain/models
    services:
      - domain/services
    datasources:
      - domain/datasources
  infra:
    services:
      - infra/services
    datasources:
      - infra/datasources
  presentation:
    components:
      - presentation/components
    screens:
      - presentation/screens
    repos:
      - presentation/repos
    middleware:
      - presentation/middleware
      - presentation/guards

defaults:
  all:
    imports:
      - import 'package:collection/collection.dart';
  model:
    fields: {}
  query_component:
    mixins:
      - StatefulQueryLoader
      - StatefulQueryError
    query_result_type: auto

discovery:
  prefer_project_types: true
  infer_config_type: true
  infer_query_component_repo: true
  infer_query_component_result_type: true
  infer_repository_query_item_type: true
  prefer_existing_directories: true

The output schema is fixed. grumpy.yaml changes both project discovery and generation-oriented defaults consumed by context-aware tools.

Every supported config field is documented directly in grumpy.schema.json via property-level descriptions. Use the schema as the canonical field reference for editor hover text and validation.

Barrel files are hidden from bucket inventories by default. Patterns are matched against the file basename only, and {folder} expands to the immediate parent folder name. If filtering removes every file in a bucket, the bucket still exists and its directoryPath is preserved while files becomes empty.

Logging

The package emits structured logs through package:logging using logger names under grumpy_context.*, for example:

  • grumpy_context.analyzer
  • grumpy_context.config
  • grumpy_context.pubspec
  • grumpy_context.scanner
  • grumpy_context.diagnostics

No log handlers are installed by default.

Schema

A JSON schema for grumpy.yaml is provided at grumpy.schema.json. All top-level fields, nested default fields, discovery flags, and model field properties are described there.

About

Context provider for grumpy projects

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages