The CS619 Gym / Fitness Management System is one of the most-often offered final year projects at Virtual University, and this guide builds it completely - in Python with tkinter and MySQL - so you can both learn and submit it. You start with the SRS: who uses the system, what it must do, and the rules (payments extend the membership, one check-in per day, and one active workout plan and one active diet plan per member). Then you design the database with an ERD, write the code module by module with line-by-line explanations, test it with 20 test cases, and finish with viva questions and answers. The complete working code is included: login with three roles, member and plan management, payments, attendance, and workout and diet plans. Follow the guide in order and you will have a working project and the understanding to defend it in the viva.
Gym / Fitness Management System — Learn + Build Guide
Course: CS619 Final Project, Virtual University of Pakistan Project: Gym / Fitness Management System (Top Project #5 — 6 gym/fitness projects in 4 semesters: GYM Buddy, Smart Gym Management System, Web based Fitness Management System, AI-Based Health & Fitness Prediction System, AI-Powered Personal Health and Fitness Coach, Online Health & Fitness Tracker; the Smart Gym Management System is rated Hard) Stack: Python 3.11+ with tkinter + MySQL, as stated in the official specification (Spring 2025 "Smart Gym Management System": PyCharm, Python 3.11+, MySQL, tkinter/PyQt, matplotlib; Fall 2016 "GYM Buddy": Visual Studio + .NET Framework + SQL Server, C#) How to use this guide: build the project in the order of this guide — SRS, then Design, then Coding, then Testing, then Viva preparation. Every section first explains the idea in plain English, then shows the work. The complete code is in the files beside this guide; the Coding section explains each module and shows the important code with line-by-line notes.
1. Project overview — what you are building
A gym keeps its records in registers and notebooks: who joined, who paid, who came today, and which trainer gave which workout plan to whom. That is slow, records get lost, and nobody knows whose membership has expired until the member is already at the door. This system replaces the registers with a desktop application.
What the system does
- The admin (gym manager) registers members, manages membership plans, records payments, and sees the dashboard: how many members, how many checked in today, how much money came in this month, and whose membership has expired.
- A trainer marks attendance, assigns workout plans and diet plans, and sees each member's plan history.
- A member logs in and sees their own plan and how many days are left, their active workout and diet plans, their payments, and their visits.
- The system itself works out the rules: a payment extends the membership, a member can check in only once a day, and a member has at most one active workout plan and one active diet plan.
Who uses it
| User | What they can do |
|---|---|
| Admin (gym manager) | Everything: members, plans, payments, attendance, workout/diet plans, dashboard |
| Trainer | Mark attendance, assign workout and diet plans, view members |
| Member | View their own plan, workout plan, diet plan, payments and attendance |
Scope — what is in, and what is not
In scope: login with three roles, member registration and management, membership plans, payment recording with receipts, attendance with check-in and check-out, workout and diet plan assignment, admin dashboard, expired-membership list, member's own page.
Out of scope (the official GYM Buddy specification mentions progress graphs and class schedules, but they are not built here): progress tracking with weight and body measurements, class timetables and booking, SMS/email reminders, and online payment. These are listed as future improvements at the end of this guide. Saying clearly what you did NOT build — and why — is something viva examiners respect.
2. What you will learn (read this before you start coding)
You do not need to know everything below in advance. Learn each item when you reach the module that uses it.
| Topic | Where you use it |
|---|---|
| Python basics: variables, if/else, loops, functions, modules | Every file |
| tkinter windows, frames, entries, buttons, Treeview tables | Every window: login, dashboard, members, ... |
| mysql-connector-python: connecting, cursors, parameterised queries | db.py — every database call |
bcrypt password hashing (hashpw / checkpw) |
Login and member registration |
| SQL: tables, primary keys, foreign keys, UNIQUE keys | schema.sql |
| SQL transactions (start, commit, rollback) | Register member, record payment, assign plan — changes that must happen together |
| SQL joins (members + users + plans + payments) | Dashboard, member list, payment history, member's own page |
Date arithmetic (timedelta, DATEDIFF) |
Membership expiry, payment extension, days left |
| Separating logic from the interface (db.py vs the windows) | The whole project — the database module is tested without any window |
Suggested order of work (about 4–6 weeks for one student)
- Week 1: install Python and MySQL, create the database, write the SRS (Section 3).
- Week 2: design the database and draw the ERD (Section 4).
- Weeks 3–4: write the code module by module (Section 5).
- Week 5: run the test cases (Section 6) and fix the bugs they find.
- Week 6: prepare the final report and practise the viva questions (Section 7).
3. SRS — Software Requirements Specification
This section is written so you can copy it into your SRS document (with your own project details) — it follows the sections VU expects in an SRS: purpose, scope, actors, functional requirements, non-functional requirements, and use cases.
3.1 Purpose
To build a desktop Gym / Fitness Management System that automates member registration, membership plans, fee payments, attendance and workout/diet plan assignment for a gym, replacing manual registers with a system that is fast, searchable and always up to date.
3.2 Scope
The system covers the daily work of a small gym: registering members, selling membership plans, collecting fees, marking who came today, assigning workout and diet plans, and reporting (dashboard counts, expired memberships, payment history). It does not cover progress tracking, class timetables, SMS/email reminders, or online payment.
3.3 Actors
- Admin (gym manager): manages the whole system. There is one admin account to start with; more admin accounts can be added directly in the database.
- Trainer: marks attendance and assigns workout and diet plans. Trainers cannot manage members, plans or payments.
- Member: a registered gym member. Members view their own plan, workout plan, diet plan, payments and attendance. Members cannot see any other member's data.
3.4 Functional requirements
| ID | Requirement |
|---|---|
| FR1 | The system shall let a user log in with a username and password. Wrong credentials shall be rejected with one general error message. |
| FR2 | The system shall show different home windows for admin/trainer (dashboard) and member (own page) after login. |
| FR3 | The admin shall register a member with name, username, email, password, phone and a membership plan. The system shall generate the membership number (GYM-0001, GYM-0002, ...). The membership shall start today and end after the plan's duration. |
| FR4 | The admin shall edit a member, including suspending a member. A suspended member shall not be able to log in or check in. |
| FR5 | The admin shall search members by membership number, name or username. |
| FR6 | The admin shall add a membership plan with name, duration in days, price and description. The plan name shall be unique. The admin shall edit a plan and deactivate it. |
| FR7 | The admin shall delete a plan only when no member is using it. A plan in use shall be deactivated instead. |
| FR8 | The admin shall record a payment with member, plan, amount and method. The amount shall be at least the plan's price. The system shall generate the receipt number (RCP-0001, RCP-0002, ...). |
| FR9 | On payment, the system shall extend the member's membership by the plan's duration: from the current end date when the membership is still valid, or from today when it has already expired. The member's plan shall change to the plan paid for. |
| FR10 | The trainer or admin shall mark a member's attendance (check-in). The system shall refuse when: the member is suspended; the membership has expired; the member already checked in today. |
| FR11 | The trainer or admin shall record a member's check-out time for today's visit. |
| FR12 | The trainer or admin shall assign a workout plan (title, goal, description, exercises, duration in weeks) to a member. A member shall have at most one active workout plan; assigning a new one shall end the old one. |
| FR13 | The trainer or admin shall assign a diet plan (title, goal, daily calories, description, meals, duration in weeks) to a member, with the same one-active-plan rule as FR12. |
| FR14 | The admin dashboard shall show: total members, active members, expired memberships, members checked in today, money collected this month, active plans, active workout plans and active diet plans, plus the list of expired memberships. |
| FR15 | A member shall see only their own data: plan and days left, active workout and diet plans, recent payments, recent attendance and total visits. |
3.5 Non-functional requirements
| ID | Requirement |
|---|---|
| NFR1 | Security: passwords shall be stored as bcrypt hashes, never as plain text. All database queries shall use parameterised queries. Windows shall check the user's role before showing admin actions. |
| NFR2 | Usability: every action shall show a success or error message. Forms shall show the plan price automatically when a plan is picked. |
| NFR3 | Correctness: a member shall never have two check-ins on the same day (enforced by the database UNIQUE key as well as the code), and a payment shall never be less than the plan price. |
| NFR4 | Performance: the member list, dashboard and attendance list shall answer in under 2 seconds with the sample data. |
| NFR5 | Portability: the system shall run on Windows (Python + MySQL/XAMPP) and on Linux (Python + MariaDB) without code changes. |
3.6 Use cases
+-----------------------------+
| Gym / Fitness Management |
| |
Admin ---------->| Login |
| | Manage Members |
| | Manage Plans |
| | Record Payments |
| | Mark Attendance |
| | Assign Workout/Diet Plans |
| | View Dashboard |
| |
Trainer -------->| Login |
| | Mark Attendance |
| | Assign Workout/Diet Plans |
| View Members |
| |
Member --------->| Login |
| View My Gym Page |
+-----------------------------+
| Use case | Actor | Main flow |
|---|---|---|
| Login | Admin, Trainer, Member | Enter username + password → system checks credentials → opens the right home window |
| Register Member | Admin | Fill the member form → system validates → member number generated, membership starts today |
| Manage Plans | Admin | Add or edit a plan → plan appears in the list and in the member/payment forms |
| Record Payment | Admin | Pick member and plan, enter amount → system checks the amount → receipt generated, membership extended |
| Mark Attendance | Admin, Trainer | Pick a member → system runs the 3 checks → check-in recorded with the time |
| Assign Workout Plan | Admin, Trainer | Fill the plan form → old active plan ends → new plan becomes active |
| Assign Diet Plan | Admin, Trainer | Same flow as workout plan, with calories and meals |
| View Dashboard | Admin, Trainer | System shows counts, money collected this month, expired memberships |
| View My Gym | Member | System shows the member's own plan, workout, diet, payments and visits |
4. Design
4.1 Architecture
Admin / Trainer / Member
|
| mouse + keyboard (tkinter windows)
v
Python application (this project)
login.py / dashboard.py / members.py / plans.py /
payments.py / attendance.py / workout_diet.py / member_view.py
|
| function calls (never SQL directly)
v
db.py — the only file that talks to MySQL
|
| mysql-connector-python (parameterised queries)
v
MySQL / MariaDB database (gym_db)
There is no framework and no web server. That is a deliberate choice
for a final-year project: every line of code is yours, you can explain
all of it in the viva, and nothing is hidden inside a library. The one
important split is between db.py (all database logic and all rules)
and the windows (only forms and tables). Because of that split, the
database logic can be tested without opening any window at all.
Request flow for every window: config.py (settings + rules) →
db.py (the function the window needs) → window shows the result.
4.2 ERD — Entity Relationship Diagram
users (1) ───< members (1) ───< payments (N) >─── (1) membership_plans
users (1) ───< attendance (N) (members 1 ───< attendance)
users (1) ───< workout_plans (N) (members 1 ───< workout_plans)
users (1) ───< diet_plans (N) (members 1 ───< diet_plans)
users (1) ───< payments (N) (recorded_by is also a user)
+----------------+ +--------------------+
| users | | members |
| id (PK) | | id (PK) |
| name | | user_id (FK, uniq) |
| username | | member_no (unique) |
| email | | gender |
| password_hash | | date_of_birth |
| role | | plan_id (FK) |
| phone, address | | membership_start |
| status | | membership_end |
+-------+--------+ | emergency_contact |
| | status |
| 1 | join_date |
| +---------+----------+
| |
+----v---------+ | 1
| attendance | |
| id (PK) | *
| member_id FK | +---------v----------+
| check_in_date| | payments |
| check_in_time| | id (PK) |
| check_out | | member_id (FK) |
| marked_by FK | | plan_id (FK) |
+--------------+ | receipt_no (unique)|
| amount, method |
+------------------+ | payment_date |
| membership_plans | | status |
| id (PK) | | recorded_by (FK) |
| name (unique) | +--------------------+
| duration_days |
| price | +------------------+
| description | | workout_plans / |
| is_active | | diet_plans |
+------------------+ | id (PK) |
| member_id (FK) |
| trainer_id (FK) |
| title, goal |
| description |
| exercises/meals |
| duration_weeks |
| start/end_date |
| status |
+------------------+
Relationships (read "1" as "one", "N" as "many"):
| Relationship | Meaning |
|---|---|
users 1 — 1 members (user_id) |
One login account belongs to one member profile; a member is a user with role member. |
members 1 — N payments (member_id) |
One member pays many times; each payment belongs to one member. |
membership_plans 1 — N payments (plan_id) |
One plan is paid for many times; each payment is for one plan. |
membership_plans 1 — N members (plan_id) |
One plan has many members; each member has one current plan. |
members 1 — N attendance (member_id) |
One member visits many days; each visit belongs to one member. |
users 1 — N attendance (marked_by) |
One trainer/admin marks many check-ins; each check-in records who marked it. |
members 1 — N workout_plans (member_id) |
One member receives many workout plans over time; each plan belongs to one member. |
members 1 — N diet_plans (member_id) |
Same as workout plans, for diet plans. |
users 1 — N workout/diet plans (trainer_id) |
One trainer assigns many plans; each plan records which trainer assigned it. |
users 1 — N payments (recorded_by) |
One admin records many payments; each payment records who took it. |
4.3 Database design, table by table
users — everyone who can log in. role is admin, trainer or
member. password_hash holds a bcrypt hash, never the password
itself. status is active or suspended; only the admin can change
it, and a suspended user cannot log in.
members — the gym profile of a member, one row per member, linked
to their login row by user_id (UNIQUE, so one login cannot have two
profiles). member_no is generated (GYM-0001, ...) and unique.
plan_id is the member's current plan. membership_start and
membership_end are the first and last day of the current paid
period. status is active or suspended and is kept in step with
the user's status. Deleting the user deletes the member row too
(ON DELETE CASCADE).
membership_plans — the plans the gym sells. duration_days is how
many days one payment covers; price is the fee in rupees for one
period. is_active lets the admin stop selling a plan without
deleting it (old members keep it). Two CHECK rules protect the
numbers: duration must be positive, price cannot be negative.
payments — one row per fee payment. receipt_no is generated
(RCP-0001, ...) and unique. amount is the rupees actually paid.
method is cash, bank transfer, card, JazzCash or EasyPaisa.
status is paid, pending or refunded. A CHECK rule says the
amount must be greater than zero; the "at least the plan price" rule
is checked in db.py, because it needs the plan's price.
attendance — one row per member per day they visit.
check_in_date + check_in_time record the arrival;
check_out_time is NULL until the member checks out. The UNIQUE key
on (member_id, check_in_date) enforces "one check-in per member
per day" in the database itself, so even two clicks at the same moment
cannot create a second row.
workout_plans — workout plans assigned by a trainer. goal is
weight loss, muscle gain, fitness, strength or endurance. exercises
is the exercise list, one exercise per line. status is active,
completed or cancelled. A member has at most one active workout
plan; assigning a new one ends the old one (see 4.5).
diet_plans — diet plans assigned by a trainer. daily_calories
is the target calories per day. meals is the meal plan, one meal per
line. Otherwise it works exactly like workout_plans.
Why "expired" is NOT a status. A tempting design is a third
member status, expired. The problem: a membership ends at midnight,
but nobody updates the database at midnight — so the stored status
would be wrong until someone runs an update. Instead this system
computes expired: a membership is expired when membership_end <
today. The answer is always correct, with no daily job. This is a
good example to quote in the viva when asked about a design decision.
4.4 UI flow (window map)
main.py
|
+-- login.py (Login window)
|
+-- admin / trainer --> dashboard.py
| |-- members.py (admin only)
| |-- plans.py (admin only)
| |-- payments.py (admin only)
| |-- attendance.py
| +-- workout_diet.py
|
+-- member -----------> member_view.py (own page)
4.5 Design decisions worth defending in the viva
- Parameterised queries everywhere. User input is never pasted into SQL. This stops SQL injection completely.
- Transactions for register, payment and plan assignment. Registering a member is two changes (user row + member row); a payment is two changes (payment row + longer membership). A transaction makes them atomic: both happen or neither does.
- UNIQUE key for one check-in per day. The rule lives in the database, not only in the code, so it holds even if two people click at the same moment.
- Computed expiry (see 4.3) — no stale data, no daily job.
- One active plan enforced by ending the old one. The old plan
keeps its history (status
completed); it is not deleted, so the member's plan history stays complete. - Database logic separated from the windows.
db.pyholds every rule and every query, so it can be tested headlessly and the windows stay short. A window that cannot reach the database can still be read and understood. - Socket fallback for the database connection. On Linux, root
often cannot log in over TCP even with an empty password, while
the local socket login works.
db.pyuses the socket file when it exists and TCP otherwise, so the same code runs on Windows (XAMPP) and Linux (MariaDB). - No framework. Every line is the student's own code and can be explained in the viva.
5. Coding — module by module
Each module is explained in plain English first, then the important code is shown with line-by-line notes. The full code is in the files beside this guide — read the module, then open its file and follow along.
5.1 Module 1 — Configuration and business rules (config.py)
What it does: holds the database settings and the gym's rules as constants, so every module uses the same numbers.
DB_HOST = 'localhost' # (1)
DB_NAME = 'gym_db'
DB_USER = 'root'
DB_PASS = '' # local default: root has no password
DB_SOCKET = '/run/mysqld/mysqld.sock' # (2)
MAX_ACTIVE_WORKOUT_PLANS = 1 # (3)
MAX_ACTIVE_DIET_PLANS = 1
CHECK_INS_PER_DAY = 1
Line by line: (1) The database settings are written once and used by
db.py. If you set a MySQL password, put it in DB_PASS. (2) On
Linux the socket file is used when it exists (see 5.2); on Windows
there is no socket file, so the TCP host above is used. (3) The gym
rules (one active workout plan, one active diet plan, one check-in per
day) are constants — changing a rule means changing one line, not
searching every file.
5.2 Module 2 — Database connection and passwords (db.py, part 1)
What it does: opens the database connection and handles password
hashing. Every other function in db.py starts by calling
get_connection().
def get_connection():
if DB_SOCKET and os.path.exists(DB_SOCKET):
return mysql.connector.connect(
unix_socket=DB_SOCKET,
database=DB_NAME, user=DB_USER, password=DB_PASS)
return mysql.connector.connect(
host=DB_HOST, database=DB_NAME,
user=DB_USER, password=DB_PASS)
os.path.exists checks whether the socket file is really there. On
this project's test machine the TCP login as root was refused (error
1698) while the socket login worked — this fallback is what makes the
same code run on both. The password helpers are short:
def hash_password(password):
return bcrypt.hashpw(password.encode('utf-8'),
bcrypt.gensalt()).decode('utf-8')
def check_password(password, password_hash):
try:
return bcrypt.checkpw(password.encode('utf-8'),
password_hash.encode('utf-8'))
except (ValueError, TypeError):
return False
bcrypt.hashpw makes a bcrypt hash with a random salt, so the same
password gives a different hash every time. checkpw compares a
typed password with a stored hash. A damaged hash returns False
instead of crashing the login — a damaged hash must never log anyone
in.
5.3 Module 3 — Login (db.verify_login, login.py)
What it does: checks a username and password, then remembers the user and opens the right home window.
cursor.execute(
'SELECT u.*, m.id AS member_id '
'FROM users u LEFT JOIN members m ON m.user_id = u.id '
'WHERE u.username = %s',
(username,))
user = cursor.fetchone()
if user is None:
return None
if user['status'] != 'active':
return None
if not check_password(password, user['password_hash']):
return None
del user['password_hash']
return user
Line by line: the %s in the query is a placeholder — the username is
sent separately, so even a username like ' OR '1'='1 cannot change
the SQL (this is the SQL-injection defence). The LEFT JOIN brings in
the member id for members, and leaves it NULL for admins and trainers.
A suspended account is rejected before the password is even checked.
The hash is deleted from the dict before it is returned, so no window
ever sees it. The error message in the window is always the same
("Invalid username or password") whether the username or the password
was wrong, so an attacker cannot learn which usernames exist.
main.py then opens the dashboard for admins and trainers, or the
member's own page for members.
5.4 Module 4 — Members (db.py member functions, members.py)
What it does: register and manage members. A member is a users
row with role = 'member' plus a members row with the gym profile.
The membership number is generated, not typed (from db.py):
cursor.execute(
"SELECT COALESCE(MAX(CAST(SUBSTRING(member_no, 5) AS UNSIGNED)), 0) "
"FROM members WHERE member_no LIKE 'GYM-%'")
highest = cursor.fetchone()[0]
return 'GYM-%04d' % (highest + 1)
It reads the highest existing number (GYM-0003 → 3), adds 1, and
pads it to 4 digits (GYM-0004). COALESCE(..., 0) handles the first
member ever, when no number exists yet.
Registering a member creates both rows in one transaction:
conn.start_transaction()
cursor.execute(
'INSERT INTO users (name, username, email, password_hash, role, ...) '
'VALUES (%s, %s, %s, %s, %s, ...)',
(name, username, email, hash_password(password), 'member', ...))
user_id = cursor.lastrowid
member_no = _next_member_no(cursor)
cursor.execute(
'INSERT INTO members (user_id, member_no, plan_id, '
' membership_start, membership_end, join_date) '
'VALUES (%s, %s, %s, %s, %s, %s)',
(user_id, member_no, plan_id, today, end_date, today))
conn.commit()
today + plan duration is the first membership end date, because
joining the gym includes the first paid period. If either INSERT
fails, the except block calls rollback() and neither row is saved
— the database can never hold a login without a member profile, or a
profile without a login.
The member list also shows "days left" per member, computed in SQL
with DATEDIFF(membership_end, CURDATE()) — negative when expired —
so the admin sees at a glance whose membership is about to end.
Delete (from db.delete_member): a member with any payment history
cannot be deleted, because payments are money records. Suspend the
member instead. A member with no payments can be deleted; deleting
their user row deletes the member row too (ON DELETE CASCADE).
5.5 Module 5 — Membership plans (db.py plan functions, plans.py)
What it does: list, add, edit and delete plans (admin only).
The checks are small but they matter: the name must not be empty, the duration must be a positive number of days, the price cannot be negative. The name is UNIQUE in the database, so adding "Monthly" twice fails with a database error instead of creating a duplicate.
Delete (from db.delete_plan): two rules. First, the window asks for
confirmation, so a plain click can never delete anything. Second, a
plan that members are using cannot be deleted — the admin must
deactivate it instead, so no new member can choose it while the old
members keep their plan.
5.6 Module 6 — Payments (db.record_payment, payments.py) — the most important module
What it does: records a fee payment and extends the membership, in one transaction.
plan = get_plan(plan_id) # (1)
if float(amount) < float(plan['price']):
raise ValueError('Amount ... is less than the ... plan price ...')
member = get_member(member_id)
if member['status'] == 'suspended':
raise ValueError('This member is suspended and cannot pay.')
today = datetime.date.today()
start = member['membership_end'] # (2)
if start is None or start < today:
start = today
new_end = start + datetime.timedelta(days=int(plan['duration_days']))
conn.start_transaction() # (3)
receipt_no = _next_receipt_no(cursor)
cursor.execute(
'INSERT INTO payments (member_id, plan_id, receipt_no, amount, '
' method, payment_date, status, recorded_by) '
'VALUES (%s, %s, %s, %s, %s, %s, %s, %s)',
(member_id, plan_id, receipt_no, float(amount), method,
today, 'paid', recorded_by))
cursor.execute(
'UPDATE members SET plan_id = %s, membership_start = %s, '
' membership_end = %s WHERE id = %s',
(plan_id, start, new_end, member_id))
conn.commit() # (4)
Line by line: (1) The amount is checked against the plan's price
before anything is saved — a short payment is refused with a clear
message instead of silently accepted. (2) The extension starts from
the current end date when the membership is still valid (paying early
does not lose days), or from today when it has already expired.
Example: a Monthly member whose membership ends on 20 November pays
on 15 November → new end is 20 December, not 15 December. (3) The
receipt number is generated like the member number (RCP-0001, ...).
(4) commit() saves both changes together. If the second failed, the
except block calls rollback() and the payment is not recorded
either — the money and the dates can never disagree.
The window helps the admin: picking a member pre-selects their current plan, picking a plan fills in its price, and a hint line shows the member's current membership end date.
5.7 Module 7 — Attendance (db.mark_attendance, attendance.py)
What it does: checks a member in for today, after three checks, and records check-out.
member = get_member(member_id)
if member['status'] == 'suspended':
raise ValueError('This member is suspended and cannot check in.')
if member['is_expired']:
raise ValueError('Membership expired on %s. Record a payment first.'
% member['membership_end'])
# ... then INSERT INTO attendance (member_id, check_in_date,
# check_in_time, marked_by) VALUES (%s, %s, %s, %s)
The three refusals each have their own message, so the trainer knows
exactly what to do: renew the membership, or re-activate the member.
The fourth rule — one check-in per day — is enforced twice: the code
does not need a check, because the UNIQUE key on (member_id,
check_in_date) makes the database refuse a second row with error
1062, which the code turns into "This member already checked in
today." Check-out is one UPDATE: set check_out_time to now where
the member checked in today and has not checked out yet.
5.8 Module 8 — Workout and diet plans (db.py plan functions, workout_diet.py)
What it does: assigns a workout or diet plan to a member, ending the previous active plan of the same kind first.
conn.start_transaction()
_end_active_plans(cursor, 'workout_plans', member_id) # (1)
cursor.execute(
'INSERT INTO workout_plans (member_id, trainer_id, title, goal, '
' description, exercises, duration_weeks, start_date, end_date) '
'VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)',
(member_id, trainer_id, title, goal, description,
exercises, int(duration_weeks), today, end_date))
conn.commit()
(1) _end_active_plans is one UPDATE: set status = 'completed'
and end_date to today for the member's active plans in that table.
Because it runs in the same transaction as the INSERT, the member can
never end up with two active plans, or with none after a failed
assign. The diet plan function is identical except for the table and
the extra daily_calories and meals fields — that is why the two
functions look alike, and that is fine. The window shows the member's
full plan history underneath the forms, so the trainer can see what
the member did before.
5.9 Module 9 — Dashboard and the member's own page (db.py, dashboard.py, member_view.py)
What it does: turns the stored rows into answers.
- Dashboard counts are single
COUNT(*)/SUM()queries — cheap and fast. "Active members" isstatus = 'active' AND membership_end >= CURDATE(); "expired" is the same count withmembership_end < CURDATE()— the computed-expiry rule again. expired_members()lists the members to follow up, ordered by expiry date, withDATEDIFF(CURDATE(), membership_end)for the days overdue.get_member_overview()collects everything for one member: profile, active workout plan, active diet plan, last 10 payments, last 10 visits, total visit count. The member window takes the member id from the login (the user dict), never from a typed value — so a member cannot view another member's page.
5.10 Module 10 — Entry point (main.py)
What it does: opens the login window; after a good login, opens the right home window and starts the tkinter main loop.
def open_home(user):
home = tk.Tk()
home.withdraw() # the home window is a Toplevel; hide the root
if user['role'] in ('admin', 'trainer'):
DashboardWindow(home, user)
else:
MemberViewWindow(home, user)
home.mainloop()
The root window is hidden because every window in this project is a
Toplevel built by gui_common.make_window() — that keeps all
windows looking the same. main.py has no database code at all: it
only decides which window to open.
6. Testing — test cases to run before submission
Run every case below against the working system and record Pass/Fail. A failed case is not a disaster — it is what testing is for; fix the bug, then run the case again. The database parts (TC-1 to TC-4 and the rule checks) were also verified headlessly during development with a 25-check smoke test; the window checks below still need a screen, so run them yourself by clicking through the system.
| ID | Test | Steps | Expected result |
|---|---|---|---|
| TC-1 | Login (admin) | Log in as admin / admin123 | Dashboard opens, admin buttons shown (Members, Plans, Payments) |
| TC-2 | Login (trainer) | Log in as trainer / trainer123 | Dashboard opens, but NO Members/Plans/Payments buttons |
| TC-3 | Login (member) | Log in as ali / member123 | My Gym page opens: plan Monthly, workout plan shown, payments shown |
| TC-4 | Wrong password | Log in as admin with a wrong password | "Invalid username or password", still on login page |
| TC-5 | Add member | Register a new member on the Monthly plan | Member number is generated (next in sequence); membership ends today + 30 days |
| TC-6 | Duplicate username | Register a member with username "ali" | Refused: username already exists |
| TC-7 | Short password | Register a member with a 3-character password | Refused: password must be at least 6 characters |
| TC-8 | Search member | Search "sara" in the Members window | Only Sara Malik is listed |
| TC-9 | Add plan | Add a plan "Student Monthly", 30 days, Rs. 2000 | Plan appears in the list and in the member/payment forms |
| TC-10 | Delete plan in use | Delete the Monthly plan | Refused: members are using it; deactivate it instead |
| TC-11 | Record payment | Pay Rs. 3000 (Monthly) for a member whose membership ends in 10 days | Receipt RCP-xxxx shown; membership end moves 30 days later (not from today) |
| TC-12 | Short payment | Pay Rs. 1000 for the Monthly plan (Rs. 3000) | Refused: amount is less than the plan price |
| TC-13 | Renew expired member | Take a member whose membership ended, pay the Monthly price | Membership restarts from today (today + 30 days) |
| TC-14 | Check-in | Check in Ali today | "Checked in at HH:MM:SS"; Ali appears in today's list |
| TC-15 | Double check-in | Check in Ali again the same day | Refused: "already checked in today" |
| TC-16 | Expired check-in | Set a member's membership_end to last week in the database, then check them in | Refused: "Membership expired on ... Record a payment first." |
| TC-17 | Check-out | Check out a member who checked in today | Check-out time appears; checking out again says they have not checked in |
| TC-18 | Assign workout plan | Assign a new workout plan to Ali (who already has one) | New plan is active; the old one is now "completed" in the history |
| TC-19 | Assign diet plan | Assign a diet plan with 0 calories | Refused: daily calories must be a positive number |
| TC-20 | Member privacy | As Ali, open the My Gym page | Only Ali's plans, payments and visits appear, never Sara's |
How to make a membership expired for TC-16: in phpMyAdmin (or the
MySQL terminal), open the members table, find the member's row, and
set membership_end to 7 days ago. Then try to check the member in
from the Attendance window.
7. Viva Q&A — questions the examiner is likely to ask
Q1. What does your project do? It runs a gym: the admin registers members, manages plans and records payments; trainers mark attendance and assign workout and diet plans; members log in to see their own plan, payments and visits. The system enforces the gym's rules itself — payments extend memberships, a member checks in once a day, and a member has one active workout and diet plan.
Q2. Which technologies did you use, and why? Python 3.11+ with tkinter and MySQL — the stack in the official project specification for the Spring 2025 "Smart Gym Management System". No framework, so all the code is mine and I can explain every line.
Q3. Show me your database design. Why seven tables?
users (login), members (gym profile), membership_plans, payments,
attendance, workout_plans, diet_plans. Seven tables because a member
is a user with a profile, a payment connects a member to a plan, a visit
connects a member to a day, and workout and diet plans are different
things with different fields (exercises vs calories and meals). The ERD
is in Section 4.2.
Q4. What is a foreign key? Give an example from your project.
A column that must match a primary key in another table.
payments.member_id must be an id from members — the database
refuses a payment for a member that does not exist.
Q5. How do you stop SQL injection?
Every query uses parameterised queries with %s placeholders.
User input is sent as data, never pasted into the SQL string, so input
like ' OR '1'='1 is treated as a plain value, not as SQL.
Q6. How are passwords stored?
With bcrypt (bcrypt.hashpw), which makes a hash with a random salt.
The plain password is never stored. Login checks with
bcrypt.checkpw.
Q7. How does a payment extend the membership?
The new end date is the current end date plus the plan's duration —
or today plus the duration when the membership has already expired.
So paying early never loses days. See db.record_payment.
Q8. Why is there no "expired" status in the database?
Because it would go stale: a membership ends at midnight, but nothing
updates the row at midnight. Instead expiry is computed —
membership_end < today — so it is always correct.
Q9. What is a transaction, and where did you use one? A group of database changes that succeed together or fail together. Recording a payment is two changes (new payment row + longer membership), so they run in one transaction; if the second failed, the first would be rolled back and the money and the dates would stay in agreement.
Q10. Two trainers check in the same member at the same moment. What happens?
The UNIQUE key on (member_id, check_in_date) lets only one row
through. The second INSERT fails with error 1062, which the code turns
into "already checked in today". Without the key, the member could
have two check-ins on the same day.
Q11. How does the system make sure a member has only one active workout plan?
Assigning a new plan first ends the old active plan (sets it to
completed with today's end date) in the same transaction as the
INSERT, so the member never has two active plans — and the old plan
stays in the history.
Q12. How does the system know who is logged in, and what they may do?
The login window checks the credentials with db.verify_login and
passes the user dict to the home window. The dashboard shows the
Members/Plans/Payments buttons only for admins; the member window
takes the member id from the login, never from a typed value.
Q13. What would you add if you had more time?
A progress tracker (weight and measurements with a matplotlib graph,
as the official specification suggests), class timetables and booking,
SMS/email reminders before a membership expires, and a printable
payment receipt. The progress tracker would need a progress table
(member, date, weight, chest, waist).
Q14. What was the hardest bug you fixed? (The student should answer from their own testing. Two real examples from building this project: the database login worked through the MySQL terminal but was refused from Python — the fix was connecting through the local socket file when it exists; and an em-dash in the sample data turned into strange characters after import, because the import ran in latin1 — the fix was plain hyphens in the sample data and importing with utf8mb4. Do not memorise an answer to this one; it must be true.)
8. Deliverables checklist (what to submit)
- [ ] SRS document (Section 3 of this guide, written as your own document)
- [ ] Design document (ERD, architecture, UI flow — Section 4)
- [ ] Source code (all files in this folder, working)
- [ ] Database file (
schema.sql) - [ ] Test report (the test cases in Section 6, with Pass/Fail filled in)
- [ ] Final report (what you built, how, and what you learned)
- [ ] Presentation slides for the final viva
- [ ] Demo video or live demo (run the system on your own laptop)
9. Common errors and fixes
| Error / symptom | Cause | Fix |
|---|---|---|
| "Access denied for user 'root'@'localhost'" (error 1698) | MySQL only lets root in through the local socket, not over TCP | Check DB_SOCKET in config.py matches your socket path (mysql -u root -e "SHOW VARIABLES LIKE 'socket';"); db.py uses the socket when the file exists |
| "No module named 'mysql'" | The MySQL driver is not installed | Run pip install mysql-connector-python bcrypt |
| "No module named 'tkinter'" | tkinter is not installed (Linux) | Run sudo apt install python3-tk; on Windows it comes with Python |
| "Table 'gym_db.users' doesn't exist" | The schema was imported into the wrong database, or not at all | Re-import schema.sql (it creates the database itself) |
| Login always fails | The sample users were not imported | Re-import schema.sql; check the user exists in phpMyAdmin |
| "Amount is less than the plan price" | The payment is below the plan price | This is correct behaviour — enter at least the plan price |
| "This member already checked in today" | The member checked in earlier today | This is correct behaviour — one check-in per day |
| "Membership expired ... Record a payment first" | The member's membership_end has passed | Record a payment for the member first; the membership restarts from today |
| Strange characters in plan titles after import | The schema was imported with a latin1 connection | Import with mysql --default-character-set=utf8mb4 -u root < schema.sql, or use phpMyAdmin |
| Window opens but looks empty / crashes on start | Python was started from another folder, so it cannot find db.py |
cd into the project folder first, then run python main.py |
| "This plan cannot be deleted: members are using it" | The plan has members on it | This is correct behaviour — deactivate the plan instead of deleting it |
10. Future improvements
- Progress tracker — a
progresstable (member, date, weight, chest, waist, arms) and a matplotlib graph of weight over time, as the official specification suggests for this project family. - Class timetable and booking — a
classestable (trainer, day, time, capacity) and a booking list, so members can book a class instead of just walking in. - Expiry reminders — a daily check that lists memberships ending in the next 7 days on the dashboard, and (later) an SMS/email to the member.
- Printable payment receipt — a receipt window that prints the receipt number, member, plan, amount and new membership end date.
- Change password page — let members change their own password after first login instead of the admin setting it.
- Multi-branch support — the official specification describes a
gym chain across Lahore, Islamabad, Rawalpindi, Karachi and
Peshawar; a
branchestable and a branch on each member would be the first step toward that.
Frequently Asked Questions
- Which stack does this Gym / Fitness Management System use? Python 3.11+ with tkinter and MySQL, as stated in the official VU specification for the Spring 2025 "Smart Gym Management System" (PyCharm, Python 3.11+, MySQL, tkinter/PyQt, matplotlib). The demo accounts are admin/admin123, trainer/trainer123 and ali/member123.
- Does the code really work? Yes. It was runtime-verified: all 12 Python files pass
python3 -m py_compile, the schema imports cleanly into MariaDB, the admin, trainer and member logins work, and a 25-check headless smoke test of the database module passed (payment, check-in and one-active-plan rules included). One honest limit: the tkinter windows themselves were not tested headlessly, because a window needs a screen — runpython main.pyand click through them yourself (test cases TC-1 to TC-20 tell you exactly what to check). - Can I use this project for my CS619 final year project? Yes — it follows VU's own phases (SRS, design, coding, testing, viva). Change the sample data, add your own features from the future-improvements list, and write the SRS in your own words before submitting.
Comments
Post a Comment