technical case study

Web App • Social network / MVC study

TwitterClone

One of my first projects, built in 2023 while learning PHP, HTML, CSS and JavaScript: a simplified Twitter clone on top of an MVC mini-framework, with sign-up, login, timeline and user search.

PHP back-end, data modeling and interface Study 2023 study project, kept as it was built
PHP MySQL PDO MVC Bootstrap 4
executive summary

Problem

Understanding in practice how a web application is organized in layers: routes, controllers, models and views, with user sessions and database persistence.

Solution

A minimal social network on an MVC mini-framework: each URL points to a controller and an action, models talk to MySQL through PDO and views render the screens inside a shared layout.

Result

Sign-up with validation, session login, posting and listing tweets and searching users by name all working end to end.

Current stage

Study project preserved as delivered: follow, unfollow, deleting tweets and profile counters stayed in the interface only.

context

First contact with MVC, by building a social network

TwitterClone dates from 2023, when I was learning PHP, HTML, CSS and JavaScript, and has been kept as it was ever since. The app runs on a simple mini-framework (MF namespace), with its own routing, a base controller class that renders views inside a layout and a container that delivers models already connected to the database.

goals and constraints

Goals

  • Map URLs to controllers and actions with a custom router
  • Keep data access in models using PDO
  • Implement sign-up, login and logout with sessions
  • Post and list tweets per user
  • Search users by name

Constraints

  • Learning-phase project, not production-ready and unmaintained since 2023
  • Local MySQL connection configured directly in the code
  • Social features (follow, delete tweet, counters) only in the interface
  • Interface in Bootstrap 4 loaded from a CDN
solution architecture

Front-end

.phtml views rendered inside a shared layout, with Bootstrap 4 and Font Awesome: login, sign-up, timeline and user search.

Back-end

MVC mini-framework: Route.php defines the routes, each controller extends an Action class that renders the views, and the Container instantiates models with the PDO connection.

Database

MySQL with users and tweets tables; the timeline joins both to show each tweet's author and formatted date.

security and safeguards

Prepared statements

Every query uses PDO's prepare and bindValue, including the name search with LIKE.

Session-protected routes

Timeline, posting and search check the session and redirect to login when no user is authenticated.

Room for improvement

Since it's from the start of my learning, passwords use md5 and tweets are displayed without escaping. A current version would use password_hash, escape output and stop the request after every redirect.

process
01

Mini-framework

Folder structure, PSR-4 autoloading with Composer and a custom router mapping URLs to controllers.

02

Sign-up and login

Field validation, checking for already registered emails and session authentication.

03

Timeline

Posting tweets and listing them with the author's name and a formatted date.

04

User search

Search by name with LIKE and a list of results.

05

Out of scope

Follow and unfollow, deleting tweets and real profile counters were left for later and never picked up again.

behind the scenes
App/Route.php PHP lines 11–57
$routes['home'] = array(
    'route' => '/',
    'controller' => 'indexController',
    'action' => 'index'
);

$routes['inscreverse'] = array(
    'route' => '/inscreverse',
    'controller' => 'indexController',
    'action' => 'inscreverse'
);

$routes['registrar'] = array(
    'route' => '/registrar',
    'controller' => 'indexController',
    'action' => 'registrar'
);

$routes['autenticar'] = array(
    'route' => '/autenticar',
    'controller' => 'AuthController',
    'action' => 'autenticar'
);

$routes['timeline'] = array(
    'route' => '/timeline',
    'controller' => 'AppController',
    'action' => 'timeline'
);

$routes['sair'] = array(
    'route' => '/sair',
    'controller' => 'AuthController',
    'action' => 'sair'
);

$routes['tweet'] = array(
    'route' => '/tweet',
    'controller' => 'AppController',
    'action' => 'tweet'
);

$routes['quemSeguir'] = array(
    'route' => '/quemSeguir',
    'controller' => 'AppController',
    'action' => 'quemSeguir'
);
The mini-framework's route table: each URL points to a controller and an action.
App/Controllers/AppController.php PHP lines 13–63
public function timeline(){
    $this->verification();

    $tweet = Container::getModel('Tweet');

    $tweet->__set('id_usuario', $_SESSION['id']);

    $tweets = $tweet->getAll();

    $this->view->tweets = $tweets;
    $this->render('timeline');

}

public function tweet(){
    $this->verification();

    $tweet = Container::getModel('tweet');

    $tweet->__set('tweet', $_POST['tweet']);
    $tweet->__set('id_usuario', $_SESSION['id']);

    $tweet->salvar();
    header('location: /timeline');
}

public function verification(){
    session_start();
    if(!isset($_SESSION['id']) || $_SESSION['id'] == '' || !isset($_SESSION['nome']) || $_SESSION['nome'] == ''){
        header('location: /?login=erro');
    }
}

public function quemSeguir(){
    $this->verification();

    $pesquisarPor = isset($_GET['pesquisarPor']) ? $_GET['pesquisarPor'] : '';

    $usuarios = [];

    if($pesquisarPor != '' ){

        $usuario = Container::getModel('Usuario');
        $usuario->__set('nome', $pesquisarPor);
        $usuarios = $usuario->getAll();
    }

    $this->view->usuarios = $usuarios;
    $this->render('quemSeguir');

}
Actions for the logged-in area (timeline, posting and search), all going through the session check.
App/Models/Tweet.php PHP lines 35–54
public function getAll(){
    $query =  " select
                    t.id, t.id_usuario, u.nome, t.tweet, DATE_FORMAT(t.data, '%d/%m/%Y %H:%i') as data
                from
                    tweets as t
                    left join
                    usuarios as u
                    on (t.id_usuario = u.id)
                 where
                    t.id_usuario = :id_usuario
                order by
                    t.data desc";

    $stmt = $this->db->prepare($query);
    $stmt->bindValue(':id_usuario', $this->__get('id_usuario'));
    $stmt->execute();

    return $stmt->fetchAll(\PDO::FETCH_ASSOC);

}
Timeline with a JOIN between tweets and users, the date formatted in SQL and a prepared parameter.
impact

Results

A complete sign-up, login, posting and search flow running on a simple MVC architecture. Today it serves as a point of comparison with the current portfolio projects, which keep the layered structure and add services and repositories.

Learnings

Understanding the path of a request (route, controller, model, view) and the care a real project demands: strong password hashing, output escaping and form protection.