πŸ† Final Project: Wiki Explorer Pro

⏱ 2-3 hours πŸ“Š Advanced 🎯 Capstone

Build a Complete Wikipedia CLI Application

This capstone project combines every concept from the course into a single, production‑ready command‑line tool. You'll create a multi‑package workspace with a polished CLI, robust error handling, structured logging, and unit tests.

🎯 Project Overview

Create a CLI tool called Wiki Explorer Pro that allows users to:

  • Search Wikipedia articles and display results with URLs
  • Get a summary of any article by title
  • View article extracts in plain text or HTML
  • Compare two articles side‑by‑side
  • Export search results or summaries to a JSON file
  • Log all requests and errors to daily log files
  • Run in interactive mode with a menu, or accept direct commands
πŸ—οΈ Architecture Requirements

Your project must use a multi‑package workspace with at least three packages:

  1. command_runner – A reusable CLI framework (commands, arguments, help)
  2. wikipedia – API client with model classes and JSON parsing
  3. cli – The main application entry point and concrete commands

Each package should have its own pubspec.yaml and be linked via a root workspace.

πŸ“‹ Detailed Requirements

1. Command Runner Package

  • Abstract Command class with name, description, run()
  • Support for flags and options (e.g., --verbose, --output)
  • Built‑in HelpCommand that displays usage for all commands
  • Custom ArgumentException for invalid user input
  • CommandRunner class that parses input and dispatches commands

2. Wikipedia Package

  • Model classes: SearchResult, ArticleSummary, Article
  • Use pattern matching in fromJson() factories
  • Methods: search(), getSummary(), getArticle()
  • Simulated API calls with realistic delays (use Future.delayed)
  • Throw custom exceptions (ArticleNotFoundException, ApiException)

3. CLI Application

  • Commands: search, summary, compare, export
  • Interactive mode when no arguments given (menu loop)
  • Accept command‑line arguments for direct execution
  • Logging: create a logger that writes to logs/YYYY_MM_DD_wiki.log
  • Log all searches, errors, and API response times
  • Graceful error handling with user‑friendly messages

4. Testing

  • Unit tests for Wikipedia model classes (valid JSON, invalid JSON, missing fields)
  • Tests for CommandRunner argument parsing
  • At least 10 test cases total

πŸ“Ί Expected Behavior

Terminal (Direct Mode)
$ dart run bin/cli.dart search Dart programming
πŸ” Searching for "Dart programming"...
1. Dart (programming language) - https://en.wikipedia.org/wiki/Dart_(programming_language)
2. Dartmoor - https://en.wikipedia.org/wiki/Dartmoor
3. Dartford - https://en.wikipedia.org/wiki/Dartford
βœ… Search completed in 1.2s

$ dart run bin/cli.dart summary Dart
πŸ“– Dart (programming language)
──────────────────────────────────────
Dart is a programming language designed by Lars Bak and Kasper Lund and developed by Google. It can be used to develop web and mobile apps as well as server and desktop applications.
──────────────────────────────────────
πŸ”— https://en.wikipedia.org/wiki/Dart_(programming_language)

$ dart run bin/cli.dart compare Dart Flutter
πŸ“Š Comparing Articles
──────────────────────────────────────
Dart                | Flutter
──────────────────────────────────────
Programming language | UI toolkit
Developed by Google  | Developed by Google
First appeared 2011  | First appeared 2017
──────────────────────────────────────
πŸ¦‹

✨ Ready for the next level?

You've mastered Dart and CLI apps β€” now build cross-platform UIs with Flutter!

πŸ”’ Click to reveal the complete solution (build it yourself first!)
name: _ publish_to: none environment: sdk: ^3.12.0 workspace: - cli - command_runner - wikipedia name: command_runner description: A reusable CLI command framework. version: 1.0.0 resolution: workspace environment: sdk: ^3.12.0 library command_runner; export 'src/command.dart'; export 'src/command_runner_base.dart'; export 'src/exceptions.dart'; abstract class Command { final String name; final String description; final List

πŸ§ͺ Testing Requirements

Create at least these tests in the wikipedia/test folder:

Dart (test/models_test.dart)
import 'package:test/test.dart';
import 'package:wikipedia/wikipedia.dart';

void main() {
  group('SearchResult', () {
    test('fromJson parses correctly', () {
      final json = {'title': 'Dart', 'url': 'https://en.wikipedia.org/wiki/Dart'};
      final result = SearchResult.fromJson(json);
      expect(result.title, equals('Dart'));
      expect(result.url, contains('wikipedia.org'));
    });
  });

  group('ArticleSummary', () {
    test('fromJson with all fields', () {
      final json = {
        'title': 'Dart',
        'extract': 'Dart is a programming language',
        'description': 'Programming language',
        'content_urls': {'desktop': {'page': 'https://en.wikipedia.org/wiki/Dart'}},
      };
      final summary = ArticleSummary.fromJson(json);
      expect(summary.title, 'Dart');
      expect(summary.description, 'Programming language');
    });

    test('throws FormatException on invalid JSON', () {
      expect(() => ArticleSummary.fromJson({}), throwsFormatException);
    });
  });
}
πŸŽ‰ Congratulations!

Completing this capstone project means you can design, structure, and implement a real‑world Dart application from scratch. You've mastered packages, async programming, JSON handling, error management, logging, and testing – skills that directly transfer to Flutter and backend Dart development.