Skip to content

Commit 45197bc

Browse files
committed
Initial commit
0 parents  commit 45197bc

20 files changed

Lines changed: 760 additions & 0 deletions

.gitignore

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
6+
# Virtual environment
7+
.venv/
8+
venv/
9+
env/
10+
11+
# Distribution / packaging
12+
build/
13+
dist/
14+
*.egg-info/
15+
.eggs/
16+
17+
# Installer logs
18+
pip-log.txt
19+
pip-delete-this-directory.txt
20+
21+
# Test / coverage
22+
.pytest_cache/
23+
.coverage
24+
coverage.xml
25+
htmlcov/
26+
27+
# Type checkers
28+
.mypy_cache/
29+
.pyre/
30+
.pytype/
31+
32+
# IDE / editors
33+
.vscode/
34+
.idea/
35+
*.swp
36+
*.swo
37+
38+
# Environment variables
39+
.env
40+
.env.*
41+
!.env.example
42+
43+
# OS files
44+
.DS_Store
45+
Thumbs.db
46+
47+
# Logs
48+
*.log
49+
50+
# SQLite (tests / local)
51+
*.db
52+
*.sqlite3
53+
54+
# Alembic (keep migrations, ignore cache)
55+
alembic/__pycache__/
56+
57+
# Docker (optional, if you use later)
58+
docker-compose.override.yml
59+
60+
# Misc
61+
*.bak
62+
*.tmp

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2026 Luiz K. Monteiro
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
# Order Management System API
2+
3+
A simple, modular FastAPI application for managing orders.
4+
Built as a **modular monolith** with clean separation of concerns, PostgreSQL for persistence,
5+
Alembic for migrations, and SQLite for fast unit tests.
6+
7+
## 📁 Project Structure
8+
9+
```
10+
.
11+
├── app/
12+
│ ├── main.py
13+
│ ├── api/
14+
│ │ └── router.py
15+
│ ├── core/
16+
│ ├── db/
17+
│ │ └── session.py
18+
│ └── modules/
19+
│ └── orders/
20+
│ ├── models.py
21+
│ ├── schemas.py
22+
│ ├── repository.py
23+
│ ├── service.py
24+
│ └── routes.py
25+
26+
├── alembic/
27+
├── tests/
28+
│ └── unit/
29+
├── pyproject.toml
30+
└── README.md
31+
```
32+
33+
## 🐍 Python Virtual Environment (venv)
34+
35+
It’s recommended to use a virtual environment to isolate dependencies.
36+
37+
### Create venv
38+
39+
```bash
40+
python -m venv .venv
41+
```
42+
43+
### Activate
44+
45+
**Linux / macOS**
46+
47+
```bash
48+
source .venv/bin/activate
49+
```
50+
51+
**Windows (PowerShell)**
52+
53+
```powershell
54+
.venv\Scripts\Activate.ps1
55+
```
56+
57+
### Install dependencies
58+
59+
```bash
60+
pip install --upgrade pip
61+
pip install -e .[dev]
62+
```
63+
64+
## 🐘 Running PostgreSQL (Docker)
65+
66+
Start a local PostgreSQL instance:
67+
68+
```bash
69+
docker run -d \
70+
--name postgres-dev \
71+
-e POSTGRES_USER=postgres \
72+
-e POSTGRES_PASSWORD=postgres \
73+
-e POSTGRES_DB=app \
74+
-p 5432:5432 \
75+
postgres:15
76+
```
77+
78+
## ⚙️ Environment Variables
79+
80+
Set your database connection:
81+
82+
```bash
83+
export DATABASE_URL=postgresql://postgres:postgres@localhost:5432/app
84+
```
85+
86+
## 🗄️ Database Migrations (Alembic)
87+
88+
Create migration:
89+
90+
```bash
91+
python -m alembic revision --autogenerate -m "init"
92+
```
93+
94+
Apply migrations:
95+
96+
```bash
97+
python -m alembic upgrade head
98+
```
99+
100+
## ▶️ Run the API
101+
102+
```bash
103+
uvicorn app.main:app --reload
104+
```
105+
106+
API will be available at:
107+
108+
```
109+
http://localhost:8000
110+
```
111+
112+
Interactive docs:
113+
114+
```
115+
http://localhost:8000/docs
116+
```
117+
118+
## 🧪 Running Tests
119+
120+
Tests use **SQLite in-memory**, so no database setup is required.
121+
122+
```bash
123+
pytest
124+
```
125+
126+
## 🔌 Example API Usage
127+
128+
### Create Order
129+
130+
```bash
131+
curl -X POST http://localhost:8000/orders/ \
132+
-H "Content-Type: application/json" \
133+
-d '{"item": "laptop"}'
134+
```
135+
136+
### Get Order
137+
138+
```bash
139+
curl http://localhost:8000/orders/1
140+
```
141+
142+
### List Orders
143+
144+
```bash
145+
curl http://localhost:8000/orders/
146+
```
147+
148+
## 🧠 Architecture
149+
150+
This project uses a **feature-based modular structure**:
151+
152+
* `modules/orders` contains everything related to orders
153+
* `repository.py` → database access
154+
* `service.py` → business logic
155+
* `routes.py` → API layer
156+
157+
This keeps the codebase:
158+
159+
* easy to navigate
160+
* easy to extend
161+
* ready to evolve into microservices if needed
162+
163+
## ⚠️ Notes
164+
165+
* Tests use SQLite (`:memory:`) with `StaticPool`
166+
* Alembic requires models to be imported in `env.py`
167+
* No need to install the package globally
168+
169+
## 📌 Future Improvements
170+
171+
* Order state transitions (finite state machine)
172+
* Update / delete endpoints
173+
* Authentication & authorization
174+
* Integration tests with PostgreSQL
175+
* Docker support for full deployment

0 commit comments

Comments
 (0)