SQL and NoSQL, Side by Side
The same users kept in SQLite and in MongoDB, to show where each database enforces its rules
Overview
One small dataset, a list of users with names and emails, managed two ways from one Tkinter app: in a relational database (SQLite) and in a document database (MongoDB, which can run locally or on MongoDB Atlas in the cloud).
The interesting part is not the app. It is the question it lets you ask: where does each kind of database put its rules?
What it shows
- SQL puts rules in the schema. The
userstable declaresemail TEXT UNIQUE NOT NULL, so SQLite itself refuses a second account with the same email. - MongoDB has no schema, so rules go in indexes. A collection accepts any document. The same one-account-per-email rule needs a unique index on
email. - Configuration stays out of the code. The MongoDB connection string is read from an environment variable or a local
.envfile. - Tests without a server. The SQL code is tested against an in-memory SQLite database and the MongoDB code against
mongomock, so the tests run anywhere, including on every push.
What I found when I came back to it
- The app said “added successfully” when it hadn’t. SQLite correctly refused a duplicate email, but the app ignored the result and showed a success message anyway.
- MongoDB accepted duplicates. The two “identical” stores followed different rules without saying so.
- Adding a user failed if you hadn’t clicked “Create Table” first.
What changed
- MongoDB gets a unique index on
email, so both stores refuse the same duplicates, and the app tells you when a record is refused. - The table is created automatically when needed.
- 4 tests, including one that checks MongoDB refuses a duplicate the way SQLite does.
Brought up to date
- Both database managers are typed and checked by mypy in strict mode.
- uv installs everything from one project file and a lock file, and Ruff lints and formats the code.
- The tests, type check and lint run on Python 3.13, 3.14 and 3.15 on every push.
I made the 2026 review and fixes with Claude, an AI assistant, as a pair programmer. Each logic fix comes with a test.
The demo video on this page shows the 2023 version, before these fixes.
Run it
Needs uv, which fetches Python 3.13 or later (with Tkinter) and every dependency.
git clone https://github.com/mcneillium/CloudBasedDataManagementSystem.git
cd CloudBasedDataManagementSystem
cp .env.example .env # add your own MongoDB connection string
uv run main_gui.py # opens the app
uv run pytest # runs the tests, no database server needed
Tech stack
Python 3.13 to 3.15, SQLite, MongoDB (PyMongo), Tkinter, pytest, mongomock, mypy, Ruff, uv, GitHub Actions.