Skip to content

Commit 1ec9437

Browse files
authored
Merge pull request #74 from BUAA-SE-coders007/release
Alpha Release
2 parents 522b377 + a3ba356 commit 1ec9437

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+3371
-2
lines changed

.env

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
SECRET_KEY=bN3hZ6LbHG7nH9YXWULCr-crcS3GAaRELbNBdAyHBuiHH5TRctd0Zbd6OuLRHHa4Fbs
2+
SENDER_PASSWORD=TXVU2unpCAE2EtEX
3+
KIMI_API_KEY=sk-icdiHIiv6x8XjJCaN6J6Un7uoVxm6df5WPhflq10ZVFo03D9

.github/workflows/check.yml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: Check FastAPI Backend
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- dev
7+
8+
jobs:
9+
test:
10+
name: Run Tests and Check FastAPI
11+
runs-on: ubuntu-latest
12+
13+
services:
14+
postgres:
15+
image: postgres:13
16+
env:
17+
POSTGRES_USER: test_user
18+
POSTGRES_PASSWORD: test_password
19+
POSTGRES_DB: test_db
20+
ports:
21+
- 5432:5432
22+
options: >-
23+
--health-cmd="pg_isready -U test_user"
24+
--health-interval=10s
25+
--health-timeout=5s
26+
--health-retries=5
27+
28+
redis:
29+
image: redis:7
30+
ports:
31+
- 6379:6379
32+
options: >-
33+
--health-cmd="redis-cli ping"
34+
--health-interval=10s
35+
--health-timeout=5s
36+
--health-retries=5
37+
38+
steps:
39+
- name: Checkout code
40+
uses: actions/checkout@v3
41+
42+
- name: Set up Python
43+
uses: actions/setup-python@v3
44+
with:
45+
python-version: '3.12'
46+
47+
- name: Install dependencies
48+
run: |
49+
python -m pip install --upgrade pip
50+
pip install -r requirements.txt
51+
52+
- name: Check FastAPI Server
53+
run: |
54+
uvicorn app.main:app --host 0.0.0.0 --port 8000 --log-level warning &
55+
sleep 5
56+
curl -f http://localhost:8000/docs

.github/workflows/deploy.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: Deploy FastAPI Backend
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- dev
8+
9+
jobs:
10+
deploy:
11+
name: Deploy to Server
12+
runs-on: ubuntu-22.04
13+
14+
steps:
15+
- name: Checkout Code
16+
uses: actions/checkout@v3
17+
18+
- name: Setup SSH
19+
uses: webfactory/[email protected]
20+
with:
21+
ssh-private-key: ${{ secrets.SERVER_SSH_KEY }}
22+
23+
- name: Add server to known_hosts
24+
run: |
25+
ssh-keyscan -H jienote.top >> ~/.ssh/known_hosts
26+
27+
- name: Sync Code to Server
28+
run: |
29+
rsync -avz --delete \
30+
--exclude '.git' \
31+
--exclude '.github' \
32+
./ \
33+
${{ secrets.REMOTE_USER }}@${{ secrets.REMOTE_HOST }}:${{ secrets.REMOTE_PATH }}
34+
35+
- name: Build and Restart Docker on Server
36+
run: |
37+
ssh ${{ secrets.REMOTE_USER }}@${{ secrets.REMOTE_HOST }} << 'EOF'
38+
cd ${{ secrets.REMOTE_PATH }}
39+
cd ..
40+
docker-compose down
41+
docker-compose build
42+
docker-compose up -d
43+
EOF

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
env
2+
__pycache__
3+
articles
4+
app.log

README.md

