Problem
Understanding in practice how a web application is organized in layers: routes, controllers, models and views, with user sessions and database persistence.
technical case study
Web App • Social network / MVC study
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.
App entry with email and password login and access to new user sign-up.
Logged-in user's timeline: posting tweets and a list with author and date, coming from a database JOIN (demo data).
Search for people by name; the follow and unfollow buttons are already in the interface, without the back-end logic yet.
Understanding in practice how a web application is organized in layers: routes, controllers, models and views, with user sessions and database persistence.
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.
Sign-up with validation, session login, posting and listing tweets and searching users by name all working end to end.
Study project preserved as delivered: follow, unfollow, deleting tweets and profile counters stayed in the interface only.
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.
.phtml views rendered inside a shared layout, with Bootstrap 4 and Font Awesome: login, sign-up, timeline and user search.
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.
MySQL with users and tweets tables; the timeline joins both to show each tweet's author and formatted date.
Every query uses PDO's prepare and bindValue, including the name search with LIKE.
Timeline, posting and search check the session and redirect to login when no user is authenticated.
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.
Folder structure, PSR-4 autoloading with Composer and a custom router mapping URLs to controllers.
Field validation, checking for already registered emails and session authentication.
Posting tweets and listing them with the author's name and a formatted date.
Search by name with LIKE and a list of results.
Follow and unfollow, deleting tweets and real profile counters were left for later and never picked up again.
$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'
);
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');
}
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);
}
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.
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.