# Source Tree Analysis - TinyQC

## Project Root Structure

```
tinyqc/
├── app/                          # Application source code (MVC)
│   ├── Config/                   # Framework and app configurations
│   ├── Controllers/              # HTTP request handlers
│   │   └── Api/                  # REST API controllers
│   ├── Database/                 # Database utilities
│   │   ├── Migrations/           # Database migrations
│   │   └── Seeds/                # Database seeders
│   ├── Filters/                  # Request filters
│   ├── Helpers/                  # Helper functions
│   ├── Language/                 # Language files
│   ├── Libraries/                # Custom libraries
│   ├── Models/                   # Data models
│   ├── ThirdParty/               # Third-party code
│   ├── Views/                    # View templates
│   ├── BaseController.php        # Controller base class
│   └── Common.php                # Common functions
├── public/                       # Web root directory
│   ├── index.php                 # Application entry point
│   ├── js/                       # JavaScript files
│   ├── css/                      # CSS files (if any)
│   ├── favicon.ico               # Site icon
│   └── .htaccess                 # Apache configuration
├── tests/                        # Unit tests
├── writable/                     # Writable files (logs, cache, debugbar)
├── _bmad/                        # BMAD development artifacts
├── vendor/                       # Composer dependencies
├── composer.json                 # Composer configuration
├── env                           # Environment template
├── phpunit.xml.dist              # PHPUnit configuration
└── spark                         # CodeIgniter CLI tool
```

---

## Application Directory (app/)

### Config Directory

| File | Purpose |
|------|---------|
| `App.php` | Main application configuration |
| `Database.php` | Database connection settings (SQL Server) |
| `Routes.php` | URL routing definitions |
| `Autoload.php` | Class autoloading configuration |
| `Boot/*.php` | Environment-specific boot configs |
| `Filters.php` | Request filter configurations |
| `Services.php` | Service container configurations |
| `Session.php` | Session settings |
| `Validation.php` | Form validation rules |

**Purpose:** Contains all CodeIgniter 4 framework configurations and application-specific settings.

---

### Controllers Directory

| Controller | Purpose |
|------------|---------|
| `BaseController.php` | Base controller with common functionality |
| `Dashboard.php` | Main dashboard controller |
| `Dept.php` | Department management |
| `Test.php` | Test/parameter management |
| `Control.php` | Control standards management |
| `Entry.php` | Daily/monthly entry management |
| `Report.php` | Report generation |
| `PageController.php` | Generic page controller |

**API Controllers:**

| Controller | Purpose |
|------------|---------|
| `Api/DeptApiController.php` | Department CRUD API |
| `Api/TestApiController.php` | Test/parameter CRUD API |
| `Api/ControlApiController.php` | Control CRUD API |
| `Api/EntryApiController.php` | Entry data API |

**Purpose:** Handle HTTP requests, process business logic, and return responses.

---

### Models Directory

| Model | Purpose |
|-------|---------|
| `BaseModel.php` | Base model with camel/snake case conversion |
| `DictDeptModel.php` | Department dictionary |
| `DictTestModel.php` | Test dictionary |
| `DictControlModel.php` | Control dictionary |
| `ControlModel.php` | Control management |
| `ControlTestModel.php` | Control-test relationships |
| `DeptModel.php` | Department operations |
| `TestModel.php` | Test operations |
| `ResultModel.php` | Result management |
| `DailyResultModel.php` | Daily QC results |
| `MonthlyCommentModel.php` | Monthly comments |
| `ResultCommentModel.php` | Result comments |

**Purpose:** Handle database operations, data validation, and business logic for each domain entity.

---

### Views Directory

| Directory/File | Purpose |
|----------------|---------|
| `layout/` | Layout templates |
| `dashboard.php` | Dashboard view |
| `dept/` | Department views |
| `test/` | Test views |
| `control/` | Control views |
| `entry/` | Entry views (daily, monthly) |
| `report/` | Report views |
| `errors/` | Error page templates |

**Purpose:** Presentation layer using PHP templates with TailwindCSS and DaisyUI styling.

---

## Public Directory

| File | Purpose |
|------|---------|
| `index.php` | Application bootstrap and entry point |
| `js/app.js` | Main JavaScript application |
| `js/tables.js` | Table functionality |
| `js/charts.js` | Chart/rendering functionality |
| `.htaccess` | URL rewriting for Apache |
| `favicon.ico` | Site icon |
| `robots.txt` | Search engine rules |

**Purpose:** Web root directory served by web server.

---

## Writable Directory

Contains runtime-generated files:
- `debugbar/` - Debug toolbar data
- `logs/` - Application logs
- `cache/` - Application cache
- `session/` - Session files

---

## Entry Points

| Entry Point | Type | Description |
|-------------|------|-------------|
| `public/index.php` | Web | Main application entry point |
| `spark` | CLI | CodeIgniter 4 CLI tool |

---

## Integration Points

This is a **monolith application** - all components are contained within a single codebase. No external service integrations detected in quick scan.

---

## Critical Folders Summary

| Folder | Critical | Purpose |
|--------|----------|---------|
| `app/Config/` | Yes | All configuration |
| `app/Controllers/` | Yes | Request handling |
| `app/Models/` | Yes | Data access layer |
| `app/Views/` | Yes | UI templates |
| `public/` | Yes | Web entry point |
| `writable/` | Yes | Runtime files |
| `tests/` | No | Unit tests |
| `_bmad/` | No | Development artifacts |
| `vendor/` | No | Dependencies |