Lines changed: 117 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,117 @@
1-
# JieNote_backend
2-
2025春季软件工程课程团队项目JieNote项目后端
1+
# JieNote Backend
2+
3+
This is the backend service for JieNote, built with FastAPI.
4+
5+
## Features
6+
- RESTful API endpoints
7+
- Modular structure for scalability
8+
9+
## File Structure
10+
- `app/`: Contains the main application code.
11+
- `main.py`: Entry point for the FastAPI application.
12+
- `models/`: Database models and schemas.
13+
- `core/`: Core configurations and settings.
14+
- include database settings
15+
- include JWT settings
16+
- include CORS settings
17+
- ……
18+
- `curd/`: CRUD operations for database interactions.
19+
- `db/`: Database connection and session management.
20+
- `schemas/`: Pydantic schemas for data validation.
21+
- `static/`: Static files (e.g., images, CSS).
22+
- `routers/`: API route definitions.
23+
- `tests/`: Contains test cases for the application.
24+
- `requirements.txt`: List of dependencies.
25+
- `README.md`: Documentation for the project.
26+
- `alembic/`: Database migration scripts and configurations.
27+
- `env/`: Virtual environment (not included in version control).
28+
- `img/`: Images used in the project.
29+
30+
## Setup
31+
1. Create a virtual environment: ✔
32+
```bash
33+
python -m venv env
34+
```
35+
2. Activate the virtual environment:
36+
- On Windows:
37+
```bash
38+
.\env\Scripts\activate
39+
```
40+
- On macOS/Linux:
41+
```bash
42+
source env/bin/activate
43+
```
44+
3. Install dependencies:
45+
```bash
46+
pip install -r requirements.txt
47+
```
48+
4. freeze requirements(do before commit !!!):
49+
```bash
50+
pip freeze > requirements.txt
51+
```
52+
53+
## Database Migration
54+
<!-- 数据库迁移使用alembic -->
55+
1. Install Alembic: ✔
56+
```bash
57+
pip install alembic
58+
```
59+
2. Initialize Alembic: ✔
60+
```bash
61+
alembic init alembic
62+
```
63+
3. Configure Alembic: ✔
64+
65+
1. Edit `alembic.ini` to set the database URL.
66+
2. Edit `alembic/env.py` to set up the target metadata.
67+
```python
68+
from app.models import Base # Import your models here
69+
target_metadata = Base.metadata
70+
```
71+
4. Create a migration script: need to modify the script
72+
```bash
73+
alembic revision --autogenerate -m "提交信息"
74+
```
75+
5. Apply the migration: need to modify the script
76+
```bash
77+
alembic upgrade head
78+
```
79+
80+
81+
## Run the Application
82+
```bash
83+
uvicorn app.main:app --reload
84+
```
85+
86+
## Redis
87+
- Redis is used for caching and session management.
88+
- Make sure to have Redis installed and running.
89+
90+
```bash
91+
cd path/to/redis
92+
# Start Redis server
93+
redis-server.exe redis.windows.conf
94+
```
95+
Attention!!!
96+
- Make sure the port is not occupied by other services.
97+
- If you want to use the default port, please modify the `redis.windows.conf` file.
98+
- Must connect Redis before running the application. ‼️‼️‼️
99+
100+
101+
## Token Authentication
102+
- JWT (JSON Web Token) is used for authentication.
103+
- Refresh tokens for 7 days and access tokens for 5min.
104+
105+
## Folder Structure
106+
- `app/`: Contains the main application code.
107+
- `tests/`: Contains test cases.
108+
- `env/`: Virtual environment (not included in version control).
109+
110+
## OCR
111+
- Must install Poppler
112+
113+
## ER Diagram
114+
![ER Diagram](img/er_diagram.jpg)
115+
116+
## License
117+
MIT License

