Skip to content

Commit a6ca394

Browse files
author
Rohul Amin
committed
HW-Amin
1 parent af17f2d commit a6ca394

File tree

113 files changed

+2956
-0
lines changed

Some content is hidden

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

113 files changed

+2956
-0
lines changed

fastapi-react-project/.prettierignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
docker-compose.yml

fastapi-react-project/README.md

+159
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
# y
2+
3+
## Features
4+
5+
- **FastAPI** with Python 3.8
6+
- **React 16** with Typescript, Redux, and react-router
7+
- Postgres
8+
- SqlAlchemy with Alembic for migrations
9+
- Pytest for backend tests
10+
- Jest for frontend tests
11+
- Perttier/Eslint (with Airbnb style guide)
12+
- Docker compose for easier development
13+
- Nginx as a reverse proxy to allow backend and frontend on the same port
14+
15+
## Development
16+
17+
The only dependencies for this project should be docker and docker-compose.
18+
19+
### Quick Start
20+
21+
Starting the project with hot-reloading enabled
22+
(the first time it will take a while):
23+
24+
```bash
25+
docker-compose up -d
26+
```
27+
28+
To run the alembic migrations (for the users table):
29+
30+
```bash
31+
docker-compose run --rm backend alembic upgrade head
32+
```
33+
34+
And navigate to http://localhost:8000
35+
36+
_Note: If you see an Nginx error at first with a `502: Bad Gateway` page, you may have to wait for webpack to build the development server (the nginx container builds much more quickly)._
37+
38+
Auto-generated docs will be at
39+
http://localhost:8000/api/docs
40+
41+
### Rebuilding containers:
42+
43+
```
44+
docker-compose build
45+
```
46+
47+
### Restarting containers:
48+
49+
```
50+
docker-compose restart
51+
```
52+
53+
### Bringing containers down:
54+
55+
```
56+
docker-compose down
57+
```
58+
59+
### Frontend Development
60+
61+
Alternatively to running inside docker, it can sometimes be easier
62+
to use npm directly for quicker reloading. To run using npm:
63+
64+
```
65+
cd frontend
66+
npm install
67+
npm start
68+
```
69+
70+
This should redirect you to http://localhost:3000
71+
72+
### Frontend Tests
73+
74+
```
75+
cd frontend
76+
npm install
77+
npm test
78+
```
79+
80+
## Migrations
81+
82+
Migrations are run using alembic. To run all migrations:
83+
84+
```
85+
docker-compose run --rm backend alembic upgrade head
86+
```
87+
88+
To create a new migration:
89+
90+
```
91+
alembic revision -m "create users table"
92+
```
93+
94+
And fill in `upgrade` and `downgrade` methods. For more information see
95+
[Alembic's official documentation](https://alembic.sqlalchemy.org/en/latest/tutorial.html#create-a-migration-script).
96+
97+
## Testing
98+
99+
There is a helper script for both frontend and backend tests:
100+
101+
```
102+
./scripts/test.sh
103+
```
104+
105+
### Backend Tests
106+
107+
```
108+
docker-compose run backend pytest
109+
```
110+
111+
any arguments to pytest can also be passed after this command
112+
113+
### Frontend Tests
114+
115+
```
116+
docker-compose run frontend test
117+
```
118+
119+
This is the same as running npm test from within the frontend directory
120+
121+
## Logging
122+
123+
```
124+
docker-compose logs
125+
```
126+
127+
Or for a specific service:
128+
129+
```
130+
docker-compose logs -f name_of_service # frontend|backend|db
131+
```
132+
133+
## Project Layout
134+
135+
```
136+
backend
137+
└── app
138+
├── alembic
139+
│ └── versions # where migrations are located
140+
├── api
141+
│ └── api_v1
142+
│ └── endpoints
143+
├── core # config
144+
├── db # db models
145+
├── tests # pytest
146+
└── main.py # entrypoint to backend
147+
148+
frontend
149+
└── public
150+
└── src
151+
├── components
152+
│ └── Home.tsx
153+
├── config
154+
│ └── index.tsx # constants
155+
├── __tests__
156+
│ └── test_home.tsx
157+
├── index.tsx # entrypoint
158+
└── App.tsx # handles routing
159+
```
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
FROM python:3.8
3+
4+
RUN mkdir /app
5+
WORKDIR /app
6+
7+
RUN apt update && \
8+
apt install -y postgresql-client
9+
10+
COPY requirements.txt ./
11+
RUN pip install --no-cache-dir -r requirements.txt
12+
13+
COPY . .
+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# A generic, single database configuration.
2+
3+
[alembic]
4+
# path to migration scripts
5+
script_location = app/alembic
6+
7+
# template used to generate migration files
8+
# file_template = %%(rev)s_%%(slug)s
9+
10+
# timezone to use when rendering the date
11+
# within the migration file as well as the filename.
12+
# string value is passed to dateutil.tz.gettz()
13+
# leave blank for localtime
14+
timezone = America/Los_Angeles
15+
16+
# max length of characters to apply to the
17+
# "slug" field
18+
# truncate_slug_length = 40
19+
20+
# set to 'true' to run the environment during
21+
# the 'revision' command, regardless of autogenerate
22+
# revision_environment = false
23+
24+
# set to 'true' to allow .pyc and .pyo files without
25+
# a source .py file to be detected as revisions in the
26+
# versions/ directory
27+
# sourceless = false
28+
29+
# version location specification; this defaults
30+
# to alembic/versions. When using multiple version
31+
# directories, initial revisions must be specified with --version-path
32+
# version_locations = %(here)s/bar %(here)s/bat alembic/versions
33+
34+
# the output encoding used when revision files
35+
# are written from script.py.mako
36+
# output_encoding = utf-8
37+
38+
[post_write_hooks]
39+
# post_write_hooks defines scripts or Python functions that are run
40+
# on newly generated revision scripts. See the documentation for further
41+
# detail and examples
42+
43+
# format using "black" - use the console_scripts runner, against the "black" entrypoint
44+
# hooks=black
45+
# black.type=console_scripts
46+
# black.entrypoint=black
47+
# black.options=-l 79
48+
49+
# Logging configuration
50+
[loggers]
51+
keys = root,sqlalchemy,alembic
52+
53+
[handlers]
54+
keys = console
55+
56+
[formatters]
57+
keys = generic
58+
59+
[logger_root]
60+
level = WARN
61+
handlers = console
62+
qualname =
63+
64+
[logger_sqlalchemy]
65+
level = WARN
66+
handlers =
67+
qualname = sqlalchemy.engine
68+
69+
[logger_alembic]
70+
level = INFO
71+
handlers =
72+
qualname = alembic
73+
74+
[handler_console]
75+
class = StreamHandler
76+
args = (sys.stderr,)
77+
level = NOTSET
78+
formatter = generic
79+
80+
[formatter_generic]
81+
format = %(levelname)-5.5s [%(name)s] %(message)s
82+
datefmt = %H:%M:%S

fastapi-react-project/backend/app/__init__.py

Whitespace-only changes.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# A generic, single database configuration.
2+
3+
[alembic]
4+
# path to migration scripts
5+
script_location = alembic
6+
7+
# template used to generate migration files
8+
# file_template = %%(rev)s_%%(slug)s
9+
10+
# timezone to use when rendering the date
11+
# within the migration file as well as the filename.
12+
# string value is passed to dateutil.tz.gettz()
13+
# leave blank for localtime
14+
# timezone =
15+
16+
# max length of characters to apply to the
17+
# "slug" field
18+
# truncate_slug_length = 40
19+
20+
# set to 'true' to run the environment during
21+
# the 'revision' command, regardless of autogenerate
22+
# revision_environment = false
23+
24+
# set to 'true' to allow .pyc and .pyo files without
25+
# a source .py file to be detected as revisions in the
26+
# versions/ directory
27+
# sourceless = false
28+
29+
# version location specification; this defaults
30+
# to alembic/versions. When using multiple version
31+
# directories, initial revisions must be specified with --version-path
32+
# version_locations = %(here)s/bar %(here)s/bat alembic/versions
33+
34+
# the output encoding used when revision files
35+
# are written from script.py.mako
36+
# output_encoding = utf-8
37+
38+
sqlalchemy.url = driver://user:pass@localhost/dbname
39+
40+
41+
[post_write_hooks]
42+
# post_write_hooks defines scripts or Python functions that are run
43+
# on newly generated revision scripts. See the documentation for further
44+
# detail and examples
45+
46+
# format using "black" - use the console_scripts runner, against the "black" entrypoint
47+
# hooks=black
48+
# black.type=console_scripts
49+
# black.entrypoint=black
50+
# black.options=-l 79
51+
52+
# Logging configuration
53+
[loggers]
54+
keys = root,sqlalchemy,alembic
55+
56+
[handlers]
57+
keys = console
58+
59+
[formatters]
60+
keys = generic
61+
62+
[logger_root]
63+
level = WARN
64+
handlers = console
65+
qualname =
66+
67+
[logger_sqlalchemy]
68+
level = WARN
69+
handlers =
70+
qualname = sqlalchemy.engine
71+
72+
[logger_alembic]
73+
level = INFO
74+
handlers =
75+
qualname = alembic
76+
77+
[handler_console]
78+
class = StreamHandler
79+
args = (sys.stderr,)
80+
level = NOTSET
81+
formatter = generic
82+
83+
[formatter_generic]
84+
format = %(levelname)-5.5s [%(name)s] %(message)s
85+
datefmt = %H:%M:%S
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Generic single-database configuration.

fastapi-react-project/backend/app/alembic/__init__.py

Whitespace-only changes.
Binary file not shown.

0 commit comments

Comments
 (0)