Codebase Structure - xopherdeep/do-it-for-the-xp GitHub Wiki

Codebase Structure

This document outlines the structure of the "Do It for the XP" codebase, highlighting key directories, files, and their purposes to help developers navigate and understand the project organization.

Project Overview

"Do It for the XP" is a gamified task management application built with Vue.js and Ionic, with support for deployment on the web, Android, and iOS platforms. The application uses a battle system metaphor to represent tasks and achievements.

Root Structure

The project is organized with the following top-level directories:

  • android/ - Android platform-specific code, build settings, and native configurations
  • ios/ - iOS platform-specific code, build settings, and native configurations
  • resources/ - App icons and splash screens for mobile platforms
  • src/ - Main application source code
  • tests/ - Unit and end-to-end tests

Core Configuration Files

  • babel.config.json - Babel configuration for JavaScript transpilation
  • battleroom.config.js - Configuration for the battleroom development environment
  • capacitor.config.json - Capacitor configuration for native platform builds
  • craco.config.js - Create React App Configuration Override for custom settings
  • cypress.json - Cypress end-to-end testing configuration
  • ionic.config.json - Ionic framework configuration
  • jest.config.json - Jest unit testing configuration
  • package.json - NPM dependencies and scripts
  • tailwind.config.js - Tailwind CSS configuration
  • tsconfig.json - TypeScript compiler configuration
  • vue.config.js - Vue.js configuration with environment-specific settings

Source Code Structure (src/)

Entry Points

  • main.ts - Application entry point
  • app.config.ts - Core application configuration
  • manifest.webmanifest - Web application manifest
  • shims-vue.d.ts - TypeScript type definitions for Vue

Main Directories

assets/

Contains static assets used throughout the application:

  • audio/ - Sound effects and music files
  • fonts/ - Font files including Font Awesome
  • fx/ - Special effects assets
  • icons/ - App and UI icons
  • images/ - Image files used throughout the app

components/

Reusable Vue components organized by feature:

  • AudioSettings/ - Audio configuration UI components
  • AvatarSelect/ - Avatar selection and customization
  • CardUserStats/ - User statistics card components
  • WeatherFX/ - Weather effects visualization
  • XpAbility/ - Ability display and management components
  • XpBackgroundSelector/ - Background selection components
  • XpCardMenu/ - Card-based menu components
  • XpDialog/ - Dialog and modal components
  • XpGp/ - Gold Points related components
  • XpIcon/ - Icon wrapper components
  • XpIntroSplash/ - Introduction and splash screens
  • XpLoading/ - Loading indicators
  • XpStatBox/ - Statistics display components
  • XpSwiperGallery/ - Image gallery components
  • XpTypingText/ - Typewriter-style text animation components

constants/

Application-wide constant values and enumerations.

hooks/

Custom Vue composition API hooks.

lib/

Core application libraries and services:

  • api/ - API client interfaces and implementations
  • databases/ - Database access and management
  • engine/ - Game engine components
  • services/ - Business logic services
    • battle/ - Battle system services
      • BattleService.ts - Manages battle interactions
      • BestiaryService.ts - Manages beast/monster data
    • gp/ - Gold Points service
  • store/ - Vuex store and state management
  • types/ - TypeScript type definitions
  • utils/ - Utility functions

mixins/

Vue component mixins for sharing functionality.

router/

Vue Router configuration and route definitions.

styles/

Global styles and theming:

  • icons/ - Icon-specific styles
  • mixins/ - SCSS mixins
  • themes/ - Theme definitions

views/

Page components for application views:

  • App/ - Core application views
  • Console/ - Console/admin views
  • Dev/ - Development and debugging tools

Mobile Platform Code

Android (android/)

Android-specific configuration:

  • app/ - Android application code
    • build.gradle - Android build configuration
    • proguard-rules.pro - Code optimization rules
    • src/ - Android-specific source code

iOS (ios/)

iOS-specific configuration:

  • App/ - iOS application code
    • Podfile - CocoaPods dependencies

Development Environments

The codebase includes specialized configurations for different development environments:

  • Regular development mode
  • Battleroom development mode (enabled via BATTLEROOM_DEV environment variable)

Key Services

Battle System

The battle system is a core feature, representing tasks and achievements as "battles" with enemies:

  • BattleService - Manages battle state and gameplay mechanics
  • BestiaryService - Manages monster/beast data and interactions

Databases

The application uses local storage databases:

  • BestiaryDb - Manages beast data storage
  • Other specialized database services for different data types

Potential Improvements

After analyzing the current codebase structure, here are some ideas for potential improvements:

1. Service Organization

Current Structure:

  • Services are organized by domain (battle, gp) with multiple services per domain.

Improvement Ideas:

  • Consider adopting a more consistent service naming convention
  • Group related services into feature modules
  • Implement a service registry pattern for easier dependency injection and testing
  • Add better service documentation with JSDoc comments

2. State Management

Current Structure:

  • Using Vuex store for state management

Improvement Ideas:

  • Consider breaking down the store into namespaced modules if not already done
  • Implement stronger typing for store state
  • Add state persistence layer for offline capability
  • Consider using Pinia for newer Vue projects as it offers better TypeScript support

3. Component Organization

Current Structure:

  • Components are organized by feature with prefix naming (XpComponent)

Improvement Ideas:

  • Adopt a more hierarchical component structure:
    • atoms/ - Basic building blocks (buttons, inputs)
    • molecules/ - Combinations of atoms (form fields with labels)
    • organisms/ - Complex UI sections composed of molecules
    • templates/ - Page layouts
  • Create a component documentation system or storybook
  • Implement stricter prop typing and validation

4. Testing Structure

Improvement Ideas:

  • Organize tests to mirror the source structure for easier navigation
  • Implement integration tests for key user flows
  • Add more comprehensive unit tests for services
  • Set up visual regression testing for UI components

5. Mobile Platform Integration

Improvement Ideas:

  • Create clearer separation between platform-specific code
  • Implement feature flags for platform-specific features
  • Better organize Capacitor plugins and native integrations
  • Document platform-specific build processes

6. Documentation

Improvement Ideas:

  • Add inline documentation for key classes and functions
  • Create architecture decision records (ADRs) for major design choices
  • Document data flow between components and services
  • Create diagrams for complex workflows

7. Build System

Improvement Ideas:

  • Review and optimize build configurations
  • Set up separate development, staging, and production environments
  • Implement better environment variable management
  • Review bundle size optimization strategies

8. Code Quality Tools

Improvement Ideas:

  • Implement more strict ESLint rules
  • Add Prettier for consistent code formatting
  • Set up pre-commit hooks for code quality checks
  • Consider adding type coverage reporting

Next Steps

  1. Prioritize these improvements based on current pain points
  2. Create a roadmap for implementing the selected improvements
  3. Start with high-impact, low-effort changes first
  4. Document the rationale for structural changes
  5. Ensure changes are backward compatible where possible