An interactive chat application built using FastAPI for the backend and Next.js for the frontend.
Table of Contents
chat_room
is an interactive chat application designed to facilitate real-time communication between users. The backend is powered by FastAPI, providing a robust and high-performance API. The frontend is built using Next.js, offering a responsive and dynamic user interface.
- Real-time Messaging: Enables users to send and receive messages instantly.
- Room Management: Create and join chat rooms.
- Message Persistence: Store and retrieve messages from a database.
- Responsive Design: Accessible on both desktop and mobile devices.
└── chat_room/
├── Dockerfile
├── LICENSE
├── README.md
├── app
│ ├── __init__.py
│ ├── alembic
│ ├── alembic.ini
│ ├── database
│ │ ├── __init__.py
│ │ └── postgres.py
│ ├── main.py
│ ├── models
│ │ ├── __init__.py
│ │ ├── message.py
│ │ ├── room_member.py
│ │ ├── room.py
│ │ └── user.py
│ ├── requirments.txt
│ ├── routes
│ │ ├── __init__.py
│ │ ├── message.py
│ │ ├── room.py
│ │ ├── user.py
│ │ └── websocket.py
│ ├── schemas.py
│ ├── services
│ │ ├── __init__.py
│ │ ├── message.py
│ │ ├── room.py
│ │ └── user.py
│ └── test_app.py
├── blueprint.md
├── docker-compose.yml
├── frontend
│ ├── .eslintrc.json
│ ├── .gitignore
│ ├── README.md
│ ├── components.json
│ ├── next.config.mjs
│ ├── package-lock.json
│ ├── package.json
│ ├── postcss.config.mjs
│ ├── public
│ ├── src
│ │ ├── app
│ │ │ ├── globals.css
│ │ │ └── layout.tsx
│ │ ├── components
│ │ │ ├── AlertsComponent.tsx
│ │ │ ├── room
│ │ │ │ ├── RoomComponent.tsx
│ │ │ │ ├── RoomMessageComponent.tsx
│ │ │ ├── ui
│ │ │ │ ├── alert.tsx
│ │ │ │ ├── button.tsx
│ │ │ │ ├── card.tsx
│ │ │ │ ├── toast.tsx
│ │ │ │ ├── toaster.tsx
│ │ │ │ └── use-toast.ts
│ │ │ ├── users
│ │ │ │ └── SignupComponent.tsx
│ │ ├── hooks
│ │ │ └── webSocket.tsx
│ │ ├── lib
│ │ │ ├── userStorage.ts
│ │ │ └── utils.ts
│ │ ├── pages
│ │ │ ├── _app.tsx
│ │ │ ├── index.tsx
│ │ │ ├── room.tsx
│ │ │ └── rooms
│ │ │ └── [roomId].tsx
│ │ └── services
│ │ ├── roomService.ts
│ │ └── userService.ts
│ ├── tailwind.config.ts
│ └── tsconfig.json
├── next.Dockerfile
├── package-lock.json
└── package.json
.
app
File |
Summary |
schemas.py |
Defines Pydantic models for data validation. |
requirments.txt |
Lists the Python dependencies. |
main.py |
Entry point for the FastAPI application. |
test_app.py |
Contains test cases for the application. |
app.database
File |
Summary |
postgres.py |
Configures the connection to the PostgreSQL database. |
app.models
File |
Summary |
user.py |
SQLAlchemy model for user data. |
message.py |
SQLAlchemy model for message data. |
room_member.py |
SQLAlchemy model for room membership data. |
room.py |
SQLAlchemy model for room data. |
app.alembic
File |
Summary |
script.py.mako |
Template for Alembic migration scripts. |
env.py |
Alembic environment configuration. |
app.alembic.versions
app.routes
File |
Summary |
user.py |
API routes for user operations. |
message.py |
API routes for message operations. |
room.py |
API routes for room operations. |
websocket.py |
API routes for WebSocket connections. |
app.services
File |
Summary |
user.py |
Service logic for user operations. |
message.py |
Service logic for message operations. |
room.py |
Service logic for room operations. |
frontend
frontend.src.app
frontend.src.components
frontend.src.components.ui
frontend.src.components.room
frontend.src.components.users
frontend.src.hooks
File |
Summary |
webSocket.tsx |
Hook for managing WebSocket connections. |
frontend.src.lib
File |
Summary |
userStorage.ts |
Utility for managing user storage. |
utils.ts |
Utility functions used across the frontend. |
frontend.src.pages
File |
Summary |
index.tsx |
Main page of the application. |
room.tsx |
Page for displaying a specific chat room. |
_app.tsx |
Custom App component for Next.js. |
frontend.src.pages.rooms
File |
Summary |
[roomId].tsx |
Dynamic page for displaying a specific room by ID. |
frontend.src.services
System Requirements:
- Python:
version 3.8+
- Node.js:
version 14+
- Docker:
version 20+
- Docker Compose:
version 1.29+
- Next.js:
version 11+
-
Clone the chat_room
repository:
git clone https://github.com/amworden/chat_room
-
Create a .env
file in the project python director and add the following environment variables:
POSTGRES_USER=postgres
POSTGRES_PASSWORD=postgres
POSTGRES_DB=chat_room
POSTGRES_HOST=postgres
POSTGRES_PORT=5432
-
Change into the project directory and run the docker-compose command:
cd chat_room && docker-compose up -d --build
-
Apply the migrations:
docker-compose exec python alembic upgrade head
-
The application will be accessible at http://localhost:3000
.
-
To run the tests, execute:
docker-compose exec python pytest
-
To stop the application, run:
![img.png](/amworden/chat_room/raw/main/img.png)