Architecture
Context
A C# desktop application for library staff: books, DVDs, magazines, orders, subscriptions. It never touches the database directly. Everything goes through a PHP REST API hosted on my VPS.
What was there
The starting WinForms application is half-built. You can search and browse books, DVDs and magazines, and record the arrival of a magazine issue. No login, no orders, and a starter REST API that can only handle a few reads.
The request
Extend the tool for library staff: book and DVD orders with step-by-step tracking, magazine subscriptions, an alert before they expire, and different access depending on the department of the logged-in user. All of it as a real client-server setup, with the API deployed on a server.
What I built
-
Login by department
On login, the application fetches the user's department and adapts what they see. One department has no access at all, another loses some tabs, and the subscription alert only shows up for the departments concerned.
-
Orders and tracking
A book or DVD order moves forward in steps. Business rules are checked before anything is sent: no going back, no paying for an order that hasn't been delivered, no more changes once it has been paid.
-
Subscriptions and deadlines
On startup, a window lists the subscriptions ending within 30 days. Sorting and date calculations are done by MySQL, not by the client.
-
Completed REST API
New PHP routes for users, tracking steps, orders and subscriptions. Every route goes through a PDO prepared statement and answers in JSON.
-
Going to production
API installed on an OVH VPS running Ubuntu (nginx, PHP-FPM, MySQL), files uploaded with WinSCP, routes tested in Postman. The client ships with a Windows installer.
-
Quality
14 MSTest unit tests, SonarLint analysis, a client-side error log in
%AppData%, and generated technical documentation.
Code excerpts
Code copied as is from the repositories:
SELECT c.id, c.dateCommande, c.montant, a.dateFinAbonnement, a.idRevue, d.titre
FROM commande c
JOIN abonnement a ON c.id = a.id
JOIN document d ON a.idRevue = d.id
WHERE a.dateFinAbonnement BETWEEN CURDATE() AND DATE_ADD(CURDATE(), INTERVAL 30 DAY)
ORDER BY a.dateFinAbonnement ASC
id key, hence the join. All the date logic stays in the database.
if (commande.IdSuivi == 3)
{
MessageBox.Show("Cette commande est déjà réglée.");
return;
}
if (commande.IdSuivi == 2 && suivi.Id == 1)
{
MessageBox.Show("Impossible de revenir en arrière.");
return;
}
if (suivi.Id == 3 && commande.IdSuivi == 1)
{
MessageBox.Show("La commande doit être livrée avant d'être réglée.");
return;
}
In hindsight
What I would
do differently.
Reread today with a more systems and database minded eye. None of this kept the project from working, but all of it would matter in production.
-
#1
Passwords
The username and password travel in the URL of a GET request and are compared in plain text against the
utilisateurtable. A URL ends up in the server logs. Today I would send them in a POST and hash the password withpassword_hash()/password_verify(). -
#2
Order numbers
The API computes the next id with
MAX(id) + 1. Two workstations confirming at the same moment can get the same number. AnAUTO_INCREMENTkey settles it. -
#3
Two writes, no transaction
An order is saved with two
INSERTstatements (thecommandetable, thencommandedocumentorabonnement). If the second one fails, an orphan order is left behind. Both need to be wrapped in aBEGIN … COMMIT. -
#4
The .env file
It is committed to the public repository. Secrets have no place in Git: server environment variables instead, and a
.env.examplein the repository.
Stack
Client
C#
.NET Framework 4.7.2
WinForms
Newtonsoft.Json
MSTest
SonarLint
API
PHP 8.4
PDO
Composer
phpDocumentor
Data
MySQL
MySQL Workbench
Infra
OVH VPS
Ubuntu
nginx
PHP-FPM
Tools
Visual Studio 2022
Postman
WinSCP
Git
Documents
- Project description sheet
- Activity report
- MSTest results
- Specifications
BTS SIO framework
The framework competencies this project puts to work.
B1IT service support and delivery
B1.2Handle incidents and requests for support and changesB1.4Work in project modeB1.5Make an IT service available to users
B2Application design and development (SLAM)
B2.1.1Model an application solutionB2.1.3Develop an application solutionB2.1.4Design and build a user interfaceB2.2.1Gather, analyse and update information about an application solutionB2.2.4Update technical and user documentationB2.2.5Design and run tests for the updated componentsB2.3.1Design or adapt a databaseB2.3.2Carry out operations on a database