A complete, production-ready registration system built from scratch with Python, PostgreSQL, and MongoDB. No frontend frameworks, no Python web frameworks - just pure code.
- π Complete Registration Form with 20+ field types:
- Text, Email, Password, Telephone
- Date picker, Country dropdown, City input
- Radio buttons (Gender, Contact method)
- Checkboxes (Interests, Terms & Conditions)
- File uploads (Profile picture, Resume, Multiple files)
- Textarea (Bio), URL (Website), Social media handles
- β Real-time validation and username/email availability checking
- π User login with secure session management
- π User dashboard with activity feed and statistics
- π Admin panel with complete user management
- π± Fully responsive design for all devices
- π Pure Python HTTP server (no Flask/Django dependencies)
- π Secure session-based authentication with HTTP-only cookies
- π File upload handling with validation and secure storage
- π Password hashing with SHA-256 (upgradable to bcrypt)
- π Comprehensive activity logging for audit trails
- π― RESTful API endpoints for all operations
- PostgreSQL: Structured user data with JSONB support for flexible metadata
- MongoDB: Activity logs, user sessions, and dynamic form submissions
- Tech Stack
- Project Structure
- Prerequisites
- Installation
- Configuration
- Running the Application
- API Endpoints
- Database Schema
- Security Features
- Extensibility
- Troubleshooting
- Contributing
- License
| Component | Technology | Version |
|---|---|---|
| Backend | Python (http.server) | 3.8+ |
| Database (Structured) | PostgreSQL | 13+ |
| Database (Unstructured) | MongoDB | 4.4+ |
| Frontend | HTML5, CSS3, Vanilla JS | - |
| Authentication | Session-based with cookies | - |
| Password Security | SHA-256 hashing | - |
registration_system/
β
βββ backend/ # Python backend server
β βββ server.py # Main HTTP server (entry point)
β βββ db_postgres.py # PostgreSQL database operations
β βββ db_mongo.py # MongoDB database operations
β βββ routes/ # API route handlers
β β βββ __init__.py # Makes routes a Python package
β β βββ register.py # Registration & login endpoints
β β βββ admin.py # Admin management endpoints
β β βββ api.py # General API endpoints
β βββ templates/ # HTML templates
β βββ base.html # Base template for pages
β
βββ frontend/ # Static frontend files
β βββ index.html # Landing page
β βββ register.html # Registration form (20+ fields)
β βββ login.html # User login page
β βββ dashboard.html # User dashboard
β βββ admin.html # Admin panel
β βββ css/
β β βββ style.css # Responsive CSS styles
β βββ js/
β βββ app.js # Frontend JavaScript logic
β
βββ uploads/ # Uploaded files (auto-created)
β βββ .gitkeep # Keep directory in version control
β
βββ .env.example # Environment variables template
βββ .gitignore # Git ignore rules
βββ requirements.txt # Python dependencies
βββ PROJECT_STRUCTURE.md # Detailed structure documentation
βββ README.md # This file
π Prerequisites
Before you begin, ensure you have the following installed:
Β· Python 3.8 or higher - Download Β· PostgreSQL 13 or higher - Download Β· MongoDB 4.4 or higher - Download Β· Git (optional) - Download
π§ Installation
- Clone the Repository
git clone https://github.com/abdulboyprogramming-arch/reg-system.git
cd reg-system- Create and Activate Virtual Environment
# Windows
python -m venv venv
venv\Scripts\activate
# Linux/Mac
python3 -m venv venv
source venv/bin/activate- Install Python Dependencies
pip install -r requirements.txt- Setup PostgreSQL
-- Connect to PostgreSQL
psql -U postgres
-- Create database
CREATE DATABASE reg_system;
-- Create user (optional, if you want a dedicated user)
CREATE USER reg_user WITH PASSWORD 'your_secure_password';
GRANT ALL PRIVILEGES ON DATABASE reg_system TO reg_user;
-- Exit
\q- Setup MongoDB
MongoDB typically runs on default settings:
Β· URI: mongodb://localhost:27017/ Β· Database: registration_system (auto-created)
To verify MongoDB is running:
# Check MongoDB status
mongod --version
# Connect to MongoDB
mongoshβοΈ Configuration
- Create Environment File
Copy the example environment file and update with your credentials:
cp .env.example .env- Edit .env with Your Credentials
# PostgreSQL Configuration
DB_NAME=reg_system
DB_USER=postgres
DB_PASSWORD=your_actual_password_here
DB_HOST=localhost
DB_PORT=5432
# MongoDB Configuration
MONGODB_URI=mongodb://localhost:27017/
MONGODB_DB_NAME=registration_system
# Security
SECRET_KEY=your-super-secret-key-here-change-this-in-production
SESSION_TIMEOUT_HOURS=24
# Server Configuration
PORT=8080
DEBUG=False
# File Upload Configuration
MAX_FILE_SIZE=5242880 # 5MB in bytes
ALLOWED_EXTENSIONS=jpg,jpeg,png,gif,pdf,doc,docx- Test Database Connections
# Create a test script or run Python commands
python -c "from backend.db_postgres import PostgresDB; PostgresDB()"
python -c "from backend.db_mongo import MongoDB; MongoDB()"π Running the Application
Start the Server
cd backend
python server.pyAccess the Application
Open your browser and navigate to:
http://localhost:8080
| URL | Description | Access |
|---|---|---|
/ |
Landing page (redirects to dashboard if logged in) | Public |
/register |
Registration form | Public |
/login.html |
Login page | Public |
/dashboard |
User dashboard | Authenticated |
/admin |
Admin panel | Admin only |
| Method | Endpoint | Description | Request Body |
|---|---|---|---|
| POST | /api/register |
Register new user | {email, username, password, confirm_password, ...} |
| POST | /api/login |
User login | {username_or_email, password} |
| POST | /api/check-availability |
Check username/email availability | {field, value} |
| GET | /api/session |
Get current session info | - |
| Method | Endpoint | Description | Access |
|---|---|---|---|
| POST | /api/upload |
Upload files | Authenticated |
| POST | /api/save-form-data |
Save custom form data | Authenticated |
| GET | /api/user-activity |
Get user activity logs | Authenticated |
| GET | /api/form-submissions |
Get user form submissions | Authenticated |
| GET | /api/stats |
Get user statistics | Authenticated |
| Method | Endpoint | Description | Access |
|---|---|---|---|
| GET | /api/users |
List all users | Admin only |
| POST | /api/update-user |
Update user details | Admin only |
| GET | /api/user-activity?user_id=X |
View specific user activity | Admin only |
| Column | Type | Description |
|---|---|---|
id |
SERIAL | Primary key |
email |
VARCHAR(255) | Unique email address |
username |
VARCHAR(100) | Unique username |
password_hash |
VARCHAR(255) | Hashed password |
full_name |
VARCHAR(255) | User's full name |
phone |
VARCHAR(50) | Phone number |
date_of_birth |
DATE | Date of birth |
gender |
VARCHAR(20) | Gender selection |
country |
VARCHAR(100) | Country of residence |
city |
VARCHAR(100) | City |
postal_code |
VARCHAR(20) | Postal/ZIP code |
created_at |
TIMESTAMP | Account creation time |
updated_at |
TIMESTAMP | Last update time |
is_active |
BOOLEAN | Account status |
is_admin |
BOOLEAN | Admin privileges |
email_verified |
BOOLEAN | Email verification status |
| Column | Type | Description |
|---|---|---|
user_id |
INTEGER | References users(id) |
metadata |
JSONB | Flexible user metadata |
preferences |
JSONB | User preferences |
| Column | Type | Description |
|---|---|---|
id |
SERIAL | Primary key |
user_id |
INTEGER | References users(id) |
token |
VARCHAR(255) | Unique verification token |
expires_at |
TIMESTAMP | Token expiration |
used |
BOOLEAN | Token usage status |
activity_logs
{
_id: ObjectId,
user_id: Number,
action: String,
ip_address: String,
user_agent: String,
details: Object,
timestamp: ISODate
}form_submissions
{
_id: ObjectId,
submission_type: String,
user_id: Number,
data: Object,
submitted_at: ISODate
}user_sessions
{
_id: ObjectId,
user_id: Number,
session_token: String,
expires_at: ISODate,
created_at: ISODate
}π Security Features
Β· β HTTP-only cookies for session storage Β· β Password hashing with SHA-256 (upgradable to bcrypt) Β· β Session expiration (24 hours default) Β· β Account deactivation capability Β· β Input validation and sanitization Β· β Activity logging for audit trails Β· β Admin-only endpoints protection Β· β File upload validation (type and size) Β· β Environment variables for secrets Β· β SQL injection prevention (parameterized queries)
π§ Extensibility
The system is designed for easy extension:
Add New API Endpoints
- Add method in appropriate route class (routes/register.py, routes/admin.py, or routes/api.py)
- Add route mapping in server.py
Add New Database Tables
- Add creation logic in db_postgres.py init_db() method
- Add helper methods for CRUD operations
Add New Frontend Pages
- Create HTML file in frontend/
- Add route in server.py GET handler
Implement Email Verification
Β· Table email_tokens is ready Β· Add email sending logic in routes/register.py
Add Password Reset
Β· Extend email_tokens table for reset tokens Β· Add new endpoints in routes/api.py
Implement Rate Limiting
Β· Add rate limiter class in server.py Β· Decorate API endpoints with rate limit checks
π Troubleshooting
Database Connection Errors
Error: psycopg2.OperationalError: could not connect to server
Solution:
# Check if PostgreSQL is running
sudo systemctl status postgresql # Linux
pg_ctl status # Mac
# Windows: Check Services
# Verify credentials in .env file
cat .env | grep DB_MongoDB Connection Errors
Error: pymongo.errors.ServerSelectionTimeoutError
Solution:
# Check if MongoDB is running
sudo systemctl status mongod # Linux
brew services list | grep mongodb # Mac
# Windows: Check Services
# Start MongoDB if needed
sudo systemctl start mongod # Linux
brew services start mongodb # MacFile Upload Issues
Error: File too large or File type not allowed
Solution:
Β· Check MAX_FILE_SIZE in .env (default: 5MB) Β· Verify ALLOWED_EXTENSIONS includes your file type Β· Ensure uploads/ directory has write permissions
Session Problems
Issue: Session not persisting or immediate logout
Solution:
Β· Clear browser cookies Β· Check MongoDB user_sessions collection for expired sessions Β· Verify SESSION_TIMEOUT_HOURS in .env
Port Already in Use
Error: Address already in use
Solution:
# Change PORT in .env file
PORT=8081
# Or kill process using the port
# Linux/Mac
lsof -ti:8080 | xargs kill -9
# Windows
netstat -ano | findstr :8080
taskkill /PID <PID> /Fπ€ Contributing
Contributions are welcome! Please follow these steps:
- Fork the repository
- Create a feature branch (git checkout -b feature/AmazingFeature)
- Commit your changes (git commit -m 'Add some AmazingFeature')
- Push to the branch (git push origin feature/AmazingFeature)
- Open a Pull Request
Development Guidelines
Β· Follow PEP 8 style guide for Python code Β· Use meaningful commit messages Β· Update documentation for new features Β· Add tests for new functionality Β· Ensure all existing features work
π License
This project is licensed under the MIT License - see the LICENSE file for details.
π Acknowledgments
Β· Built with Python's built-in http.server module Β· PostgreSQL for reliable structured data storage Β· MongoDB for flexible document storage Β· Vanilla JavaScript for lightweight frontend
π Support
For issues, questions, or contributions:
Β· Open an issue on GitHub Β· Contact the maintainer Β· Check the troubleshooting section
Β· HTTPS with SSL/TLS certificates Β· Strong password hashing (bcrypt/argon2) Β· Rate limiting on all endpoints Β· CSRF protection Β· Regular security updates Β· Database encryption at rest
Made with β€οΈ for the developer community