DIRECTORY_STRUCTURE - nself-org/cli GitHub Wiki

nself Directory Structure Guide

Overview

This document outlines the directory structure for nself v0.3.9, designed for maintainability, modularity, and clear separation of concerns.

Root Directory Structure

nself/
โ”œโ”€โ”€ README.md                    # Project overview and quick start
โ”œโ”€โ”€ CHANGELOG.md                 # Version history and release notes
โ”œโ”€โ”€ LICENSE                      # MIT License
โ”œโ”€โ”€ install.sh                   # Installation script for system-wide setup
โ”œโ”€โ”€ .gitignore                   # Git ignore patterns
โ”œโ”€โ”€ bin/                         # Executable entry points
โ”œโ”€โ”€ src/                         # Source code and implementation
โ””โ”€โ”€ docs/                        # Documentation and guides

Source Code Organization (src/)

Core Structure

src/
โ”œโ”€โ”€ VERSION                      # Current version (v0.3.9)
โ”œโ”€โ”€ cli/                         # Command-line interface implementations
โ”œโ”€โ”€ lib/                         # Shared libraries and utilities
โ”œโ”€โ”€ services/                    # Service management modules
โ”œโ”€โ”€ templates/                   # Configuration and Docker templates
โ””โ”€โ”€ tools/                       # Development and maintenance tools

CLI Commands (src/cli/)

All command implementations following consistent patterns:

cli/
โ”œโ”€โ”€ nself.sh                     # Main CLI dispatcher and router
โ”œโ”€โ”€ help.sh                      # Help system and documentation
โ”œโ”€โ”€ init.sh                      # Project initialization
โ”œโ”€โ”€ build.sh                     # Infrastructure generation
โ”œโ”€โ”€ start.sh                     # Service startup management
โ”œโ”€โ”€ stop.sh                      # Service shutdown management
โ”œโ”€โ”€ restart.sh                   # Service restart management
โ”œโ”€โ”€ status.sh                    # Service status monitoring
โ”œโ”€โ”€ logs.sh                      # Log viewing and management
โ”œโ”€โ”€ doctor.sh                    # System diagnostics
โ”œโ”€โ”€ backup.sh                    # Backup and restore operations
โ”œโ”€โ”€ db.sh                        # Database operations
โ”œโ”€โ”€ email.sh                     # Email service configuration
โ”œโ”€โ”€ ssl.sh                       # SSL certificate management
โ”œโ”€โ”€ urls.sh                      # Service URL display
โ”œโ”€โ”€ prod.sh                      # Production configuration
โ”œโ”€โ”€ trust.sh                     # SSL certificate installation
โ”œโ”€โ”€ validate.sh                  # Configuration validation
โ”œโ”€โ”€ exec.sh                      # Container command execution
โ”œโ”€โ”€ scale.sh                     # Resource scaling management
โ”œโ”€โ”€ metrics.sh                   # Metrics and monitoring
โ”œโ”€โ”€ clean.sh                     # Docker cleanup operations
โ”œโ”€โ”€ diff.sh                      # Configuration difference analysis
โ”œโ”€โ”€ reset.sh                     # Project reset operations
โ”œโ”€โ”€ rollback.sh                  # Version rollback management
โ”œโ”€โ”€ monitor.sh                   # Real-time monitoring
โ”œโ”€โ”€ scaffold.sh                  # Service scaffolding
โ”œโ”€โ”€ update.sh                    # nself version updates
โ”œโ”€โ”€ version.sh                   # Version information
โ”œโ”€โ”€ admin.sh                     # Admin UI management (v0.3.9)
โ”œโ”€โ”€ search.sh                    # Search service management (v0.3.9)
โ”œโ”€โ”€ deploy.sh                    # VPS deployment (v0.3.9)
โ””โ”€โ”€ wizard/                      # Interactive setup wizard (v0.3.9)
    โ”œโ”€โ”€ init-wizard.sh           # Main wizard controller
    โ”œโ”€โ”€ detection.sh             # Project framework detection
    โ”œโ”€โ”€ prompts.sh               # Interactive UI components
    โ””โ”€โ”€ templates.sh             # Project template definitions

Shared Libraries (src/lib/)

Reusable functionality organized by purpose:

lib/
โ”œโ”€โ”€ utils/                       # Common utilities
โ”‚   โ”œโ”€โ”€ display.sh               # Output formatting and colors
โ”‚   โ”œโ”€โ”€ env.sh                   # Environment file handling
โ”‚   โ”œโ”€โ”€ docker.sh                # Docker operations
โ”‚   โ”œโ”€โ”€ network.sh               # Network utilities
โ”‚   โ””โ”€โ”€ validation.sh            # Input validation helpers
โ”œโ”€โ”€ config/                      # Configuration management
โ”‚   โ”œโ”€โ”€ constants.sh             # System constants
โ”‚   โ”œโ”€โ”€ smart-defaults.sh        # Intelligent default values
โ”‚   โ””โ”€โ”€ validation.sh            # Configuration validation
โ”œโ”€โ”€ hooks/                       # Command lifecycle hooks
โ”‚   โ”œโ”€โ”€ pre-command.sh           # Pre-execution hooks
โ”‚   โ””โ”€โ”€ post-command.sh          # Post-execution hooks
โ”œโ”€โ”€ ssl/                         # SSL certificate management
โ”‚   โ”œโ”€โ”€ auto-ssl.sh              # Automatic SSL generation
โ”‚   โ””โ”€โ”€ auto-renew.sh            # Certificate renewal
โ”œโ”€โ”€ monitoring/                  # System monitoring
โ”‚   โ”œโ”€โ”€ health.sh                # Health check utilities
โ”‚   โ”œโ”€โ”€ metrics.sh               # Metrics collection
โ”‚   โ””โ”€โ”€ alerts.sh                # Alert management
โ”œโ”€โ”€ backup/                      # Backup operations
โ”‚   โ”œโ”€โ”€ core.sh                  # Core backup functionality
โ”‚   โ””โ”€โ”€ s3.sh                    # S3 integration
โ”œโ”€โ”€ deployment/                  # Deployment utilities
โ”‚   โ”œโ”€โ”€ ssh.sh                   # SSH deployment helpers
โ”‚   โ””โ”€โ”€ validation.sh            # Deployment validation
โ””โ”€โ”€ wizard/                      # Wizard system (v0.3.9)
    โ””โ”€โ”€ environment-manager.sh   # Multi-environment management

Service Management (src/services/)

Service-specific logic and configurations:

services/
โ”œโ”€โ”€ postgres/                    # PostgreSQL management
โ”œโ”€โ”€ redis/                       # Redis configuration
โ”œโ”€โ”€ minio/                       # MinIO object storage
โ”œโ”€โ”€ hasura/                      # Hasura GraphQL engine
โ”œโ”€โ”€ auth/                        # Authentication service
โ”œโ”€โ”€ nginx/                       # Nginx reverse proxy
โ”œโ”€โ”€ docker/                      # Docker Compose generation
โ””โ”€โ”€ monitoring/                  # Monitoring stack

Templates (src/templates/)

Configuration templates and examples:

templates/
โ”œโ”€โ”€ .env.example                 # Complete environment reference
โ”œโ”€โ”€ docker-compose/              # Docker Compose templates
โ”œโ”€โ”€ nginx/                       # Nginx configuration templates
โ”œโ”€โ”€ ssl/                         # SSL certificate templates
โ””โ”€โ”€ certs/                       # Pre-generated certificates
    โ”œโ”€โ”€ localhost/               # Local development certificates
    โ””โ”€โ”€ nself-org/               # nself.org domain certificates

Documentation (docs/)

Comprehensive documentation for users and developers:

docs/
โ”œโ”€โ”€ COMMANDS.md                  # Complete command reference
โ”œโ”€โ”€ v0.3.9.md                    # v0.3.9 release notes
โ”œโ”€โ”€ ARCHITECTURE.MD              # System architecture overview
โ”œโ”€โ”€ ENVIRONMENT_CONFIGURATION.MD # Environment setup guide
โ”œโ”€โ”€ TROUBLESHOOTING.MD           # Common issues and solutions
โ”œโ”€โ”€ API.MD                       # API documentation
โ”œโ”€โ”€ CHANGELOG.MD                 # Version history
โ”œโ”€โ”€ ROADMAP.md                   # Future development plans
โ”œโ”€โ”€ CONTRIBUTING.MD              # Contribution guidelines
โ”œโ”€โ”€ RELEASES.MD                  # Release information
โ”œโ”€โ”€ EXAMPLES.MD                  # Usage examples
โ””โ”€โ”€ README.MD                    # Getting started guide

Executable Entry Points (bin/)

Simple wrappers for system-wide installation:

bin/
โ”œโ”€โ”€ nself                        # Main nself command wrapper
โ”œโ”€โ”€ urls                         # Direct URL display
โ””โ”€โ”€ [other-commands]             # Additional command aliases

Design Principles

Modularity

  • Each command is self-contained in its own file
  • Shared functionality is centralized in lib/
  • Clear separation between CLI, logic, and templates

Consistency

  • All commands follow the same structure and patterns
  • Consistent naming conventions throughout
  • Standardized help and error handling

Extensibility

  • New commands can be added easily in src/cli/
  • Service modules are pluggable and independent
  • Template system supports customization

Maintainability

  • Clear file organization by functionality
  • Documented interfaces between modules
  • Comprehensive testing structure

Backward Compatibility

  • Existing command structure preserved
  • New v0.3.9 features are additive
  • Legacy functionality remains unchanged

File Naming Conventions

  • Commands: command-name.sh (kebab-case with .sh extension)
  • Libraries: module-name.sh (descriptive, organized by directory)
  • Templates: template-name.ext (matches target file extension)
  • Documentation: TOPIC.MD (uppercase .MD for main docs, lowercase .md for version-specific)

Execution Flow

  1. Entry Point: bin/nself โ†’ src/cli/nself.sh
  2. Command Routing: nself.sh identifies and sources appropriate command file
  3. Library Loading: Commands source required libraries from src/lib/
  4. Template Processing: Commands use templates from src/templates/
  5. Service Integration: Commands interact with services via src/services/

This structure supports nself's evolution from a simple CLI tool to a comprehensive backend platform while maintaining clarity and ease of development.

โš ๏ธ **GitHub.com Fallback** โš ๏ธ