Building a PHP Framework: Part 4 - The Foundation
Tags: php, webdev
Published: 2018-05-10 01:22:41

---
title: Building a PHP Framework: Part 4 - The Foundation
published: true
description: As with every sturdy house, a framework needs a solid foundation. This post discusses said foundation for the Analyze PHP framework. Test Driven Development (TDD) is also discussed.
tags: php, webdev
cover_image: http://developmentmatt.com/wp-content/uploads/2018/05/foundation-2660502_1280.jpg
---

[Part 3](https://dev.to/mattsparks/building-a-php-framework-part-3---time-for-action-9pl) was all about action – without actually taking any or writing any code. This installment will actually see the groundwork for the Analyze framework taking shape.

## Framework Structure

Most frameworks I have experience with or have researched take approach of having a main "core" framework along with an example app. Some examples include Slim, which has it's [core framework](https://github.com/slimphp/Slim) along with a [skeleton app](https://github.com/slimphp/Slim-Skeleton). [CakePHP](https://github.com/cakephp/cakephp) does does as well. [Laravel](https://github.com/laravel/framework) doesn't call [theirs](https://github.com/laravel/laravel) an "example" or "skeleton" app, but for all intents and purposes it is.

I'll follow the path these great frameworks have laid and structure Analyze the same. Below you will find the repositories for each:

[Analyze PHP Core Framework](https://github.com/AnalyzePHP/framework)
[Analyze PHP Example/Skeleton App](https://github.com/AnalyzePHP/analyze)

For the time being I will focus on the core Analyze PHP framework. After all, without it there's no reason to have an example app.

## Directory Structure

To get started, let's take a look at where the Analyze directory structure stands as of this writing.

```
+ /src
+ /tests
+ .gitignore
+ composer.json
+ LICENSE
+ README.md
```

## /src

The `/src` directory will contain the framework. All that Analyze is and ever will be is housed here.

## /tests

As the name suggests, this directory will hold all of our tests for the framework – more on that in a second.

## .gitignore

File to keep unwanted items out of the repo. Learn more about .gitignore files [here](https://git-scm.com/docs/gitignore).

## composer.json

This file details the framework's dependencies and other info. Learn more about it [here](https://getcomposer.org/doc/04-schema.md).

## LICENSE

Text file describing the framework's license, which is MIT.

## README.md

Read me markdown file. Not much to it at the moment.

## Test Driven Development

While building Analyze I'm going to try my hand at [TDD](https://en.wikipedia.org/wiki/Test-driven_development). I've dabbled with TDD in the past, but I've never built something to this scale. I will go into much greater detail in the next post, but for more information checkout "Further Reading" below.

## Further Reading

[Introduction to Test Driven Development (TDD)](http://agiledata.org/essays/tdd.html)

[Grumpy Learning](https://grumpy-learning.com/)
When it comes to TDD and PHP, Chris Hartjes is where it's at. I recently picked up his book "Minimum Viable Tests" and can't recommend it enough. For the record, I'm not being paid to endorse Grumpy Learning. I just dig it and want to share.

[Originally Posted on DevelopmentMatt.com](http://developmentmatt.com/building-a-php-framework-part-4-the-foundation/)