A full-stack learning project demonstrating modern web development patterns with a Python REST API backend and a reactive TypeScript frontend.
This is a simple Customer Management System that lets you Create, Read, Update, and Delete customer records. Despite its simplicity, it covers essential full-stack development concepts:
- Backend: REST API design, dependency injection, database ORM
- Frontend: Reactive UI components, API integration, TypeScript for type safety
- DevOps: CORS configuration, environment management, client-server communication
- FastAPI — modern Python async web framework
- SQLAlchemy — SQL toolkit and ORM for database abstraction
- SQLite — lightweight file-based database
- Pydantic — data validation and serialization
- Python-dotenv — environment variable management
- SvelteKit — full-stack Svelte framework (v2.x)
- Svelte — reactive component framework (v5.x)
- TypeScript — strongly-typed JavaScript
- Vite — fast build tool
This project demonstrates:
| Concept | Where | Why It Matters |
|---|---|---|
| REST API | app/main.py routes |
Standard pattern for client-server communication |
| ORM (Object-Relational Mapping) | app/models.py, app/database.py |
Abstracts SQL, maps DB rows to Python objects |
| Pydantic Schemas | app/schemas.py |
Input validation, serialization, API documentation |
| Dependency Injection | get_db dependency in routes |
Clean architecture, testability |
| CORS (Cross-Origin Resource Sharing) | app/main.py middleware |
Allows frontend to safely call backend API |
| Database Transactions | app/crud.py |
ACID properties ensure data consistency |
| Reactive UI | frontend/src/routes/+page.svelte |
UI auto-updates when data changes |
| Environment Configuration | .env, frontend/.env |
Secrets and config stay out of version control |
| TypeScript Type Safety | Frontend components | Catch errors at compile time, not runtime |
- Python 3.8+ — Install Python
- Node.js 18+ and npm 9+ — Install Node.js
- Git (optional, for version control)
-
Create a Python virtual environment:
python -m venv venv
-
Activate the virtual environment:
- On Windows:
venv\Scripts\activate
- On macOS/Linux:
source venv/bin/activate
- On Windows:
-
Install Python dependencies:
pip install fastapi uvicorn sqlalchemy python-dotenv pydantic
-
Verify installation:
uvicorn --version
-
Navigate to frontend directory:
cd frontend -
Install npm dependencies:
npm install
-
Return to project root:
cd ..
# Make sure your virtual environment is activated
uvicorn app.main:app --reload- API runs at: http://localhost:8000
- Interactive API docs (Swagger UI): http://localhost:8000/docs
- Alternative docs (ReDoc): http://localhost:8000/redoc
The --reload flag automatically restarts the server when you modify code.
cd frontend
npm run dev- Frontend runs at: http://localhost:5173
- Open your browser to http://localhost:5173 and start creating customers
All endpoints return JSON and accept/return Content-Type: application/json.
| Method | Endpoint | Purpose | Request Body | Response |
|---|---|---|---|---|
GET |
/ |
Welcome message | — | {"message": "Welcome..."} |
GET |
/customers |
List all customers | — | [{id, name, email, created_at}, ...] |
POST |
/customers |
Create a customer | {name, email} |
{id, name, email, created_at} |
PUT |
/customers/{id} |
Update a customer | {name, email} |
{id, name, email, created_at} |
DELETE |
/customers/{id} |
Delete a customer | — | {id, name, email, created_at} |
# Get all customers
curl http://localhost:8000/customers
# Create a customer
curl -X POST http://localhost:8000/customers \
-H "Content-Type: application/json" \
-d '{"name": "Alice", "email": "alice@example.com"}'
# Update a customer (ID 1)
curl -X PUT http://localhost:8000/customers/1 \
-H "Content-Type: application/json" \
-d '{"name": "Alice Smith", "email": "alice.smith@example.com"}'
# Delete a customer (ID 1)
curl -X DELETE http://localhost:8000/customers/1fastapi_svelte_project/
│
├── README.md # This file
├── requirements.txt # Python dependencies (reference only)
├── customers.db # SQLite database (created automatically)
├── .env # Backend environment variables (git-ignored)
├── .gitignore # Git ignore rules
│
├── app/ # FastAPI backend
│ ├── main.py # App entry point, CORS setup, route handlers
│ ├── database.py # SQLAlchemy engine, session, Base
│ ├── models.py # SQLAlchemy ORM models (Customer table)
│ ├── schemas.py # Pydantic request/response schemas
│ └── crud.py # Database CRUD operations
│
├── frontend/ # SvelteKit frontend
│ ├── src/
│ │ ├── app.html # HTML shell template
│ │ ├── routes/
│ │ │ ├── +layout.svelte # Root layout component
│ │ │ └── +page.svelte # Main page (customer UI)
│ │ └── lib/
│ │ ├── index.ts # Library exports
│ │ └── assets/
│ │ └── favicon.svg # App icon
│ ├── .env # Frontend environment variables
│ ├── package.json # npm dependencies and scripts
│ ├── svelte.config.js # SvelteKit configuration
│ ├── vite.config.ts # Vite build configuration
│ ├── tsconfig.json # TypeScript configuration
│ └── static/ # Static assets
│
└── venv/ # Python virtual environment (git-ignored)
app/main.py— Defines all API routes and middleware (CORS, error handling)app/models.py— Defines theCustomertable schema with SQLAlchemy ORMapp/schemas.py— Defines Pydantic models for request/response validationapp/crud.py— Contains reusable database operations (Create, Read, Update, Delete)app/database.py— Configures SQLAlchemy engine and session factory
frontend/src/routes/+page.svelte— Main UI component with form and customer listfrontend/.env— StoresVITE_API_BASE_URL(backend API endpoint)
DATABASE_URL=sqlite:///./customers.db
CORS_ORIGINS=http://localhost:5173,http://127.0.0.1:5173
VITE_API_BASE_URL=http://127.0.0.1:8000
- Ensure Python virtual environment is activated
- Check that port 8000 is available (not in use by another app)
- Try:
uvicorn app.main:app --reload --host 0.0.0.0 --port 8001
- Run
npm installagain (dependencies may be corrupted) - Ensure port 5173 is available
- Try:
npm run dev -- --port 5174
- Check that backend is running (
uvicorncommand) - Verify
VITE_API_BASE_URLinfrontend/.envmatches backend URL - Check browser console (F12) for detailed error messages
- Ensure frontend URL is listed in
.envCORS_ORIGINS - Restart backend after changing
.env
- FastAPI Documentation — Building REST APIs
- SQLAlchemy ORM Tutorial — Database abstraction
- SvelteKit Docs — Full-stack Svelte framework
- Pydantic Docs — Data validation
- REST API Best Practices — API design principles
- Add Edit and Delete buttons to the UI (currently only List and Create)
- Write tests:
pytestfor backend,vitestfor frontend - Add a proper database schema with migrations (use
Alembic) - Implement authentication (JWT tokens)
- Add error handling and validation messages to the UI
- Deploy to a cloud platform (Heroku, Vercel, Railway)
This is a learning project. Feel free to modify and use as you wish!