A complete beginner Welcome to CardSense! This guide will help you understand everything about this project, even if you're brand new to software development.
- What Does CardSense Do?
- The Big Picture: How Web Apps Work
- CardSense Architecture
- Technologies We Use
- Project Structure Explained
- How the Code Works Together
- Database & Data Flow
- Getting Started
- Common Beginner Questions
CardSense is a web application that helps people manage their money and credit cards better. Think of it like a smart assistant for your wallet.
-
Budget Tracking π°
- Users can set a monthly budget (e.g., "I want to spend $500 this month")
- The app tracks how much they've spent
- Warns them when they're getting close to their limit
-
Transaction Tracking π
- Users can record every purchase they make
- Like keeping a digital receipt book
- Can upload CSV files (spreadsheets) with lots of transactions at once
-
Credit Card Management π³
- Store information about all your credit cards
- Each card has different rewards (cashback, points, miles)
- Keep track of which cards you own
-
Smart Optimizer π§
- Tells you which card to use for maximum rewards
- Example: "Use Card A for groceries (5% back), Card B for gas (3% back)"
- Helps you earn more rewards automatically
Imagine Sarah has 3 credit cards. She's about to buy groceries ($100), gas ($50), and go out to eat ($30). CardSense tells her:
- Use Chase Freedom for groceries β earn $5 back
- Use Discover for gas β earn $2.50 back
- Use AmEx for dining β earn $1.50 back
Total rewards: $9 saved! Without CardSense, she might have used just one card and only earned $3 total.
Before diving into CardSense specifically, let's understand how ANY web application works:
Think of a web app like a restaurant:
-
Frontend (the dining room) ποΈ
- This is what customers SEE and INTERACT with
- Nice decorations, menus, tables
- In web apps: the buttons, forms, colors you see in your browser
-
Backend (the kitchen) π§
- This is where the actual WORK happens
- Cooking food, preparing orders, managing inventory
- In web apps: processing data, doing calculations, managing user accounts
-
Database (the pantry/storage) ποΈ
- Where all the ingredients are stored
- In web apps: where all user data, transactions, card info is saved permanently
User clicks "Add Transaction" button
β
Frontend: "Hey Backend, save this $50 grocery purchase"
β
Backend: Receives request, validates it, processes it
β
Database: Backend saves the transaction data
β
Backend: "Done! Here's confirmation"
β
Frontend: Shows "Transaction saved successfully!" message to user
CardSense is built with a "Client-Server" architecture:
βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β YOUR BROWSER β
β βββββββββββββββββββββββββββββββββββββββββββββββββ β
β β FRONTEND (React App) β β
β β - Login page, Dashboard, Forms β β
β β - Runs on: http://localhost:3000 β β
β β - Language: JavaScript/TypeScript β β
β βββββββββββββββββββββββββββββββββββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β HTTP Requests
βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β YOUR COMPUTER β
β βββββββββββββββββββββββββββββββββββββββββββββββββ β
β β BACKEND (Django Server) β β
β β - API Endpoints, Business Logic β β
β β - Runs on: http://127.0.0.1:8000 β β
β β - Language: Python β β
β βββββββββββββββββββββββββββββββββββββββββββββββββ β
β β β
β βββββββββββββββββββββββββββββββββββββββββββββββββ β
β β DATABASE (SQLite) β β
β β - Stores: users, cards, transactions, budgets β β
β β - File: db.sqlite3 β β
β βββββββββββββββββββββββββββββββββββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
- Two separate programs run at the same time
- Frontend and Backend talk using HTTP requests (like sending letters back and forth)
- They run on different ports (think of ports like different TV channels)
- Port 3000 = Frontend
- Port 8000 = Backend
- What it is: A JavaScript library for building user interfaces
- What it does: Creates the buttons, forms, pages you see
- Think of it like: LEGO blocks for building websites
- File extension:
.jsxor.tsx(TypeScript version)
- What it is: JavaScript with extra rules
- What it does: Helps catch mistakes before you run the code
- Think of it like: Spell-check for code
- Example:
// JavaScript (no type checking) let age = "25"; // Oops, should be a number! // TypeScript (catches the mistake) let age: number = "25"; // β ERROR: Can't assign string to number!
- What it is: A tool for styling (making things pretty)
- What it does: Makes buttons look nice, colors, layouts, etc.
- Example:
<button className="bg-blue-500 text-white rounded-lg px-4 py-2"> Click Me </button>
- What it is: A tool for making HTTP requests
- What it does: Sends data to the backend and receives responses
- Think of it like: The mail carrier between frontend and backend
- What it is: A beginner-friendly programming language
- What it does: The main language for our backend logic
- Why Python: Easy to read, lots of libraries, great for beginners
- What it is: A Python web framework
- What it does: Provides tools for building web backends quickly
- Think of it like: A toolkit with hammers, screwdrivers, etc. for building a house
- Features it provides:
- User authentication (login/logout)
- Database management
- URL routing
- Security features
- What it is: An add-on for Django
- What it does: Makes it easy to create APIs (endpoints the frontend calls)
- Example API endpoint:
POST /api/transactions/ β Creates a new transaction
- What it is: A lightweight database
- What it does: Stores all data permanently
- Think of it like: An Excel spreadsheet, but way more powerful
- The file:
db.sqlite3in your project folder
Let's go through every folder and understand what it does:
CardSense/
β
βββ web/ β FRONTEND (React App)
β βββ src/ β Source code (the actual code you write)
β β βββ components/ β Reusable UI pieces
β β β βββ auth/ β Login & Register pages
β β β βββ Dashboard/ β Main dashboard after login
β β β βββ Transactions/ β Transaction management pages
β β β βββ Budgets/ β Budget creation & tracking
β β β βββ Landing.tsx β First page visitors see
β β β
β β βββ services/ β Code that talks to backend
β β β βββ api.ts β Main HTTP client setup
β β β βββ auth.service.ts β Login/logout functions
β β β βββ card.service.ts β Card-related API calls
β β β βββ ... β Other service files
β β β
β β βββ types/ β TypeScript type definitions
β β β βββ index.ts β Defines data structures
β β β
β β βββ App.tsx β Main app component
β β βββ index.js β Entry point (starts the app)
β β
β βββ public/ β Static files (images, icons)
β βββ package.json β Lists all frontend dependencies
β βββ node_modules/ β Installed libraries (auto-generated)
β
βββ accounts/ β BACKEND: User authentication
β βββ models.py β Database table for users
β βββ views.py β Login, register, logout logic
β βββ serializers.py β Converts data between JSON and Python
β βββ urls.py β API endpoint routes
β
βββ transactions/ β BACKEND: Transaction management
β βββ models.py β Transaction database table
β βββ views.py β CRUD operations for transactions
β βββ serializers.py β Transaction data formatting
β βββ urls.py β Transaction API endpoints
β
βββ budgets/ β BACKEND: Budget management
β βββ models.py β Budget database table
β βββ views.py β Budget creation, tracking
β βββ services.py β Budget calculation logic
β βββ signals.py β Auto-updates when transactions change
β
βββ cards/ β BACKEND: Credit card management
β βββ models.py β Card & reward rules tables
β βββ views.py β Card CRUD operations
β βββ management/ β Custom commands
β βββ commands/
β βββ add_default_rewards.py β Adds default card data
β
βββ optimizer/ β BACKEND: Card recommendation engine
β βββ services.py β Algorithm for best card selection
β βββ views.py β API endpoint for recommendations
β βββ models.py β Optimization history
β
βββ api/ β DJANGO PROJECT SETTINGS
β βββ settings.py β Main configuration file
β βββ urls.py β Master URL routing
β βββ wsgi.py β Server entry point
β
βββ venv/ β Python virtual environment
β βββ ... β Isolated Python packages
β
βββ db.sqlite3 β THE DATABASE FILE
βββ manage.py β Django command-line tool
βββ requirements.txt β Python package list
βββ README.md β Project overview
- A reusable piece of UI
- Example: A button, a form, a card display
- Like building blocks that you combine to make a full page
// Simple component example
function WelcomeMessage() {
return <h1>Welcome to CardSense!</h1>;
}- Code that performs a specific task
- Usually talks to the backend
- Keeps your code organized
// Example service function
async function createTransaction(data) {
const response = await axios.post('/api/transactions/', data);
return response.data;
}- Defines what data looks like in the database
- Like a blueprint or template
# Example Django model
class Transaction(models.Model):
amount = models.DecimalField(max_digits=10, decimal_places=2)
description = models.CharField(max_length=200)
date = models.DateField()
category = models.CharField(max_length=50)Let's trace what happens when a user adds a transaction:
// User fills out form and clicks "Add Transaction"
// File: web/src/components/Transactions/AddTransaction.tsx
const handleSubmit = async (e) => {
e.preventDefault(); // Stop page from refreshing
const transactionData = {
amount: 50.00,
description: "Groceries",
category: "food",
date: "2024-11-28"
};
// Call the service to send data to backend
await transactionService.create(transactionData);
};// File: web/src/services/transaction.service.ts
export async function create(data) {
// Send POST request to backend
const response = await api.post('/api/transactions/', data);
return response.data;
}# File: transactions/views.py
@api_view(['POST'])
def create_transaction(request):
# Step 1: Receive data from frontend
data = request.data
# Step 2: Validate data using serializer
serializer = TransactionSerializer(data=data)
if serializer.is_valid():
# Step 3: Save to database
transaction = serializer.save(user=request.user)
# Step 4: Send success response back
return Response({
'success': True,
'data': serializer.data,
'message': 'Transaction created!'
})
else:
return Response({'error': serializer.errors}, status=400)-- Django automatically creates this SQL command:
INSERT INTO transactions_transaction
(amount, description, category, date, user_id)
VALUES
(50.00, 'Groceries', 'food', '2024-11-28', 1);{
"success": true,
"data": {
"id": 42,
"amount": 50.00,
"description": "Groceries",
"category": "food",
"date": "2024-11-28"
},
"message": "Transaction created!"
}// Show success message
alert('Transaction added successfully!');
// Refresh the transaction list
fetchTransactions();User clicks button
β
React Component (handleSubmit)
β
Service Function (transactionService.create)
β
HTTP POST Request β http://127.0.0.1:8000/api/transactions/
β
Django URL Router β routes to create_transaction view
β
Django View Function (create_transaction)
β
Serializer validates data
β
Database saves transaction
β
Response sent back β HTTP Response (JSON)
β
Service Function receives response
β
Component updates UI
β
User sees "Success!" message
The database stores tables (like Excel sheets) with rows (individual records) and columns (fields):
| id | user_id | amount | description | category | date |
|---|---|---|---|---|---|
| 1 | 5 | 50.00 | Groceries | food | 2024-11-28 |
| 2 | 5 | 25.50 | Gas | transport | 2024-11-27 |
| 3 | 7 | 100.00 | Restaurant | dining | 2024-11-28 |
-
accounts_user
- Stores user accounts
- Columns: id, email, password (encrypted), first_name, last_name
-
transactions_transaction
- Stores all transactions
- Columns: id, user_id, amount, description, category, date, card_id
-
budgets_budget
- Stores monthly budgets
- Columns: id, user_id, amount, month, year, spent
-
cards_card
- Stores credit cards
- Columns: id, user_id, name, issuer, last_four_digits
-
cards_rewardrule
- Stores reward rates for each card
- Columns: id, card_id, category, reward_rate, reward_type
User (accounts_user)
βββ Has many β Transactions
βββ Has many β Cards
βββ Has one β Budget
Card (cards_card)
βββ Belongs to β User
βββ Has many β Transactions
βββ Has many β Reward Rules
Transaction (transactions_transaction)
βββ Belongs to β User
βββ Belongs to β Card (optional)
This is called a relational database because tables are related to each other.
-
Python 3.x
- Download: https://www.python.org/downloads/
- Check if installed:
python --version
-
Node.js & npm
- Download: https://nodejs.org/
- Check if installed:
node --versionandnpm --version
-
Git
- Download: https://git-scm.com/
- Check if installed:
git --version
-
A Code Editor
- Recommended: VS Code (https://code.visualstudio.com/)
git clone https://github.com/btaquee/CardSense.git
cd CardSense# Create virtual environment (isolated Python environment)
python -m venv venv
# Activate it (Windows)
.\venv\Scripts\Activate.ps1
# Install Python packages
pip install -r requirements.txt
# Run database migrations (creates tables)
python manage.py migrate
# Create a superuser (admin account)
python manage.py createsuperuser
# Start the backend server
python manage.py runserverBackend should now be running at: http://127.0.0.1:8000/
Open a NEW terminal window (keep backend running):
# Navigate to web folder
cd web
# Install Node packages
npm install
# Start the React development server
npm startFrontend should now be running at: http://localhost:3000/
Your browser should automatically open!
A: Think of it like a restaurant:
- Frontend (React) = The dining room customers see
- Backend (Django) = The kitchen where food is prepared
They're separate because:
- Different people might work on them
- They can be deployed to different servers
- Keeps code organized and maintainable
A: It's like a separate bubble for your Python packages.
Why? Different projects need different versions of libraries. Without venv:
- Project A needs Django 4.0
- Project B needs Django 5.0
- They would conflict! π±
With venv, each project has its own isolated set of packages.
A: It means "this computer" or "my computer".
localhost:3000= React server running on YOUR computer, port 3000127.0.0.1:8000= Django server running on YOUR computer, port 8000
(127.0.0.1 is the IP address for localhost)
A: These are HTTP methods:
-
GET = "Give me data"
- Example: Fetch all transactions
- Like asking a waiter for a menu
-
POST = "Here's data, save it"
- Example: Create a new transaction
- Like giving your order to a waiter
-
PUT/PATCH = "Update existing data"
-
DELETE = "Remove this data"
A: API = Application Programming Interface
Think of it as a menu at a restaurant:
- Lists what you can order (endpoints)
- Tells you what information you need to provide
- Returns what you asked for
CardSense API Example:
Menu of Available Endpoints:
GET /api/transactions/ β Get all transactions
POST /api/transactions/ β Create a transaction
GET /api/transactions/5/ β Get transaction #5
DELETE /api/transactions/5/ β Delete transaction #5
GET /api/cards/ β Get all cards
POST /api/budgets/ β Create a budget
A: JSON = JavaScript Object Notation
It's a way to format data that both JavaScript and Python understand:
{
"id": 1,
"name": "Chase Freedom",
"issuer": "Chase",
"rewards": {
"groceries": 5,
"gas": 3
}
}Think of it like filling out a form with labels and values.
A: It means "don't wait, keep going".
Synchronous (waiting):
Make coffee β (wait 5 minutes)
β
Make toast π (wait 2 minutes)
β
Total time: 7 minutes
Asynchronous (parallel):
Start coffee β (5 minutes)
While coffee is brewing...
β Make toast π (2 minutes)
Total time: 5 minutes
In code:
// Synchronous - waits for each step
const data = fetchData(); // Waits...
console.log(data);
// Asynchronous - keeps going
fetchData().then(data => {
console.log(data);
});
console.log("This runs immediately!");A:
- JavaScript = The original language
- TypeScript = JavaScript + Type checking
Example:
// JavaScript - no types
function add(a, b) {
return a + b;
}
add(5, "10"); // Returns "510" - BUG! π
// TypeScript - with types
function add(a: number, b: number): number {
return a + b;
}
add(5, "10"); // β ERROR: Can't add number + stringTypeScript catches bugs BEFORE you run the code!
A: Props = Properties = Data passed to components
Like function parameters, but for UI components:
// Parent component
<WelcomeMessage name="Alice" age={20} />
// WelcomeMessage component
function WelcomeMessage(props) {
return (
<div>
<h1>Hello, {props.name}!</h1>
<p>You are {props.age} years old</p>
</div>
);
}
// Displays: "Hello, Alice! You are 20 years old"A: State = Data that can change over time
Like variables that, when updated, automatically update the UI:
function Counter() {
const [count, setCount] = useState(0); // State variable
return (
<div>
<p>Count: {count}</p>
<button onClick={() => setCount(count + 1)}>
Increment
</button>
</div>
);
}Every time you click the button:
countincreases- React automatically re-renders the component
- You see the new number
A: A serializer converts data between formats:
# Python Object β JSON (for sending to frontend)
transaction = Transaction.objects.get(id=1)
serializer = TransactionSerializer(transaction)
json_data = serializer.data
# Result: {"id": 1, "amount": 50.00, "description": "Groceries"}
# JSON β Python Object (for saving to database)
data = {"amount": 50.00, "description": "Groceries"}
serializer = TransactionSerializer(data=data)
if serializer.is_valid():
serializer.save() # Saves to databaseThink of it as a translator between database and API.
A: Migrations = Instructions for updating the database
When you change your models, Django creates migration files:
# You change the model
class Transaction(models.Model):
amount = models.DecimalField(max_digits=10, decimal_places=2)
description = models.CharField(max_length=200)
# NEW: Added category field
category = models.CharField(max_length=50)Run python manage.py makemigrations β Creates a migration file
Run python manage.py migrate β Updates the database
It's like version control for your database structure!
Django comes with a built-in admin interface:
- URL: http://127.0.0.1:8000/admin/
- You can view/edit all database records
- Super useful for debugging!
Error messages tell you exactly what went wrong:
ModuleNotFoundError: No module named 'lucide-react'
This means: You need to install the lucide-react package!
Press F12 in your browser to open DevTools:
- Console tab: See JavaScript errors and logs
- Network tab: See all HTTP requests to the backend
- Elements tab: Inspect HTML/CSS
Essential commands:
git status # See what changed
git add . # Stage all changes
git commit -m "Message" # Save changes
git push # Upload to GitHub
git pull # Download from GitHub
git checkout branch-name # Switch branches- You can always
git checkoutto undo changes - The database is just a file (db.sqlite3) - you can delete and recreate it
- Experiment and learn!
When stuck:
- Read the error message
- Google the error (add "django" or "react" to your search)
- Check the documentation
- Ask your teammates!
- React: https://react.dev/learn
- Django: https://docs.djangoproject.com/
- Django REST Framework: https://www.django-rest-framework.org/
- TypeScript: https://www.typescriptlang.org/docs/
- React for Beginners: https://react.dev/learn/tutorial-tic-tac-toe
- Django Tutorial: https://docs.djangoproject.com/en/stable/intro/tutorial01/
- HTTP/APIs: https://developer.mozilla.org/en-US/docs/Web/HTTP
- Postman: Test API endpoints (https://www.postman.com/)
- DB Browser for SQLite: View database graphically (https://sqlitebrowser.org/)
- VS Code Extensions:
- Python
- ES7+ React/Redux/React-Native snippets
- Prettier (code formatter)
Congratulations! You now understand:
- β What CardSense does
- β How frontend and backend work together
- β The technologies we use
- β How data flows through the application
- β How to get started
Next Steps:
- Get the project running on your machine
- Explore the code (start with simple components)
- Make a small change and see what happens
- Break things and fix them - that's how you learn!
Remember: Every expert developer started as a beginner. The only difference is they kept learning and practicing. You got this! πͺ
Questions? Ask your teammates or create an issue on GitHub!
Happy Coding! π