A full-featured forum system built with FastAPI and MariaDB, supporting user authentication, topic discussions, replies, private messaging, voting, and category management.
- π User Authentication: Register, login, and JWT-based authentication.
- π£οΈ Topic Discussions: Create, view, and reply to topics.
- ποΈ Categories: Organize topics into categories, with privacy and locking controls.
- π Voting: Upvote or downvote replies.
- π¬ Conversations: Private messaging between users.
- π οΈ Admin Controls: Category creation and privacy management.
Forum-System/
β
βββ routers/ # API route definitions
βββ services/ # Business logic and database operations
βββ data/ # Database models and schema
βββ common/ # Shared utilities (responses, authentication)
βββ utils/ # Utility functions
βββ others/ # Other miscellania
βββ db_config.json # Database connection config (not in repo)
βββ encrypt_key.json # JWT encryption key (not in repo)
βββ requirements.txt # Python dependencies
βββ README.md
β
βββ main.py # FastAPI app entry point
1οΈβ£ Clone the repository:
git clone <repo-url>
2οΈβ£ Navigate to the repository root:
cd Forum-System
3οΈβ£ Install project dependencies:
pip install -r requirements.txt
4οΈβ£ Setup a working MariaDB server:
- Option 1: π₯οΈ Download and install from the official MariaDB page.
- Option 2: π³ Setup a MariaDB container with Docker:
- Pull MariaDB:
docker pull mariadb
- Run MariaDB:
docker run -p 3306:3306 --name <NAME> -e MYSQL_ROOT_PASSWORD=<PASSWORD> -d mariadb:latest
- Pull MariaDB:
5οΈβ£ Configure the project environment:
-
Create a
.env
file in the root directory:# Private MariaDB Connection Params DB_USER=your_db_user DB_PASSWORD=your_db_password DB_HOST=your_host_address DB_PORT=your_host_port DB_NAME=forum_system_db # Private JWT Encryption Key ENCRYPT_KEY=your_secret_key # Private Cloudinary Config (Optional) CLDNR_CLOUD_NAME=your_cloudinary_cloud_name CLDNR_API_KEY=your_cloudinary_api_key CLDNR_API_SECRET=your_cloudinary_api_secret # Private NASA API Key (Optional) NASA_API_KEY=your_nasa_api_key
-
Import the schema from
db_schema.sql
(located in thedata
folder) into your running MariaDB server.
6οΈβ£ Start the server
- Option 1: Run the
main.py
file with your preferred IDE. - Option 2: In CMD or Powershell, navigate to the project root and run:
If everything is configured properly, the web server will be available at: http://localhost:8000/
python ./main.py
π Interactive API docs available at: http://localhost:8000/docs
Method | Endpoint | Description | Auth Required |
---|---|---|---|
POST | /api/users/login |
Authenticate user | No |
POST | /api/users/register |
Register new user | No |
GET | /api/users/info |
Get current user info | Yes |
GET | /api/conversations/ |
List user's conversations | Yes |
GET | /api/conversations/{conversation_id} |
Get conversation details | Yes |
POST | /api/conversations/ |
Create new conversation | Yes |
POST | /api/conversations/{conversation_id} |
Add message to conversation | Yes |
PUT | /api/conversations/{conversation_id}/users |
Add user to conversation | Yes |
DELETE | /api/conversations/{conversation_id}/users |
Remove user from conversation | Yes |
All authenticated endpoints require a user token (u-token
) in the request headers.
- Purpose: Authenticate an existing user.
- Request Body: User credentials (username and password).
- Response: User authentication token (
u-token
).
- Purpose: Create a new user account.
- Request Body: User credentials (username and password).
- Response: Account creation status.
- Purpose: Retrieve current user's profile information.
- Authentication: Required (
u-token
). - Response: User profile data.
- Purpose: Retrieve user's conversations.
- Authentication: Required (
u-token
). - Query Parameters:
contains_user
(optional) - Response: List of conversation summaries.
- Purpose: Get details of a specific conversation.
- Authentication: Required (
u-token
). - Response: Conversation details and messages.
- Purpose: Create a new conversation.
- Authentication: Required (
u-token
). - Request Body: Conversation details and participants.
- Purpose: Add a new message to a conversation.
- Authentication: Required (
u-token
). - Request Body: Message content.
- Purpose: Add a user to a conversation.
- Authentication: Required (
u-token
). - Request Body: Username to add.
- Purpose: Remove a user from a conversation.
- Authentication: Required (
u-token
). - Request Body: Username to remove.
- Purpose: Retrieve topics with filtering.
- Query Parameters:
sort
,sort_by
,search
- Response: Paginated list of topics.
- Purpose: Retrieve a specific topic with its replies.
- Response: Topic and replies.
- Purpose: Create a new topic in a category.
- Authentication: Required (
u-token
). - Request Body: Topic details and category ID.
- Purpose: Add a reply to a topic.
- Authentication: Required (
u-token
). - Request Body: Reply content.
- Purpose: Vote on a reply.
- Authentication: Required (
u-token
). - Request Body: Vote type (up/down).
- Purpose: Mark a reply as the best.
- Authentication: Required (
u-token
). - Request Body: Reply ID.
- Purpose: Lock a topic.
- Authentication: Required (
u-token
). - Request Body: New locked status.
- Purpose: Retrieve all categories.
- Response: List of categories.
- Purpose: Retrieve topics in a category.
- Query Parameters:
sort
,sort_by
,search
- Response: Paginated list of topics.
- Purpose: Create a new category.
- Authentication: Required (
u-token
). - Request Body: Category details.
- Purpose: Update category privacy.
- Authentication: Required (
u-token
). - Request Body: New privacy status.
- Purpose: Lock a category.
- Authentication: Required (
u-token
). - Response: Updated category.
- Error responses include appropriate HTTP status codes and error messages.
- Refer to the Interactive API documentation for up-to-date request/response formats.
This project is licensed under the MIT License. View π LICENSE for details.