alembic.ini

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
# A generic, single database configuration.
2+
3+
[alembic]
4+
# path to migration scripts
5+
# Use forward slashes (/) also on windows to provide an os agnostic path
6+
script_location = alembic
7+
8+
# template used to generate migration file names; The default value is %%(rev)s_%%(slug)s
9+
# Uncomment the line below if you want the files to be prepended with date and time
10+
# see https://alembic.sqlalchemy.org/en/latest/tutorial.html#editing-the-ini-file
11+
# for all available tokens
12+
# file_template = %%(year)d_%%(month).2d_%%(day).2d_%%(hour).2d%%(minute).2d-%%(rev)s_%%(slug)s
13+
14+
# sys.path path, will be prepended to sys.path if present.
15+
# defaults to the current working directory.
16+
prepend_sys_path = .
17+
18+
# timezone to use when rendering the date within the migration file
19+
# as well as the filename.
20+
# If specified, requires the python>=3.9 or backports.zoneinfo library and tzdata library.
21+
# Any required deps can installed by adding `alembic[tz]` to the pip requirements
22+
# string value is passed to ZoneInfo()
23+
# leave blank for localtime
24+
# timezone =
25+
26+
# max length of characters to apply to the "slug" field
27+
# truncate_slug_length = 40
28+
29+
# set to 'true' to run the environment during
30+
# the 'revision' command, regardless of autogenerate
31+
# revision_environment = false
32+
33+
# set to 'true' to allow .pyc and .pyo files without
34+
# a source .py file to be detected as revisions in the
35+
# versions/ directory
36+
# sourceless = false
37+
38+
# version location specification; This defaults
39+
# to alembic/versions. When using multiple version
40+
# directories, initial revisions must be specified with --version-path.
41+
# The path separator used here should be the separator specified by "version_path_separator" below.
42+
# version_locations = %(here)s/bar:%(here)s/bat:alembic/versions
43+
44+
# version path separator; As mentioned above, this is the character used to split
45+
# version_locations. The default within new alembic.ini files is "os", which uses os.pathsep.
46+
# If this key is omitted entirely, it falls back to the legacy behavior of splitting on spaces and/or commas.
47+
# Valid values for version_path_separator are:
48+
#
49+
# version_path_separator = :
50+
# version_path_separator = ;
51+
# version_path_separator = space
52+
# version_path_separator = newline
53+
#
54+
# Use os.pathsep. Default configuration used for new projects.
55+
version_path_separator = os
56+
57+
# set to 'true' to search source files recursively
58+
# in each "version_locations" directory
59+
# new in Alembic version 1.10
60+
# recursive_version_locations = false
61+
62+
# the output encoding used when revision files
63+
# are written from script.py.mako
64+
# output_encoding = utf-8
65+
66+
sqlalchemy.url = mysql+pymysql://root:[email protected]:3306/JieNote
67+
68+
69+
[post_write_hooks]
70+
# post_write_hooks defines scripts or Python functions that are run
71+
# on newly generated revision scripts. See the documentation for further
72+
# detail and examples
73+
74+
# format using "black" - use the console_scripts runner, against the "black" entrypoint
75+
# hooks = black
76+
# black.type = console_scripts
77+
# black.entrypoint = black
78+
# black.options = -l 79 REVISION_SCRIPT_FILENAME
79+
80+
# lint with attempts to fix using "ruff" - use the exec runner, execute a binary
81+
# hooks = ruff
82+
# ruff.type = exec
83+
# ruff.executable = %(here)s/.venv/bin/ruff
84+
# ruff.options = check --fix REVISION_SCRIPT_FILENAME
85+
86+
# Logging configuration
87+
[loggers]
88+
keys = root,sqlalchemy,alembic
89+
90+
[handlers]
91+
keys = console
92+
93+
[formatters]
94+
keys = generic
95+
96+
[logger_root]
97+
level = WARNING
98+
handlers = console
99+
qualname =
100+
101+
[logger_sqlalchemy]
102+
level = WARNING
103+
handlers =
104+
qualname = sqlalchemy.engine
105+
106+
[logger_alembic]
107+
level = INFO
108+
handlers =
109+
qualname = alembic
110+
111+
[handler_console]
112+
class = StreamHandler
113+
args = (sys.stderr,)
114+
level = NOTSET
115+
formatter = generic
116+
117+
[formatter_generic]
118+
format = %(levelname)-5.5s [%(name)s] %(message)s
119+
datefmt = %H:%M:%S

alembic/README

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Generic single-database configuration.

0 commit comments

Comments
 (0)